Code:
#include <windows.h>
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpArgz, int nCmdShow){
HWND hwnd;
MSG msg;
WNDCLASSEX WinClass;
HDC hdc;
WinClass.lpszMenuName = NULL;
WinClass.lpszClassName = "WinClass1";
WinClass.cbSize = sizeof(WinClass);
WinClass.cbClsExtra = 0;
WinClass.cbWndExtra = 0;
/////////////////////////
WinClass.hInstance = hInstance;
WinClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
WinClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WinClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
WinClass.hCursor = LoadCursor(NULL, IDC_ARROW);
///////////////////////////
WinClass.style = CS_OWNDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
WinClass.lpfnWndProc = WinProc;
RegisterClassEx(&WinClass);
if(!(hwnd = CreateWindowEx((DWORD) NULL,
"WinClass1",
"Window Title",
WS_VISIBLE | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL,
hInstance,
NULL))){ return 0; }
RECT rect;
hdc = GetDC(hwnd);
static int ax=0;
GetClientRect(hwnd, &rect);
while(TRUE){
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if(msg.message == WM_QUIT){
break;
}
}
TranslateMessage(&msg);
DispatchMessage(&msg);
while(ax<=200000){
SetPixel(hdc, rand()%rect.right, rand()%rect.bottom, RGB(rand()%255, rand()%255, rand()%255));
ax++;
}
}
ReleaseDC(hwnd, hdc);
return 0;
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
DeleteObject(hPen);
GetClientRect(hwnd, &rect);
switch(msg){
case WM_PAINT:
GetClientRect(hwnd, &rect);
InvalidateRect(hwnd, &rect, FALSE);
if(wParam==1){
InvalidateRect(hwnd, &rect, TRUE);
wParam = 0;
}
hdc = BeginPaint(hwnd, &ps);
SetBkColor(hdc, RGB(255, 255, 255));
SetTextColor(hdc, RGB(0, 0, 0));
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 0, 0, "Hello", strlen("Hello"));
EndPaint(hwnd, &ps);
return 0;
break;
case WM_CREATE:
return 0;
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
break;
case WM_MOUSEMOVE:
{
int x_ = LOWORD(lParam), y_ = HIWORD(lParam);
int stat = (int) wParam;
if(stat & MK_LBUTTON){
hdc = GetDC(hwnd);
TextOut(hdc, x_, y_, "O", 1);
ReleaseDC(hwnd, hdc);
}
}break;
case WM_LBUTTONDOWN:
{
int x_ = LOWORD(lParam), y_ = HIWORD(lParam);
int stat = (int) wParam;
if(stat & MK_LBUTTON){
hdc = GetDC(hwnd);
TextOut(hdc, x_, y_, "O", 1);
SendMessage(hwnd, WM_PAINT, 0, 0);
ReleaseDC(hwnd, hdc);
}
}break;
case WM_RBUTTONDOWN:
SendMessage(hwnd, WM_USER, 0, 0);
break;
case WM_USER:
InvalidateRect(hwnd, &rect, TRUE);
SendMessage(hwnd, WM_PAINT, 1, 0);
break;
default: break;
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}