resizing a dialog box in MFC. is it possialbe?

Started by
4 comments, last by Endurion 19 years, 3 months ago
In my program,I want to hide some of the buttons until user click on a button called "advanced user".My idea is to size the dialog box small enough to cover up those buttons I dont wanna show,and resize it when the button is clicked.Is it possible to be done in MFC?how?thanks in advance.
Advertisement
Hi,

Of course it is possible.

When you receive your click, you can hide any dialog button by using CWnd *GetDlgItem(UINT nID). Using the resulting CWnd, you can ShowWindow(SW_HIDE) it. To resize your window, juste use this->MoveWindow(&newRect). Take care: this will not change the position of any control in the window. Therefore, you can use either hide them or create big empty areas.

Regards,
Thanks for helping me again.:)actually I tried rezise my dialog box using moveWindow() but it errors.when I debug it,I found out there is a ASSERT(isWindow(hwnd)) in moveWindow() function.because I am doing it in a dialog,so it gives me a assert violation.How can I solve that?
Make sure that your not doing it in a constructor. Also make sure the CWnd* thay you get is actually valid and not null.

Your not trying to hide the dialog are you, just temporarily hide the dialogs controls.
I actually know what is wrong with it now.for some reason,the dialog I created doesnt have m_hwnd.so it fails in the assertion.Can anybody tell me how that happens,pls?thanks
In MFC, a CDialog or any other CWnd derived class is NOT the same as a HWND. It encapsulates a HWND, but can exist without one.

In other words, if you simply call the constructor of a CDialog the dialog itself will not exist (yet). It will be created when calling any of the CreateDialog (modeless) or DoModal (modal) functions. Therefore, if you call any functions which need to be delegated to the HWND below, they won't work (assert) if there's no created HWND.

Call MoveWindow in OnCreate or better, OnInitDialog, not before.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement