Solved

Buttons disappearing on Dialog Box

Posted on 2003-11-18
7
332 Views
Last Modified: 2010-04-01
This is probably really simple and I'm just being totally stupid, but I have a Dialog Box created using no MFC. There's 2 buttons on the form which are hidden when the application begins.

At the end of the process the buttons need to be shown which i am doing using ShowWindow(hwndBtn, SW_SHOW). Then I call RedrawWindow(hwndBtn, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW) to redraw it. The only problem is every time the window is obscured the buttons don't get redrawn.

I thought that when a window is obscured the system automatically sends a WM_PAINT message to the window to redraw itself and it's child windows, but it doesn't appear to be doing this.

Any help would be much appreciated.

0
Comment
Question by:EvilMungo
  • 3
  • 3
7 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 9770413
those 2 buttons ... how were they created
did you make them childs of the dialog?
are they owner drawn?
do you subclass the standard windows button?

i'm asking those questions because the redrawing shoud be made automatcaly... unless you overide the WM_Paint message
0
 

Author Comment

by:EvilMungo
ID: 9770443
I have a dialog resource in my program that includes buttons which are not visible at run-time. They aren't owner drawn or subclassed.
When I then make them visible using ShowWindow they don't appear unless I call RedrawWindow (which I thought was strange).
Then if i move another window over the top and then bring the window back into view, the buttons have disappeared.
I haven't overridden the WM_PAINT message either.
0
 

Author Comment

by:EvilMungo
ID: 9778083
Ok, I've sorted this now. It was simply because I had a label covering the buttons so the window was obviously drawing the buttons first and then drawing the label over the top. My solution at the moment is to resize the label so it doesn't cover the buttons (this was ok because I only need a small portion of the label when the buttons become visible). Although this isn't the best solution it works.

If anybody can tell me how to do this without resizing, u get the 50 points.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 11

Expert Comment

by:Agarici
ID: 9778933
since all the controls in your dialog box are windows, you can reorder them - their Z order - (SetWindowPos) or just bring the buttons to top (BringWindowToTop)
0
 

Author Comment

by:EvilMungo
ID: 9779491
Thats what I thought I could do, but I tried that previously using SetWindowPos. I've now tried it using the BringWindowToTop (just incase it was me not using the SetWindowPos function correctly), and its still doing the same thing. Any ideas?
0
 
LVL 11

Accepted Solution

by:
Agarici earned 50 total points
ID: 9785753
probably you are doing something wrong ...

basically you shoud get the button hwnd using getdlgitem => hWndBtn
the same for the label => hWndLabel
use setwindowpos to insert hWndLabel after hWndBtn

in the flags param. of setwindowpos you must not specify swp_nozorder

this should work...




A.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10249272
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: Agarici {http:#9785753}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now