1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <windows.h>
#define WINDOW_POS_X 0
#define WINDOW_POS_Y 0
#define CLIENT_SIZE_X 400
#define CLIENT_SIZE_Y 300
LRESULT CALLBACK WindowProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp ) {
switch( msg ) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hwnd, &ps );
MoveToEx( hdc, 0, 0, NULL );
LineTo( hdc, CLIENT_SIZE_X, CLIENT_SIZE_Y );
EndPaint( hwnd, &ps );
break;
}
case WM_MOUSEMOVE: {
HDC hdc = GetDC( hwnd );
SetPixelV( hdc, LOWORD( lp ), HIWORD( lp ), RGB( 0, 0, 0 ));
ReleaseDC( hwnd, hdc );
break;
}
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, msg, wp, lp );
}
return 0;
}
void registerWindow( HINSTANCE hinst, char *className,
WNDPROC wndproc, HBRUSH hbr, BOOL dblClicks ) {
WNDCLASSEX wc = { sizeof( wc )}; // set first member, zero the rest
wc.style = CS_HREDRAW | CS_VREDRAW | (dblClicks?CS_DBLCLKS:0);
wc.hInstance = hinst;
wc.lpszClassName = className;
wc.lpfnWndProc = wndproc;
wc.hbrBackground = hbr;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
if( !RegisterClassEx( &wc )) {
MessageBox( 0, "RegisterClassEx failed", 0, 0 );
exit( 1 );
}
}
HWND createWindow( DWORD exStyle,
char* className, char* windowName,
DWORD style,
int x, int y, int clientWidth, int clientHeight,
HWND hwndParent, HMENU hMenu, HINSTANCE hInst ) {
RECT r = { 0, 0, clientWidth, clientHeight };
AdjustWindowRect( &r, style, hMenu?TRUE:FALSE );
HWND hwnd = CreateWindowEx( exStyle,
className, windowName, style | WS_VISIBLE,
x, y, r.right - r.left, r.bottom - r.top,
hwndParent, hMenu, hInst, NULL );
if( !hwnd ) {
MessageBox( 0, "CreateWindowEx failed", 0, 0 );
exit( 1 );
}
return hwnd;
}
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE unused,
PSTR cmd, int show) {
char *appName = "App";
MSG msg;
registerWindow( hInst, appName, WindowProc,
(HBRUSH) GetStockObject( WHITE_BRUSH ), FALSE );
createWindow(
0
// | WS_EX_COMPOSITED
// | WS_EX_LAYERED
,
appName, appName,
WS_OVERLAPPEDWINDOW,
WINDOW_POS_X, WINDOW_POS_Y, CLIENT_SIZE_X, CLIENT_SIZE_Y,
HWND_DESKTOP, NULL, hInst );
while( GetMessage( &msg, NULL, 0, 0 )) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
|