• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

How to display tooltips

Started by Chris Chancellor, September 08, 2018, 06:48:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Chancellor

Hello Charles

i was trying to display tooltips for a button with ported  codes from PB
but not successful

the following is the program in O2 which can be compile and works except that it couldn't display tooltips


' DialogTT.o2bas


' Dialog with Tooltips


$ filename "DialogTT.exe"
uses rtl64

uses dialogs
uses user




' tooltips constants
% TB_SETTOOLTIPS = 1060
% EBTOOLTIPS = 256
% TBSTYLE_TOOLTIPS = &H100
% TBSETTIP = 9
% TTS_ALWAYSTIP = &H1
% TTS_NOPREFIX = &H2
% TTS_BALLOON = &H40 ' comctl32.dll v5.8 require
% TTM_ACTIVATE = WM_USER+1

% TTM_ADDTOOL = (WM_USER + 4)
% TTM_DELTOOL = (WM_USER + 5)
% TTM_NEWTOOLRECT = (WM_USER + 6)
% TTM_GETTOOLINFO = (WM_USER + 8)
% TTM_SETTIPBKCOLOR = (WM_USER + 19)
% TTM_SETTIPTEXTCOLOR = (WM_USER + 20)
% TTM_SETMAXTIPWIDTH = (WM_USER + 24)
% TTM_UPDATETIPTEXT  = 1036
% TTDT_AUTOPOP = 2
% TTDT_INITIAL = 3

% TTF_IDISHWND = &H1
% TTF_CENTERTIP = &H2
% TTF_SUBCLASS = &H10


Type TOOLINFO
    cbSize      As sys
    uFlags      As sys
    hWnd        As sys
    uId          As sys
    cRect       As RECT
    hinst       As sys
    lpszText    As sys
End Type



def varptr @ %1

macro MakeLong(lo,hi) { ( (lo) or ( (hi)<<16 ) ) }



sys  hToolTip , hDlg

declare sub SetToolTip( sys hcontrol, string TipText)




'=======================================
' display tooltips
SUB SetToolTip(sys hControl , string TipText )

      dim TI AS TOOLINFO

    hToolTip = CreateWindowEx(BYVAL 0, "tooltips_class32", "", TTS_ALWAYSTIP OR TTS_BALLOON,  _
              0, 0, 0, 0, BYVAL hDlg, 0, GetModuleHandle(BYVAL NULL),  0)

   '  SendMessage hToolTip, TTM_SETTIPTEXTCOLOR,RGB_MAGENTA,0
   '  SendMessage hToolTip, TTM_SETTIPBKCOLOR, RGB_HONEYDEW,0

      TI.cbSize    = LEN(TI)
      TI.uFlags    = TTF_SUBCLASS OR TTF_IDISHWND
      TI.hWnd      = GetParent(hToolTip)
      TI.uId         = hControl
      TI.lpszText  = VARPTR(TipText)
      SendMessage hToolTip, %TTM_ADDTOOL, 0, VARPTR(ti)
END SUB                         







sys hInstance = GetModuleHandle(null)
 

% ID_Button   = 1004


init_common_controls()




'=====================================
sub winmain()

  Dialog( 0, 0, 300, 200, "Dialog with Tooltips",
          WS_OVERLAPPEDWINDOW or DS_CENTER or DS_SETFONT,
          10, "Arial")

      PushButton("Button1", ID_Button, 50,80,65,15)



' for labeling  text on the screen
  LText("Hover mouse over the button to get tooltips", -1, 20,160, 250,20)

 
  CreateModalDialog( null, @DialogProc, 0)
end sub




==========================================================
function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as sys callback
 
  select case uMsg
 
    case WM_INITDIALOG
             '  sys hButton =  FindWindowEx(0,0, "Button1", NULL)   

               sys hButton =  FindWindow(NULL, "Button1")   
                 print hbutton     ' returns 0  did not work

           '  display the tooltips  -- did not work
            ' SetToolTip(hButton, "The Button 1 will do some thing")


 
    case WM_COMMAND
      select case loword(wParam)

        case IDCANCEL
                   EndDialog( hDlg, null )

        case ID_Button
                    mbox "Button clicked"
               
      end select
     

    case WM_CLOSE
      EndDialog( hDlg, null )
               
  end select

  return 0
end function







winmain()






Chris Chancellor

the main problem with the code is at the WM_INITDIALOG section


case WM_INITDIALOG
             '  sys hButton =  FindWindowEx(0,0, "Button1", NULL)   

               sys hButton =  FindWindow(NULL, "Button1")   
                 print hbutton     ' returns 0  did not work

           '  display the tooltips  -- did not work
            ' SetToolTip(hButton, "The Button 1 will do some thing")



  firstly it cannot get the handle of the Button1   -- it returns 0

and then the sub SetTooltip()   will just exit !


the PB code is as below


#COMPILE EXE
#DIM ALL
#INCLUDE "CommCtrl.inc"
%IDC_Button = 500
GLOBAL hDlg, hToolTip, hButton AS DWORD


'=================================================
FUNCTION PBMAIN() AS LONG
   DIALOG NEW PIXELS, 0, "Test Code",300,300,200,200, %WS_OVERLAPPEDWINDOW TO hDlg
   CONTROL ADD BUTTON, hDlg, %IDC_Button,"Push", 50,10,100,20
   CONTROL HANDLE hDlg, %IDC_Button TO hButton

   SetToolTip(hButton, "My Button")
   DIALOG SHOW MODAL hDlg
END FUNCTION


'=======================================
SUB SetToolTip(hControl AS DWORD, TipText AS ASCIIZ*256)

      LOCAL TI AS TOOLINFO

    hToolTip = CreateWindowEx(BYVAL 0, "tooltips_class32", "", %TTS_ALWAYSTIP OR %TTS_BALLOON,  _
              0, 0, 0, 0, BYVAL hDlg, BYVAL 0, GetModuleHandle(BYVAL %NULL), BYVAL 0)

     SendMessageW hToolTip, %TTM_SETTIPTEXTCOLOR,%RGB_MAGENTA,0
     SendMessageW hToolTip, %TTM_SETTIPBKCOLOR, %RGB_HONEYDEW,0

      TI.cbSize    = LEN(TI)
      TI.uFlags    = %TTF_SUBCLASS OR %TTF_IDISHWND
      TI.hWnd      = GetParent(hToolTip)
      TI.uId       = hControl
      TI.lpszText  = VARPTR(TipText)
      SendMessage hToolTip, %TTM_ADDTOOL, 0, VARPTR(ti)
END SUB






José Roca

OMG. Using FindWindow to retrieve the handle of a button!

Use

sys hButton =  GetDlgItem(hDlg, ID_Button)

Chris Chancellor

Thanxx a lot Jose

any suggestion on how to get this SetToolTip()  working ?

now the program just exit when inside this routine


'=======================================
' display tooltips
SUB SetToolTip(sys hControl , string TipText )

      dim TI AS TOOLINFO

    hToolTip = CreateWindowEx(BYVAL 0, "tooltips_class32", "", TTS_ALWAYSTIP OR TTS_BALLOON,  _
              0, 0, 0, 0, BYVAL hDlg, 0, GetModuleHandle(BYVAL NULL),  0)

   
   '  SendMessage hToolTip, TTM_SETTIPTEXTCOLOR,RGB_MAGENTA,0
   '  SendMessage hToolTip, TTM_SETTIPBKCOLOR, RGB_HONEYDEW,0

      TI.cbSize    = LEN(TI)
      TI.uFlags    = TTF_SUBCLASS OR TTF_IDISHWND
      TI.hWnd      = hdlg    'GetParent(hToolTip)

      TI.uId          = hControl
      TI.lpszText  = VARPTR(TipText)

      SendMessage hToolTip, TTM_ADDTOOL, 0, VARPTR(ti)
END SUB                         


José Roca


Chris Chancellor

Anyway  Thanxx Jose


Finally i did not get any GPF for this cleanup code but the tooltips are still not showing?

can some one help me on this, all help is appreciated


' DialogTT.o2bas


' Dialog with Tooltips


$ filename "DialogTT.exe"
uses rtl64

uses dialogs
uses user
uses minwin



' tooltips constants
% TB_SETTOOLTIPS = 1060
% EBTOOLTIPS = 256
% TBSTYLE_TOOLTIPS = &H100
% TBSETTIP = 9
% TTS_ALWAYSTIP = &H1
% TTS_NOPREFIX = &H2
% TTS_BALLOON = &H40 ' comctl32.dll v5.8 require
% TTM_ACTIVATE = WM_USER+1

% TTM_ADDTOOL = (WM_USER + 4)
% TTM_DELTOOL = (WM_USER + 5)
% TTM_NEWTOOLRECT = (WM_USER + 6)
% TTM_GETTOOLINFO = (WM_USER + 8)
% TTM_SETTIPBKCOLOR = (WM_USER + 19)
% TTM_SETTIPTEXTCOLOR = (WM_USER + 20)
% TTM_SETMAXTIPWIDTH = (WM_USER + 24)
% TTM_UPDATETIPTEXT  = 1036
% TTDT_AUTOPOP = 2
% TTDT_INITIAL = 3

% TTF_IDISHWND = &H1
% TTF_CENTERTIP = &H2
% TTF_SUBCLASS = &H10


Type TOOLINFO
    cbSize      As sys
    uFlags      As sys
    hWnd        As sys
    uId          As sys
    cRect       As RECT
    hinst       As sys
    lpszText    As   sys   
    lParam     AS LONG
     lpReserved AS sys
End Type


% ID_Button   = 1004

def varptr @ %1

macro MakeLong(lo,hi) { ( (lo) or ( (hi)<<16 ) ) }


sys hInstance = GetModuleHandle(null)
sys  hToolTip , hDlg
sys hButton

declare sub SetToolTip( string TipText)



'=====================================
sub winmain()

  Dialog( 0, 0, 300, 200, "Dialog with Tooltips",
          WS_OVERLAPPEDWINDOW or DS_CENTER or DS_SETFONT,
          10, "Arial")

      PushButton("Button1", ID_Button, 50,80,65,15)

       hDlg =  FindWindow(NULL, "Dialog with Tooltips")
       hButton =  GetDlgItem(hDlg, ID_Button)

' for labeling  text on the screen
  LText("Hover mouse over the button to get tooltips", -1, 20,160, 250,20)


  CreateModalDialog( null, @DialogProc, 0)
end sub



'
==========================================================
function DialogProc( sys hDlg,uint uMsg, sys wParam, lParam ) as sys callback
 
  select case uMsg
 
    case WM_INITDIALOG
                 
           '  display the tooltips  -- but did not work
             SetToolTip( "The Button 1 will do some thing")

 
    case WM_COMMAND
        select case loword(wParam)

           case IDCANCEL
                     EndDialog( hDlg, null )

           case ID_Button
                    mbox "Button1 was clicked"
               
      end select
     

    case WM_CLOSE
         EndDialog( hDlg, null )
               
  end select

  return 0
end function




'=======================================
' display tooltips
SUB SetToolTip( string TipText )

    '  dim TI AS TOOLINFO

     TOOLINFO  TI

    hToolTip = CreateWindowEx( 0, "tooltips_class32", "", TTS_ALWAYSTIP  | TTS_BALLOON,  _
              0, 0, 0, 0,  hDlg, 0,hInstance,  0)

     '  hDlg =  FindWindow(NULL, "Dialog with Tooltips")

 
   '  SendMessage hToolTip, TTM_SETTIPTEXTCOLOR,RGB_MAGENTA,0
   '  SendMessage hToolTip, TTM_SETTIPBKCOLOR, RGB_HONEYDEW,0


      TI.cbSize    =  Sizeof(TI)        '  we cannot use LEN(TI) as it will GPF
      TI.uFlags    =  TTF_SUBCLASS | TTF_IDISHWND
      TI.hWnd      =  GetParent(hToolTip)

      TI.uId          =  hbutton
      TI.lpszText  =   VARPTR(TipText)

      SendMessage hToolTip, TTM_ADDTOOL, 0,   VARPTR(TI)
END SUB                         





init_common_controls()
winmain()





José Roca

You must initialize the Common Controls Library.
See: InitCommonControls

Chris Chancellor