子ウィンドウの作成方法
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
ATOM InitApp(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
TCHAR szClassName[] = TEXT("Window01");
TCHAR szClassName2[] = TEXT("Window02");
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,LPSTR lpsCmdLine, int nCmdShow){
MSG msg;
BOOL bRet;
if (!InitApp(hCurInst))
return FALSE;
if (!InitInstance(hCurInst, nCmdShow))
return FALSE;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
if (bRet == -1) {
break;
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
ATOM InitApp(HINSTANCE hInst)
{
WNDCLASSEX wc;
WNDCLASSEX wc2;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc.hCursor = (HCURSOR)LoadImage(
NULL, MAKEINTRESOURCE(IDC_ARROW),
IMAGE_CURSOR, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc.hbrBackground =
(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
wc.hIconSm = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc2.cbSize = sizeof(WNDCLASSEX);
wc2.style = CS_HREDRAW | CS_VREDRAW;
wc2.lpfnWndProc = WndProc;
wc2.cbClsExtra = 0;
wc2.cbWndExtra = 0;
wc2.hInstance = hInst;
wc2.hIcon = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc2.hCursor = (HCURSOR)LoadImage(
NULL, MAKEINTRESOURCE(IDC_ARROW),
IMAGE_CURSOR, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc2.hbrBackground =
(HBRUSH)GetStockObject(BLACK_BRUSH);
wc2.lpszMenuName = NULL;
wc2.lpszClassName = szClassName;
wc2.hIconSm = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
if((RegisterClassEx(&wc)||RegisterClassEx(&wc2)==0))
return 0;
return TRUE;
}
BOOL InitInstance(HINSTANCE hInst, int nCmdShow)
{
HWND hWnd;
HWND hWnd2;
hWnd = CreateWindow(szClassName,
TEXT("親ウィンドウ"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL
);
if(!hWnd) return FALSE;
hWnd2 = CreateWindow(szClassName2,
TEXT("子ウィンドウ"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hWnd,
NULL,
hInst,
NULL
);
if(!hWnd2) return FALSE;
ShowWindow(hWnd, nCmdShow);
ShowWindow(hWnd2, nCmdShow);
UpdateWindow(hWnd);
UpdateWindow(hWnd2);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, msg, wp, lp));
}
return 0;
}
子ウィンドウの作り方を理解したく、ただウィンドウを表示するプログラムを作ろうとしました。
しかし、うまくいきません。
一体なにがダメなんでしょうか?
お礼
がんばります!!