Like Tree2Likes
  • 1 Post By SMurf
  • 1 Post By grumpy

Displaying a bmp file that is being changed

This is a discussion on Displaying a bmp file that is being changed within the Windows Programming forums, part of the Platform Specific Boards category; Hello World!! I hit a wall once again!. I have an application that performs some calculation and creates as a ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    8

    Question Displaying a bmp file that is being changed

    Hello World!!

    I hit a wall once again!. I have an application that performs some calculation and creates as a result a bmp file, then displays this result as a pop-up window (in a dialog box) that appears after pressing a button located in the main window.

    Then, if I changed the parameters for the calculation the application creates a new bmp file; but If I press the button again the resultant image is always the first one to be loaded, i.e. the display does not updates itself even though the file has changed.

    I did the implementation of the displaying of the image inside the WM_ERASEBKGND case of the dialog box procedure, using the LoadBitmap function. I do the cleaning and freeing of the Device context properly.

    The question is, why is this happening? How can I make the reading and displaying of the image responding in real time to the changes in the bmp file?

    Thanks a lot.

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,255
    Hard to say without showing your code. Do you delete the bitmap handle (with DeleteObject) at the end of the WM_ERASEBKGND handler?

    From a correctness point of view, this sort of thing is usually handled in WM_PAINT.
    Johnzzz likes this.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    5,884
    Quote Originally Posted by SMurf View Post
    From a correctness point of view, this sort of thing is usually handled in WM_PAINT.
    It is also necessary, when handling the WM_PAINT, to render the new image as needed.

    The process of updating an image (in memory, or on disk) is distinct from the process of rendering it. If an image is rendered, and then updated, it is necessary to render it again (or, at least, the parts that have changed).

    This may seem (because it is) a statement of the blindingly obvious, but I've seen a lot of people wondering why a display is not updated by magic when they change the object being displayed.
    Johnzzz likes this.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    8
    Quote Originally Posted by SMurf View Post
    Hard to say without showing your code. Do you delete the bitmap handle (with DeleteObject) at the end of the WM_ERASEBKGND handler?

    From a correctness point of view, this sort of thing is usually handled in WM_PAINT.
    Hello there,

    I solved the problem, by using the LoadImage function instead of LoadBitmap. In regard to your comment I do delete the handle a the end of WM_ERASEBKGND; that was not the problem in any case.

    Also you are right I could do this in the WM_PAINT message, but I do not see any difference and already works.

    Thanks.

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    8
    Quote Originally Posted by grumpy View Post
    It is also necessary, when handling the WM_PAINT, to render the new image as needed.

    The process of updating an image (in memory, or on disk) is distinct from the process of rendering it. If an image is rendered, and then updated, it is necessary to render it again (or, at least, the parts that have changed).

    This may seem (because it is) a statement of the blindingly obvious, but I've seen a lot of people wondering why a display is not updated by magic when they change the object being displayed.
    Thanks for your ideas, I already solved the problem by using LoadImage instead of LoadBitmap. Now it works as I want it to.

    On the other hand I was not expecting a magic update, I actually controlled the momment in which the image is loaded and displayed, so if the file changes, then the application must load the new file and then the display would be updated. As I said before, it works now.

    Thanks again.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by Johnzzz View Post
    Also you are right I could do this in the WM_PAINT message, but I do not see any difference and already works.
    WM_PAINT messages are generated using UpdateWindow(), often generated outside your app (by the users interaction with other windows).

    Only if the last param is TRUE will a WM_ERASEBKGND msg be generated.

    So as long as you don't mind some external and internal sources of paint msgs possibly NOT updaing your screen you will not have an issue.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 06-24-2011, 02:57 AM
  2. Replies: 3
    Last Post: 02-06-2011, 07:41 AM
  3. how gnu make tells if file's been changed?
    By thinhare in forum C Programming
    Replies: 2
    Last Post: 03-19-2008, 03:10 AM
  4. Wait a file to be changed
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 12-12-2005, 05:51 AM
  5. Displaying BMP file
    By nmalik in forum C Programming
    Replies: 2
    Last Post: 04-01-2002, 08:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21