#include<Windows.h>
int sx, sy, oldx, oldy;
BOOL bNowDraw;
HINSTANCE g_hInst;
LPCTSTR MyClassName = TEXT("FistClass");
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
WNDCLASS wndclass{};
HWND hWnd{};
MSG msg{};
g_hInst = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = MyClassName;
wndclass.hInstance = hInstance;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.cbWndExtra = 0;
wndclass.cbClsExtra = 0;
wndclass.lpszMenuName = NULL;
wndclass.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(255, 255, 255));
wndclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
hWnd = CreateWindowExW(NULL, MyClassName, MyClassName,WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return((int)msg.wParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
HDC hdc{};
bNowDraw = FALSE;
switch (iMessage){
case WM_LBUTTONDOWN:
sx = lParam & 0x0000FFFF;
sy = (lParam>>16) & 0x0000FFFF;
oldx = sx;
oldy = sy;
bNowDraw = TRUE;
return(0);
case WM_MOUSEMOVE:
if (bNowDraw == TRUE) {
hdc = GetDC(hWnd);
SetROP2(hdc, R2_NOT);
MoveToEx(hdc, sx, sy, NULL);
LineTo(hdc, oldx, oldy);
oldx = lParam & 0x0000FFFF;
oldy = (lParam >> 16) & 0x0000FFFF;
MoveToEx(hdc, sx, sy, NULL);
LineTo(hdc, oldx, oldy);
ReleaseDC(hWnd, hdc);
}
return(0);
case WM_LBUTTONUP:
bNowDraw = FALSE;
hdc = GetDC(hWnd);
MoveToEx(hdc, sx, sy, NULL);
LineTo(hdc, oldx, oldy);
return(0);
case WM_DESTROY:
PostQuitMessage(0);
return(0);
}
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
--------------------------------------------------------------------------------------------------------------------------------------
Àü¿ªº¯¼ö·Î ÁöÁ¤µÈ BOOL bNowDraw »ó¿¡ FALSE¸¦ ´ëÀÔ½ÃŰÁö ¾Ê°í WndProcÇÔ¼ö¾È¿¡¼ bNowDraw¸¦ FALSE·Î Á¤ÀÇÇϸé
±×¸®±â°¡ ¾È µÇ´Âµ¥ ÀÌÀ¯¸¦ ¾Ë°í½Í½À´Ï´Ù. ¶ÇÇÑ Ã¥ ¿¹Á¦¿¡ WM_LBUTTONUP ³»¿¡ MoveToEx¿Í LineTo°¡ ¾ø¾îµµ Á¦´ë·Î ÀÛµ¿µÇ´Âµ¥ ÇØ´ç ºÎºÐÀº ¿ÀŸÀÎÁö ±Ã±ÝÇÕ´Ï´Ù. ´äº¯ ºÎʵ右´Ï´Ù.

±è¹Î¼ö
403 Forbidden403 Forbidden |
|