a1programmer
asked on
Create viewport on window with other win32 controls...
I have a window, 600 x 400, and I want to display a small gl drawing viewport on the right 300 pixels (or near that), and the left to contain various controls.
I've tried simply calling glViewport(300,375,250,250 ), but the whole window becomes black, overwriting my controls...
What am I doing wrong?
Here's my WinMain
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow )
{
time_t now;
time(&now);
srand(now % 65535);
WNDCLASS wc;
HWND hWnd;
HWND hwnd_static1, hStatic2;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
// register window class
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1) ;
wc.lpszClassName = "openGL";
RegisterClass( &wc );
// create window
hWnd = CreateWindow(
"openGL",
"Fur Generator",
WS_CAPTION |WS_POPUPWINDOW | WS_VISIBLE,
175, 50, 600, 300,
NULL, NULL, hInstance, NULL );
strcpy(lf.lfFaceName,"verd ana");
lf.lfHeight = 14;
lf.lfWeight = 500;
hFont = CreateFontIndirect(&lf); //or any other font creation method chosen;
lf.lfHeight = 12;
hSmallFont = CreateFontIndirect(&lf);
//+++ make "create" button
hButton1 = CreateWindow("BUTTON","Cre ate",WS_CH ILD | WS_VISIBLE ,190,180,100,20, hWnd,(HMENU)ID_BUTTON1,hIn stance,NUL L);
SendMessage(hButton1, WM_SETFONT, (WPARAM)hFont, 1);
//--- made create button
//+++ make "source" button
hButton1 = CreateWindow("BUTTON","Sou rce File",WS_CHILD | WS_VISIBLE ,10,0,100,20, hWnd,(HMENU)ID_BUTTON_SOUR CE,hInstan ce,NULL);
SendMessage(hButton1, WM_SETFONT, (WPARAM)hSmallFont, 1);
//--- made source button
//+++ make "output" button
hButton1 = CreateWindow("BUTTON","Out put File",WS_CHILD | WS_VISIBLE ,10,21,100,20, hWnd,(HMENU)ID_BUTTON_SOUR CE,hInstan ce,NULL);
SendMessage(hButton1, WM_SETFONT, (WPARAM)hSmallFont, 1);
//--- made output button
//+++ make "preview" outline (until glviewport works)
HWND gloutput = CreateWindow("static","",W S_BORDER | WS_CHILD | WS_VISIBLE ,350,15,220,220, hWnd,(HMENU)ID_BUTTON_SOUR CE,hInstan ce,NULL);
HWND gloutputlabel = CreateWindow("static","pre view", WS_CHILD | WS_VISIBLE ,350,0,220,220, hWnd,(HMENU)ID_BUTTON_SOUR CE,hInstan ce,NULL);
SendMessage(gloutputlabel , WM_SETFONT, (WPARAM)hFont, 1);
//--- made output frame
//+++ make the source object dropdown
hwnd_static1 = CreateWindow("static","Obj ects:",WS_ CHILD | WS_VISIBLE | SS_LEFT,10,50,200,18,hWnd, NULL,hInst ance,NULL) ;
SendMessage(hwnd_static1, WM_SETFONT, (WPARAM)hFont, 1);
SetWindowText(hwnd_static1 ,"Source Object");
hSourceCombo = CreateWindow("combobox", "", WS_BORDER | WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_TABSTOP,110,45,160,100, hWnd,NULL, hInstance, NULL);
SendMessage(hSourceCombo, WM_SETFONT, (WPARAM)hFont, 1);
//SendMessage(hSourceCombo ,CB_ADDSTR ING,0,(lon g)"object1 ");
//SendMessage(hSourceCombo ,CB_ADDSTR ING,0,(lon g)"object2 ");
//SendMessage(hSourceCombo ,CB_ADDSTR ING,0,(lon g)"object3 ");
//--- made source object dropdown
// +++ create percent edit box etc...
hEditPercent= CreateWindow("edit","0", WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE | SS_RIGHT,10,90,35,20,hWnd, NULL,hInst ance,NULL) ;
hStatic2 = CreateWindow("static","% of points used:",WS_CHILD | WS_VISIBLE | SS_LEFT,47,92,120,18,hWnd, NULL,hInst ance,NULL) ;
SendMessage(hStatic2, WM_SETFONT, (WPARAM)hFont, 1);
SendMessage(hEditPercent, WM_SETFONT, (WPARAM)hFont, 1);
// --- created percent edit box, etc...
EnableOpenGL( hWnd, &hDC, &hRC );
glViewport(350,300,220,220 );
// main program loop
while ( !bQuit ) {
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
// handle or dispatch messages
if ( msg.message == WM_QUIT ) {
bQuit = TRUE;
} else {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
} else {
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
SwapBuffers( hDC );
} // else
} // while peek_message
return msg.lParam;
} // end of winmain
I've tried simply calling glViewport(300,375,250,250
What am I doing wrong?
Here's my WinMain
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow )
{
time_t now;
time(&now);
srand(now % 65535);
WNDCLASS wc;
HWND hWnd;
HWND hwnd_static1, hStatic2;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
// register window class
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1)
wc.lpszClassName = "openGL";
RegisterClass( &wc );
// create window
hWnd = CreateWindow(
"openGL",
"Fur Generator",
WS_CAPTION |WS_POPUPWINDOW | WS_VISIBLE,
175, 50, 600, 300,
NULL, NULL, hInstance, NULL );
strcpy(lf.lfFaceName,"verd
lf.lfHeight = 14;
lf.lfWeight = 500;
hFont = CreateFontIndirect(&lf); //or any other font creation method chosen;
lf.lfHeight = 12;
hSmallFont = CreateFontIndirect(&lf);
//+++ make "create" button
hButton1 = CreateWindow("BUTTON","Cre
SendMessage(hButton1, WM_SETFONT, (WPARAM)hFont, 1);
//--- made create button
//+++ make "source" button
hButton1 = CreateWindow("BUTTON","Sou
SendMessage(hButton1, WM_SETFONT, (WPARAM)hSmallFont, 1);
//--- made source button
//+++ make "output" button
hButton1 = CreateWindow("BUTTON","Out
SendMessage(hButton1, WM_SETFONT, (WPARAM)hSmallFont, 1);
//--- made output button
//+++ make "preview" outline (until glviewport works)
HWND gloutput = CreateWindow("static","",W
HWND gloutputlabel = CreateWindow("static","pre
SendMessage(gloutputlabel , WM_SETFONT, (WPARAM)hFont, 1);
//--- made output frame
//+++ make the source object dropdown
hwnd_static1 = CreateWindow("static","Obj
SendMessage(hwnd_static1, WM_SETFONT, (WPARAM)hFont, 1);
SetWindowText(hwnd_static1
hSourceCombo = CreateWindow("combobox", "", WS_BORDER | WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_TABSTOP,110,45,160,100,
SendMessage(hSourceCombo, WM_SETFONT, (WPARAM)hFont, 1);
//SendMessage(hSourceCombo
//SendMessage(hSourceCombo
//SendMessage(hSourceCombo
//--- made source object dropdown
// +++ create percent edit box etc...
hEditPercent= CreateWindow("edit","0", WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE | SS_RIGHT,10,90,35,20,hWnd,
hStatic2 = CreateWindow("static","% of points used:",WS_CHILD | WS_VISIBLE | SS_LEFT,47,92,120,18,hWnd,
SendMessage(hStatic2, WM_SETFONT, (WPARAM)hFont, 1);
SendMessage(hEditPercent, WM_SETFONT, (WPARAM)hFont, 1);
// --- created percent edit box, etc...
EnableOpenGL( hWnd, &hDC, &hRC );
glViewport(350,300,220,220
// main program loop
while ( !bQuit ) {
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
// handle or dispatch messages
if ( msg.message == WM_QUIT ) {
bQuit = TRUE;
} else {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
} else {
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
SwapBuffers( hDC );
} // else
} // while peek_message
return msg.lParam;
} // end of winmain
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the child-frame is one way, but you could get some problems, when you try to draw i.e. an background to the whole window. In this case it would be more easy to lay viewport and Ortho to the whole screen an enable the glScissorBox to your drawing-area. Thus your controlls will not be overwritten...
ASKER
I did try not doing the double buffering, and using a PFD_SUPPORT_GDI (or whatever) , but this is better.
__
A1