-2

I have tried tooltip feature in win32 code, when 'OK' clicked the message displays only when we hover on particular box. But the feature Iam expecting is auto display of message at particular box when 'OK' is clicked. Is it possible to add such feature of auto popup? I need some balloon type of error popup. My exact scenario is to error popup when Zero is given as input in a dialog, when 'OK' is clicked.

HWND gzui_controls::create_tool_tip_balloon(HWND hdlg, int tool_id, PTSTR text) const { if (!tool_id || !hdlg || !text) { return FALSE; }

HWND hwndTool = GetDlgItem(hdlg, tool_id);
if (WM_LBUTTONUP)
{
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
        WS_POPUP | SWP_NOMOVE | TTS_NOPREFIX | TTS_BALLOON | BS_PUSHBUTTON,
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        hdlg, NULL,
        getModuleInstance(), NULL);

    if (!hwndTool || !hwndTip)
    {
        return (HWND)NULL;
    }

    // Associate the tooltip with the tool.
    TOOLINFO toolInfo = { 0 };
    toolInfo.cbSize = sizeof(toolInfo);
    toolInfo.hwnd = hdlg;
    toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
    toolInfo.uId = (UINT_PTR)hwndTool;
    toolInfo.lpszText = text;
    SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
    return hwndTip;
}
Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79

1 Answers1

0

The following is an example of balloon tip for display information when input value is not valid.

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

// ...

   editHwnd = CreateWindow(L"EDIT", 
       NULL, 
       WS_VISIBLE | WS_CHILD | ES_MULTILINE | WS_BORDER,
       120,
       10,
       100,
       100,
       hWnd,
       NULL,
       hInst,
       NULL);

// ...

case WM_COMMAND:
    {
        if (HIWORD(wParam) == EN_CHANGE)
        {
            // TODO: Add logic of detecting input value here
            if (editHwnd == (HWND)lParam) // && inputVal == 0
            {
                balloonTip.cbStruct = sizeof(EDITBALLOONTIP);
                balloonTip.pszText = L"Zero is given as input";
                balloonTip.pszTitle = L"Tips";
                balloonTip.ttiIcon = TTI_INFO;
                Edit_ShowBalloonTip(editHwnd, &balloonTip);
            }
        }
    }
    break;

Refer to Edit Control, EDITBALLOONTIP structure, Edit_ShowBalloonTip macro

Note To use Edit_ShowBalloonTip macro, you must provide a manifest specifying Comclt32.dll version 6.0.

It will like this:

enter image description here

Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • Yes i had tried message box also, but I would like to display as a balloon kind of tip in my dialog box. Like in the below link https://learn.microsoft.com/en-us/windows/win32/uxguide/ctrl-balloons ...Is there any possiblity? – Mohanasudharsan K Feb 17 '20 at 10:07
  • @MOHANASUDHARSANK If you want to use clicking `OK` button as a trigger, you can use your code piece to replace the `MessageBox` line in my answer, but don't call `EndDialog` otherwise the tip message will disappear together with the dialog window. Call `EndDialog` when you make sure the input is valid. And still the tip message will disappear after about several seconds as same as all other tooltips. – Rita Han Feb 18 '20 at 03:52
  • @MOHANASUDHARSANK To change the tip message display time and other features you can refer to [Balloons](https://learn.microsoft.com/en-us/windows/win32/uxguide/ctrl-balloons) for detailed information. – Rita Han Feb 18 '20 at 03:58
  • @MOHANASUDHARSANK Check my update answer for snapshot of using tooltip after clicked the button. – Rita Han Feb 18 '20 at 04:04
  • @MOHANASUDHARSANK Check the "[Is this the right control?](https://learn.microsoft.com/en-us/windows/win32/uxguide/ctrl-balloons)" part for how to decide which control to use. – Rita Han Feb 18 '20 at 04:06
  • Han Tried Balloon feature , but simply my need is to give a message at error spot location by triggering 'OK' . If it is possible to pop up such auto balloon like structures, It would be better than message box. The pop up should not appear only on hover, it should be auto appear on invalid input. – Mohanasudharsan K Feb 18 '20 at 09:12
  • @MOHANASUDHARSANK I update an example of a balloon tip you can have a try. For how to detect the input is valid or not you can add your own logic. – Rita Han Feb 18 '20 at 10:13