开发者

Manually create a dialog child window using an ID from resource.h

开发者 https://www.devze.com 2023-01-02 17:15 出处:网络
I want to add a simple panel to a dialog created using Visual Studio resource editor, but the resource editor doesn\'t allow this - I need to add my own CWnd as a dialog child. However that way I thin

I want to add a simple panel to a dialog created using Visual Studio resource editor, but the resource editor doesn't allow this - I need to add my own CWnd as a dialog child. However that way I think I have to use CWnd::Create manually, and pass in names for the class and the window.

I want to create an ID like IDC_MYPANEL, and as much as possible add the window so it works like something de开发者_StackOverflow中文版fined in the template. What's the right way to do this, and what's the best MFC class to use as a simple panel... just use CWnd itself?


What do you mean by 'a simple panel'? If it's a custom control, derive from CWnd, override Create() and call CWnd::Create() with NULL as the class name so that MFC makes its own, and add a line to resource.h with the IDC_XXX value of your control. If it's a sub-dialog, with controls on it, derive from CDialog and call CDialog::Create() with the IDD that you define in your dialog.

The only difference when creating a control at runtime is that in OnInitDialog, you do some Create() and initialisation things, and you don't include a DDX_Control() line for that control. For the rest everything works the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消