190703-1
교육을 받으면서 노트필기 했던 내용을 날것 그대로 업로드합니다.
WS_CHILD : 부모 내에서만 동작
WS_OVERLAPPEDWINDOW : 겹쳐지는 윈도우
hwndChild = CreateWindow(_T("ChildWindow"),
_T("Child Window !!"),
WS_OVERLAPPEDWINDOW|WS_CHILD,
100,
100,
300,
300,
hwndParent,
(HMENU)NULL, //저번 코드 수정 NULL로 주어야 한다.
g_hInst,
NULL
);
__declspec(thread) static int count = 0;
#include <windows.h>
#include <TCHAR.H>
DWORD __stdcall DrawThread(LPVOID pParam);
DWORD __stdcall UIThread(LPVOID pParam);
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK ChildProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam);
HINSTANCE g_hInst;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
g_hInst = hInstance;
HWND hwnd;
MSG msg;
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = _T("Window Class Name");
RegisterClass(&WndClass);
WndClass.lpfnWndProc = ChildProc;
WndClass.lpszClassName = _T("ChildWindow");
RegisterClass(&WndClass);
hwnd = CreateWindow(_T("Window Class Name"),
_T("Window Title Name"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
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 iMsg,
WPARAM wParam, LPARAM lParam)
{
static HANDLE hThread;
static DWORD threadID;
switch (iMsg)
{
case WM_CREATE:
hThread = CreateThread(NULL, 0, DrawThread, hwnd, 0, &threadID);
break;
case WM_LBUTTONDOWN:
CloseHandle(CreateThread(NULL, 0, UIThread, hwnd, 0, &threadID));
break;
case WM_DESTROY:
PostQuitMessage(0);
CloseHandle(hThread);
break;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
DWORD __stdcall DrawThread(LPVOID pParam) { // Worker 쓰레드 라고한다.
HWND hwnd = (HWND)pParam;
HDC hdc = GetDC(hwnd);
for (int i = 0; i < 100; i++)
{
Rectangle(hdc, 100 + i, 100, 200 + i, 200);
Sleep(20);
}
ReleaseDC(hwnd, hdc);
return 0;
}
LRESULT CALLBACK ChildProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
__declspec(thread) static int count = 0;
TCHAR buf[100];
HDC hdc;
switch (iMsg)
{
case WM_CREATE:
SetTimer(hwnd, 10, 500, NULL);
break;
case WM_TIMER:
wsprintf(buf, "count:%d", ++count);
SetWindowText(hwnd, buf);
break;
case WM_LBUTTONDOWN:
hdc = GetDC(hwnd);
Rectangle(hdc, LOWORD(lParam), HIWORD(lParam), LOWORD(lParam) + 50, HIWORD(lParam) + 50);
ReleaseDC(hwnd, hdc);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
DWORD __stdcall UIThread(LPVOID pParam) { // UI 쓰레드 라고 한다.
HWND hwndParent=(HWND)pParam;
HWND hwndChild;
MSG msg;
hwndChild = CreateWindow(_T("ChildWindow"),
_T("Child Window !!"),
WS_OVERLAPPEDWINDOW| WS_POPUPWINDOW |WS_CHILD,
100,
100,
300,
300,
hwndParent,
(HMENU)NULL,
g_hInst,
NULL
);
ShowWindow(hwndChild, SW_SHOW);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
return 0;
}
'System Programming' 카테고리의 다른 글
[system programming] 플래그, 자원 관리 클래스 (0) | 2019.07.05 |
---|---|
[system programming] 유저, 커널모드 동기화 (크리티컬 섹션, 뮤텍스, 세마포어, 이벤트 등) (0) | 2019.07.05 |
[system programming] 핸들, 커널 오브젝트, 프로세스 등 (0) | 2019.07.04 |
[system programming] WS_CHILD, SuspendThread, ResumeThread 등 (0) | 2019.07.04 |
[system programming] TLS, ResumeThread, nterlockedIncrement 등 (0) | 2019.07.04 |