up hwnd is only id in the windows program and control of windows
Relationship Between a C++ Window Object and an HWND Home | Overview | How Do I | TutorialThe window object is an object of the C++ CWnd class (or a derived class) that your program creates directly. It comes and goes in response to your program’s constructor and destructor calls. The Windows window, on the other hand, is an opaque handle to an internal Windows data structure that corresponds to a window and consumes system resources when present. A Windows window is identified by a “window handle” (HWND) and is created after the CWnd object is created by a call to the Create member function of class CWnd. The window may be destroyed either by a program call or by a user’s action. The window handle is stored in the window object’s m_hWnd member variable. The following figure shows the relationship between the C++ window object and the Windows window. Creating windows is discussed in Creating Windows. Destroying windows is discussed in Destroying Window Objects. Detaching a CWnd from Its HWND Home | Overview | How Do I | TutorialIf you need to circumvent the object-HWND relationship, MFC provides another CWnd member function, Detach, which disconnects the C++ window object from the Windows window. This prevents the destructor from destroying the Windows window when the object is destroyed. What do you want to know more about? Creating windows Window destruction sequence Allocating and deallocating window memory
CWnd *pp;
HWND hWnd=pp->GetSafeHwnd();
hwnd is only id in the windows program and control of windows
Home | Overview | How Do I | TutorialThe window object is an object of the C++ CWnd class (or a derived class) that your program creates directly. It comes and goes in response to your program’s constructor and destructor calls. The Windows window, on the other hand, is an opaque handle to an internal Windows data structure that corresponds to a window and consumes system resources when present. A Windows window is identified by a “window handle” (HWND) and is created after the CWnd object is created by a call to the Create member function of class CWnd. The window may be destroyed either by a program call or by a user’s action. The window handle is stored in the window object’s m_hWnd member variable. The following figure shows the relationship between the C++ window object and the Windows window. Creating windows is discussed in Creating Windows. Destroying windows is discussed in Destroying Window Objects.
Detaching a CWnd from Its HWND
Home | Overview | How Do I | TutorialIf you need to circumvent the object-HWND relationship, MFC provides another CWnd member function, Detach, which disconnects the C++ window object from the Windows window. This prevents the destructor from destroying the Windows window when the object is destroyed. What do you want to know more about?
Creating windows
Window destruction sequence
Allocating and deallocating window memory
这需要看具体函数~
比如
Messagebox();中的HWND hWnd,可以用NULL~
有的函数中的用this代替就可以了~
有的是Windows中自己定义的全局变量……
如:
SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
m_hWnd就是基于对话框程序的的指针~
有的需要你去获得~
CWnd* pCAPwnd=GetDlgItem(IDC_EDIT_CAPTION);//取得编辑框的类指针
SendMessage(pCAPwnd->GetSafeHwnd(),WM_SETTEXT,0,(LPARAM)(LPCTSTR)m_EditPos);有时你无法获得HWND~这就需要你去进行强制类型转换~
如:HWND pCAPwnd=(HWND)GetDlgItem(IDC_EDIT_CAPTION);
//GetDlgItem得到的是CWnd* ~我们需要把它进行转换成HWND~
HWND h=AfxGetApp()->m_pMainWnd->m_hWnd;