GetDlgItem

GetDlgItem

GetDlgItem,是根據繼承關係的函式功能,返回視窗中指定參數ID的子元素的句柄,可以通過返回的句柄對視窗內的子元素進行操作。

基本介紹

  • 外文名:GetDlgItem
  • 說明:,
  • 返回值:標識所標記的控制視窗句柄
  • 參數 nID:接收訊息的控制項的標識
函式說明,用法,

函式說明

根據繼承關係,有如下幾類:
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:指定將被檢索的控制項標識符
返回值:如果函式調用成功則返回值為給定控制項的視窗句柄。如果函式調用失敗,則返回值為NULL,表示為一個無效的對話框句柄或一個不存在的控制項。若想獲得更多錯誤信息,請調用GetLastError函式。
備註:可以通過使用任何父子視窗對來使用GetDlgltem函式,而不僅只是對話框。只要hDlg參數指定一個父視窗,且子視窗有一個獨立的標識符(象CreateWindow中hMenu參數指定的或創建子視窗的CreateWindowEx指定的那樣),GetDlgltem就會返回一個有效的句柄到子視窗。
Windows CE:GetDlgltem函式只為對話框中的直接於控制工作,它不通過嵌套的對話框來搜尋。
速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:1.0及以上版本;頭檔案:winuser.h;庫檔案:user32.lib。
多數以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.

相關詞條

熱門詞條

聯絡我們