PocketMatrix forums

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

I tried to set the window background color

Hi,

I tried to set the window background color by override the original init function in the Game class.

When i tried to run the program though, I encountered a First-chance exception Access Violation error. This error occured in Rasterizer::Clear function.

What happened ? What should I do ?

nightcat
I assume you mean you are trying to clear the screen to a color in the GameInit section.

My first guess would be that your 'display' pointer is invalid. Do you call GetDisplay first?
Actually I'm trying to overide the Game::Init function. I copied the Init function from game.cpp and change the line

GetWndClassInfo().m_wc.hbrBackground = 0;

to

GetWndClassInfo().m_wc.hbrBackground = (HBRUSH) GetStockObject (DKGRAY_BRUSH);

The problem occurs when I override the Game::Init function. Whenever I use my own code of Game::Init I get the error and when I comment this function the program works.
Maybe you are trying to get this:

Code:
void YourGame::GameLoop ()
{
Display * pDisplay;
pDisplay = GetDisplay();
pDisplay->Clear(Color(255, 255, 0));
// Your Code here
pDisplay->Update();
)
nightcat wrote:Actually I'm trying to overide the Game::Init function. I copied the Init function from game.cpp and change the line


You can not move functions around like this and expect the code to work. Game::Init() isn't a virtual function that you can override.


nightcat wrote:GetWndClassInfo().m_wc.hbrBackground = (HBRUSH) GetStockObject (DKGRAY_BRUSH);


PocketFrog doesn't use GDI for graphics. This is not not going to do what you want. See Bigben's reply for how to clear the screen.
well, the clear method works fine when I am drawing graphics. What I am trying to do is to put some controls and a menu bar on the screen using CreateWindow.

I can see the window beneath my application on the bottom and right edges of my listviews and command buttons. I have used the clear method and the edges around the controls are still there.

Is there any way that I can get rid of these "holes" around the edges ?
Oh I see. You are trying to use Win32 "controls" with PF. I have never tested if it can be done (it most probably can).

One thing that you can do is create a GDISurface and retarget the rasterizer to it. This way rendering will be done to the GDISurface and you can then blit it using GDI to whatever window you have.
thanx. I'll give it a go.
Hi,

The GDISurface Thierry mentioned above is for DirectX. But I am working on the PocketPC 2002. Is there an alternative ?
No GDISurface is a PocketFrog class, not a DirectX one. It sure works on the Pocket PCs because it is used for loading images.
So do I retarget the rasterizer like this ?

Display* display = GetDisplay();
PHAL::GDISurface* gdibuffer = PHAL::GDISurface::Create(240, 320);
display->SetRenderTarget(gdibuffer);
display->Clear(Color(192, 192, 192));
display->Update();

But I got a compile error at the SetRenderTarget line:

error C2664: 'SetRenderTarget' : cannot convert parameter 1 from 'class PHAL::GDISurface *' to 'class Frog::Surface *'
Oops. My bad. Create a normal PocketFrog surface:

Frog::Surface* surface = new Frog::Surface( 240, 320 );

Then get the DC on it directly:

HDC hdc = surface->GetDC();

You can then use that hdc to blit to your window.

TT
Yes, it works. Thank you so much.