Writing a DLL encapsulation Dialog Box always involves how to get the window handle. Mark it and forget it.
1. directly obtain the handle
Getactivewindow (); // activate the window handle.
Getforegroundwindows (); // front-end window handle
Afxgetapp ()-> getmainwnd ()-> getsafehwnd () // It is common and involves many methods.
2. Enumeration type
Hwnd getwindow (
HwndHwnd,
UintUcmd); // You must first haveHwnd, and then specify ucmdRelationship
Hwnd find1_wex (
HwndHwndparent,
HwndHwndchildafter,
LpctstrLpszclass,
LpctstrLpszwindow); // Handle from the class name and window title. There may be more than one handle, so it is not uniquely determined.
3. Handle of other parameters
Process ID:
MARK: The ID obtained by the handle can be getwindowthreadprocessid ()
The handle of ID can only be enumerated and compared.
Repeat all the forms and obtain their corresponding hwnd to further obtain the corresponding PID, which is consistent with the known PID. Of course, you may need to judge the form status, if a process has only one form, no more.
Example:
If you want to display all windows in the list box
Bool callback enumwindowsproc (
Hwnd, // handle to parent window
Lparam // application-defined value
)
{
Char lpwintitle [256];
: Getwindowtext (hwnd, lpwintitle, 256-1 );
Cstring m_strtitle;
M_strtitle.format ("% s", lpwintitle );
Clistbox * p_l = (clistbox *) lparam;
If (! M_strtitle.isempty ())
{
P_l-> addstring (lpwintitle );
}
Return true;
}
Call enumwindows (enumwindowsproc, (lparam) getdlgitem (idc_list1 ));
This sectionProgramMark in the attached Assis DLL