![]() |
| | #1 |
| Mad Join Date: Jan 2005 Location: Umeå, Sweden
Posts: 555
| Can't create child windows Code: const char wndclass[] = "OpenGL Program";
const char oglclass[] = "OpenGL Renderer";
WNDPROC oldconproc;
HWND window;
int WINAPI WinMain (HINSTANCE inst, HINSTANCE pinst, char* args, int show)
{
WNDCLASSEX wc;
WNDCLASSEX oc;
MSG msg;
ZeroMemory(&wc, sizeof(wc));
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = wndproc;
wc.hInstance = inst;
wc.hbrBackground = COLOR_WINDOW;
wc.lpszClassName = wndclass;
ZeroMemory(&oc, sizeof(oc));
oc.cbSize = sizeof(oc);
oc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
oc.lpfnWndProc = oglproc;
oc.hInstance = inst;
oc.hbrBackground = COLOR_WINDOW;
oc.lpszClassName = oglclass;
if (!RegisterClassEx(&wc) || !RegisterClassEx(&oc)) {
Error();
return 1;
}
window = CreateWindowEx(WS_EX_CLIENTEDGE, wndclass, "OpenGL", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, inst, NULL);
if (window == NULL) {
Error();
return 1;
}
ShowWindow(window, show);
UpdateWindow(window);
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
The wndproc function, cut off to show the important parts: Code: LRESULT CALLBACK wndproc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
static HWND ogl;
static HWND con;
static int fonth;
switch (msg) {
case WM_CREATE:
{
HFONT font, oldfont;
HDC condc;
TEXTMETRIC tm;
font = CreateFont(-MulDiv(12, GetDeviceCaps(GetDC(hwnd), LOGPIXELSY), 72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Shell Dlg"));
/*Here comes the trouble makers*/
ogl = CreateWindowEx(0, oglclass, TEXT(""), WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 0, 0, window, NULL, GetModuleHandle(NULL), NULL);
con = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 0, 0, 0, 0, window, NULL, GetModuleHandle(NULL), NULL);
if (font == NULL || ogl == NULL || con == NULL) { /*End of the line*/
Error();
PostQuitMessage(1);
break;
}
oldconproc = SetWindowLongPtr(con, GWLP_WNDPROC, (LONG_PTR) conproc);
SendMessage(con, WM_SETFONT, (WPARAM) font, MAKELPARAM(FALSE, 0));
condc = GetDC(con);
oldfont = SelectObject(condc, font);
GetTextMetrics(condc, &tm);
SelectObject(condc, oldfont);
ReleaseDC(con, condc);
fonth = tm.tmHeight;
break;
}
Looking up the error message doesn't help me solve my problem, "As part of its user interface, an application has tried to create a child window at an inappropriate level.", what are these "levels" to begin with? |
| OnionKnight is offline | |
| | #2 |
| erstwhile Join Date: Jan 2002
Posts: 2,223
| The variable window isn't a valid window handle until CreateWindowEx returns (recall that a WM_CREATE message is issued during system processing of that api function) so the child windows essentially have a NULL handle as a parent. A top-level window is a non-child window, like your main window. Just use the HWND parameter passed to the window procedure in the WM_CREATE handler as the parent handle when creating the child windows .
__________________ CProgramming FAQ Caution: this person may be a carrier of the misinformation virus. |
| Ken Fitlike is offline | |
| | #3 |
| Mad Join Date: Jan 2005 Location: Umeå, Sweden
Posts: 555
| You're right, I had forgotten about that, even though I copypasted stuff from another program which used hwnd instead. :| Now it works fine, except that the OpenGL window isn't showing anything. EDIT: Forgot WS_VISIBLE. Now everything's like it should. Last edited by OnionKnight; 11-30-2006 at 08:15 PM. |
| OnionKnight is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can you make a parent process wait for a child? I'm gettin a seg fault. | mr_coffee | C Programming | 3 | 10-15-2008 09:24 AM |
| Removing/Hiding Child Windows | Hysteresis | Windows Programming | 4 | 07-14-2006 11:50 AM |
| Child window inside child window | Magos | Windows Programming | 13 | 04-20-2004 06:51 AM |
| child windows | face_master | Windows Programming | 14 | 03-01-2002 07:08 AM |