獲得一個對話方塊上的所有控制項

來源:互聯網
上載者:User

方法一:
m_hWnd代表對話方塊window  
  HWND   hwndChild   =   GetWindow(   m_hWnd   ,   GW_CHILD   );  
  while(   hwndChild   )  
  {  
  hwndChild   =   GetWindow(   hwndChild   ,   GW_HWNDNEXT   );  
  }

GetWindow
The GetWindow function retrieves a handle to a window that has the specified relationship (Z order or owner) to the specified window.

HWND GetWindow(
  HWND hWnd,  // handle to original window
  UINT uCmd   // relationship flag
);

Parameters
hWnd
Handle to a window. The window handle retrieved is relative to this window, based on the value of the uCmd parameter.
uCmd
Specifies the relationship between the specified window and the window whose handle is to be retrieved.
This parameter can be one of the following values: Value Meaning

GW_CHILD   The retrieved handle identifies the child window at the top of the Z order,
     if the specified window is a parent window; otherwise, the retrieved handle is NULL.
     The function examines only child windows of the specified window.
     It does not examine descendant windows.
GW_HWNDNEXT The retrieved handle identifies the window below the specified window in the Z order.
     If the specified window is a topmost window, the handle identifies the topmost window below
     the specified window. If the specified window is a top-level window,
      the handle identifies the top-level window below the specified window.
      If the specified window is a child window, the handle identifies the sibling window
       below the specified window.
....
請查看msdn獲得更多資訊

方法二:
vector<HWND> hwv;
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
 TCHAR buf[100];

 ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
 if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 ) /

{
  *(HWND*)lParam = hwnd;//子視窗控制代碼哦
  hwv.push_back( hwnd ); //收集所有的字視窗控制代碼
  //return FALSE;
 }
 else
  return TRUE;
};

//You can store the interface pointer in a member variable
//for easier access
void CDlg::OnGetDocInterface()
{
  HWND hWnd = this->m_hWnd;
  if ( hWnd != NULL )
  {
   HWND hWndChild=NULL;
   // Get 1st document window
   /*
   系統會尋找hWnd的字視窗,然後對每一字視窗都要調用函數EnumChildProc
   並把字視窗的控制代碼欻給函數EnumChildProc,另外還會把參數(LPARAM)&hWndChild 傳給EnumChildProc,
   所以每一個回調EnumChildProc,傳進去的參數有一個都是相同的(即 (LPARAM)&hWndChild).
   另外一個參數則總是不同(即字視窗控制代碼).
   只有當 對所有字視窗都進行回呼函數的調用或者回呼函數返回FLASE,EnumChildWindows才會返回.
   */
   ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );
   if ( hWndChild )
   {
   
   } // else document not ready
  }

}

EnumChildWindows
The EnumChildWindows function enumerates the child windows that belong to the specified parent window
by passing the handle to each child window, in turn, to an application-defined callback function.
 EnumChildWindows continues until the last child window is enumerated
 or the callback function returns FALSE.

BOOL EnumChildWindows(
  HWND hWndParent,         // handle to parent window
  WNDENUMPROC lpEnumFunc,  // pointer to callback function
  LPARAM lParam            // application-defined value
);
....
請查看msdn獲得更多資訊
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.