The previous thread might be a bit offtopic for these questions so creating a new one was more appropriate.
This is a basic program I did, in an effort to understand how win32 works. It is supposed to draw a 32x32 box, using a custom function called drawpixel. Additionally when the right mouse button is clicked it is meant to draw a single pixel at 700, 600. But none of the two works as expected. The drawpixel function only draws a 32pixel-long line and the right-click drawing case doesn't work at all. Any ideas?
(This was also posted in neogaf.com, but didn't get an answer.)
C
#include <Windows.h>
#include <tchar.h>
HDC hdc;
int drawpixel (int x, int y){
int y2=y+32;
int x2=x+32;
for (y; y<y2; )
{
for (x; x<x2; x++)
{
SetPixelV(hdc, x, y, RGB(100,0,0));}
y=y++;
}
return 0;}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
drawpixel(32, 32);
return 0;
EndPaint(hwnd, &ps);
return 0;
case WM_RBUTTONDOWN:
SetPixelV(hdc, 700, 600, RGB(1,0,0));
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, message, wparam, lparam);}
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX cx;
cx.cbSize = sizeof(WNDCLASSEX);
cx.style = CS_HREDRAW | CS_VREDRAW;
cx.lpfnWndProc = WndProc;
cx.cbClsExtra = 0;
cx.cbWndExtra = 0;
cx.hInstance = hInstance;
cx.hIcon = NULL;
cx.hCursor = LoadCursor(NULL, IDC_ARROW);
cx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
cx.lpszMenuName = NULL;
cx.lpszClassName = _T("wcn");
cx.hIconSm = NULL;
RegisterClassEx(&cx);
HWND hWnd = CreateWindow( _T("wcn"), _T("t"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
Display More