0

I have a dialog box with a list box,slider and a button. I tried to change the background color but I couldn't managed to change that, so i thought that if I add a "picture control" as a bitmap and put it in the background i will succed, but now the problem is that the "picture control" is on top of all the controls.

I tried to change the the tab control with Ctrl+d but it didn't change anything. I also tried to use SetWindowPos to top or buttom but also it didn't change anything.

I noticed that if I click in the location of the button it's brought to the front as I want. Is there any way to "click" all the controls at the begining? do i miss something in order to bring the control to the top?

David
  • 287
  • 2
  • 3
  • 13

2 Answers2

1

If you need to change the background colour of the dialog box, you need to handle the WM_CTLCOLORDLG message and return the handle to a brush (if the brush is not a stock object, make sure you delete the brush after the dialog box is closed) -- or, you can process the WM_ERASEBKGND message and erase the background yourself.

Edward Clements
  • 5,040
  • 2
  • 21
  • 27
  • I already tried the 2 methods and nothing happened. I prefer to understand how to change the order of the controls – David Jun 12 '13 at 14:33
  • If you would like to go ahead with the order of the controls, I would recommend what Balog Pal said above: edit the .rc file directly and move the picture control as the first control of the dialog. However, I have tried handling the `WM_CTLCOLORDLG` message in a simple "About" dialog box and it does work! `CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { m_hbrBackground = CreateSolidBrush(RGB(255, 0, 0)); }` `CAboutDlg::~CAboutDlg() { DeleteObject(m_hbrBackground); }` in the WindowProc: `if (message == WM_CTLCOLORDLG) return (LRESULT) m_hbrBackground;` – Edward Clements Jun 12 '13 at 15:12
  • MSDN article on [Changing the Tab Order of Controls](http://msdn.microsoft.com/en-us/library/csz6b8x8.aspx) – Edward Clements Jun 12 '13 at 15:49
  • I know how to change the tab order. I need to change the "z order" of the controls. I tried to change the tab order because I read that in that way I change also the "z order" – David Jun 12 '13 at 19:19
0

I tried to change the the tab control with Ctrl+D but it didn't change anything. I also tried to use SetWindowPos to top or buttom but also it didn't change anything.

Ctrl+D does get you in reordering mode, however there is a more reliable way of checking. The dialog template is in text form in .RC file, where you can review the order of control with text editor and sort lines manually the way you wish. This will be the order of control creation and tab order as well. Sometimes it's even easier to reorder controls this way.

More to that, when your application is running, Spy++ SDK tool can enumerate windows and again it will give you window order for checking.

SetWindowPos with proper arguments changes Z-order of controls on runtime as well.

Roman R.
  • 68,205
  • 6
  • 94
  • 158