The previous Windows MFC global modal implementation introduced the first method, but there is a problem with this method, even if you can not click outside the dialog box, click the mouse outside the box, the current need to manipulate the window is also lost focus. This affects the user experience more seriously. And there is a problem, if you want to fit 32-bit, 64-bit system, to achieve global mode (disable mouse effect) requires 32, 64-bit two libraries, and to be called by 32, 64-bit system, respectively. The use of conditional restrictions is more stringent.
So here's a note on how to use transparent windows:
1. Insert a dialog box in the project
2. Set the dialog box property to remove the tick of the title bar
3, add a OnInitDialog function, in this function to implement subsequent calls
4. Add a full screen to the Settings dialog box within the OnInitDialog
<span style= "White-space:pre" ></span>crect m_fullscreenrect;int nfullwidth=getsystemmetrics (SM_ cxscreen); int nfullheight=getsystemmetrics (sm_cyscreen); m_fullscreenrect.left = 0;m_fullscreenrect.top = 0;m_ Fullscreenrect.right = m_fullscreenrect.left + nfullwidth;m_fullscreenrect.bottom = m_FullScreenRect.top + nFullHeight ; MoveWindow (0,0,m_fullscreenrect.width (), M_fullscreenrect.height (), 1);
5. Increase the transparency of the Setup dialog box in OnInitDialog
<span style= "White-space:pre" ></span>typedef BOOL (WINAPI *lpfnsetlayeredwindowattributes) (HWND hwnd, COLORREF Crkey, BYTE balpha, DWORD dwFlags); Lpfnsetlayeredwindowattributes setlayeredwindowattributes;// Set into Edge transparent COLORREF maskcolor=rgb (0,0,0); Hmodule HUser32 = GetModuleHandle (TEXT ("user32.dll")); Load dynamic link library setlayeredwindowattributes = (lpfnsetlayeredwindowattributes) GetProcAddress (HUser32, " SetLayeredWindowAttributes ");//Get SetLayeredWindowAttributes function pointer//For window Add ws_ex_layered extended property SetWindowLong (this-> GetSafeHwnd (), Gwl_exstyle, GetWindowLong (GetSafeHwnd (), Gwl_exstyle) ^ws_ex_layered);// Call the Setlayeredwinowattributes function SetLayeredWindowAttributes (This->getsafehwnd (), MaskColor, 1, LWA_ALPHA); To set at least 1 transparency, 0 indicates that the dialog box does not exist FreeLibrary (HUSER32); Releasing a dynamic-link library
6. Call the DoModal of the transparent full-screen box in the original parent window of the dialog box that needs modal
7, in the Transparent full-screen box OnInitDialog finally increase the thread calls need modal dialog box DoModal. The reason for using thread invocation is to prevent blocking normal pop-up full-screen transparent box
8, after the thread call needs the modal box DoModal, increases the transparent box exit code
Over
Project Source
The most significant improvement in this approach is the encapsulation of the dialog box: Assuming that there are multiple dialogs that require global modal, directly inheriting a class, it automatically becomes a dialog box with global modal properties, rather than having to write code separately for each dialog box.
Windows MFC Global Modal Implementation (II)