Author Topic: Tool Tips  (Read 5002 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Tool Tips
« on: September 16, 2018, 07:10:23 PM »
Quote from: CC@JRS
Hello all

this is an example which i have modified Roland's Treeview codes and added in tooltips

That sure seems like a lot of code to get a tool tip to work. I'm spoiled using VB6 as tool tips is a control property








« Last Edit: September 16, 2018, 10:42:35 PM by John »

  • Guest
Re: Tool Tips
« Reply #1 on: September 16, 2018, 11:36:04 PM »
Yes, spoiled is the right word. If you let a visual designer to do the work for you, you never learn. If you know how it works, you can write wrappers to not have to do a lot of work each time you need it, e.g.

Code: [Select]
DIM hTooltip AS HWND = AfxAddTooltip(hButton, "This is a button with a tooltip", TRUE, TRUE)
AfxSetTooltipText(hTooltip, hButton, "This is a modified text")
AfxDeleteTooltip(hTooltip, hButton)

JRS

  • Guest
Re: Tool Tips
« Reply #2 on: September 17, 2018, 06:22:11 AM »
Quote
Yes, spoiled is the right word. If you let a visual designer to do the work for you, you never learn. If you know how it works, you can write wrappers to not have to do a lot of work each time you need it,

My clients assume that I'm well educated being their consultant / programmer. They are paying me for results not feeding my curiosity.

Make sure you don't let Paul know about you're distaste for UI designers.  :)
« Last Edit: September 17, 2018, 07:22:24 AM by John »

Arnold

  • Guest
Re: Tool Tips
« Reply #3 on: September 17, 2018, 08:51:37 AM »
To compare Oxygenbasic with a full featured VB6 or any other environment is a killer argument. This can be used for anything related to Oxygenbasic. And I am glad that I am still a bit curious.

The code for tooltips is not very big in size if you ignore the constants and types. If I could inspect the code of the tooltips property of VB6, certainly there would be much more code necessary. (thus of course the implementation is more versatile)

As I have access to WinFBE, (btw: a spended all-in-one suite) I looked for AfxAddTooltip. I suppose Chris could do something similar in ToolTipsO2.inc too:

% TTF_CENTERTIP=2
...

function SetToolTip(sys hwnd, string TipText, optional bool Balloon=false, bCentered=false) as sys
...

I know I am a little bit outdated, not quite up to date. Is it possible to create 64-bit apps with VB6?


José Roca

  • Guest
Re: Tool Tips
« Reply #4 on: September 17, 2018, 09:40:58 AM »
> Make sure you don't let Paul know about you're distaste for UI designers.  :)

It never has been a secret.

> I know I am a little bit outdated, not quite up to date. Is it possible to create 64-bit apps with VB6?

No, but for John this is only a terrible shortcoming if the compiler is called PowerBasic.

  • Guest
Re: Tool Tips
« Reply #5 on: September 17, 2018, 10:54:39 AM »
> And I am glad that I am still a bit curious.

This is the way to go if you want to be a truly programmer instead of a tool user. Imagine an scientist not being able to do a sum without the help of a calculator.

Millions of VB6 users have been using COM Automation under the hood and most don't know anything or very little about this technology. Most of the OCXs that they used where written by C++ programers using ATL. If you write one with VB6, you become dependent of the VB6 runtime.

JRS

  • Guest
Re: Tool Tips
« Reply #6 on: September 17, 2018, 02:05:40 PM »
Most BASIC users want a way to control their computer without having to be a career programmer to do it.

If your goal is to be a full time programmer, don't take short cuts.

If you're already a seasoned programmer, steal / borrow code from the net and refactor it to your needs.

I would have to say your documentation is a gold standard in my eyes. When you finish your FB includes, would you consider documenting Oxygen  Basic?
« Last Edit: September 17, 2018, 08:09:34 PM by John »

Arnold

  • Guest
Re: Tool Tips - a bit enhanced
« Reply #7 on: September 18, 2018, 12:19:24 PM »
Hi Charles,

Chris had a really brilliant idea: creating tooltips for Windows controls done in an Oxygenbasic include file. The routines can be used to create 32-bit and 64-bit exes. The routines can be applied for controls in a dialog or created via CreateWindoEx. I could not resist and added José's idea of balloons and centering plus four helper functions. Reading the MSDN documentation, there would be still more possible, but the provided routines are more than sufficient.

Following is tooltips.inc, a bit enhanced and a further demo. I knew about the TOOLINFO structure but Chris had the idea which could be used effectively. There should be more people like him who are thinking about a problem and how to solve it.

Roland

Tooltips.inc
Code: OxygenBasic
  1. 'ToolTips.inc
  2. 'https://docs.microsoft.com/de-de/windows/desktop/Controls/tooltip-control-reference
  3.  
  4. 'uses corewin
  5.  
  6. ' tooltips constants
  7. % TTF_IDISHWND=1
  8. % TTF_CENTERTIP=2
  9. % TTF_SUBCLASS=16
  10. % TTI_NONE  0
  11. % TTI_INFO  1
  12. % TTI_WARNING  2
  13. % TTI_ERROR  3
  14. % TTI_INFO_LARGE  4
  15. % TTI_WARNING_LARGE  5
  16. % TTI_ERROR_LARGE  6
  17. % TTM_ADDTOOL=1028
  18. % TTM_DELTOOL=1029
  19. % TTM_SETTIPBKCOLOR=1043
  20. % TTM_SETTIPTEXTCOLOR=1044
  21. % TTM_SETMAXTIPWIDTH=1048
  22. % TTM_SETTITLE=1056
  23. % TTS_ALWAYSTIP=1
  24. % TTS_BALLOON=64
  25.  
  26. type TOOLINFO
  27.   UINT      cbSize
  28.   UINT      uFlags
  29.   sys       hwnd
  30.   sys       uId    'UINT_PTR
  31.  RECT      rect   'must be checked
  32.  sys       hinst
  33.   char*     lpszText
  34.   sys       lParam
  35.   sys      *lpReserved
  36. end type
  37.  
  38. '============================
  39. ' RGB function for O2
  40. function RGB(int rcc, gcc, bcc) as int
  41.    return (rcc + gcc*256 + bcc*65536)
  42. end Function
  43. '=======================================
  44.  
  45. function SetToolTip(sys hwnd, string TipText, optional bool Balloon=false, bCentered=false) as sys
  46.  
  47.     TOOLINFO TI
  48.     sys flags=TTS_ALWAYSTIP
  49.     uint uFlags=TTF_SUBCLASS or TTF_IDISHWND
  50.  
  51.     if Balloon then flags=flags or TTS_BALLOON
  52.     if bCentered then uflags=uflags or TTF_CENTERTIP
  53.  
  54.     sys hToolTip = CreateWindowEx(0, "tooltips_class32", "", flags,
  55.                                   0, 0, 0, 0, hwnd, null, GetModuleHandle(null), null)
  56.  
  57.     TI.cbSize    = sizeof(TI)
  58.     TI.uFlags    = uflags
  59.     TI.hWnd      = GetParent(hToolTip)
  60.     TI.uId       = hwnd
  61.     TI.lpszText  = strptr TipText
  62.     SendMessage (hToolTip, TTM_ADDTOOL, 0, &ti)
  63.  
  64.      return hToolTip
  65. end function
  66.  
  67. 'set the text color
  68. sub setTooltipTextColor(sys hTool, int FGcolor)
  69.     SendMessage (hTool, TTM_SETTIPTEXTCOLOR, FGcolor, 0)
  70. end sub
  71.  
  72. 'for the background color
  73. sub setTooltipBackColor(sys hTool, int BKcolor)
  74.     SendMessage (hTool, TTM_SETTIPBKCOLOR, BKcolor)
  75. end sub
  76.  
  77. 'set a title for the tooltip
  78. sub setTooltipTitle(sys hTool, string Text, optional sys icon=TTI_INFO)
  79.    SendMessage(hTool, TTM_SETTITLE, icon, Text)
  80. end sub
  81.  
  82. 'limit Tooltip max width
  83. sub setTooltipWidth(sys hTool, int maxwidth)
  84.    SendMessage(hTool, TTM_SETMAXTIPWIDTH, 0, maxwidth)
  85. end sub      
  86.  


DemoTooltips.o2bas
Code: OxygenBasic
  1. $ filename "DemoToolTips.exe"
  2.  
  3. 'uses rtl32
  4. 'uses rtl64
  5.  
  6. uses WinUtil
  7. uses ToolTips
  8.  
  9. sys Button_Exit, Button_Ok, Button_Cancel, Button_Apply, MleText1, MleText2
  10.  
  11. enum  Control_ids
  12.    ID_Button_Exit=1001
  13.    ID_Button_OK
  14.    ID_Button_Cancel
  15.    ID_Button_Apply
  16.    ID_MleText1
  17.    ID_MleText2  
  18. end enum
  19.  
  20. % Btn_Style    = WS_CHILD|WS_VISIBLE|WS_TABSTOP
  21. % Btn_ExtStyle = WS_EX_STATICEDGE
  22. % Mle_Style    = WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|WS_BORDER|ES_LEFT|ES_MULTILINE
  23. % Mle_ExtStyle = WS_EX_CLIENTEDGE
  24. string crlf = chr(13,10)
  25.  
  26. sys hInstance=inst
  27. MainWindow 410,340,WS_OVERLAPPEDWINDOW
  28.  
  29. function createControl(string ctlclass, string Text, sys hwnd, int id, x,y,w,h, int Style, optional ExStyle=0) as sys
  30.    sys hCtrl
  31.    hCtrl=CreateWindowEx(ExStyle, ctlclass, Text, Style, x,y,w,h,  hWnd, id, hInstance, null)
  32.    if hCtrl=null then mbox "Error: Cannot create " ctlclass
  33.    return hCtrl
  34. end function
  35.  
  36. function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
  37.     string hint="Lorem ipsum dolor sit amet, consetetur sadipscing elitr," &
  38.                  "sed diam nonumy eirmod tempor invidunt ut labore et dolore" &
  39.                  "magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores"
  40.  
  41.     select uMsg
  42.  
  43.         case WM_CREATE
  44.            SetWindowText(hwnd, "tooltips Demo")
  45.            Button_Exit = CreateControl("Button","Exit",hwnd,ID_Button_Exit, 296, 8, 88, 24, Btn_Style, Btn_ExtStyle)
  46.            Button_Ok = CreateControl("Button","OK",hwnd,ID_Button_Ok, 8, 272, 88, 24, Btn_Style, Btn_ExtStyle)
  47.            Button_Cancel = CreateControl("Button","Cancel",hwnd,ID_Button_Cancel, 152, 272, 88, 24, Btn_Style, Btn_ExtStyle)
  48.            Button_Apply = CreateControl("Button","Apply",hwnd,ID_Button_Apply, 296, 272, 88, 24, Btn_Style, Btn_ExtStyle)
  49.            MleText1 = CreateControl("Edit","",hwnd,ID_MleText1, 8, 8, 232, 256, Mle_Style, Mle_ExtStyle)
  50.            MleText2 = CreateControl("Edit","",hwnd,ID_MleText2, 248, 48, 136, 216, Mle_Style, Mle_ExtStyle)
  51.  
  52.            sys hTool1=SetToolTip(hwnd, "This is the Main Window", true)
  53.            sys hTool2=SetToolTip(Button_Exit, "This will leave the program. Do not forget to save",true,true)
  54.            setToolTipTitle(hTool2, "Exit Program")
  55.            setToolTipWidth(hTool2, 20)
  56.            sys hTool3=SetToolTip(Button_ok, "OK", true, true)
  57.            sys hTool4=SetToolTip(Button_Cancel, "Cancel", ,true)
  58.            sys hTool5=SetToolTip(Button_Apply, "Apply",true)
  59.            sys hTool6=SetToolTip(MleText1, hint, true)
  60.            setToolTipBackColor(hTool6, CYAN)
  61.            sys hTool7=SetToolTip(MleText2,hint ,true))
  62.            setToolTipTextColor(hTool7, RGB(250,150,0))
  63.            setToolTipBackColor(hTool7, WHITE)
  64.            setToolTipWidth(hTool7, 80)
  65.                      
  66.         case WM_COMMAND          
  67.            select case loword(wParam)  'id
  68.              case ID_Button_Exit
  69.                  Sendmessage(hwnd, WM_CLOSE)
  70.               case ID_Button_Ok, ID_Button_Cancel, ID_Button_Apply
  71.                  mbox "Button clicked"  
  72.            end select
  73.            
  74.         case WM_CLOSE
  75.            DestroyWindow(hwnd)
  76.  
  77.         case WM_DESTROY
  78.            PostQuitMessage(0)
  79.  
  80.         case else
  81.            return DefWindowProc(hwnd, uMsg, wParam, lParam)
  82.            
  83.     end select
  84.  
  85.     return 0
  86. end function
  87.  


Aurel

  • Guest
Re: Tool Tips
« Reply #8 on: September 18, 2018, 01:40:04 PM »
I can something similar in awinh.inc tooltip functions but i never think that might be usefull  ::)

JRS

  • Guest
Re: Tool Tips
« Reply #9 on: September 18, 2018, 01:47:07 PM »
Hubcaps aren't required to make the wheels turn but they look nice.

José Roca

  • Guest
Re: Tool Tips
« Reply #10 on: September 18, 2018, 02:15:36 PM »
Quote
I would have to say your documentation is a gold standard in my eyes. When you finish your FB includes, would you consider documenting Oxygen  Basic?

Please, John, how I'm going to write documentation for a language that I don't know how to use because there is no documentation for it?

JRS

  • Guest
Re: Tool Tips
« Reply #11 on: September 18, 2018, 02:23:43 PM »
Quote
Please, John, how I'm going to write documentation for a language that I don't know how to use because there is no documentation for it?

Sounds like the chicken / egg question?

There are basic docs along with tons of examples and if you're still confused, ask Charles or look at the O2 source.

Did you not learn the Windows API by creating PB includes? Writing professional docs for O2 will allow you to master the language just like everything else you do.
« Last Edit: September 18, 2018, 02:43:35 PM by John »

  • Guest
Re: Tool Tips
« Reply #12 on: September 18, 2018, 03:05:28 PM »
I could not have been able to write the PB include files if there was not documentation for the Windows API. When I write a new class in Free Basic, I write the documentation. I don't expect that somebody else will figure how to use it reading the code and then write the documentation for me.

JRS

  • Guest
Re: Tool Tips
« Reply #13 on: September 18, 2018, 04:22:50 PM »
That's the problem. This is an open source project and not PB. This type of language is built and supported by the community. If you're not a team player, this project isn't for you.

José Roca

  • Guest
Re: Tool Tips
« Reply #14 on: September 18, 2018, 05:04:52 PM »
Despite to your insistence, THIS IS NOT an open source project and it is not being built and supported by any community. It is Charle's personal project and it is PUBLIC DOMAIN.