Device Context not covering whole Window

Hi,

how can I create an opengl device context, which does not cover the whole window, sothat i can also create some windows buttons. This this temporary not possible because the glcontext overlapps the buttons.

I guess i have to set the dc to the rect i want the glcontext to be.

This is my creation function:

HINSTANCE hInstance = GetModuleHandle(NULL);

WNDCLASS wc;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDC_ARROW);
wc.hCursor = LoadCursor(NULL, IDI_APPLICATION);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;

RegisterClass(&wc);

hWnd = CreateWindow(szAppName, L"Image Capture", WS_OVERLAPPEDWINDOW,
	0, 0, 740, 480,
	0, 0, hInstance, 0);

CreateWindow(L"BUTTON", L"Webcam", 
	WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
	0, 0, 100, 40, 
	hWnd,
	(HMENU) ID_BUTTON1,
	hInstance, NULL);

CreateWindow(L"BUTTON", L"Load Bmp", 
	WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
	0, 40, 100, 40, 
	hWnd,
	(HMENU) ID_BUTTON2,
	hInstance, NULL);

hDC = GetDC(hWnd);

static PIXELFORMATDESCRIPTOR pfd;				// pfd Tells Windows How We Want Things To Be
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

pfd.nSize			= sizeof(PIXELFORMATDESCRIPTOR);								//size
pfd.nVersion		= 1;															//version
pfd.dwFlags			= PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;	//flags
pfd.iPixelType		= PFD_TYPE_RGBA;												//rgba
pfd.cColorBits		= 32;															//color bits
pfd.cRedBits		= 8;
pfd.cGreenBits		= 8;
pfd.cBlueBits		= 8;
pfd.cAlphaBits		= 8;
pfd.cDepthBits		= 24;															//depth bits
pfd.cStencilBits	= 8;															//stencil bits
pfd.iLayerType		= PFD_MAIN_PLANE;

int PixelFormat = ChoosePixelFormat(hDC, &pfd);

SetPixelFormat(hDC, PixelFormat,&pfd);

hRC = wglCreateContext(hDC);

wglMakeCurrent(hDC, hRC);

glViewport(100, 0, 640, 480);



ShowWindow(hWnd, TRUE);
UpdateWindow(hWnd);

return true;

how can I create an opengl device context, which does not cover the whole window, sothat i can also create some windows buttons.

You don’t. You instead create a child window of the main window that you manually keep in sync with the main window. When the main window is resized, you resize the child. Etc. That way, you can make the window whatever sub-area of the main window you want; that will give you room to make other child windows (ie: buttons) that don’t overlap with it.

mixing GDI with opengl is depreciated in Vista/7 so just don’t bother.

if you create a window to use with opengl and then create child windows inside it - that is ok and will work. Just make sure the parent window is created with WS_CLIPCHILDREN flag - this will make sure the opengl drawing in the parent wont touch the areas of the child windows (buttons).

This is not mixing of opengl and GDI and is not deperecated - each window is being used only by one of opengl (the parent) and GDI (the buttons).
What is deprecated is mixing both in SINGLE window.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.