在MFC中获取窗口句柄

转】 
 要找到某个CWnd对象的HWND,用GetSafeHwnd()。

 

在窗口类中,有句柄的成员变量,可以直接访问:   m_hWnd  
  在窗口类外,可以用AfxGetMainWnd()->m_hWnd获得。

 

 在MainFrame里直接用this;  
  其它地方用  
  CMainFrame*   pMainFrame   =   (CMainFrame*)theApp.m_pMainWnd;  

 

想得到一个控件的的句柄

GetDlgItem(ID…)->m_hWnd

 

得到视图的句柄

AfxGetMainWnd()->GetActiveView();

 

SDI:  
  ((CFrameWnd*)(AfxGetApp()->m_pMainWnd))->GetActiveView();  
   
  MDI:  
  ((CFrameWnd*)(AfxGetApp()->m_pMainWnd))->GetActiveFrame()->GetActiveView();

posted @ 2012-10-23 00:26  小城zjc  阅读(33)  评论(0)    收藏  举报