Harry123

Hi, my (PocketPC) app normally used GAPI but I'm now moving it to DirectX to support WM6. (My app is written in VC++) I have a question:

If I wish to clear the screen and draw stuff to it. If I call the below Render function in the OnPaint() function of my dialog everything is fine and dandy:

LPDIRECT3DMOBILEDEVICE g_pd3dmDevice = NULL; // My rendering device

VOID Render()
{
if( NULL == g_pd3dmDevice )
return;
// Clear the backbuffer to a blue color
g_pd3dmDevice->Clear( 0, NULL, D3DMCLEAR_TARGET, D3DMCOLOR_XRGB(0,0,255), 1.0f, 0 );

// Begin the scene
if( SUCCEEDED( g_pd3dmDevice->BeginScene() ) )
{
// do stuff here blah blah

// End the scene
g_pd3dmDevice->EndScene();
}

// Present the backbuffer contents to the display
g_pd3dmDevice->Present( NULL, NULL, NULL, NULL );

}


But the problem I'm having is that I have a class that I normally make full screen and then draw stuff in it, like so:

m_pFullScreen = new CFullView();

m_pFullScreen ->CreateEx(
WS_EX_TOPMOST,
AfxRegisterWndClass(
CS_HREDRAW | CS_VREDRAW,
0,
(HBRUSH)COLOR_WINDOW),
_T("Full View"),
WS_VISIBLE | WS_POPUP,
0,0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
NULL,
NULL);

Then I had a function in this class called UpdateDisplay() which used to use GXBeginDraw() etc to draw to screen but now I wish to use the code above in the Render function. It does not work (Nothing is drawn to the screen).

If the Render function is called from OnPaint then it works but if there is not an OnPaint() function(Which my CFullScreen class does not have as it is not a dialog) then it does not work

Does anyone know how to solve my problem

Thanks

Harry



Re: Visual C++ General Draw to screen without using OnPaint()

Pintu Shukla

Because OnPaint() Method is responsible for Updating your Screen .and when you call Render() Function inside OnPaint() that time it Work but when ever you Call this outside your OnPaint() it Will Not Invoke because OnPaint() invoke only at the time when your screen paint itself or refresh it. So if your want that Again OnPaint Will Come in Picture Simply call InvalidateRect() .which will make a call to your OnPaint Internally and again your are able to see your drawing stuff on your Screen.Second thing there is no need to call Render Function inside your OnPaint() Simply call it anywhere in your Program and to update your Screen call InvalidateRect() or RedrawWindow() Function etc.


Thanx





Re: Visual C++ General Draw to screen without using OnPaint()

Simple Samples

Harry123 wrote:
If the Render function is called from OnPaint then it works but if there is not an OnPaint() function(Which my CFullScreen class does not have as it is not a dialog) then it does not work

What is CFullScreen What is it derived from Non-dialog windows get sent the WM_PAINT message and it can be processed (override OnPaint). If you don't see an OnPaint or OnDraw fumction then you need to add a function to process the WM_PAINT message.