GetDlgItem()函数作用

  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.

phWnd

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.

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清水迎朝阳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值