Window BG is bugged

I made a window with another child-window inside. The child window is where i draw my OpenGL. But the background of the parent window gets obstructed and wierd, and the rendering window (child-window) is chopped off.

Pic: https://dl.dropbox.com/u/38127392/Pic.jpg
Executable: https://dl.dropbox.com/u/38127392/Debug.rar

Here is the relevant files:
OGLAbstr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef _OGLABSTR_H_
#define _OGLABSTR_H_

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glew32.lib")

#include <GL/glew.h>
#include <GL/wglew.h>
#include <string.h>
#include <iostream>
#include <Windows.h>
#include "LogMgr.h"
#include "resource.h"

class OGLAbstr
{
public:
	OGLAbstr(HINSTANCE hInst, LogMgr* mLog);
	~OGLAbstr();

	bool initGL(int AA=0);
	bool initGLEW();

	bool openGameWindow(WNDCLASSEX wc, std::string title, int x=0, int y=0);
	bool openEditorWindow(WNDCLASSEX wc);

	void renderFrame();

	HWND Window;
	HWND RenderWindow;

private:
	HDC hDC;
	HMENU Menu;
	HINSTANCE hInstance;
	WNDCLASSEX fakeClass;
	HGLRC hRC;
	std::string className;
	LogMgr* log;
};

#endif 


OGLAbstr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "OGLAbstr.h"

LRESULT CALLBACK WndProcFake(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	}
	return (DefWindowProc(hWnd, msg, wParam, lParam));
}

OGLAbstr::OGLAbstr(HINSTANCE hInst, LogMgr* mLog)
{
	hInstance = hInst;
	log = mLog;

	fakeClass.cbSize = sizeof(WNDCLASSEX);
	fakeClass.style =  CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	fakeClass.lpfnWndProc = WndProcFake;
	fakeClass.cbClsExtra = 0; fakeClass.cbWndExtra = 0;
	fakeClass.hInstance = hInstance;
	fakeClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	fakeClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	fakeClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	fakeClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
	fakeClass.lpszMenuName = NULL;
	fakeClass.lpszClassName = "temp";

	RegisterClassEx(&fakeClass);
	log->logMessage(log->WND, "Registered dummy class");
}

OGLAbstr::~OGLAbstr()
{
}

bool OGLAbstr::initGLEW()
{
   HWND hWndFake = CreateWindow("temp", "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN, 0, 0, 800, 600, NULL, NULL, hInstance, NULL);
   hDC = GetDC(hWndFake);

   // First, choose false pixel format
   
   PIXELFORMATDESCRIPTOR pfd;
   memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
         pfd.nSize= sizeof(PIXELFORMATDESCRIPTOR);
   pfd.nVersion   = 1;
   pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
   pfd.iPixelType = PFD_TYPE_RGBA;
   pfd.cColorBits = 32;
   pfd.cDepthBits = 32;
   pfd.iLayerType = PFD_MAIN_PLANE;
 
   int iPixelFormat = ChoosePixelFormat(hDC, &pfd);
   if (iPixelFormat == 0)return false;

   if(!SetPixelFormat(hDC, iPixelFormat, &pfd))return false;

   // Create the false, old style context (OpenGL 2.1 and before)
   HGLRC hRCFake = wglCreateContext(hDC);
   wglMakeCurrent(hDC, hRCFake);

   if(glewInit() != GLEW_OK)
   {
      MessageBox(NULL, "Couldn't initialize GLEW!", "Fatal Error", MB_ICONERROR | MB_OK);
	  log->logMessage(log->GLERR, "Could not initialize GLEW!");
	  return false;
   }
   log->logMessage(log->GL, "Initialized GLEW");

   wglMakeCurrent(NULL, NULL);
   wglDeleteContext(hRCFake);
   DestroyWindow(hWndFake);
   UnregisterClass("temp", hInstance);

   return true;
}

bool OGLAbstr::initGL(int AA)
{
#ifdef _EDITOR
	hDC = GetDC(RenderWindow);
#endif
#ifdef _GAME
	hDC = GetDC(Window);
#endif

	if(hDC == NULL)
	{
		log->logMessage(log->GLERR, "Could not get DC");
		return false;
	}

	PIXELFORMATDESCRIPTOR pfd;

	const int iPixelFormatAttribList[] =
	{
		WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
		WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
		WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
		WGL_COLOR_BITS_ARB, 32,
		WGL_DEPTH_BITS_ARB, 24,
		WGL_STENCIL_BITS_ARB, 8,
		WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
		0 // End of attributes list
	};
	int iContextAttribs[] =
	{
		WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
		WGL_CONTEXT_MINOR_VERSION_ARB, 0,
		WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
		0 // End of attributes list
	};

	int iPixelFormat, iNumFormats;
	if(!wglChoosePixelFormatARB(hDC, iPixelFormatAttribList, NULL, 1, &iPixelFormat, (UINT*)&iNumFormats))
	{
		log->logMessage(log->GLERR, "Could not find Pixel Format!");
		return false;
	}

	// PFD seems to be only redundant parameter now
	if(!SetPixelFormat(hDC, iPixelFormat, &pfd))return false;
	hRC = wglCreateContextAttribsARB(hDC, 0, iContextAttribs);
	// If everything went OK
	if(hRC) wglMakeCurrent(hDC, hRC);
	log->logMessage(log->GL, "Created DC");

	glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
	return true;
}

bool OGLAbstr::openGameWindow(WNDCLASSEX wc, std::string title, int x, int y)
{
	Window = CreateWindowEx(0, wc.lpszClassName, title.c_str(), WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_VISIBLE | WS_CLIPCHILDREN, x, y, 800, 600, 0, 0, hInstance, 0);
	if(Window == NULL)
		return false;
	ShowWindow(Window, SW_SHOW);
	ShowWindow(Window, SW_MAXIMIZE);
	log->logMessage(log->WND, "Created Game window");
 	return true;
}

void OGLAbstr::renderFrame()
{
	glClear(GL_COLOR_BUFFER_BIT);
	SwapBuffers(hDC);

	//Rendering code
}

bool OGLAbstr::openEditorWindow(WNDCLASSEX wc)
{
	Window = CreateWindowEx(0, wc.lpszClassName, "Echeos Editor", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_VISIBLE | WS_CLIPCHILDREN, 0, 0, 800, 600, 0, 0, hInstance, 0);
	if(!Window)
	{
		log->logMessage(log->WNDERR, "Could not create Window");
		return false;
	}
	Menu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU));
	RECT rect;
	GetClientRect(Window, &rect);
	RenderWindow = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, rect.right-rect.left, rect.bottom-rect.top, Window, NULL, hInstance, 0);
	SetMenu(Window, Menu);
	ShowWindow(Window, SW_SHOW);
	ShowWindow(Window, SW_MAXIMIZE);
	log->logMessage(log->WND, "Created Editor window");
	return true;
}


I am calling the openEditorWindow(WNDCLASSEX wc) Function in my program and supply it with a window class

wc class:
1
2
3
4
5
6
7
8
9
10
11
12
wc.cbSize = sizeof(WNDCLASSEX);
	wc.style =  CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc = callback->WndProcEditor;
	wc.cbClsExtra = 0; 
	wc.cbWndExtra = 0;
	wc.hInstance = hInst;
	wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_APPLICATION));
	wc.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(IDI_APPLICATION));
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_MENUBAR+1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "EC";


And of course the callback functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
LRESULT CALLBACK hMsg::WndProcEditor(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	switch (msg)
	{
		case WM_PAINT:
			BeginPaint(hWnd, &ps);							
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY: 
			PostQuitMessage(0); 
			break;
		case WM_COMMAND: 
			MenuProc(hWnd, msg, wParam, lParam);
			break;
		case WM_SIZE: resize(hWnd, msg, wParam, lParam);
			break;
		case WM_RBUTTONUP: //app->regPopup(LOWORD(lParam), HIWORD(lParam)); 
			break;
		default:
			DefWindowProc(hWnd, msg, wParam, lParam);
			break;
	}
	return (DefWindowProc(hWnd, msg, wParam, lParam));
}

LRESULT CALLBACK hMsg::MenuProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (lParam)
	{
		//default:
			//DefWindowProc(hWnd, msg, wParam, lParam);
	}
	switch (wParam)
	{
		case ID_FILE_EXIT:
			PostQuitMessage(0);
			break;
		default:
			DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return (DefWindowProc(hWnd, msg, wParam, lParam));

}


void hMsg::pumpMessage()
{
	if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		if(msg.message == WM_QUIT)
		{
			stop = false;
		}
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
}

LRESULT CALLBACK hMsg::resize(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	hmsg.resizeView();
	return(0);
}

void hMsg::resizeView()
{
	RECT rect; 
	GetClientRect(gl->Window, &rect);
#ifdef _EDITOR
	MoveWindow(gl->RenderWindow, 0, 0, rect.right-rect.left, rect.bottom-rect.top, true);
	GetClientRect(gl->RenderWindow, &rect);
#endif
	glViewport(0, 0, (GLsizei)rect.left-rect.right, (GLsizei)rect.top-rect.bottom);
}

void hMsg::getGL(OGLAbstr* GL)
{
	gl = GL;
}


Thanks in advance!
Last edited on
*bump*
Double bump? :/. I really need help on this one...
Topic archived. No new replies allowed.