-
GetDlgItem
鎖定
GetDlgItem,是根據繼承關係的函數功能,返回窗口中指定參數ID的子元素的句柄,可以通過返回的句柄對窗口內的子元素進行操作。
- 外文名
- GetDlgItem
- 説 明
- ,
- 返回值
- 標識所標記的控制窗口句柄
- 參數 nID
- 接收消息的控件的標識
GetDlgItem函數説明
根據繼承關係,有如下幾類:
(1).CWindow::GetDlgItem
HWND GetDlgItem( intnID)const;
説明——
參數 nID:接收消息的控件的標識;
返回值:標識所標記的控制窗口句柄;
(2).CWnd::GetDlgItem
CWnd* GetDlgItem ( intnID) const;
void CWnd::GetDlgItem( int nID, HWND *phWnd) const;
説明——
參數 nID:接收消息的控件的標識;
參數phWnd:子類窗口的指針;
返回值:標識所標記的控件(或子類窗口)的指針;
Example
// Uses GetDlgItem to return a pointer to a user interface control.
CEdit* pBoxOne;
pBoxOne = (CEdit*) GetDlgItem(IDC_EDIT1);
GotoDlgCtrl(pBoxOne);
(3).Windows SDK
HWND GetDlgItem
(HWNDhDlg, // handle to dialog box intnIDDlgItem// control identifier);
參數説明:
hDlg:標識含有控件的對話框。
nlDDlgltem:指定將被檢索的控件標識符。
備註:可以通過使用任何父子窗口對來使用GetDlgltem函數,而不僅只是對話框。只要hDlg參數指定一個父窗口,且子窗口有一個獨立的標識符(象CreateWindow中hMenu參數指定的或創建子窗口的CreateWindowEx指定的那樣),GetDlgltem就會返回一個有效的句柄到子窗口。
Windows CE:GetDlgltem函數只為對話框中的直接於控制工作,它不通過嵌套的對話框來搜尋。
速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:1.0及以上版本;頭文件:winuser.h;庫文件:user32.lib。
多數以GetDlgitem(控件標識符)來使用
GetDlgItem用法
C#
IntPtr hwnd;
IntPtr hwnd1;
IntPtr hwnd2;
IntPtr hwnd3;
IntPtr hwnd4;
hwnd = FindWindow(null, "QQ2011");
hwnd1 = GetDlgItem(hwndQQ, 0);
hwnd2 = GetDlgItem(hwnd1, 0);
hwnd3 = GetDlgItem(hwnd2, 894);
SendMessage(hwnd3, 194, 0, this.txtInput.Text);
hwnd4 = GetDlgItem(hwnd1, 1);
SendMessage(hwnd4, 245, 0, Convert.ToString(0));/*
GetDlgItem Function
TheGetDlgItemfunction retrieves a handle to a control in the specified dialog box.
Syntax
HWND GetDlgItem(HWNDhDlg, intnIDDlgItem);
Parameters
hDlg[in] Handle to the dialog box that contains the control.nIDDlgItem[in] Specifies the identifier of the control to be retrieved.
Return Value
If the function succeeds, the return value is the window handle of the specified control.
If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.
Remarks
You can use theGetDlgItemfunction with any parent-child window pair, not just with dialog boxes. As long as thehDlgparameter specifies a parent window and the child window has a unique identifier (as specified by thehMenuparameter in the CreateWindowor CreateWindowExfunction that created the child window),GetDlgItemreturns a valid handle to the child window.