Jump to content
  • Advertisement
Sign in to follow this  
jimywang

resizing a dialog box in MFC. is it possialbe?

This topic is 4914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!