您的位置:首页 > 其它

how to get internal items from a dialog created from wizard of VC2005

2009-12-03 19:46 453 查看
1. It is pretty fast and convinient to create a dialog based application from VC2005's

project wizard. But Once you created it, it is very difficult for you to customize it.

For example, modifying a dialog based project into a multi-document one requires much more

efforts than create it from project wizard directly.

2. If, after creating a dialog based application, you want to cutomize it, say changing the

languages, changing some properties of the items. A dialog sceleton contains a label,

instance of CStatic, two buttons, an about dialog and a main dialog(that dialog which will be

showed). Chances are that you want to change the titles or the contents of the label. To do that,

you have to get the instances of the items. Then you can change their properties through their

member functions. To get the instances, you must provide their ids, which are their identifications.

Those items are contained by the main dialog, which is the parent of those items. You can get the

child items through their ids. Here main dialog is the parent and its label and its buttons are

child items. Function:

GetDlgItem(const int id);

are used to retrieve child items from parent instance.

Here to get the label, the two buttons from a typical dialog based applicaiton.

button_cancel = (CButton *) GetDlgItem(IDCANCEL); // you should change IDCANCEL to your id
            button_ok = (CButton *) GetDlgItem(IDOK);
            label = (CStatic *) GetDlgItem(IDC_STATIC1);



Then you can set properties for those items, e.g. change the title:

label->SetWindowText(label_tip); // label_tip is the contents you want
            button_ok->SetWindowText(ok_title); // title for button OK
            button_cancel->SetWindowText(cancel_title);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: