工具提示显示,然后隐藏然后再次显示 [英] Tooltip shows, then hides and then shows again

查看:120
本文介绍了工具提示显示,然后隐藏然后再次显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码将工具提示添加到选定的窗口区域(RECT):



I use the following code for adding tooltip to selected window region (RECT):

INITCOMMONCONTROLSEX icc;
InitCommonControlsEx(&icc);
icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
icc.dwICC = ICC_BAR_CLASSES;

HWND tooltip_hwnd = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, "MyTooltip", WS_POPUP | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, (HINSTANCE)GetModuleHandle(NULL), NULL);

SetWindowPos(tooltip_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |WP_NOACTIVATE);

SendMessage(tooltip_hwnd, TTM_SETMAXTIPWIDTH, 0, 200);
SendMessage(tooltip_hwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, 15000);
SendMessage(tooltip_hwnd, TTM_SETDELAYTIME, TTDT_RESHOW, 10);

TOOLINFO ti = {0};
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwnd;
ti.hinst = (HINSTANCE)GetModuleHandle(NULL);
ti.uId = 1;
ti.lpszText = "tooltip_text";
ti.rect.left = 10;
ti.rect.top = 10;
ti.rect.right = 100;
ti.rect.bottom = 80;
SendMessage(tooltip_hwnd, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);





好​​的。问题在于:当鼠标光标出现在选定的矩形上方时,工具提示窗口会快速显示,然后隐藏然后再次显示。这段代码哪里出错?以及如何修复这个错误?



OK. And problem is in here: when the mouse cursor appears above the selected rect, then tooltip window quickly shows, then hides and then shows again. Where is mistake in this code? And how to fix this bug?

推荐答案

以下对我来说效果很好。



我做的事情已更改:

1.在创建任何窗口之前将initcommoncontrols移动到

2.已更改WP_NOACTIVATE - > SWP_NOACTIVATE

3.将提示的大小设置为CW_USEDEFAULT,CW_USEDEFAULT(您忘了指定它)

4.为_WIN32_IE添加了一个定义并包含了commctrl.h



下面的代码不显示你描述的文物,不知道你的情况有什么问题。



main.cpp

The following works just fine for me.

Things I've changed:
1. Moved initcommoncontrols to before any windows are created
2. changed WP_NOACTIVATE --> SWP_NOACTIVATE
3. Set the size of the tip to CW_USEDEFAULT,CW_USEDEFAULT (you forgot to specify this)
4. added a define for _WIN32_IE and included commctrl.h

The code below does not display the artefacts that you describe, not sure what's wrong in your case.

main.cpp
#define _WIN32_IE 0x0300    // for INITCOMMONCONTROLSEX struct

#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>
#include <commctrl.h>       // for INITCOMMONCONTROLSEX struct

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

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");

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 */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    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 */
    if (!RegisterClassEx (&wincl))
        return 0;

    INITCOMMONCONTROLSEX icc;
    InitCommonControlsEx(&icc);
    icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icc.dwICC = ICC_BAR_CLASSES;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           _T("Code::Blocks Template Windows App"),       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* 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 */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

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


/*  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 tooltip_hwnd = CreateWindowEx(WS_EX_TOPMOST,
                                               TOOLTIPS_CLASS,
                                               "MyTooltip",
                                               WS_POPUP | TTS_ALWAYSTIP,
                                               CW_USEDEFAULT, CW_USEDEFAULT,
                                               CW_USEDEFAULT, CW_USEDEFAULT,
                                               hwnd, NULL, (HINSTANCE)GetModuleHandle(NULL), NULL);

            SetWindowPos(tooltip_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |SWP_NOACTIVATE);

            SendMessage(tooltip_hwnd, TTM_SETMAXTIPWIDTH, 0, 200);
            SendMessage(tooltip_hwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, 15000);
            SendMessage(tooltip_hwnd, TTM_SETDELAYTIME, TTDT_RESHOW, 10);

            TOOLINFO ti = {0};
            ti.cbSize = sizeof(TOOLINFO);
            ti.uFlags = TTF_SUBCLASS;
            ti.hwnd = hwnd;
            ti.hinst = (HINSTANCE)GetModuleHandle(NULL);
            ti.uId = 1;
            ti.lpszText = "tooltip_text";
            ti.rect.left = 10;
            ti.rect.top = 10;
            ti.rect.right = 100;
            ti.rect.bottom = 80;
            SendMessage(tooltip_hwnd, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
        }
        return 0;

        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天全站免登陆