CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Hybrid View

  1. #1
    Join Date
    Apr 2013
    Posts
    77

    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

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by manjut19 View Post
    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.
    Quote Originally Posted by manjut19 View Post
    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

  3. #3
    Join Date
    Apr 2013
    Posts
    77

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by D_Drmmr View Post
    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;

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by manjut19 View Post
    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

  5. #5
    Join Date
    Apr 2013
    Posts
    77

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by VictorN View Post
    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?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by manjut19 View Post
    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

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  8. #8
    Join Date
    Apr 2013
    Posts
    77

    Re: Continous sending of WM_PAINT message

    Sir please tell me what and all will be a reason for the failure of BeginPaint()function?

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by manjut19 View Post
    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

  10. #10
    Join Date
    Apr 2013
    Posts
    77

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by VictorN View Post
    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.

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  12. #12
    Join Date
    Apr 2013
    Posts
    77

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by VictorN View Post
    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;
    	
    }

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Continous sending of WM_PAINT message

    One more question: what are "Default painting" and "Modified painting"? how are they implemented?
    Victor Nijegorodov

  14. #14
    Join Date
    Apr 2013
    Posts
    77

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by VictorN View Post
    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

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured