Another tip: Use Spy++ to eyeball the controls. Looking at the NextChild, etc. window relationships might shake something loose that explains what's happening.
Main Topics
Browse All TopicsI have two CBitmapButtons. One is dragable by the mouse, the other is static on the screen. It is essentially a slider control made just from CbItmapButtons.
In, OnInitDialog() I call,
ButtonBase.Create(_T("btnb
ButtonBase.LoadBitmapFF(St
ButtonBase.SizeToContent()
Button1.Create(_T("btn1"),
Button1.LoadBitmapFF(Strin
Button2.Create(_T("btn2"),
Button2.LoadBitmapFF(Strin
This is basically what i have, Their is 30 of the base buttons(ButtonBase)
making a solid bar about 800 pixels long. Button1&2 are the position
indicators.
When i launch with this code the dialog comes up and the Position Button(Button2, aka "PB") is drawn under neath the Base Button(ButtonBase, aka "BB"). I've tried using every combination of SetWindowPos i can think of and also a few other functions like SetWindowPlacement. I tried changing the order of the Create() functions above and using SetWindowPos and others. Every time it comes out it either draws properly and you cant click it or it draws improperly and you can click it and then it looks fine. Right now with the above code i can call Button2.Invalidate() From a separate button press call of another button on the screen or i can call it X number of seconds from a separate thread that is sleeping upon start up. It then redraws the PB on top of the BB properly. But if i try calling Button2.Invalidate() in OnInitDialog(), the PB does not draw on top of BB. It will Stay behind it. Outside of making some kind of ungly work around i've run out of ideas. Any help is appreciated.
Just a side note. The resource ID being used in the above code it the ID of button created through the resource editor. The tab order is set properly on the buttons in the dialog. But by creating these dynamically, i'm pretty sure it overrides the tab order from the resource editor. And the buttons have their "Visible" State set to "false" as they are just plain CButtons and im using bitmap buttons.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If I understand the question, SetWindowPos should be enough - with HWND_TOP or HWND_TOPMOST (&wdnTopMost in MFC). You need to change the z-order. Can you show the line with SetWindowPos that does not work? Something like the following:
pBtn->SetWindowPos(&CWnd::w
SWP_NOMOVE|SWP_NOSIZE|SWP_
Do you control the focus? Which button is focused when you see the problem? Probably, not the PB?
Thanks for the quick reply Dan. It works now, although its a work around. I don't have the time to figure out what the little discrepancy is. Question now is will it give me anymore issues when i add another button in between these two...:) Nothing can ever be simple.
pgnatyuk, i had previously tried that. Not sure if i tried it exactly like that so i gave it another try and i got one of the same results as before. The PB Draw underneath the BB. But when you click it, it brings it right to the top and stay on top the rest of the time. Worked, but only half way. Thanks though.
Would like to make one note, thanks for assuming the obvious and not nit picking little things i left out, and turning the whole thing into flaming requiring a explanation for every little thing when it's not needed.
Business Accounts
Answer for Membership
by: DanRollinsPosted on 2009-10-29 at 16:49:46ID: 25699259
I am assuming that you call CDialog::OnInitDialog early in your own OnInitDialog().
With proper setup, this should not happen. The buttons should be drawn in Tab Order, so if the one you want topmost is drawn last, it should look correct.
That said... there is a trick I'vve used to get something down without a timer and to enforce a cetain sequence of events:
At the end of OnInitDialog(), post a user-defined message to yourself. Just
#define WM_ContinueInit (WM_APP+100)
...then...
PostMessage( WM_ContinueInit );
or whatever (if you need help with this let me know). It's important to use PostMessage (not SendMessage).
The result is that the dialog is completely initialized when your "WM_ContinueInit" handler gets control. At that point, you can Invalidate, move, set topmost, etc... whatever makes things work right.