Code:
#include <windows.h>
#include "resource1.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hWnd;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
TCHAR szAppName[] = TEXT("Default window"); // Header
MSG msg;
WNDCLASSEX wc;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); // Ico
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); // Ico_sm
wc.hCursor = (HCURSOR)LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR));
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+0); // Background
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
RegisterClassEx(&wc);
hWnd = CreateWindowEx(0,szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, // Margin from left
CW_USEDEFAULT, // Margin from top
CW_USEDEFAULT, // Widht
CW_USEDEFAULT, // Height
NULL,
NULL,
hInstance,NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void OnWM_MOUSEMOVE(WPARAM wParam, LPARAM lParam)
{
POINTS ptCursor;
TCHAR chText[30];
ptCursor = MAKEPOINTS(lParam);
_stprintf(chText, "x=%d, y=%d", ptCursor.x, ptCursor.y);
SetWindowText(hWnd, chText);
}
void Draw(HWND hWnd)
{
HDC hDC;
hDC = GetDC(hWnd);
DrawIcon(hDC, 50, 50,
(HICON)(WORD)GetClassLong(hWnd, GCL_HICON));
ReleaseDC(hWnd, hDC);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
Draw(hWnd);
break;
case WM_MOUSEMOVE:
OnWM_MOUSEMOVE(wParam, lParam);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}