Solved

Dialog : Button hides behind the Bitmap ( Picture control )

Posted on 2001-08-30
9
603 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
 
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
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 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

14 Experts available now in Live!

Get 1:1 Help Now