PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Pocketfrog/HAL on desktop redraw while inactive?

I'm used to programming on embedded devices, but windows desktop less-so. Perhaps a noddy question, but -

When a PocketFrog/HAL game runs on desktop and the window does not have focus, it doesn't get redrawn if another window passes in front of it. Does anyone know how to get the window to at least redraw its last frame, so it 'looks' semi-alive even though not the active window? I suspect something to do with capturing the last buffer just before suspend,then rendering it to the window client area outside of PocketHAL in a redraw/paint event, other than that I've not much idea! (using C++)

Help much appreciated!
OK, I found a basic way of doing this - code here for the benefit of those interested, though judging by the replies not many :)

Firstly I placed 4 members in the Game class:
Code:


HDC _hdc;
HBITMAP _hbmp;
int _sx;
int _sy;



In GameInit:
Code:


// Create DC big enough to store client area bitmap
#ifndef _WIN32_WCE
_sx = GetDisplay()->GetWidth();
_sy = GetDisplay()->GetHeight();

HDC hdc = GetDisplay()->GetBackBuffer()->GetDC();
_hdc = CreateCompatibleDC(hdc);
_hbmp = CreateCompatibleBitmap(hdc,_sx,_sy);
SelectObject(_hdc, _hbmp);
GetDisplay()->GetBackBuffer()->ReleaseDC(hdc);
#endif



Then (a bit expensive, but this is desktop only for a relatively static turn-based game) just before the Update in GameLoop:

Code:


// Save the last client area bitmap
#ifndef _WIN32_WCE
HDC hdc = GetDisplay()->GetBackBuffer()->GetDC();
BitBlt(_hdc, 0, 0, _sx, _sy, hdc, 0, 0, SRCCOPY);
GetDisplay()->GetBackBuffer()->ReleaseDC(hdc);
#endif



and finally in the OnPaint method:

Code:


PAINTSTRUCT ps;

BeginPaint( &ps; );

// Copy back invalidated regions of stored bitmap when other windows cross yours
#ifndef _WIN32_WCE
HDC hdc = ps.hdc;
BitBlt( hdc,
ps.rcPaint.left,
ps.rcPaint.top,
ps.rcPaint.right - ps.rcPaint.left,
ps.rcPaint.bottom - ps.rcPaint.top,
_hdc,
ps.rcPaint.left,
ps.rcPaint.top,
SRCCOPY);
ReleaseDC(hdc);
#endif

EndPaint( &ps; );



I'll probably be able to optimise later, but it's a start.