在createWindow()调用中,将0传递到位置和大小参数中。
尝试修改你的wm_创建这样的案例。
case WM_CREATE:
AddMenus(hMainWindow);
hwnd = CreateWindowEx(
0,
"ChildWClass",
(LPCTSTR) NULL,
WS_CHILD | WS_BORDER | WS_VISIBLE,
CW_USEDEFAULT, // x location
CW_USEDEFAULT, // y location
400, // width
300, // height
hMainWindow,
NULL,
NULL,
NULL);
ShowWindow(hwnd, SW_SHOW);
break;
下面是我对你想做的事情的解释,至少考虑到儿童窗。(我仍然不明白为什么需要第二个线程,但一次出现一个问题。)
#include <windows.h>
LRESULT CALLBACK TheWndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lP) {
HDC hdc;
HWND hwother;
switch( msg ) {
case WM_CREATE:
hwother =
CreateWindowEx(0, "TerribleClassName100405", "child title",
WS_OVERLAPPEDWINDOW,
100, 100, // location
200, 160, // size
(HWND)hwnd, // parent
(HMENU)NULL,
NULL,
NULL);
ShowWindow(hwother, SW_SHOW);
break;
case WM_CHAR: // quit app using escape key
switch( LOWORD(wP) ) {
case 27:
SendMessage(hwnd, WM_CLOSE, 0, 0);
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wP, lP);
}
LRESULT CALLBACK AltWndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lP) {
HDC hdc;
switch( msg ) {
case WM_CREATE:
break;
case WM_CHAR: // quit app using X
switch( LOWORD(wP) ) {
case 'X':
SendMessage(hwnd, WM_CLOSE, 0, 0);
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wP, lP);
}
void registerCustomWindows(HINSTANCE hInst) {
WNDCLASSEX wc1;
WNDCLASSEX wc2;
wc1.lpszClassName = "TerribleClassName040914";
wc1.hInstance = hInst;
wc1.lpfnWndProc = TheWndProc;
wc1.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc1.cbSize = sizeof(wc1);
wc1.cbClsExtra = 0;
wc1.cbWndExtra = 0;
wc1.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc1.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc1.hCursor = LoadCursor(NULL, IDC_ARROW);
wc1.hbrBackground = GetStockObject(WHITE_BRUSH);
wc1.lpszMenuName = NULL;
RegisterClassEx(&wc1);
wc2.lpszClassName = "TerribleClassName100405";
wc2.hInstance = hInst;
wc2.lpfnWndProc = AltWndProc;
wc2.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc2.cbSize = sizeof(wc2);
wc2.cbClsExtra = 0;
wc2.cbWndExtra = 0;
wc2.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc2.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc2.hCursor = LoadCursor(NULL, IDC_ARROW);
wc2.hbrBackground = GetStockObject(WHITE_BRUSH);
wc2.lpszMenuName = NULL;
RegisterClassEx(&wc2);
}
int WINAPI WinMain(HINSTANCE hThis, HINSTANCE hPrev, LPSTR cml, int iCS) {
MSG msg;
HWND hwnd;
registerCustomWindows(hThis);
hwnd = CreateWindowEx(0, "TerribleClassName040914", "two windows skeleton",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, // location
640, 480, // size
(HWND)NULL, // parent
(HMENU)NULL,
hThis,
NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
while( GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
我在一个名为demo.c的文件中有这个确切的代码,并使用MS Visual Studio Express 2005来编译它
cl demo.c user32.lib gdi32.lib
…我有两扇窗户。为了区分我有两个窗口类,其中一个通过按Esc退出,另一个通过大写X退出。
为发布第二条回复而道歉。我的另一个回答是非常普遍的,可能只是OBE,因为OP提供了更多的细节。