CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2009
    Posts
    3

    Question Help with picture box

    Hello. I am trying to add to a math game (Visual C++, MFC, dialog based app) that I have developed for my daughter. Trying to make it a little more graphics based, and thus, more entertaining for her. I am having a problem. I made a simple bitmap icon in the resource editor. I have associated the picture box with the bitmap icon (under picture box properties (IDC_ANSWERICON in my program, "image" property is set to corresponding bitmap). When the program starts, the idea is to hide the picture box with the following code:

    this -> GetDlgItem (IDC_ANSWERICON) -> ShowWindow (SW_HIDE); // this part works

    When she correctly answers the math problem, I un-hide the picture box:

    this -> GetDlgItem (IDC_ANSWERICON) -> ShowWindow (SW_SHOW); // this part does NOT work
    UpdateData (FALSE); // Update the dialog
    wait (2); // wait 2 seconds to allow user time to see icon

    Then I hide the icon again. However, the icon never appears. Additionally I have a message box that I want to phase out. Oddly enough, if I leave the code in for the message box, the icon appears. I'm not sure what I am doing wrong. I want to take out the message box because it covers up the icon and is wholly unnecessary at this point in my daughter's educational development.

    Hopefully I have included enough information in my posting. If not, please let me know. I have taken college courses in C++, but I am pretty new at Visual C++- so take it easy on me. If there is a better way to do this, I would like to know but keep in mind I am a newbie and may need it broken down a little. Thanks for all of your help. It is greatly appreciated!

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Help with picture box

    What's with the wait function?
    Does it have a loop in it?

    Try Sleep(2000) to wait for 2 seconds.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Aug 2009
    Posts
    3

    Re: Help with picture box

    Any thoughts on my actual problem????

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Help with picture box

    When you call wait it kicks in before the picture box gets a chance to draw itself. When wait expires you tell the picture box to hide itself again. So in effect, you never really give it a chance to draw itself. Try calling UpdateWindow on the picture box before the wait call.

  5. #5
    Join Date
    Aug 2009
    Posts
    3

    Smile Re: Help with picture box

    GCDEF,

    Thanks for your input. Your solution was most helpful and solved my problem. It's very frustrating getting stuck, even on a simple program such as mine. By the way, what's the difference between UpdateDialogControl, UpdateWindow, and UpdateData??? UpdateWindow is the only one that worked in this case, as I had tried the other two and met only with utter hopelessness.

    Thanks again for the solution!

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Help with picture box

    Quote Originally Posted by abollmeyer View Post
    GCDEF,

    Thanks for your input. Your solution was most helpful and solved my problem. It's very frustrating getting stuck, even on a simple program such as mine. By the way, what's the difference between UpdateDialogControl, UpdateWindow, and UpdateData??? UpdateWindow is the only one that worked in this case, as I had tried the other two and met only with utter hopelessness.

    Thanks again for the solution!
    Glad I could help. MSDN would do a better job explaining those functions that I could, but basically UpdateWindow forces the target window to redraw itself immediately. UpdateData transfers information between controls and variables. I'm not familiar with UpdateDialogControl.

Tags for this Thread

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