Solved

Dialog : Button hides behind the Bitmap ( Picture control )

Posted on 2001-08-30
9
625 Views
Last Modified: 2013-11-20

 I created a dialog ( derives from CSimpleDialog ) with two controls in it
 1. Picture control 2. Button control. I placed the Button control on top of
 the Picture control. Picture control shows Bitmap in it. In the resource
 editor, the button control is visible on top of the Picture control. But
 at the run time, Button hides behind the bitmap. It becomes visible when
 i click on that area. I tried to change the z order of the button.
 I tried the following code.. Nothing works. Does any one knows how to
 place controls on top of a Picture control ?

LRESULT CAboutDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
     // Bring OK button to the front.
     HWND m_hwndOKButton = ::GetDlgItem(m_hWnd, ID_OK);
     if (m_hwndOKButton != NULL)
          ::SetWindowPos(m_hwndOKButton, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_FRAMECHANGED);

     HWND hwndPictureBox = ::GetDlgItem(m_hWnd, IDC_BITMAP);
     if (hwndPictureBox != NULL)
          ::SetWindowPos(hwndPictureBox, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_FRAMECHANGED);

     return 1;  // Let the system set the focus
}

I tried it with ::BringWindowToTop(buttonhandle) method. It didnt work. Is there
any way to bring the Button to the front ?


 TIA,

 Sankar S.

0
Comment
Question by:sankars98
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Accepted Solution

by:
BogdyPtr earned 150 total points
ID: 6442432
Try overriding OnPaint method of CDialog and call RedrawWindow for picture and then for button. This sould work.
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6442449
Nothing positive, but I would try:

   o Forcing the button to rease and repaint itself at the end of OnInitDialog
   o Setting the static (picture) control's TRANSPARENT and/or DISABLED styles

Just a couple of thoughts...

-=- James.
0
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6442483
It works. I just tested it.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 4

Expert Comment

by:jtwine100697
ID: 6442530
> Try overriding OnPaint method of CDialog and call RedrawWindow for picture and then for button. This
sould work
>
> It works. I just tested it.

Would you have to attach classes to, and manually have each of you GUI items redraw themselves in that example?  Meaning, if my dialog contains 23 other controls, do I have to trigger drawing for each of them as well?

-=- James.
0
 
LVL 1

Author Comment

by:sankars98
ID: 6442543

 jtwine,

    Thanks for the response. I tried it before. It didnt
    work.

 BogdyPtr, Excellent.. It worked.. But i tried it in WindowProc function. I am using ATL Dialog. Thanks..

 Sankar S.
0
 
LVL 1

Author Comment

by:sankars98
ID: 6442577

 > Meaning, if my dialog contains 23 other controls, do I have to trigger drawing for each of
them as well?

  jtwine, I didnt see your second response. Yes i think
  that's how i should do.. :(. But i tried several
  things. Nothing seems to be working. Can you tell me
  a better place to put that redraw code ? I dont want
  to put it in paint method ( WM_PAINT ). I will
  post another question if you like..
 
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6442895
When I try just putting a button overlapping a static control, it works for me just like that(!).

When you say "Picture Control", do you mean a static control that will display a bitmap, or some kind of custom "Picture" control?

-=- James.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6446013
Hi sankars98.

The proper way to fix your problem, is to change the order in the ResourceView.
Simple steps:
1. Display your dialog in the ResoureView.
2. Press Ctrl-D (Or main-menu Layout->TabOrder)
3. Change the order of your Bitmap control and the Button control.

What ever order you see it in, change it so that the opisite comes first.
This will change the order that your control is displayed.
0
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6446052
You don't have to trigger drawing for all controls, you must doit only for picture and then for the controls obscured by the picture.
Also u don't have to define classes for controls; there is a api function RedrawWindow.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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