GetDlgItem()函数

 

MSDN中的解释:

Retrieves a pointer to the specified control or child window in a dialog box or other window

即:返回一个指向指定控件或子窗口的指针。

CWnd* <span style="color: rgb(255, 255, 255); background-color: rgb(49, 106, 197);">GetDlgItem</span>(
   int nID 
) const;
void <span style="color: rgb(255, 255, 255); background-color: rgb(49, 106, 197);">GetDlgItem</span>(
   int nID,
   HWND* phWnd
) const;
<dt><span class="nonLinkTerms"><span class="parameter"><em>nID</em></span> </span></dt><dd><p>Specifies the identifier of the control or child window to be retrieved.</p></dd><dt><span class="nonLinkTerms"><span class="parameter"><em>phWnd</em></span> </span></dt><dd><p>A pointer to a child window.</p></dd>

比如:绘图时,需要获得对话框中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.

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值