CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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

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

    Re: Continous sending of WM_PAINT message

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

  3. #18
    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

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

    Re: Continous sending of WM_PAINT message

    I don't care whether your "development PC" does or does not "internet connection".
    It's up to you to post your actual and properly formatted code if you hope to get some help from this Forum!
    What prevents you to copy/paste code from one PC to another? Don't you have some USB stick?
    Victor Nijegorodov

  5. #20
    Join Date
    Apr 2013
    Posts
    77

    Re: Continous sending of WM_PAINT message

    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))
              {
                // idea got from msdn.microsoft.com/en-us/library/windows/desktop/dd162493
                   case ID_CIRCLE:
                   {
                      hdc1=GetDc(hWnd);//Retrieve  a handle to  a DC
                      DrawCircle( hdc1);//calling a function to drawing without WM_PAINT message
                      ReleaseDc(hWnd,hdc1);//Release Dc
                   
                     }
                    break;
               }
            }
           break;
    
         default:
    			
          return DefWindowProc(hWnd, message, wParam, lParam);
            break;
       }
    return 0;
    	
    }
    Last edited by manjut19; September 30th, 2013 at 06:30 AM.

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

    Re: Continous sending of WM_PAINT message

    I have to repeat my quesrtions:
    Quote Originally Posted by VictorN View Post
    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?

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

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

    Re: Continous sending of WM_PAINT message

    Quote Originally Posted by manjut19 View Post
    Code:
    ...
           case WM_COMMAND:
           {
              g_bFirstPass=false;
              switch(LOWORD(wParam))
              {
                // idea got from msdn.microsoft.com/en-us/library/windows/desktop/dd162493
                   case ID_CIRCLE:
                   {
                      hdc1=GetDc(hWnd);//Retrieve  a handle to  a DC
                      DrawCircle( hdc1);//calling a function to drawing without WM_PAINT message
                      ReleaseDc(hWnd,hdc1);//Release Dc
                   
                     }
                    break;
    ...
    The link you posted contains this:
    An application that enables drawing, as in this example, typically records either the points or lines so that the lines can be redrawn whenever the window is updated.
    In other words, you need to do all your drawing in the WM_PAINT handler (or functions that are only called from there). If you draw in the WM_COMMAND handler, whatever you draw will be gone when the window gets repainted.
    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

  8. #23
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Continous sending of WM_PAINT message

    You use GetDC and ReleaseDC to obtain and release a handle to a device context.

    Note also that in your WM_PAINT message, g_bFirstPass will always be true as it is always set to true before the switch statement!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 2 FirstFirst 12

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