Is it possible to have <CR> in a text with Gadgettooltip ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

Can anyone figure out why this code resets the Windows 10 desktop?
This works in Windows 7 and Windows 10 BEFORE the Creator Update this week.

Code: Select all

; ToolTipID() code from netmaestro
; http://www.purebasic.fr/english/viewtopic.php?t=36765&start=0
Procedure EnumProc(hwnd, lparam)
  Shared ctrl
  cn$ = Space(100)
  GetClassName_(hwnd, @cn$, 99)
  If UCase(cn$) = "TOOLTIPS_CLASS32"
    With ti.TOOLINFO
      \cbSize = SizeOf(TOOLINFO)
      \hwnd = GetParent_(ctrl)
      \uid = ctrl
    EndWith
    If SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti)
      PokeI(lparam, hwnd)
      ProcedureReturn 0
    Else
      ProcedureReturn 1
    EndIf
  Else
    ProcedureReturn 1
  EndIf
EndProcedure
ProcedureDLL.i ToolTipID(gadget)
  Shared ctrl
  ctrl = gadget
  EnumWindows_(@EnumProc(),@TTID)
  ProcedureReturn TTID
EndProcedure
OpenWindow(0, 180, 400, 270, 100, "GadgetTooltip")
ButtonGadget(0, 10, 30, 250, 30, "Button with Tooltip")
GadgetToolTip(0, "Multiline Tooltip" + #CRLF$ + "with [CR][LF].")
;////////
; This sendmessage() resets the Windows 10 desktop screen for several seconds.
; But the code still creates a multiline tooltip.
SendMessage_(ToolTipID(GadgetID(0)), #TTM_SETMAXTIPWIDTH, 0, 100)
;////////
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by Fluid Byte »

EnumWindows_(), why so complicated?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

Maybe could be simpler, but your comment does not explain the Windows 10 Desktop reset with:
SendMessage_(ToolTipID(GadgetID(0)), #TTM_SETMAXTIPWIDTH, 0, 500)?
The reset is when modifying a PB created ToolTip.
I do not have a problem with my own ToolTip windows.

ToolTip(Tooln)=CreateWindowEx_(0,"ToolTips_Class32",#Empty$,#WS_POPUP | #TTS_NOPREFIX,0,0,0,0,WindowID,0,GetModuleHandle_(#Null),0)
I may have to go this way to keep the multi-line functionality in Windows 10.

Unless PB extends support for Multi-line Tooltips? 8)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by RASHAD »

Hi
No problem PB 5.44 x86 Windows 10 x64
But like FB said why this too much hassle
Glad to see you back FB :)

Code: Select all

If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 10, 10, 200, 90)
    GadgetToolTip(0, "Tooltip for Button 0"+#CRLF$+"         It is OK"+#CRLF$+"     Just for now")
    CanvasGadget(1, 10, 110, 200, 100)
    GadgetToolTip(1, "Tooltip for Button 1"+#CRLF$+"         It is OK"+#CRLF$+"     Just for now")
    ttip = FindWindow_("tooltips_class32",0)
    SetWindowTheme_(ttip, @null.w, @null.w) 
    SendMessage_(ttip,#TTM_SETTIPTEXTCOLOR,#Red,0)
    SendMessage_(ttip,#TTM_SETTIPBKCOLOR,$CBFEFD,0)
    SendMessage_(ttip,#TTM_SETMAXTIPWIDTH,0,150)
    r.RECT : r\left = 4: r\right = 4: r\top = 4: r\bottom = 4
    SendMessage_(ttip,#TTM_SETMARGIN,0,r)
    SetWindowLongPtr_(ttip,#GWL_STYLE,GetWindowLongPtr_(ttip, #GWL_STYLE)|#TTS_BALLOON)
    
    Repeat
      Event = WaitWindowEvent()
          
      If Event = #PB_Event_Gadget And EventGadget() = 0 
        If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
          If StartDrawing(CanvasOutput(0))
            x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
            y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
            Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
            StopDrawing()
          EndIf
        EndIf
      EndIf    
      
    Until Event = #PB_Event_CloseWindow
  EndIf
Egypt my love
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

Hi RASHAD,
Your example does not work when compiled x64 on Windows 10. :(
No color or multi-line tooltip. Just standard tooltip.
But, your code does not reset the Windows 10 Desktop.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by RASHAD »

Hi skywalk
My version works fine with PB x64
But I just noticed that you are running the enumerate from within the SendMessage
So try the next

Code: Select all

GadgetToolTip(0, "Multiline Tooltip" + #CRLF$ + "with [CR][LF].")
ttid = ToolTipID(GadgetID(0))
;////////
; This sendmessage() resets the Windows 10 desktop screen for several seconds.
; But the code still creates a multiline tooltip.
SendMessage_(ttid, #TTM_SETMAXTIPWIDTH, 0, 100)
;////////
Egypt my love
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

Yeah, that has no effect on the latest Windows 10(Creator Update).
I tried PB v56 x86 & x64.
The same code works fine on Windows 7.

Does anyone know how to use Spy++ to capture a tooltip window?
The tooltip window pops up but Spy++ does not display a change.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

Thanks RASHAD for asking to break out the ToolTipID().
Digging more, ToolTipID() was resetting the Windows 10 Desktop.

Code: Select all

SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti);<-- THIS LINE RESETS WINDOWS 10 DESKTOP!?
; NOT This...
SendMessage_(ttid, #TTM_SETMAXTIPWIDTH, 0, 150)
So, I tried TS_Soft's approach using PB's internal gadget properties and no RESETS! :D
Whew!

Code: Select all

  CompilerIf 1
    ; ToolTipID() code from TS-Soft
    ; http://www.purebasic.fr/english/viewtopic.php?t=36765&start=0
    Import ""
      PB_Object_GetThreadMemory(*Mem)
      PB_Gadget_Globals
    EndImport
    Structure GadgetGlobals
      CurrentWindow.i
      FirstOptionGadget.i
      DefaultFont.i
      *PanelStack
      PanelStackIndex.l
      PanelStackSize.l
      ToolTipWindow.i
    EndStructure
    Procedure.i ToolTipID(hGadget.i) ; hGadget not required, but shown to compare netmaestro's function.
      Protected *gg.GadgetGlobals
      *gg = PB_Object_GetThreadMemory(PB_Gadget_Globals)
      ProcedureReturn *gg\ToolTipWindow
    EndProcedure
  CompilerElseIf 0
    ; ToolTipID() code from netmaestro
    ; http://www.purebasic.fr/english/viewtopic.php?t=36765&start=0
    Procedure.i ToolTipID(hGadget.i)
      Shared ctrl
      ctrl = hGadget
      EnumWindows_(@EnumProc(),@TTID)
      ProcedureReturn TTID
    EndProcedure
    Procedure EnumProc(hwnd, lparam)
      Shared ctrl
      cn$ = Space(#MAX_PATH)
      GetClassName_(hwnd, @cn$, 99)
      If LCase(cn$) = "tooltips_class32"
        With ti.TOOLINFO
          \cbSize = SizeOf(TOOLINFO)
          \hwnd = GetParent_(ctrl)
          \uid = ctrl
        EndWith
        If SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti);<-- THIS LINE RESETS WINDOWS 10 DESKTOP!?
          PokeI(lparam, hwnd)
          ProcedureReturn 0
        Else
          ProcedureReturn 1
        EndIf
      Else
        ProcedureReturn 1
      EndIf
    EndProcedure
  CompilerEndIf
  OpenWindow(0, 180, 400, 270, 100, "GadgetTooltip on Windows 10")
  ButtonGadget(0, 10, 30, 250, 30, "Button with Multi-line Tooltip")
  GadgetToolTip(0, "Multi-line Tooltip" + #CRLF$ + "with [CR][LF].")
  If 1
    SendMessage_(ToolTipID(GadgetID(0)), #TTM_SETMAXTIPWIDTH, 0, 150)
  EndIf
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by Fluid Byte »

Again, why EnumWindows_()?

Code: Select all

OpenWindow(0,0,0,300,200,"Tooltips Demo",#WS_SYSMENU | #WS_CAPTION | 1)
ButtonGadget(0,5,5,105,25,"New Document")

hwndToolTip = CreateWindowEx_(0,"tooltips_class32",0,0 | #TTS_CLOSE,0,0,0,0,0,0,0,0)
SendMessage_(hwndToolTip,#TTM_SETMAXTIPWIDTH,0,300)
SendMessage_(hwndToolTip,#TTM_SETTITLE,1,"Caption")

Procedure AddToolTip(hwnd,Gadget,Text.s)
	Protected tti.TOOLINFO
	
	tti\cbSize = SizeOf(TOOLINFO)
	tti\uFlags = #TTF_SUBCLASS
	tti\hwnd = GadgetID(Gadget)
	tti\rect\right = GadgetWidth(Gadget)
	tti\rect\bottom = GadgetHeight(Gadget)
	tti\lpszText = @Text
	
	ProcedureReturn SendMessage_(hwnd,#TTM_ADDTOOL,0,tti)
EndProcedure

AddToolTip(hwndToolTip,0,"New Document" + #CRLF$ + "Multiline")

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

Jeez, I thought I posted in English?
There is NO reset problem creating your own tooltip window.
Reset occurs only on Windows 10(Creator Update) when you query PB's internal tooltip window with:
SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti);<-- THIS LINE RESETS WINDOWS 10 DESKTOP!?
Why the fascination with EnumWindows_() :?:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by Fluid Byte »

skywalk wrote:Jeez, I thought I posted in English?
Sure, unfortunately I didn't see the part where you said EnumWindows_() is a requirement.
skywalk wrote:There is NO reset problem creating your own tooltip window.
Then create your own tooltip, problem solved.
skywalk wrote:Reset occurs only on Windows 10(Creator Update) when you query PB's internal tooltip window with:
SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti);<-- THIS LINE RESETS WINDOWS 10 DESKTOP!?
The recent Windows creator update broke a lot of things and there is nothing you can do about that expect to wait for MS to release a patch. Also you are modifying PB gadgets with external API and wounder why something broke, that's adorable.
skywalk wrote:Why the fascination with EnumWindows_() :?:
You still failed to explain why it is necessary. Use the code I provided and the problem is gone. I don't understand why you make it complicated without a reason.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

My gui's are created from single line macros that drive all settings and enumerations for pb's gadgets,shortcuts,menus,toolbars,etc.
The multiline tooltip works with the flow I showed. Adding my own tooltip windows would work also, but more code to write/debug in my gui generator. Each gadget handle is assumed to be the sole target of any action.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by Fluid Byte »

So is this problem solved?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
skywalk
Addict
Addict
Posts: 3999
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Is it possible to have <CR> in a text with Gadgettooltip

Post by skywalk »

Yes, you showed there is no error creating our own tooltip window and I showed the workaround if you use PB's internal Tooltip window. It is up to the user to choose their preferred method. Better still if PB eventually supports multiline tooltips.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply