Displaying a tool tip on a dialog

This is a discussion on Displaying a tool tip on a dialog within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I need to display a ToolTip on a DialogBox (for example, to display the mouse coordinates). I'm drawing some ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    10

    Displaying a tool tip on a dialog

    Hi,

    I need to display a ToolTip on a DialogBox (for example, to display the mouse coordinates). I'm drawing some graphics on a Dialog using CPaintDC device context in OnPaint handler function (WM_PAINT message). I can't see any ToolTipText() member function or something in CPaintDC.

    Thanks,
    Mullah,
    MSVC++6.0
    (Win 2K Pro)

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I don't know if you can use this:
    Code:
    /************************************\
     * Adds a tooltip to a control      *
     * Input:                           *
     *  hWndDlg	->ParentWindowHandle    *
     *  hWndCtrl->Handle to the control *
     *  hInst	  ->Application instance  *
     *  achTip	->Text for the tip      *
     * Output:                          *
     *  0=ERR, 1=OK                     *
     * Author: Knut Øverli              *
    \************************************/
    long AddTip(HWND hWndDlg, HWND hWndCtrl, HINSTANCE *hInst, char *achTip){
    	TOOLINFO ti;
    	HWND hWndTip;
    
    	memset(&ti, 0, sizeof(TOOLINFO));
    	hWndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWndDlg, NULL, *hInst, NULL);
    	SetWindowPos(hWndTip, HWND_TOPMOST,0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
    	SendMessage(hWndTip, TTM_ACTIVATE, TRUE, 0);
    	
    	ti.cbSize = sizeof(ti);
    	ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
    	ti.uId = (UINT)hWndCtrl;
    	ti.lpszText = achTip;
    	ti.hinst = *hInst;
    	ti.hwnd = hWndDlg;
    	return SendMessage(hWndTip, TTM_ADDTOOL, 0, (long)&ti);
    }

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    the parent will get WM_NOTIFY msg's and you will have to respond to the TTN_GETDISPINFO code and insert the text you need. This will need the ID of the control (or some way to get the right string).

    In knutso's example he does not set the HMENU param in the CreateWindow to the int ID of the control, you should set it to a unique value (use a hash define)

    Code:
    case WM_NOTIFY:
    	switch (((LPNMHDR) lParam)->code) 
    	{ 
    		case TTN_GETDISPINFO: 
    			lpttt = (LPTOOLTIPTEXT)  lParam; 
    			lpttt->hinst = hInst; 
    			idCtrl = lpttt->hdr.idFrom; 
    			lpttt->lpszText = sText;
    			return TRUE;
    		break; //syntax
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  2. Displaying a balloon tip on sys trap app at startup
    By BobS0327 in forum Windows Programming
    Replies: 0
    Last Post: 03-25-2005, 07:35 PM
  3. Displaying strings in a dialog window
    By Frandy in forum Windows Programming
    Replies: 11
    Last Post: 09-27-2004, 08:46 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Displaying bitmaps on a dialog
    By minesweeper in forum Windows Programming
    Replies: 2
    Last Post: 05-15-2002, 03:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21