Render to a child window
Im using c++ win32 and opengl. Im trying to create a simple map editor for my game but i cant figure out hot to create a child window on the main window to render to. I want to make a window on the side similar to q3radiant. Ive searched google but couldnt find anything.
Please could someone tell me how to do this
Thanks
What have you tried? What exactly isn't working?
All you need to do is use CreateWindow and pass the handle of your parent window into the function. If you want the window to have the tool window style, take a look at the styles property (you might need to use CreateWindowEx) in MSDN for the appropriate style.
All you need to do is use CreateWindow and pass the handle of your parent window into the function. If you want the window to have the tool window style, take a look at the styles property (you might need to use CreateWindowEx) in MSDN for the appropriate style.
This is what i use to create the two windows
When i run my program it creates 2 windows instead of the render window onto the parent window
hwnd = CreateWindow( L"MapEditor", L"MapEditor", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, HWND_DESKTOP, NULL, hThisInstance, NULL ); if(!hwnd) { MessageBox(NULL,L"Window Creation Error.",L"ERROR",MB_OK|MB_ICONERROR); return 0; } g_RenderhWnd = CreateWindowEx( WS_EX_CLIENTEDGE, L"MapEditor", L"MapEditor", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 10, 10, 100, 100, hwnd, NULL, hThisInstance, NULL );
When i run my program it creates 2 windows instead of the render window onto the parent window
this is the whole WinMain
int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){ HWND hwnd; GLuint PixelFormat; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = L"MapEditor"; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL,IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl)) { MessageBox(NULL,L"Failed To Register The Window Class.",L"ERROR",MB_OK|MB_ICONERROR); return 0; } static PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; hwnd = CreateWindow( L"MapEditor", L"MapEditor", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, HWND_DESKTOP, NULL, hThisInstance, NULL ); if(!hwnd) { MessageBox(NULL,L"Window Creation Error.",L"ERROR",MB_OK|MB_ICONERROR); return 0; } g_RenderhWnd = CreateWindowEx( WS_EX_CLIENTEDGE, L"MapEditor", L"MapEditor", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 10, 10, 100, 100, hwnd, NULL, hThisInstance, NULL ); g_hWnd = hwnd; g_hInstance = hThisInstance; g_hDC = GetDC(g_RenderhWnd); PixelFormat = ChoosePixelFormat(g_hDC,&pfd); SetPixelFormat(g_hDC,PixelFormat,&pfd); g_hRC = wglCreateContext(g_hDC); wglMakeCurrent(g_hDC,g_hRC); ResizeWindow(800,600); InitGL(); ShowWindow(g_hWnd,nFunsterStil); ShowWindow(g_RenderhWnd,SW_SHOW); SetForegroundWindow(g_hWnd); SetFocus(g_hWnd); return MainLoop(); }
I believe you need to specify WS_CHILD as part of the Window style for the child window. I think otherwise your first window just owns the second window, without actually containing it.
_RenderhWnd = CreateWindowEx( WS_EX_CLIENTEDGE, L"MapEditor", L"MapEditor", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CHILD, 10, 10, 100, 100, hwnd, NULL, hThisInstance, NULL );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement