void CModelessDlg::OnDestroy() { CPersistDlg::OnDestroy(); GetSafeOwner()->SendMessage(UWM_MODELESSDESTROY, WPARAM(this)); // notify owner }
// // creates a new balloon window // Parameters: // strTitle | Title of balloon // strContent | Content of balloon // ptAnchor | point tail of balloon will be "anchor"ed to // unOptions | One or more of: // : unCLOSE_ON_LBUTTON_UP | closes window on WM_LBUTTON_UP // : unCLOSE_ON_MBUTTON_UP | closes window on WM_MBUTTON_UP // : unCLOSE_ON_RBUTTON_UP | closes window on WM_RBUTTON_UP // : unCLOSE_ON_LBUTTON_DOWN | closes window on WM_LBUTTON_DOWN // : unCLOSE_ON_MBUTTON_DOWN | closes window on WM_MBUTTON_DOWN // : unCLOSE_ON_RBUTTON_DOWN | closes window on WM_RBUTTON_DOWN // : unCLOSE_ON_MOUSE_MOVE | closes window when user moves mouse past threshhold // : unCLOSE_ON_KEYPRESS | closes window on the next keypress message sent to this thread. (!!! probably not thread safe !!!) // : unDELETE_THIS_ON_CLOSE | deletes object when window is closed. Used by LaunchBalloon(), use with care // : unSHOW_CLOSE_BUTTON | shows close button in upper right // : unSHOW_INNER_SHADOW | draw inner shadow in balloon // : unSHOW_TOPMOST | place balloon above all other windows // : unDISABLE_FADE | disable the fade-in/fade-out effects (overrides system and user settings) // : unDISABLE_FADEIN | disable the fade-in effect // : unDISABLE_FADEOUT | disable the fade-out effect // pParentWnd | Parent window. If NULL will be set to AfxGetMainWnd() and anchor to screen // strURL | If not empty, when the balloon is clicked ShellExecute() will // | be called, with strURL passed in. // unTimeout | If not 0, balloon will automatically close after unTimeout milliseconds. // hIcon | If not NULL, the icon indicated by hIcon will be displayed at top-left of the balloon. // // Returns: // TRUE if successful, else FALSE // BOOL CBalloonHelp::Create(const CString& strTitle, const CString& strContent, const CPoint& ptAnchor, unsigned int unOptions, CWnd* pParentWnd /*=NULL*/, const CString strURL /*= ""*/, unsigned int unTimeout /*= 0*/, HICON hIcon /*= NULL*/) { m_strContent = strContent; SetAnchorPoint(ptAnchor, pParentWnd); m_unOptions = unOptions; m_strURL = strURL; m_unTimeout = unTimeout; if ( NULL != hIcon ) SetIcon(hIcon); pParentWnd = GetSafeOwner(pParentWnd); if (NULL == pParentWnd) return FALSE; // if no fonts set, use defaults if ( NULL == m_pContentFont ) { m_pContentFont = new CFont; if ( !m_pContentFont->CreateStockObject(DEFAULT_GUI_FONT) ) return FALSE; } // title font defaults to bold version of content font if ( NULL == m_pTitleFont ) { m_pTitleFont = new CFont; LOGFONT LogFont; m_pContentFont->GetLogFont(&LogFont); LogFont.lfWeight = FW_BOLD; if ( !m_pTitleFont->CreateFontIndirect(&LogFont) ) return FALSE; } if ( !GetClassAtom() ) // couldn't register class return FALSE; // check system settings: if fade effects are disabled or unavailable, disable here too BOOL bFade = FALSE; ::SystemParametersInfo(SPI_GETTOOLTIPANIMATION, 0, &bFade, 0); if (bFade) ::SystemParametersInfo(SPI_GETTOOLTIPFADE, 0, &bFade, 0); if (!bFade || NULL == m_fnAnimateWindow) m_unOptions |= unDISABLE_FADE; // create invisible at arbitrary position; then position, set region, and finally show // the idea with WS_EX_TOOLWINDOW is, you can't switch to this using alt+tab DWORD dwExStyle = WS_EX_TOOLWINDOW; if ( m_unOptions&unSHOW_TOPMOST ) // make topmost, if requested dwExStyle |= WS_EX_TOPMOST; if ( !CreateEx(dwExStyle, _T("BalloonHelpClass"), strTitle, WS_POPUP, CRect(0,0,10,10), pParentWnd, 0, NULL) ) return FALSE; PositionWindow(); if ( (m_unOptions&unCLOSE_ON_MOUSE_MOVE) ||(m_unOptions&unCLOSE_ON_LBUTTON_UP) ||(m_unOptions&unCLOSE_ON_LBUTTON_DOWN) ||(m_unOptions&unCLOSE_ON_MBUTTON_UP) ||(m_unOptions&unCLOSE_ON_MBUTTON_DOWN) ||(m_unOptions&unCLOSE_ON_RBUTTON_UP) ||(m_unOptions&unCLOSE_ON_RBUTTON_DOWN) ) { ::GetCursorPos(&m_ptMouseOrig); SetMouseHook(); } // these need to take effect even if the window receiving them // is not owned by this process. So, if this process does not // already have the mouse captured, capture it! if ( (m_unOptions&unCLOSE_ON_LBUTTON_UP) ||(m_unOptions&unCLOSE_ON_MBUTTON_UP) ||(m_unOptions&unCLOSE_ON_RBUTTON_UP) ) { // no, i don't particularly need or want to deal with a situation // where a balloon is being created and another program has captured // the mouse. If you need it, it shouldn't be too hard, just do it here. if ( NULL == GetCapture() ) SetCapture(); } if ( m_unOptions&unCLOSE_ON_KEYPRESS ) SetKeyboardHook(); ShowBalloon(); return TRUE; }