In my University College we work via DirectX and WIN32 for our Windows PC Games. ( For some project we work with XNA, which enables us to create Xbox360 games). For my private windows projects I'm creating a WIN32 API based framework. So what do I already have and how do I do certain things?
- Create very fast a win32 application with custom style settings, windows class settings, window general settings, etc...
- Draw simple geometrical figures(normal or filled), polygons. Normal or filled), lines, etc...
- Change window application settings dynamically at runtime
- Draw Text
- I paint everything via the Double buffering concept. I got that concept from here. I made some changes to it and extended it, thanks to the help of my prof.
Now what are my problems?
- When I start the application the menu is hidden by default, it is only when I resize my window that the menu appears. From then on the menu stays as well.
- After a short period, between 30 and 40 seconds, my entire window ( client rect + caption + ... ) gets filled with a static gray color. So the entire window is just that gray color. Nothing is disabled nor painted. So for example, you can still click the close (cross at the top right corner ) button to close the application.
Because of the size of my framework, and the many files + my own library (which is getting quite big) it is impossible to upload all my code. Here you can see the code which paints everything. If something is unclear or if you need more code related to a specific action, then please ask it. I'm trying to be as clear as possible.
Code from my WinMain part:
//..... a lot of code lines
//.... WinMain() {
//.....some code lines
#pragma warning ( disable : 4127 )
while(true)
{
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
// Process the message
if (msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else // Game Cycle / OpenGl Cycle / DirectX Cycle
{
if(!WinEngine::GetSingleton()->GetSleep() && _bAppLoop_) //win engine aint sleeping
{
// Make sure the game engine isn't sleeping
//Tick timing is independent from Paint timing
_swpAppTimer_->Tick();
double tickTimeNow = _swpAppTimer_->GetAppTime();
if( tickTimeNow > GetFrameRate())
{
//.... Keyboard stuff
RECT rect;
HDC hDC = GetDC(_hWND_);
GetClientRect(_hWND_, &rect);
//Double buffering code (c) Kevin Hoefman
HDC hBufferDC = CreateCompatibleDC(hDC);
//Create the bufffer
HBITMAP hBufferBmp = CreateCompatibleBitmap(hDC, GetWindowWidth(), GetWindowHeight());
HBITMAP hOldBmp = (HBITMAP) SelectObject(hBufferDC, hBufferBmp);
// user defined drawning
_hDC_ = hBufferDC;
_bIsDoubleBuffering_ = true;
_pApp_->AppTick(tickTimeNow);
_fpspApp_->Tick(tickTimeNow); // FPS timer...
UserPaint();
//UserPaint();
_bIsDoubleBuffering_ = false;
// As a last step copy the memdc to the hdc
BitBlt(hDC, 0, 0, _iWinWidth_, _iWinHeight_, hBufferDC, 0, 0, SRCCOPY);
//reset the old bmp of the buffer
SelectObject(hBufferDC,hOldBmp);
//kill the buffer
DeleteObject(hBufferBmp);
DeleteDC(hBufferDC);
//Release DC
ReleaseDC(_hWND_, _hDC_);
//reset Timer
_swpAppTimer_->Reset();
_swpAppTimer_->Start();
}
else
Sleep(1); // if no cpu cycle has ellpases sleep than for 1 ms
// doing this prevent the loop from hogging the cpu hog
}
else
WaitMessage(); // If sleeping or if looping is disabled we just
// handle the window messages...
}
}
#pragma warning ( default : 4127 )
//..... some code lines
// } // WinMain closes
//..... a lot of code lines
code from in my WM_PAINT message in my WndProc function
case WM_PAINT:
?//..... a lot of code
// .... WndProc {
// .. some code
GetClientRect(_hWND_, &rect);
nw = rect.right-rect.left; // new main window width
nh = rect.bottom-rect.top; // new main window height
if(_bDoubleBuffering_ == false) //Single Buffer
{
_hDC_ = BeginPaint (hwnd, &ps);
_bIsPainting_ = true;
UserPaint();
PaintRatioBorders(rect);
_bIsPainting_ = false;
EndPaint (hwnd, &ps);
}
else //Double buffer
//http://www.gamedev.net/topic/411559-win32-double-buffering/
{
hdc = BeginPaint(hwnd,&ps);
_hDC_ = CreateCompatibleDC(_hDC_);
bitmap = CreateCompatibleBitmap(hdc,nw,nh);
hOldBmp = (HBITMAP) SelectObject(_hDC_,bitmap);
_bIsPainting_ = true;
UserPaint();
PaintRatioBorders(rect);
_bIsPainting_ = false;
BitBlt(hdc, 0, 0, nw, nh, _hDC_, 0, 0, SRCCOPY); // copy the memdc to the hdc
SelectObject(_hDC_, hOldBmp); // reset old buffer.OldBMP
// Kill buffer
DeleteObject(bitmap);
DeleteDC(_hDC_);
// End paint
EndPaint(_hWND_,&ps);
}
return 0;
// some code
// } // WndProc closes
//... a lot of code
Here you see what I mean with the second problem. (The problem which specifies that everything gets gray after a short period of running time ).
I hope you guys can help me. Thanks already for your time!