Created
October 23, 2013 07:30
-
-
Save anonymous/7114034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* to compile: cl.exe scribble.c /link /SUBSYSTEM:WINDOWS user32.lib gdi32.lib */ | |
#define WIN32_LEAN_AND_MEAN | |
#define VC_EXTRALEAN | |
#include <windows.h> | |
#include <tchar.h> | |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); | |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) | |
{ | |
static TCHAR szWindowClass[] = _T("Scribble"); | |
static TCHAR szTitle[] = _T("Scribble"); | |
MSG msg; | |
HWND hWnd; | |
WNDCLASSEX wcex; | |
wcex.cbSize = sizeof(WNDCLASSEX); | |
wcex.style = CS_HREDRAW | CS_VREDRAW; | |
wcex.lpfnWndProc = WndProc; | |
wcex.cbClsExtra = 0; | |
wcex.cbWndExtra = 0; | |
wcex.hInstance = hInstance; | |
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); | |
wcex.hCursor = LoadCursor(NULL, IDC_CROSS); | |
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |
wcex.lpszMenuName = NULL; | |
wcex.lpszClassName = szWindowClass; | |
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); | |
RegisterClassEx(&wcex); | |
hWnd = CreateWindow( | |
szWindowClass, | |
szTitle, | |
WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, | |
CW_USEDEFAULT, CW_USEDEFAULT, | |
NULL, | |
NULL, | |
hInstance, | |
NULL | |
); | |
ShowWindow(hWnd, iCmdShow); | |
UpdateWindow(hWnd); | |
while (GetMessage(&msg, NULL, 0, 0)) | |
{ | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
return (int)msg.wParam; | |
} | |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
{ | |
static int x1, y1, x2, y2; | |
HDC hdc; | |
switch (message) | |
{ | |
case WM_LBUTTONDOWN: | |
InvalidateRect(hWnd, NULL, FALSE); | |
x1 = LOWORD(lParam); | |
y1 = HIWORD(lParam); | |
return 0; | |
case WM_RBUTTONDOWN: | |
InvalidateRect(hWnd, NULL, TRUE); | |
return 0; | |
case WM_MOUSEMOVE: | |
if (wParam & MK_LBUTTON) | |
{ | |
hdc = GetDC(hWnd); | |
x2 = LOWORD(lParam); | |
y2 = HIWORD(lParam); | |
MoveToEx(hdc, x1, y1, NULL); | |
LineTo(hdc, x2, y2); | |
ReleaseDC(hWnd, hdc); | |
x1 = x2; | |
y1 = y2; | |
} | |
return 0; | |
case WM_LBUTTONUP: | |
InvalidateRect(hWnd, NULL, FALSE); | |
return 0; | |
case WM_CLOSE: | |
DestroyWindow(hWnd); | |
return 0; | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
return 0; | |
} | |
return DefWindowProc(hWnd, message, wParam, lParam); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment