?
Solved

Why tooltip doesn't show up?

Posted on 2003-11-12
6
Medium Priority
?
1,542 Views
Last Modified: 2007-12-19
Hi! This is a Windows program. Not just a plain C++. Here is the list of all C++, header and resource files. I couldn't figure out why the tooptip of the toolbar refuses to show. It doesn't seem to send TTN_NEEDTEXT notification message to the parent window.

Here is the list of codes.

Please advise.

Jzzhang

Domm.cpp

#include <windows.h>
#include <commctrl.h>
#include "Domm.h"
#include "ToolStatusBar.h"

char g_szClassName[] = "DOM Manager";
HINSTANCE g_hinst;
HWND g_hwnd;
HWND g_hwndSB;
HWND g_hwndTB;

LRESULT CALLBACK WindowFunc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
      static int i = 0;
      int iCode;
      char szMsg[100];
      LPTOOLTIPTEXT lpttt;
      UINT idButton;

      switch (msg)
      {
            case WM_COMMAND:
                  switch (LOWORD(wParam))
                  {
                        case ID_FILE_OPEN:
                              InfoMsgBox(g_hwnd, "Open");
                              break;
                        case ID_DOCUMENT_NEW:
                              InfoMsgBox(g_hwnd, "New");
                              break;
                        case ID_DOCUMENT_REVISE:
                              InfoMsgBox(g_hwnd, "Revise");
                              break;
                        case ID_FILE_EXIT:
                              PostMessage(hwnd, WM_CLOSE, 0, 0);
                              break;
                  }
                  break;

            case WM_NOTIFY:
                  iCode = ((LPNMHDR) lParam)->code;
                  switch (iCode)
                  {
                        case TTN_NEEDTEXT:
                              lpttt = (LPTOOLTIPTEXT) lParam;
                              lpttt->hinst = g_hinst;
 
                              idButton = lpttt->hdr.idFrom;

                              wsprintf(szMsg, "%d code: %u", i++, iCode);
                              SendMessage(g_hwndSB, SB_SETTEXT, 0, (LPARAM) szMsg);

                              switch (idButton)
                              {
                                    case ID_FILE_OPEN:
                                          lpttt->lpszText = MAKEINTRESOURCE(IDS_FILE_OPEN);
                                          break;
                                    case ID_DOCUMENT_NEW:
                                          lpttt->lpszText = MAKEINTRESOURCE(IDS_DOCUMENT_NEW);
                                          break;
                                    case ID_DOCUMENT_REVISE:
                                          lpttt->lpszText = MAKEINTRESOURCE(IDS_DOCUMENT_REVISE);
                                          break;
                              }
                        break;
                        default:
                              break;
                  }
                  break;

            case WM_SIZE:
                  SendMessage(g_hwndTB, TB_AUTOSIZE, 0, 0);
                  SendMessage(g_hwndSB, WM_SIZE, 0, 0);
                  break;

            default:
                  return DefWindowProc(hwnd, msg, wParam, lParam);
      }
      return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
      MSG msg;
      WNDCLASSEX wc;

    INITCOMMONCONTROLSEX icex;
    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC  = ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES;
    InitCommonControlsEx(&icex);

      g_hinst = hInstance;

      wc.cbSize = sizeof(WNDCLASSEX);
      wc.style = 0;
      wc.lpfnWndProc = WindowFunc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DOMM_ICON));
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
      wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU_MAIN);
      wc.lpszClassName = g_szClassName;
      wc.hIconSm = NULL;

      if (!RegisterClassEx(&wc)) return 0;

      g_hwnd = CreateWindowEx(0, g_szClassName, "DOM Manager", WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 800, 480, NULL, NULL, hInstance, NULL);

      if (!g_hwnd) return 0;

      g_hwndTB = CreateToolbar(g_hinst, g_hwnd);
      if (g_hwndTB == NULL)
            ErrMsgBox(g_hwnd, "Error creating toolbar");

      g_hwndSB = CreateStatusbar(g_hinst, g_hwnd);
      if (g_hwndSB == NULL)
            ErrMsgBox(g_hwnd, "Error creating statusbar");

      ShowWindow(g_hwnd, nCmdShow);
      UpdateWindow(g_hwnd);

      while (GetMessage(&msg, g_hwnd, 0, 0) > 0)
      {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }

      return msg.wParam;
}

ToolStatusBar.cpp

#include <windows.h>
#include <commctrl.h>
#include "Domm.h"

#define BITMAP_NUM       3
#define BUTTON_NUM       4

void InfoMsgBox(HWND hwndParent, char* pszMsg)
{
      MessageBox(hwndParent, pszMsg, "INFO", MB_ICONINFORMATION | MB_OK);
}

void ErrMsgBox(HWND hwndParent, char* pszMsg)
{
      MessageBox(hwndParent, pszMsg, "ERROR", MB_ICONEXCLAMATION | MB_OK);
}

HWND CreateToolbar(HINSTANCE hInst, HWND hwndParent)
{
      HWND hwndTB;
      TBADDBITMAP tbab;
      TBBUTTON tbb[BUTTON_NUM];
      int iFirstId;

      hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
            WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, 0, 0, 0, 0,
            hwndParent, (HMENU)IDC_TOOLBAR, hInst, NULL);
      if(hwndTB == NULL)
            return NULL;

      SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

      tbab.hInst = hInst;
      tbab.nID = IDR_DOMM_TOOLBAR;
      iFirstId = SendMessage(hwndTB, TB_ADDBITMAP, BITMAP_NUM, (LPARAM)&tbab);
      if (iFirstId == -1)
            return NULL;

      tbb[0].iBitmap = iFirstId++;
      tbb[0].idCommand = ID_FILE_OPEN;
      tbb[0].fsState = TBSTATE_ENABLED;
      tbb[0].fsStyle = TBSTYLE_BUTTON;
      tbb[0].dwData = 0;
      tbb[0].iString = 0;
 
      tbb[1].iBitmap = 0;
      tbb[1].idCommand = 0;
      tbb[1].fsState = TBSTATE_ENABLED;
      tbb[1].fsStyle = TBSTYLE_SEP;
      tbb[1].dwData = 0;
      tbb[1].iString = 0;

      tbb[2].iBitmap = iFirstId++;
      tbb[2].idCommand = ID_DOCUMENT_NEW;
      tbb[2].fsState = TBSTATE_ENABLED;
      tbb[2].fsStyle = TBSTYLE_BUTTON;
      tbb[2].dwData = 0;
      tbb[2].iString = 0;

      tbb[3].iBitmap = iFirstId;
      tbb[3].idCommand = ID_DOCUMENT_REVISE;
      tbb[3].fsState = TBSTATE_ENABLED;
      tbb[3].fsStyle = TBSTYLE_BUTTON;
      tbb[3].dwData = 0;
      tbb[3].iString = 0;

      SendMessage(hwndTB, TB_ADDBUTTONS, BUTTON_NUM, (LPARAM)&tbb);
      SendMessage(hwndTB, TB_AUTOSIZE, 0, 0);
      return hwndTB;
}

HWND CreateStatusbar(HINSTANCE hInst, HWND hwndParent)
{
      HWND hwndSB;
      int statwidths[] = {100, -1};

      hwndSB = CreateWindowEx(0, STATUSCLASSNAME, NULL,
                        WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
                        hwndParent, (HMENU)IDC_STATUSBAR, hInst, NULL);
      if(hwndSB == NULL)
            return NULL;

      SendMessage(hwndSB, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
      SendMessage(hwndSB, SB_SETTEXT, 0, (LPARAM)"Ready");
      return hwndSB;
}

Domm.h

// Resource ids
#define IDI_DOMM_ICON       101
#define IDR_MENU_MAIN       102
#define IDR_DOMM_TOOLBAR    103
#define IDM_DOMM_TOOLBAR    104

#define IDC_TOOLBAR         500
#define IDC_STATUSBAR       501

#define ID_FILE_OPEN                    40001
#define ID_FILE_EXIT                    40002
#define ID_DOCUMENT_NEW                 40003
#define ID_DOCUMENT_REVISE              40004
#define ID_DOCUMENT_VIEW                40005

#define IDS_FILE_OPEN                   60001
#define IDS_DOCUMENT_NEW                60002
#define IDS_DOCUMENT_REVISE             60003

ToolStatusBar.h

// Interfaces of toolbar, statusbar and custom message boxs

void InfoMsgBox(HWND hwndParent, char* pszMsg);
void ErrMsgBox(HWND hwndParent, char* pszMsg);
HWND CreateToolbar(HINSTANCE hInst, HWND hwndParent);
HWND CreateStatusbar(HINSTANCE hInst, HWND hwndParent);

Domm.rc

#include "Domm.h"

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.

IDI_DOMM_ICON               ICON    DISCARDABLE     "Domm.ico"

/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDR_MENU_MAIN MENU DISCARDABLE
BEGIN
    POPUP "File"
    BEGIN
        MENUITEM "Open",                        ID_FILE_OPEN
        MENUITEM "Exit",                        ID_FILE_EXIT
    END
    POPUP "Document"
    BEGIN
        MENUITEM "New",                         ID_DOCUMENT_NEW
        MENUITEM "Revise",                      ID_DOCUMENT_REVISE
        MENUITEM "View",                        ID_DOCUMENT_VIEW
    END
END

/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//

IDR_DOMM_TOOLBAR            BITMAP  DISCARDABLE     "Domm.bmp"

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE DISCARDABLE
BEGIN
    IDS_FILE_OPEN           "Open Project"
    IDS_DOCUMENT_NEW        "New doc"
    IDS_DOCUMENT_REVISE     "Revise doc"
END
0
Comment
Question by:jzzhang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:LuCkY
ID: 9735254
I don't think it will ever receive the TTN_NEEDTEXT messages as the toolbar has its own tooltip handling mechanism if you use the TBSTYLE_TOOLTIPS flag. It will send a TBN_GETINFOTIP message instead of TTN_NEEDTEXT through a WM_NOTIFY message if I'm not mistaken. Try catching that message instead.
0
 
LVL 2

Author Comment

by:jzzhang
ID: 9736574
I think TTN_NEEDTEXT should work too. Since I made a similar program using TTN_NEEDTEXT, it works. Why this time it doesn't work?

Jzzhang
0
 
LVL 2

Author Comment

by:jzzhang
ID: 9737040
I tested TBN_GETINFOTIP message, it doesn't seem to get this notification message either.

Jzzhang
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:jzzhang
ID: 9749872
I found the reason is that I only process the messages from the main window.

     while (GetMessage(&msg, g_hwnd, 0, 0) > 0)

I need to change it to:

     while (GetMessage(&msg, NULL, 0, 0) > 0)

So I process messages from all windows.

Jzzhang
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10249076
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10308138
PAQed, with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question