XBalloonMsg - a non-MFC balloon-shaped message box

来源:互联网 发布:websoc是什么软件 编辑:程序博客网 时间:2024/06/07 05:57
原文链接:XBalloonMsg - a non-MFC balloon-shaped message box

只需要调用下面两个函数:

Function

Description

void Show()

显示气泡状信息

void Destroy()

从屏幕上删除气泡状信息


//=============================================================================
// special symbol for title string - replaced with module name
#define LPCTSTR_DEFAULT_TITLE    ((LPCTSTR)-1L)

//=============================================================================
class CXBalloonMsg
//=============================================================================
{
// Construction
public:
    CXBalloonMsg();
    
virtual ~CXBalloonMsg();

// Attributes
public:
    
static HWND m_hWndBalloon;

// Operations
public:
    
static void Show(LPCTSTR lpszTitle, 
                     LPCTSTR lpszMsg, 
                     HWND hCtrl, 
                     HWND hParent,
                     HINSTANCE hInstance,
                     UINT nIcon 
= TTI_INFO,
                     BOOL bUseBalloonTips 
= TRUE,
                     UINT nTimeOutSeconds 
= 0,
                     LPRECT pRect 
= NULL);
    
static void Destroy();

// Implementation
protected:
    
static LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
    
static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
    
static LRESULT __stdcall DefWindowProcX(HWND hWnd,
                                UINT message,
                                WPARAM wParam,
                                LPARAM lParam);
    
static void CALLBACK TimerProcX(HWND hwnd,
                                UINT message,
                                UINT_PTR nIdEvent,
                                DWORD dwTime);
    
static BOOL GetEnableBalloonTips();
    
static void GetStrings(LPCTSTR lpszTitle, LPCTSTR lpszMsg, HINSTANCE hInstance);
    
static TCHAR * GetModuleName(HINSTANCE hInstance);
    
static void PositionBalloon(LPRECT pRect, LPRECT pNewRect, BOOL bBalloon);

    
static BOOL            m_bInit;            // TRUE = initialization finished
    static BOOL            m_bUseBalloonTips;    // TRUE = use balloon tips if possible
    static BOOL            m_bBalloon;            // TRUE = balloon tips not disallowed in 
                                            
// registry
    static HINSTANCE    m_hInstance;        // app instance
    static UINT            m_nIcon;            // icon to use
    static UINT            m_nLastMessage;        // last message received
    static UINT            m_nTimeOutSeconds;    // message timeout in seconds;
                                            
// 0 = no timeout
    static UINT            m_nTimerId;            // timer id returned by SetTimer()
    static LPRECT        m_pRect;            // NULL = use control rect
    static HWND            m_hWnd;                // hwnd of CXBalloonMsg
    static HWND            m_hParent;            // parent hwnd
    static HWND            m_hCtrl;            // control hwnd
    static WNDPROC        m_wndProc;            // window proc for parent subclassing
    static HHOOK        m_hKeyboardHook;    // keyboard hook
    static HHOOK        m_hMouseHook;        // mouse hook
    static TCHAR        m_szTitle[500];        // title string
    static TCHAR        m_szMsg[4000];        // message string
}
;

实现代码

显示API详解

      Show函数创建,显示并操作一个气泡状的消息对话框。这个消息对话框包含一个消息字段和标题,一个关闭按钮,和一个可选的图标。
 

void Show(

LPCTSTR lpszTitle,
LPCTSTR lpszMsg,
HWND hCtrl,
HWND hParent,
HINSTANCE hInstance,
UINT nIcon = TTI_INFO,
BOOL bUseBalloonTips = TRUE,
UINT nTimeOutSeconds = 0,
LPRECT pRect = NULL

);

Parameters

lpszTitle

[in] Pointer to a null-terminated string that contains the balloon message title. If this parameter is NULL, no title and no icon will be displayed. The special symbol LPCTSTR_DEFAULT_TITLE may be used; it will cause the executable module name to be displayed.


lpszMsg

[in] Pointer to a null-terminated string that contains the balloon message to be displayed. Must not be null. Text callbacks (LPSTR_TEXTCALLBACK) are not used, so the text string can be as long as you want, up to the size of the internal text buffer m_szMsg.


hCtrl

[in] Handle to the control that the message is being displayed for. Must not be null.


hParent

[in] Handle to the parent window of the control. Must not be null.


hInstance

[in] Handle to the instance of the module that contains the string resource. May be null if string resource is not used.


nIcon

[in] Specifies the icon to associate with the balloon message. This can be one of the following values:

Value

Meaning

TTI_ERROR

Use the error icon

TTI_INFO

Use the information icon

TTI_NONE

Use no icon

TTI_WARNING

Use the warning icon

This parameter may also be the handle of an icon obtained from LoadIcon or LoadImage functions. If not present, this parameter defaults to TTI_INFO.

bUseBalloonTips

[in] Specifies whether balloon tips are to be used to display the message. If this parameter is TRUE, balloon tips will be used unless disabled in the registry. If this parameter is FALSE, regular tooltips will be used, regardless of value of registry key. If not present, this parameter defaults to TRUE.


nTimeOutSeconds

[in] Specifies the number of seconds before the balloon message is automatically closed. If this parameter is zero, the balloon message will not be automatically closed. If not present, this parameter defaults to zero.


pRect

[in] Pointer to a RECT struct that contains position where balloon message is to be displayed. May be null if default position should be used. If not present, this parameter defaults to null.