若在子对话框中动态生成静态文本框,在点击按钮生成该对话框的同时就要创建静态文本框了。

1.首先,在子对话框类中添加CStatic m_staticText成员变量。

2.在点击button的处理函数中创建完子对话框后,添加如下代码:

1 CRect rect;
2 CWnd* pWnd;
3 pWnd = GetActiveWindow();
4 pWnd->GetClientRect(&rect);
5 m_prectTranDlg->m_staticText = new CStatic;
6 m_prectTranDlg->m_staticText->Create(_T("静态文本"),WS_CHILD|WS_VISIBLE|SS_CENTER|SS_CENTERIMAGE, 
7         rect, pWnd);

 

函数原型:

virtual BOOL Create(LPCTSTR lpszText,DWORD dwStyle,const RECT& rect,CWnd* pParentWnd,UINT nID = 0xffff);

函数说明:创建指定风格、指定内容的静态文本框

参数说明:

lpszText 指定静态文本框中要显示的内容

dwStyle 指定静态文本框的窗口风格,常用的有以下几种:

SS_BITMAP   Specifies a bitmap is to be displayed in the static control.

SS_CENTER   Designates a simple rectangle and displays the given text centered in the rectangle.

 

SS_CENTERIMAGE   Specifies that, if the bitmap or icon is smaller than the client area of the static control, the rest of the client area is filled with the color of the pixel in the top left corner of the bitmap or icon. If the static control contains a single line of text, the text is centered vertically in the client area of the control.(前面不知道说了什么,但是最后一句话说明可以使单行文本垂直居中)

rect 指定静态文本框放置的位置和大小,可以是CRect类,也可以是RECT类

pParentWnd  指定静态文本框的父窗口,通常是CDialog类,一定不能为NULL

nID  指定该静态文本框的空间ID

返回值:

 

非零代表创建成功,返回0说明创建失败

posted on 2013-08-07 22:13  胡小颖颖  阅读(620)  评论(0编辑  收藏  举报