-
September 27th, 2013, 12:16 AM
#1
Continous sending of WM_PAINT message
Hi all,
I have a win32 application,in that user can draw different shapes on the screen by selecting different tool bar buttons with mouse ie,user can select a toolbar button,then i will change the cursor shape based on button clicked,after that when user clicking on the client area,that shape will print there.
My problem is after printing(drawing) 15 or 20 shapes(same or different),application getting hang,I tried to trace out the problem,i found that after a drawing a 15 or 20 shapes,system continously sending WM_PAINT message.In my code for each printing time(Clicking on the screen)i am invalidating the client area,so every time (Clicking mouse on the client area)system will send WM_PAINT message and drawing the shape on client area.What may be the reason for a continous WM_PAINT message sending without getting clicked on the screen
Regards,
Manju
-
September 27th, 2013, 01:48 AM
#2
Re: Continous sending of WM_PAINT message
Originally Posted by manjut19
In my code for each printing time(Clicking on the screen)i am invalidating the client area,so every time (Clicking mouse on the client area)system will send WM_PAINT message and drawing the shape on client area.
That's not correct. All that invalidating the client area does, is tell the window to repaint itself the next time the message queue becomes empty. It doesn't send a WM_PAINT message directly.
Originally Posted by manjut19
What may be the reason for a continous WM_PAINT message sending without getting clicked on the screen
Well, you did something wrong. Maybe you are sending WM_PAINT messages yourself or calling UpdateWindow or invalidating in your WM_PAINT message handler. Hard to tell without seeing your code.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
September 27th, 2013, 04:42 AM
#3
Re: Continous sending of WM_PAINT message
Originally Posted by D_Drmmr
Well, you did something wrong. Maybe you are sending WM_PAINT messages yourself or calling UpdateWindow or invalidating in your WM_PAINT message handler. Hard to tell without seeing your code.
sorry sir, I canot post the code,because its a very big one,any way iam posting the WM_PAINT handler
Code:
case WM_PAINT:
GetClientRect(hWnd, &rc);
hdc = BeginPaint(hWnd, &ps);
SelectObject( hdc,hpen2);
if(g_bFirstPass)//First time blank screen
{
pLadder->SelectElement(hWnd,hdc,0); //Default painting
}
else if((!g_bEdting)) //user clicked on the screen for drawing
{
pLadder->SelectElement(hWnd,hdc,pLadder->m_iLastSelectedIndex); //Modified painting
}
else
break;
ReleaseDC(hWnd,hdc);
EndPaint(hWnd, &ps);
break;
-
September 27th, 2013, 05:29 AM
#4
Re: Continous sending of WM_PAINT message
Originally Posted by manjut19
Code:
case WM_PAINT:
GetClientRect(hWnd, &rc);
hdc = BeginPaint(hWnd, &ps);
SelectObject( hdc,hpen2);
if(g_bFirstPass)//First time blank screen
{
pLadder->SelectElement(hWnd,hdc,0); //Default painting
}
else if((!g_bEdting)) //user clicked on the screen for drawing
{
pLadder->SelectElement(hWnd,hdc,pLadder->m_iLastSelectedIndex); //Modified painting
}
else
break;
ReleaseDC(hWnd,hdc);
EndPaint(hWnd, &ps);
break;
1. You have to select the original pen after the drawing:
Code:
hdc = BeginPaint(hWnd, &ps);
HPEN hOldPen = SelectObject( hdc,hpen2);
...
SelectObject( hdc, hOldPen);
EndPaint(hWnd, &ps);
2. Why do you call ReleaseDC(hWnd,hdc);? You don't need it!
Victor Nijegorodov
-
September 27th, 2013, 05:47 AM
#5
Re: Continous sending of WM_PAINT message
Originally Posted by VictorN
2. Why do you call ReleaseDC(hWnd,hdc);? You don't need it!
ReleaseDC function to release the display device context,what i used.Isn't correct?
-
September 27th, 2013, 05:54 AM
#6
Re: Continous sending of WM_PAINT message
Originally Posted by manjut19
ReleaseDC function to release the display device context,what i used.Isn't correct?
From MSDN:
Remarks
The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common DC.
Do you call (and where?) either GetWindowDC function or the GetDC one?
Victor Nijegorodov
-
September 29th, 2013, 02:37 AM
#7
Re: Continous sending of WM_PAINT message
Well if you "have a doubt about WM_PAINT Message" why don't you read the documentation?
From MSDN WM_PAINT message:
The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.
...
Victor Nijegorodov
-
September 30th, 2013, 01:48 AM
#8
Re: Continous sending of WM_PAINT message
Sir please tell me what and all will be a reason for the failure of BeginPaint()function?
-
September 30th, 2013, 02:53 AM
#9
Re: Continous sending of WM_PAINT message
Originally Posted by manjut19
Sir please tell me what and all will be a reason for the failure of BeginPaint()function?
Do you mean the BeginPaint() function returns NULL?
In such a case only GetLastError can tell you the exact reason!
Victor Nijegorodov
-
September 30th, 2013, 03:16 AM
#10
Re: Continous sending of WM_PAINT message
Originally Posted by VictorN
Do you mean the BeginPaint() function returns NULL?
In such a case only GetLastError can tell you the exact reason!
The program runs fine for several hundreds of frames.Then randomly freezes. On failure, the call to BeginPaint() reurns NULL. Once it fails the first time, it never recovers,ie application hang (unless terminated and restarted). Calling GetLastError() immediately after BeginPaint fails return a invalid Dc handle
Last edited by manjut19; September 30th, 2013 at 03:26 AM.
-
September 30th, 2013, 03:29 AM
#11
Re: Continous sending of WM_PAINT message
Are you sure it is BeginPaint that fails with error code ERROR_DC_NOT_FOUND (1425)?
Please, post your actual code for painting, including all the error checkings!
Victor Nijegorodov
-
September 30th, 2013, 04:42 AM
#12
Re: Continous sending of WM_PAINT message
Originally Posted by VictorN
Are you sure it is BeginPaint that fails with error code ERROR_DC_NOT_FOUND (1425)?
Please, post your actual code for painting, including all the error checkings!
Ya iam getting the error code 1425.
Code:
LRESULT CALLBACK LadderWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc,hdc1;
RECT rc;
g_bFirstPass=true;
switch (message)
{
case WM_PAINT:
{
GetClientRect(hWnd, &rc);
hdc = BeginPaint(hWnd, &ps);
if(hdc==NULL)
{
DWORD dw=GetLastError();
break;
}
else
{
HPEN hOldPen=SelectObject( hdc,hpen2);
if(g_bFirstPass)
{
pLadder->SelectElement(hWnd,hdc,0); //Default painting
}
else if((!g_bEdting))
{
pLadder->SelectElement(hWnd,hdc,pLadder->m_iLastSelectedIndex); //Modified painting
}
SelectObject( hdc,hOldPen);
}
EndPaint(hWnd, &ps);
}
break;
case WM_COMMAND:
{
g_bFirstPass=false;
switch(LOWORD(wParam))
{
case ID_CIRCLE:
{
hdc1=GetDc(hWnd);
DrawCircle( hdc1);//calling a function to draw a circle
ReleaseDc(hWnd,hdc1);
}
break;
}
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
-
September 30th, 2013, 05:26 AM
#13
Re: Continous sending of WM_PAINT message
One more question: what are "Default painting" and "Modified painting"? how are they implemented?
Victor Nijegorodov
-
September 30th, 2013, 05:40 AM
#14
Re: Continous sending of WM_PAINT message
Originally Posted by VictorN
One more question: what are "Default painting" and "Modified painting"? how are they implemented?
Initialy before selecting any buttons some drawings are there in the screen that are drawing on the screen through default painting,if user selecting some tool bar button(shapes),that shape will be printing on the screen through modified painting.ID_CIRCLE is the identifier for one tool bar button of circle shape.In my development PC no internet connection,So each time i am typing the code for posting ,so only my coding is looking so bad,Sorry for the inconvienance.
Regards,
Manju
-
September 30th, 2013, 05:22 AM
#15
Re: Continous sending of WM_PAINT message
1. If you thought that so bad formatted code is easy to read/understand then you was wrong!
2. What is GetDc?
3. What is ReleaseDc?
4. What are you trying to do within the case ID_CIRCLE: of case WM_COMMAND:? Why "draw a circle" NOT in response to WM_PAINT?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|