Jump to content
  • Advertisement
Sign in to follow this  
hahaha

Render to a child window

This topic is 4082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
This is what i use to create the two windows


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

Share this post


Link to post
Share on other sites
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();

}

Share this post


Link to post
Share on other sites
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
);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!