WM_PAINT란, Windows Massage Event 중에 Paint(다시 그림을 그리는 이벤트)가 발생할 경우. 해당 값을 출력하는 이벤트이다.
WIndows 10에서는 문제 없이 작동이 되는걸 확인 되었다.
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 | #include <stdlib.h> #include <tchar.h> #include <windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); HINSTANCE g_hInst; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { HWND hWnd; MSG Message; WNDCLASS WndClass; g_hInst = hInstance; //윈도우 클래스 초기화 WndClass.cbClsExtra=0; WndClass.cbWndExtra=0; WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=(WNDPROC)WndProc; WndClass.lpszClassName="ApiBase"; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; //윈도우 클래스 생성. RegisterClass(&WndClass); //윈도우 객체 생성. hWnd = CreateWindow("ApiBase", "Test", WS_OVERLAPPEDWINDOW, 10,// X 100,// Y 400,// Width 400,// Height NULL, (HMENU)NULL, hInstance, NULL); //윈도우 창 띄우기. ShowWindow(hWnd,nCmdShow); while(GetMessage(&Message,0,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; } LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; long dwStyle; switch(iMessage) { case WM_DESTROY: PostQuitMessage(0); break; case WM_LBUTTONDOWN: hdc = GetDC(hWnd); TextOut(hdc, 100, 50, "Hello World",11); ReleaseDC(hWnd, hdc); break; case WM_PAINT: break; } return DefWindowProc(hWnd,iMessage,wParam, lParam); } | cs |
이렇게 사용해도 상관 없으며,
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 | #include <stdlib.h> #include <tchar.h> #include <windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); HINSTANCE g_hInst; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { HWND hWnd; MSG Message; WNDCLASS WndClass; g_hInst = hInstance; //윈도우 클래스 초기화 WndClass.cbClsExtra=0; WndClass.cbWndExtra=0; WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=(WNDPROC)WndProc; WndClass.lpszClassName="ApiBase"; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; //윈도우 클래스 생성. RegisterClass(&WndClass); //윈도우 객체 생성. hWnd = CreateWindow("ApiBase", "Test", WS_OVERLAPPEDWINDOW, 10,// X 100,// Y 400,// Width 400,// Height NULL, (HMENU)NULL, hInstance, NULL); //윈도우 창 띄우기. ShowWindow(hWnd,nCmdShow); while(GetMessage(&Message,0,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; } LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; long dwStyle; switch(iMessage) { case WM_DESTROY: PostQuitMessage(0); break; case WM_LBUTTONDOWN: break; case WM_PAINT: hdc = GetDC(hWnd); TextOut(hdc, 100, 50, "Hello World",11); ReleaseDC(hWnd, hdc); break; } return DefWindowProc(hWnd,iMessage,wParam, lParam); } | cs |
이렇게 해도 된다.
'연습' 카테고리의 다른 글
Windows API 프로그래밍 -9. 점 출력. - (0) | 2016.06.25 |
---|---|
Windows API 프로그래밍 -8. 텍스트 출력. - (0) | 2016.06.24 |
Windows API 프로그래밍 -6. GDI와 DC에 대한 설명. - (0) | 2016.06.22 |
Windows API 프로그래밍 -5. 윈도우 배경색 처리. - (0) | 2016.06.21 |
Windows API 프로그래밍 -4. 윈도우 타이틀 처리. - (0) | 2016.06.20 |