MSDN中的解释:
Retrieves a pointer to the specified control or child window in a dialog box or other window
即:返回一个指向指定控件或子窗口的指针。
CWnd* GetDlgItem(
int nID
) const;
void GetDlgItem(
int nID,
HWND* phWnd
) const;
nID
Specifies the identifier of the control or child window to be retrieved.
A pointer to a child window.
比如:绘图时,需要获得对话框中picture控件的信息,这时就需要使用GetDlgItem()
程序如下:
CPaintDC dc(this);
CWnd *pwnd=GegDlgItem(IDC_SHOW);
然后就可以用pwnd 进行绘图操作
绘图时要进行坐标变换
CRect rect;
HDC hdc;
pwnd->GetWindowRect(rect); // 获得屏幕坐标
ScreenToClient(rect); // 转换为客户坐标
hdc=dc.GetSafeHdc(); // 获得设备描述表句柄
MoveToEx(hdc,sub,rect.top,NULL);
LineTo(hdc,sub,rect.bottom);
...
...
又比如: 我们要获得对话框中 ID为 IDC_EDIT1 控件的信息
需要用到如下语句:
CEdit *pEdit;
pEdit=(CEdit *)GetDlgItem(IDC_EDIT1);
GotoDlgCtrl(pEdit); // Moves the focus to the specified control in the dialog box.