点击按钮[改写以反映编辑内容]后,工具提示永远不再显示 [英] Tooltip is never shown again after I click on the button [rephrased to reflect edited content ]

查看:71
本文介绍了点击按钮[改写以反映编辑内容]后,工具提示永远不再显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的工具提示,当用户将鼠标悬停在按钮上时会弹出。



为此,我研究过此示例 [ ^ ]。



第一次时一切正常时间悬停在按钮上,但之后工具提示 从不再次显示(我有检查 HWND 工具提示以及 SendMessage(...,TTM_ADDTOOL, ...)并且没有错误。)



我试图在线找到解决方案,但都失败了。我发现可能有用的唯一资源是本教程 [ ^ ]但建议 subclass 控件以便将鼠标消息转发到工具提示 control-I 不会接受这种类型的解决方案,因为我相信我要求的是基本功能 工具提示控制提供。



********************************************* ********************** *

2014年1月21日编辑:



按照此MSDN链接 [ ^ ]我能够部分解决问题。现在点击主窗口的客户区后显示工具提示,然后将鼠标悬停在按钮上。



然而,点击按钮后 工具提示 从未显示再次



浏览互联网,我找到了这个例子 [ ^ ]并在添加这些指令后:

  #pragma comment(链接器,/ manifestdependency:\type ='win32'\ 
name = ' Microsoft.Windows.Common-Controls' version = ' 6.0.0.0' \
processorArchitecture = ' *' publicKeyToken = ' 6595b64144ccf1df' \
language = ' *' \

#pragma comment(lib, comctl32.lib)



问题似乎消失了。现在我可以点击按钮,将鼠标悬停在编辑控件编辑控件将出现工具提示



然而,点击<$ c后$ c>按钮,然后点击主窗口的客户区然后将鼠标悬停在上按钮再次工具提示未显示!



然后我继续在互联网上搜索并找到了这篇文章 [ ^ ]在 CodeProject <大>它完全符合我的需要



所以我开始分析源代码第一个例子和这篇文章。我无法看出差异。但是,外观不同!看来文章没有使用视觉样式,并考虑了 MSDN文章我已经链接到此编辑的最顶层,我开始怀疑这可能是明显的问题



所以我我试图编译所有程序,而不是上面提交的第一个 pragma评论,但是在我的测试应用程序中(创建为默认Win32项目) InitCommonControlsEx 失败,在示例程序中我遇到错误无法将更新后的清单保存到文件。\Debug \ foosyerdoos tooltip.exe.embed.manifest。参数不正确。,文章应用程序无法创建工具提示控件。



创建新的空白项目后,以及复制第一个示例中的代码后 - 此次没有 pragma comment - SendMessage 无法添加 工具提示 s。



因此,如果没有上面提交的 pragma评论,我就无法使用工具提示看起来很好。



编辑结束

*** ************************************************** ***************



以下是创建说明问题的最小示例的说明:



1.在 MS Visual Studio中创建默认Win32项目 ;

2.添加以下 WM_CREATE 处理程序:



3.编译并运行 - 工具提示应显示在第一次悬停,但永远不会

  case  WM_CREATE:
{
HWND hButton = CreateWindowEx( 0 ,L 按钮,L 测试我!
WS_CHILD | WS_VISIBLE | WS_BORDER | BS_PUSHBUTTON,
50 150 150 25 ,hWnd,(HMENU) 8003 ,hInst, 0 );

HWND hwndTip = CreateWindowEx(NULL,TOOLTIPS_CLASS,NULL,
WS_POPUP | TTS_ALWAYSTIP,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
hWnd,NULL ,hInst,NULL);

// 将工具提示与工具相关联。
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof (toolInfo);
toolInfo.hwnd = hWnd;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId =(UINT_PTR)hButton;
toolInfo.lpszText = L test 1;

SendMessage(hwndTip,TTM_ADDTOOL, 0 ,(LPARAM)& toolInfo);
}
返回 0L;



我工作 Windows XP ,使用 MS Visual Studio Express 2008



视觉样式已启用,我已链接 comctl32.lib 并已启动 INITCOMMONCONTROLSEX 结构的 dwICC 成员 ICC_STANDARD_CLASSES | ICC_TAB_CLASSES | ICC_BAR_CLASSES



编辑(2014年1月31日):

***********************************



在我的笔记本电脑上测试了这个非常好的代码片段,它有 Windows 7 我可以确认一切正常。这是我的 Windows XP 的问题我猜...



END OF编辑

********************************* ***



我的问题很简单:



如何调整我的代码以便<$每次用户将鼠标悬停在按钮时,都会显示c $ c>工具提示?



谢谢。



祝你好运。

解决方案

你好

in我的情况(在MFC中)

1.创建工具提示变量(〜.h)

 CToolTipCtrl m_toolTipCtrl; 





2.在OnInitDialog()中初始化tooltip vaiable(〜.cpp)

  if (m_toolTipCtrl.m_hWnd == NULL)
{
m_toolTipCtrl.Create( this );
m_toolTipCtrl.Activate(TRUE);
}
m_toolTipCtrl.AddTool(GetDlgItem(IDC_BTN_INIT),_ T( 这是按钮。 ));





3.在PreTranslateMessage(MSG * pMsg)

 m_toolTipCtrl.RelayEvent(PMSG); 





就是这样。

祝你有愉快的一天。

我可以看到你没有做的一件事是将工具提示控件设置为最顶层,因此工具提示可能在父窗口后面。



拿一个请查看此处的创建部分: http:// msdn.microsoft.com/en-us/library/windows/desktop/bb760250(v=vs.85).aspx#Tooltip_Creation [ ^ ]以获取最顶层的示例。

正如评论中所提到的,这不会解决手头的问题 - 虽然我在XP SP3的干净安装下运行时注意到两个按钮的不同行为。



你可以清楚地看到SetWindowSubclass更整洁/更容易使用。它还具有以下优点:您可以使用不同的WndProcs多次应用它,并有选择地删除链中的任何WndProcs。然而,旧方法并没有真正提供同时将控件子类化几次的方法 - 如果我没记错的话,文档解释了这一点 - 我认为那里也可能有一两个例子。



main.cpp

  #define UNICODE 1 
#define _WIN32_WINNT 0x0501
#define WINVER 0x0500
#include < windows.h >
#include < commctrl.h >

/ * Dec lare Windows procedure * /
LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);

/ * 将类名设为全局变量* /
wchar_t szClassName [] = L CodeBlocksWindowsApp< /跨度>;

HINSTANCE hInst;

ATOM myRegClass()
{
/ * Window结构* /
WNDCLASSEX wincl; / * windowclass的数据结构* /
wincl.hInstance = hInst;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; / * 此函数由windows * /
wincl.style = CS_DBLCLKS调用; / * 抓住双击* /
wincl.cbSize = sizeof (WNDCLASSEX);

/ * 使用默认图标和鼠标指针* /
wincl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL,IDC_ARROW);
wincl.lpszMenuName = NULL; / * 无菜单* /
wincl.cbClsExtra = 0 ; / * 窗口类后没有额外的字节* /
wincl.cbWndExtra = 0 ; / * 结构或窗口实例* /

/ * 使用Windows的默认颜色作为窗口的背景* /
wincl.hbrBackground =(HBRUSH)COLOR_BACKGROUND;

/ * 注册窗口类,如果失败则退出程序* /
return RegisterClassEx(& wincl);
}

int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; / * 这是我们窗口的句柄* /
MSG消息; / * 此处保存到应用程序的消息* /

hInst = hThisInstance ;

if (myRegClass()== NULL)
return - 1 ;

/ * 该类已注册,我们创建程序* /
hwnd = CreateWindow(szClassName,L Code :: Blocks Windows App,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
544 375
HWND_DESKTOP,NULL ,hThisInstance,NULL);

/ * 在屏幕上显示窗口* /
ShowWindow(hwnd,nCmdShow);

/ * 运行消息循环。它将一直运行,直到GetMessage()返回0 * /
(GetMessage(& messages,NULL, 0 0 ))
{
/ * 将虚拟密钥消息转换为字符消息* /
if (IsDialogMessage(hwnd,& amp; ; message)== 0
{
TranslateMessage(& messages);
/ * 发送消息给WindowProcedure * /
DispatchMessage(& messages) ;
}
}

/ * 程序返回值是0 - PostQuitMessage()给出的值* /
return messages.wParam;
}


HWND addTip(HWND目标, wchar_t * tipText)
{
HWND parentWnd = GetParent(target);
HWND hwndTip = CreateWindowEx(NULL,TOOLTIPS_CLASS,NULL,
WS_POPUP | TTS_ALWAYSTIP,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
parentWnd,NULL,hInst,NULL );

// 将工具提示与工具相关联。
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof (toolInfo);
toolInfo.hwnd = parentWnd;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId =(UINT_PTR)目标;
toolInfo.lpszText = tipText;
SendMessage(hwndTip,TTM_ADDTOOL, 0 ,(LPARAM)& toolInfo);

return hwndTip;
}
// SetWindowSubclass

void onPaint(HWND hwnd,WPARAM wParam,LPARAM lParam,COLORREF col)
{
RECT rc;
PAINTSTRUCT ps;
HDC hdc;

if (wParam == NULL)
hdc = BeginPaint(hwnd,& ps);
else
hdc =(HDC)wParam;

GetClientRect(hwnd,& rc);
HBRUSH hbr = CreateSolidBrush(col);
FillRect(hdc,& rc,hbr);
DeleteObject(hbr);

int txtLen,oldMode;
wchar_t * wndTxt;

txtLen = GetWindowTextLength(hwnd);
wndTxt = new wchar_t [txtLen + 2];
GetWindowText(hwnd,wndTxt,txtLen + 1);
oldMode = SetBkMode(hdc,TRANSPARENT);
DrawText(hdc,wndTxt, - 1 ,& rc,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
SetBkMode(hdc,oldMode);
delete wndTxt;

if (GetFocus()== hwnd)
{
RECT focusRect = rc;
focusRect.left + = 4 ;
focusRect.top + = 4 ;
focusRect.right - = 4 ;
focusRect.bottom - = 4 ;
DrawFocusRect(hdc,& focusRect);
}

if (wParam == NULL)
EndPaint(hwnd,& ps);
}

LRESULT CALLBACK Btn2SubclassProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam,UINT_PTR uIdSubclass,DWORD_PTR dwRefData)
{
switch (uMsg)
{
case WM_ERASEBKGND:
返回 1 ;

case WM_PAINT:
onPaint(hwnd,wParam,lParam,RGB( 50) 140 87 ));
return 0 ;
}
return DefSubclassProc(hwnd,uMsg,wParam,lParam);
}

LRESULT CALLBACK Btn1Proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_ERASEBKGND:
return 1 ;

case WM_PAINT:
onPaint(hwnd,wParam,lParam,RGB( 87) 140 50 ));
return 0 ;
}

WNDPROC oldProc;
oldProc =(WNDPROC)GetWindowLong(hwnd,GWL_USERDATA);
return CallWindowProc(oldProc,hwnd,uMsg,wParam,lParam);
}

/ * 此函数由Windows函数DispatchMessage()调用* /
LRESULT CALLBACK WindowProcedure(HWND hWnd,UINT消息,WPARAM wParam,LPARAM lParam)
{
switch (消息) / * 处理消息* /
{
case WM_CREATE:
{
HWND hButton = CreateWindow(L 按钮,L 测试我!,WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 50 50 75 23 ,hWnd,(HMENU) 8003 ,hInst, 0 );
addTip(hButton,L test1);
long origProc;
origProc = GetWindowLong(hButton,GWL_WNDPROC);
SetWindowLong(hButton,GWL_USERDATA,origProc);
SetWindowLong(hButton,GWL_WNDPROC,( long )Btn1Proc);

HWND btn2 = CreateWindow(L 按钮,L btn2,WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 50 85 75 23 ,hWnd,(HMENU) 8004 ,hInst, 0 );
SetWindowSubclass(btn2,Btn2SubclassProc, 1 ,NULL);
addTip(btn2,L test2);
}
return 0L;

case WM_DESTROY:
PostQuitMessage( 0 ); / * 将WM_QUIT发送到消息队列* /
断裂;

默认 / * 对于我们不处理的消息* /
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0 ;
}


I want to create a simple tooltip that will pop when user hovers over a button.

To do that I have studied this example[^] from MSDN.

Everything works fine when I first time hover over the button, but after that tooltip never shows up again ( I have checked return values for HWND of the tooltip and for SendMessage( ..., TTM_ADDTOOL, ... ) and there were no errors ).

I have tried to find the solution online, but have failed. The only resource I have found that might be useful is this tutorial[^] but it suggests to subclass the control in order to relay mouse messages to the tooltip control-I will not accept this type of solution because I believe what I ask for is the basic functionality tooltip control provides.

*******************************************************************
EDITED ON JANUARY 21st 2014:

Following instructions from this MSDN link[^] I was able to partially solve the problem. Now tooltip is shown after clicking on the main window's client area and then hovering back over the button.

However, after I click on the button tooltip never shows up again .

Browsing through Internet, I have found this example[^] and after adding these directives:

#pragma comment( linker, "/manifestdependency:\"type='win32' \
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
    processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
    language='*'\"")

#pragma comment( lib, "comctl32.lib")


the problem seemed to disappear. Now I was able to click on a button, hover over edit control and edit control's tooltip would appear.

However, after clicking on a button, then clicking on the client area of the main window, and then hovering over the button again its tooltip did not show!

Then I have continued to search over the Internet and have found this article[^] on CodeProject and it does exactly what I need.

So I have started to analyze the source code of the first example and this article. I was unable to see the difference. However, appearances were different! It seems that the article did not use Visual Styles, and taking into the consideration MSDN article I have linked to at the very top of this edit, I start to suspect that this might be the manifest issue.

So I have tried to compile all the programs without the first pragma comment submitted above, but in my test application ( the one created as default Win32 project ) InitCommonControlsEx failed, in the example program I have got error Failed to save the updated manifest to the file ".\Debug\foosyerdoos tooltip.exe.embed.manifest". The parameter is incorrect., and the article application failed to create tooltip controls.

After creating the fresh blank project, and after copying the code from the first example-only this time without pragma comment-SendMessage failed to add both tooltips.

So, without first pragma comment submitted above, I can not use tooltip controls or so it seems.

END OF EDIT
********************************************************************

Here are the instruction for creating the minimal example that illustrates the problem:

1. Create default Win32 project in MS Visual Studio ;
2. Add the bellow WM_CREATE handler:

3. Compile and run-tooltip should show on first hover, but never again.

case WM_CREATE:
    {
        HWND hButton = CreateWindowEx( 0, L"Button", L"test me!", 
            WS_CHILD | WS_VISIBLE | WS_BORDER | BS_PUSHBUTTON,
            50, 150, 150, 25, hWnd, (HMENU)8003, hInst, 0 );

        HWND hwndTip = CreateWindowEx( NULL, TOOLTIPS_CLASS, NULL,
            WS_POPUP | TTS_ALWAYSTIP,
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            hWnd, NULL, hInst, NULL );

        // Associate the tooltip with the tool.
        TOOLINFO toolInfo = { 0 };
        toolInfo.cbSize = sizeof(toolInfo);
        toolInfo.hwnd = hWnd;
        toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
        toolInfo.uId = (UINT_PTR)hButton;
        toolInfo.lpszText = L"test 1";

        SendMessage( hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo );
    }
    return 0L;


I work on Windows XP, using MS Visual Studio Express 2008.

Visual Styles are enabled, I have linked comctl32.lib and have initiated INITCOMMONCONTROLSEX structure's dwICC member with ICC_STANDARD_CLASSES | ICC_TAB_CLASSES | ICC_BAR_CLASSES.

EDIT ( January 31st, 2014 ):
***********************************

After testing this very code snippet on my laptop, which has Windows 7 I can confirm that everything works fine. This is the problem with my Windows XP I guess...

END OF EDIT
************************************

My question is really simple:

How to adjust my code so the tooltip is shown every time user hovers over the button?

Thank you.

Best regards.

解决方案

hello
in my case(in MFC)
1. create tooltip variable(~.h)

CToolTipCtrl	m_toolTipCtrl;



2. initialize tooltip vaiable(~.cpp) in OnInitDialog()

if (m_toolTipCtrl.m_hWnd == NULL)
	{
		m_toolTipCtrl.Create(this);
		m_toolTipCtrl.Activate(TRUE);
	}
m_toolTipCtrl.AddTool(GetDlgItem(IDC_BTN_INIT), _T("this is button."));



3. in PreTranslateMessage(MSG* pMsg)

m_toolTipCtrl.RelayEvent(pMsg);



That's it.
Have a nice day.


One thing I can see that you are not doing is setting the tooltip control as topmost, so the tooltip might be behind the parent window.

Take a look at the creation section here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb760250(v=vs.85).aspx#Tooltip_Creation[^] for an example with topmost being set.


As mentioned in the comments, this wont solve the problem at hand - although I did notice different behaviour of the two buttons when running under a clean install of XP SP3.

You can clearly see that SetWindowSubclass is much neater/easier to use. It also has the advantage that you can both apply it many times with different WndProcs and selectively remove any of the WndProcs in the chain. The old method however doesn't really offer a way to subclass the control several times simultaneously - the documentation explains this if I remember correctly - I think there may also be an example or two in there somewhere too.

main.cpp

#define UNICODE 1
#define _WIN32_WINNT 0x0501
#define WINVER 0x0500
#include <windows.h>
#include <commctrl.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
wchar_t szClassName[ ] = L"CodeBlocksWindowsApp";

HINSTANCE hInst;

ATOM myRegClass()
{
    /* The Window structure */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */
    wincl.hInstance = hInst;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */

    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    return RegisterClassEx (&wincl);
}

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */

    hInst = hThisInstance;

    if (myRegClass() == NULL)
        return -1;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindow(szClassName, L"Code::Blocks Windows App", WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, CW_USEDEFAULT,
                        544, 375,
                        HWND_DESKTOP,NULL,hThisInstance,NULL);

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        if (IsDialogMessage(hwnd, &messages) == 0)
        {
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


HWND addTip(HWND target, wchar_t *tipText)
{
    HWND parentWnd = GetParent(target);
    HWND hwndTip = CreateWindowEx( NULL, TOOLTIPS_CLASS, NULL,
        WS_POPUP | TTS_ALWAYSTIP,
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        parentWnd, NULL, hInst, NULL );

    // Associate the tooltip with the tool.
    TOOLINFO toolInfo = { 0 };
    toolInfo.cbSize = sizeof(toolInfo);
    toolInfo.hwnd = parentWnd;
    toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
    toolInfo.uId = (UINT_PTR)target;
    toolInfo.lpszText = tipText;
    SendMessage( hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo );

    return hwndTip;
}
//SetWindowSubclass

void onPaint(HWND hwnd, WPARAM wParam, LPARAM lParam, COLORREF col)
{
    RECT rc;
    PAINTSTRUCT ps;
    HDC hdc;

    if (wParam == NULL)
        hdc = BeginPaint(hwnd, &ps);
    else
        hdc = (HDC)wParam;

    GetClientRect(hwnd, &rc);
    HBRUSH hbr = CreateSolidBrush(col);
    FillRect(hdc,&rc,hbr);
    DeleteObject(hbr);

    int txtLen, oldMode;
    wchar_t *wndTxt;

    txtLen = GetWindowTextLength(hwnd);
    wndTxt = new wchar_t[txtLen+2];
    GetWindowText(hwnd, wndTxt, txtLen+1);
    oldMode = SetBkMode(hdc, TRANSPARENT);
    DrawText(hdc, wndTxt, -1, &rc, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
    SetBkMode(hdc, oldMode);
    delete wndTxt;

    if (GetFocus() == hwnd)
    {
        RECT focusRect = rc;
        focusRect.left += 4;
        focusRect.top += 4;
        focusRect.right -= 4;
        focusRect.bottom -= 4;
        DrawFocusRect(hdc, &focusRect);
    }

    if (wParam == NULL)
        EndPaint(hwnd, &ps);
}

LRESULT CALLBACK Btn2SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
    switch (uMsg)
    {
        case WM_ERASEBKGND:
            return 1;

        case WM_PAINT:
            onPaint(hwnd, wParam, lParam,RGB(50,140,87));
            return 0;
    }
    return DefSubclassProc(hwnd, uMsg, wParam, lParam);
}

LRESULT CALLBACK Btn1Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_ERASEBKGND:
            return 1;

        case WM_PAINT:
            onPaint(hwnd, wParam, lParam,RGB(87,140,50));
            return 0;
    }

    WNDPROC oldProc;
    oldProc = (WNDPROC)GetWindowLong(hwnd, GWL_USERDATA);
    return CallWindowProc(oldProc, hwnd, uMsg, wParam, lParam);
}

/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:
            {
                HWND hButton = CreateWindow( L"Button", L"test me!",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP,50, 50, 75, 23, hWnd, (HMENU)8003, hInst, 0 );
                addTip(hButton, L"test1");
                long origProc;
                origProc = GetWindowLong(hButton, GWL_WNDPROC);
                SetWindowLong(hButton, GWL_USERDATA, origProc);
                SetWindowLong(hButton, GWL_WNDPROC, (long)Btn1Proc);

                HWND btn2 = CreateWindow(L"Button", L"btn2", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP, 50, 85, 75, 23, hWnd, (HMENU)8004,hInst,0);
                SetWindowSubclass(btn2,Btn2SubclassProc, 1, NULL);
                addTip(btn2, L"test2");
            }
            return 0L;

        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;

        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hWnd, message, wParam, lParam);
    }
    return 0;
}


这篇关于点击按钮[改写以反映编辑内容]后,工具提示永远不再显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆