Page 1 of 1

Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 10:43 am
by jassing
Is it possible to change the tooltip for the standard 'minimize' button?
Image

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 11:27 am
by RASHAD
Hi

Code: Select all

Global hToolTip,hwnd

Procedure WinCallback(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NCMOUSEMOVE
      If wParam = #HTMINBUTTON
        For i = 65550 To 65600
        If IsWindowVisible_(i)
          ShowWindow_(i, #SW_HIDE)
        EndIf
        Next
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

Procedure.l AddTooltips()
  hToolTip = CreateWindowEx_(0, "ToolTips_Class32", "", #WS_POPUP |#TTS_NOPREFIX |#TTS_ALWAYSTIP, 0, 0, 0, 0, WindowID(0), 0, GetModuleHandle_(0), 0)
  SetWindowPos_(hToolTip, #HWND_TOPMOST	, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)
  SendMessage_(hToolTip, #TTM_SETDELAYTIME, #TTDT_INITIAL,10)
  SetWindowTheme_(hToolTip, @null.w, @null.w) 
  ttAdd.TOOLINFO\cbSize = SizeOf(TOOLINFO)
  ttAdd\uFlags = #TTF_SUBCLASS
  ttAdd\hwnd = WindowID(0)
  ttAdd\hInst = 0  
  buttonW = GetSystemMetrics_(#SM_CXSIZE)
  buttonH = GetSystemMetrics_(#SM_CYSIZE)  
  winW = WindowWidth(0)
  ttAdd\uId = #HTMINBUTTON
  SetRect_(@ttAdd\rect,winW - 3*buttonW, - buttonH - 3, winW - 2*buttonW,- 3)
  ttAdd\lpszText = @"Press to minimize to system tray"
  SendMessage_(hToolTip, #TTM_ADDTOOL, 0, ttAdd)
  SendMessage_(hToolTip, #TTM_UPDATE , 0, 0)
 
  ProcedureReturn hToolTip
EndProcedure

hwnd = OpenWindow(0, 0, 0, 300, 300, "Custom Caption Tooltips", #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
  SetWindowCallback(@WinCallback())
  
  AddTooltips()
  SetActiveWindow(0)
  Repeat
    event = WaitWindowEvent()

  Until event = #PB_Event_CloseWindow 

End

Edit :Code modified
Edit :Modified again

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 11:38 am
by MachineCode
Rashad, I see no difference with your code on XP? Same tooltip text as normal.

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 11:45 am
by RASHAD
Sorry MC :)
Check it now
Code modified

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 12:01 pm
by MachineCode
Nope? I put the mouse over all 3 buttons, and no tooltip appears for about 5 seconds or so, and then I just see "Minimize", "Maximize" or "Close" like normal. What's meant to happen?

[Edit] Okay, it shows the longer tooltip message for minimize if I move the mouse onto the box from the left or right, but not if I move it on from up or down. Any way to fix that?

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 12:09 pm
by RASHAD
Code modified again
Please check

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 12:15 pm
by TI-994A
Hi RASHAD. Nice code, although the problem for MachineCode may be the WinXP themes. I see that you've disabled it in your modified code, but IIRC, that doesn't always work.

BTW, in the callback, what's the relevance of hiding windows 65550 To 65600?

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 12:17 pm
by MachineCode
Rashad, that works every time now, yes. :) But not with a balloon shape, it's just a rectangle. Best compromise, I guess?

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 1:08 pm
by TI-994A
Hello again, RASHAD. I noticed that you had actually disabled the tooltip for the Minimize button (65550 To 65600?) and activated a custom-drawn tooltip for its region of the window. Great workaround, although I'm still wondering why the callback hides 50 windows.

Regarding the issue MachineCode had with the windows themes/styles, you seem to have circumvented it with the SetWindowTheme() function. However, in one of my earlier codes, the custom-drawn tooltip stops showing after an initial time-out. I was hoping you might know the reason behind this:

Code: Select all

EnableExplicit

Enumeration
  #MainWindow
  #TextInput
  #ToolTipIcon
EndEnumeration

Define.i toolTip, wFlags, tti.TOOLINFO
Define.s iconFileName, defaultPathFile, displayPattern 

defaultPathFile = "C:\"
displayPattern = "Icon Files (*.ico) | *.ico"
iconFileName = OpenFileRequester("Please choose an icon to use", defaultPathFile, displayPattern, 0)
If iconFileName And LoadImage(#ToolTipIcon, iconFileName)
  wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
  OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 300, "Graphic Tooltips", wFlags)
  StringGadget(#TextInput, 50, 100, 200, 30, "Hover mouse to see the graphic tooltip...")
  
  toolTip = CreateWindowEx_(0, #TOOLTIPS_CLASS, #NULL$, #TTS_BALLOON, 0, 0, 0, 0, GadgetID(#TextInput), 0, GetModuleHandle_(0), 0)

  With tti
    \cbSize = SizeOf(TOOLINFO)
    \hWnd = WindowID(#MainWindow)
    \uId = GadgetID(#TextInput)
    \uFlags = #TTF_IDISHWND | #TTF_SUBCLASS
    \lpszText = @"A gadget tooltip with graphics..."
  EndWith  
  
  SendMessage_(toolTip, #TTM_ADDTOOL, 0, tti)
  SendMessage_(toolTip, #TTM_SETMAXTIPWIDTH, 0, 200)
  SendMessage_(toolTip, #TTM_SETTITLE, ImageID(#ToolTipIcon), "Custom Tooltip")

  While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend 
  
EndIf
End
If the mouse pointer is left on the gadget and the tooltip is allowed to fade-out on its own, it's gone for good. Any idea what may be causing this?

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 2:39 pm
by luis
TI-994A wrote: If the mouse pointer is left on the gadget and the tooltip is allowed to fade-out on its own, it's gone for good. Any idea what may be causing this?
On windows XP only ? Because that's an XP bug if I'm not mistaken.

Try do do the same with some other program iconized in the notification area. The tooltip doesn't come back.
If you go to another icon with a tooltip, the new tooltip will re-enable the one precedently disabled.

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 5:34 pm
by jassing
Thanks Rashad!

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 5:44 pm
by TI-994A
luis wrote:Try do do the same with some other program iconized in the notification area. The tooltip doesn't come back. If you go to another icon with a tooltip, the new tooltip will re-enable the one precedently disabled.
Hi luis. You're right, once they time out, they don't come back until another is popped first. Strange behaviour. Thanks for pointing that out.

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 6:01 pm
by luis
@ti-994a

I remember doing something like destroying and recreating the tooltip, or disabling it in some way and re-enabling him when the mouse pointer was leaving the icon area, I don't remember the details... anyway a quick search brought this thread out

http://stackoverflow.com/questions/5597 ... -first-use

Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 6:02 pm
by RASHAD
@jassing you are welcome

@TI-994A
For 65550 To 65600 question that is because the handle of the tip is different for
each windows version but usually it is between that range

Next code to solve windows XP bug
Hope you like it

Code: Select all

EnableExplicit

Enumeration
  #MainWindow
  #TextInput
  #ToolTipIcon
EndEnumeration

Define.i wFlags, tti.TOOLINFO
Define.s iconFileName, defaultPathFile, displayPattern

Global Result,m.MSG,tooltip

Procedure WndProc(hwnd, uMsg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  If uMsg = #WM_MOUSEMOVE
    m.MSG
    m\hwnd = hwnd
    m\message = uMsg
    m\wParam = wParam
    m\lParam = lParam
    SendMessage_(tooltip, #TTM_RELAYEVENT, 0,m)
  EndIf
  ProcedureReturn Result
EndProcedure

defaultPathFile = "C:\"
displayPattern = "Icon Files (*.ico) | *.ico"
iconFileName = OpenFileRequester("Please choose an icon to use", defaultPathFile, displayPattern, 0)
If iconFileName And LoadImage(#ToolTipIcon, iconFileName)
  wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
  OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 300, "Graphic Tooltips", wFlags)
  StringGadget(#TextInput, 50, 100, 200, 30, "Hover mouse to see the graphic tooltip...")

 
  toolTip = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_BALLOON, 0, 0, 0, 0, GadgetID(#TextInput), 0, GetModuleHandle_(0), 0)

    tti\cbSize = SizeOf(TOOLINFO)
    tti\uFlags = #TTF_IDISHWND | #TTF_SUBCLASS
    tti\hWnd = GadgetID(#TextInput)
    tti\uId = GadgetID(#TextInput)
    tti\lpszText = @"A gadget tooltip with graphics..."
 
  SendMessage_(toolTip, #TTM_ADDTOOL, 0, tti)
  SendMessage_(toolTip, #TTM_SETMAXTIPWIDTH, 0, 200)
  SendMessage_(toolTip, #TTM_SETTITLE, ImageID(#ToolTipIcon), "Custom Tooltip")
  
  SetWindowCallback(@WndProc())
  
While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend 
 
EndIf
End


Re: Change tooltip for 'minimize' button?

Posted: Fri Nov 16, 2012 7:27 pm
by TI-994A
RASHAD wrote:For 65550 To 65600 question that is because the handle of the tip is different for each windows version but usually it is between that range
Wow! Where do you get these details?
RASHAD wrote:Next code to solve windows XP bug
Hi RASHAD. Shoukran. I was struggling with that for some time, but never knew about the #TTM_RELAYEVENT message. It works great now. Thank you.