[Quest] How to restore Objects of Window after WM_PAINT Message
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [Quest] How to restore Objects of Window after WM_PAINT Message

  1. #1
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    [Quest] How to restore Objects of Window after WM_PAINT Message

    I want to know how to restore objects that appear on window I will expalin in one Example;

    Example (1)

    case WM_COMMAND:
    /////// Draw One Line
    hdc=GetDC(hWnd);
    MoveToEx(hd1,300,20,NULL);
    LineTo(hd1,400,20);
    ReleaseDC(hWnd,hd1);
    /////////////////////////

    My Problem Now is , if I the Application sends WM_PAINT message , I see the line is disappeared,
    I know I can Draw the line under WM_PAINT message, But if I want to draw Line by using WM_COMMAND message , is thesr any tool to let me keep the objects on the window after application sent WM_PAINT Message.
    I try to use InvalidateRect() function but It was not working..

    Thanks & Regards

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,058

    Re: [Quest] How to restore Objects of Window after WM_PAINT Message

    The only one reliable place to draw something in window client area, is under WM_PAINT message.
    From any another place (e.g. from a command message) call InvalidateRect or RedrawWindow.
    That didn't work for you most possible because a mistake in your code.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    Re: [Quest] How to restore Objects of Window after WM_PAINT Message

    Thanks oviducucu,
    And I hope to find solution ,
    My Question is : How to get the content of window (Lines and dots) and restore it again after sending WM_PAINT message
    I hope Igor will provide us his effective answers..

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,051

    Re: [Quest] How to restore Objects of Window after WM_PAINT Message

    The main principle: window must be able to redraw itself at any moment of its life.

    This means:
    • application should support Model approach: a number of data structures containing every entity information at least in aspect of drawing. Typically this is implemented as a polymorphic class hierarchy for drawing primitives/shapes/sprites. The drawing primitive instances appear stored in containers of an appropriate type
    • application should support View approach: a rendering logic able to proceed based on the Model data. Typically this rendering occurs in response to every WM_PAINT message.
    • application should support Controller approach: a logic for changing Model data in response to input from user or any other source of events. Typically Controller is comprised of a number of message handlers performing changes to Model and initiating window self redraw by means of InvalidateRect. Ideally this should be a single per-window class implementing controlling logic.


    In accordance with this MVC approach you have your drawing not scattered all over the window procedure but being neatly structured and reliably tidy.
    Last edited by Igor Vartanov; September 30th, 2012 at 08:23 AM.
    Best regards,
    Igor

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,051

    Re: [Quest] How to restore Objects of Window after WM_PAINT Message

    See this post as a demo for the approach above.
    Best regards,
    Igor

  6. #6
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    Re: [Quest] How to restore Objects of Window after WM_PAINT Message

    Thanks Igor for your proffesional answers ;

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center