<p>Has anyone implemented Lightbox style background dimming on a modal dialog box in a MFC/non .net app.<br>
I think the procedure would have to be something like:</p>

<p>steps:</p>

<ol>
<li><p>Get dialog parent HWND or CWnd*     </p></li>
<li><p>Get the rect of the parent window and draw an overlay with a translucency over that window  </p></li>
<li>allow the dialog to do it's modal draw routine, e.g DoModal()</li>
</ol>

<p>Are there any existing libraries/frameworks to do this, or what's the best way to drop a translucent overlay in MFC?<br>
<strong>edit</strong> Here's a mockup of what i'm trying to achieve if you don't know what 'lightbox style' means<br>
<strong>Some App</strong>:<br>
<img src="https://farm4.static.flickr.com/3065/2843243996_8a4536f516_o.png" alt="alt text">  </p>

<p>with a lightbox dialog box<br>
<img src="https://farm4.static.flickr.com/3280/2842409249_4a1c7f5810_o.png" alt="alt text"></p>

[{'answer_id': 51979, 'author': 'Brian Lyttle', 'author_id': 636, 'author_profile': 'https://Stackoverflow.com/users/636', 'pm_score': 2, 'selected': False, 'text': '<p>I think you just need to create a window and set the transparency. There is an MFC <a href="http://www.codeproject.com/KB/dialog/CGlassDialog.aspx" rel="nofollow noreferrer">CGlassDialog sample on CodeProject</a> that might help you. There is also an <a href="http://www.codeproject.com/KB/winsdk/quaker1.aspx" rel="nofollow noreferrer">article</a> on how to do this with the Win32 APIs.</p>\n'}, {'answer_id': 54341, 'author': 'geocoin', 'author_id': 379, 'author_profile': 'https://Stackoverflow.com/users/379', 'pm_score': 3, 'selected': True, 'text': '<p>Here\'s what I did* based on Brian\'s links<br>\nFirst create a dialog resource with the properties:</p>\n\n<ul>\n<li>border <strong>FALSE</strong></li>\n<li>3D look <strong>FALSE</strong></li>\n<li>client edge <strong>FALSE</strong></li>\n<li>Popup style</li>\n<li>static edge <strong>FALSE</strong></li>\n<li>Transparent <strong>TRUE</strong></li>\n<li>Title bar <strong>FALSE</strong>  </li>\n</ul>\n\n<p>and you should end up with a dialog window with no frame or anything, just a grey box.\noverride the Create function to look like this:  </p>\n\n<pre><code>BOOL LightBoxDlg::Create(UINT nIDTemplate, CWnd* pParentWnd)\n{\n\n    if(!CDialog::Create(nIDTemplate, pParentWnd))\n        return false;\n    RECT rect;\n    RECT size;\n\n    GetParent()-&gt;GetWindowRect(&amp;rect);\n    size.top = 0;\n    size.left = 0;\n    size.right = rect.right - rect.left;\n    size.bottom = rect.bottom - rect.top;\n    SetWindowPos(m_pParentWnd,rect.left,rect.top,size.right,size.bottom,NULL);\n\n    HWND hWnd=m_hWnd;  \n    SetWindowLong (hWnd , GWL_EXSTYLE ,GetWindowLong (hWnd , GWL_EXSTYLE ) | WS_EX_LAYERED ) ;\n    typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);\n    PSLWA pSetLayeredWindowAttributes;\n    HMODULE hDLL = LoadLibrary (_T("user32"));\n    pSetLayeredWindowAttributes = \n        (PSLWA) GetProcAddress(hDLL,"SetLayeredWindowAttributes");\n    if (pSetLayeredWindowAttributes != NULL) \n    {\n        /*\n        * Second parameter RGB(255,255,255) sets the colorkey \n        * to white LWA_COLORKEY flag indicates that color key \n        * is valid LWA_ALPHA indicates that ALphablend parameter \n        * is valid - here 100 is used\n        */\n        pSetLayeredWindowAttributes (hWnd, \n            RGB(255,255,255), 100, LWA_COLORKEY|LWA_ALPHA);\n    }\n\n\n    return true;\n}\n</code></pre>\n\n<p>then create a small black bitmap in an image editor (say 48x48) and import it as a bitmap resource (in this example IDB_BITMAP1)<br>\noverride the WM_ERASEBKGND message with:</p>\n\n<pre><code>BOOL LightBoxDlg::OnEraseBkgnd(CDC* pDC)\n{\n\n    BOOL bRet = CDialog::OnEraseBkgnd(pDC);\n\n    RECT rect;\n    RECT size;\n    m_pParentWnd-&gt;GetWindowRect(&amp;rect);\n    size.top = 0;\n    size.left = 0;\n    size.right = rect.right - rect.left;\n    size.bottom = rect.bottom - rect.top;\n\n    CBitmap cbmp;\n    cbmp.LoadBitmapW(IDB_BITMAP1);\n    BITMAP bmp;\n    cbmp.GetBitmap(&amp;bmp);\n    CDC memDc;\n    memDc.CreateCompatibleDC(pDC);\n    memDc.SelectObject(&amp;cbmp);\n    pDC-&gt;StretchBlt(0,0,size.right,size.bottom,&amp;memDc,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);\n\n    return bRet;\n}\n</code></pre>\n\n<p>Instantiate it in the DoModal of the desired dialog, Create it like a Modal Dialog i.e. on the stack(or heap if desired), call it\'s Create manually, show it then create your actual modal dialog over the top of it:  </p>\n\n<pre><code>INT_PTR CAboutDlg::DoModal()\n{\n    LightBoxDlg Dlg(m_pParentWnd);//make sure to pass in the parent of the new dialog\n    Dlg.Create(LightBoxDlg::IDD);\n    Dlg.ShowWindow(SW_SHOW);\n\n    BOOL ret = CDialog::DoModal();\n\n    Dlg.ShowWindow(SW_HIDE);\n    return ret;\n}\n</code></pre>\n\n<p>and this results in something <strong>exactly</strong> like my mock up above  </p>\n\n<p>*there are still places for improvment, like doing it without making a dialog box to begin with and some other general tidyups.</p>\n'}]
['https://Stackoverflow.com/questions/51687', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/379/']