TitleBarButton Library

Windows specific forum
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

TitleBarButton Library

Post by Dräc »

Hi everybody,

You can find here the first version of a library called >TitleBarButton<, which offers adding and managing easily a new button to a window caption.
You can create your own button or use one of the two preset button functions available:
Rull-Up and Stay On Top functions

The actual big limitation of the library takes on than only one button can by add to the same window.

Nevertheless, source code is included and any suggestions, code advices and efforts are welcome.

The actual code version takes its inspiration into the jaPBe and TailBite source codes.
Thanks to their authors to have put them.

Thanks to the French forum too, for the beta test (One bug known on XPpro: button can disappear!! :? ).

Enjoy it!

Dräc.
Last edited by Dräc on Sat Jan 01, 2005 1:07 am, edited 1 time in total.
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

Very nice thanks Dräc :D
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: TitleBarButton Library

Post by PB »

Looks good, thanks Dräc! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Drac,

That is really cool!

I found a problem with Windows XP (Home/Pro): The tooltips are not displayed on the new button. Has anyone else seen this?

Regards,
Eric
Manne
User
User
Posts: 30
Joined: Mon Apr 28, 2003 8:49 pm

Post by Manne »

Under WIN XP SP2 i get nor result for "GetTitleBarButtonState".
Anybody else with this problem?

greetz

Manne
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

@ebs: Normally it’s fixed with the new updated version 1.2.
You can download at the same address: >TitleBarButton v1.2<

@Manne: I’m surprised!
What does the following test code displayed on your debug window ?
Normally, you can check that the button state is well return by the GetTitleBarButtonState() function…

Code: Select all

; Title Bar Labrary validation test
Result=AddTitleBarButton(0,#True,  -1, -1, "BtnState1", "BtnState2")
Debug "AddTitleBarButton:" +Str(Result)
Result=GetTitleBarButtonState(0)
Debug "GetTitleBarButtonState:" +Str(Result)
Result=SetTitleBarButtonState(0,#True)
Debug "SetTitleBarButtonState:" +Str(Result)

; Test de get et set
#ToolWind_WIDTH = 150
#ToolWind_HEIGHT = 100
#ToolWindow=1

Procedure test(Param.l)
  state = GetTitleBarButtonState(Param)
  Repeat
  If GetTitleBarButtonState(Param)<>state
    state = GetTitleBarButtonState(Param)
    Debug state
  EndIf
  ForEver
EndProcedure

ToolWindowId= OpenWindow(#ToolWindow,10,20,#ToolWind_WIDTH,#ToolWind_HEIGHT, #PB_Window_SystemMenu | #PB_Window_SizeGadget |#PB_Window_ScreenCentered  , "ToolWindow", WindowId)
Result=AddStayOnTopButton(#ToolWindow, #False, -1, -1, "BtnState1", "BtnState2")
Debug "AddTitleBarButton:" +Str(Result)


SetTitleBarButtonState(#ToolWindow, #True)
Debug GetTitleBarButtonState(#ToolWindow)

Quit=#False
Repeat
  WndEvent = WaitWindowEvent()
  If WndEvent = #PB_Event_CloseWindow
    Select EventWindowID()
      Case #ToolWindow
        Quit =#True
    EndSelect
  EndIf

Until Quit

SetTitleBarButtonState(#ToolWindow, #False)
Debug GetTitleBarButtonState(#ToolWindow)

CreateThread(@test(), #ToolWindow)

 Quit=#False
  Repeat
    WndEvent = WaitWindowEvent()
    If WndEvent = #PB_Event_CloseWindow
      Select EventWindowID()
        Case #ToolWindow
          Quit =#True
      EndSelect
    EndIf
Until Quit
Manne
User
User
Posts: 30
Joined: Mon Apr 28, 2003 8:49 pm

Post by Manne »

@Dräc

As of your code i get the following output.
AddTitleBarButton:0
GetTitleBarButtonState:-1
SetTitleBarButtonState:0
AddTitleBarButton:1
1
But if i click on the button during runtime the event would not be recognized and the result is still 1.
I'm using the latest PB 3.92 and WIN XP Pro SP2.

greetz

Manne
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Drac,

Thanks for the fast response. Version 1.2 fixes the tooltip problem.

I noticed one other odd thing: All titlebar buttons, even one that's supposed to be blank, have a small rectangular outline near the bottom. I don't have a place to post an image, but the buttons have a small rectangular outline just above the bottom edge, similar to the Windows Minimize button. This is in addition to any image that is supposed to be on the button.

Can you (or anyone else) reproduce this?

Regards,
Eric
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

@Manne: I forgot to inform you: The result you have is normal, you need to close the window once to pass at the following of the code, or take this one directly (where I’ve set lines into comments):

Code: Select all

; Title Bar Labrary validation test 
Result=AddTitleBarButton(0,#True,  -1, -1, "BtnState1", "BtnState2") 
Debug "AddTitleBarButton:" +Str(Result) 
Result=GetTitleBarButtonState(0) 
Debug "GetTitleBarButtonState:" +Str(Result) 
Result=SetTitleBarButtonState(0,#True) 
Debug "SetTitleBarButtonState:" +Str(Result) 

; Test de get et set 
#ToolWind_WIDTH = 150 
#ToolWind_HEIGHT = 100 
#ToolWindow=1 

Procedure test(Param.l) 
  state = GetTitleBarButtonState(Param) 
  Repeat 
    If GetTitleBarButtonState(Param)<>state 
      state = GetTitleBarButtonState(Param) 
      Debug state 
    EndIf 
  ForEver 
EndProcedure 

ToolWindowId= OpenWindow(#ToolWindow,10,20,#ToolWind_WIDTH,#ToolWind_HEIGHT, #PB_Window_SystemMenu | #PB_Window_SizeGadget |#PB_Window_ScreenCentered  , "ToolWindow", WindowId) 
Result=AddStayOnTopButton(#ToolWindow, #False, -1, -1, "BtnState1", "BtnState2") 
Debug "AddTitleBarButton:" +Str(Result) 


SetTitleBarButtonState(#ToolWindow, #True) 
Debug GetTitleBarButtonState(#ToolWindow) 

;Quit=#False 
;Repeat 
;  WndEvent = WaitWindowEvent() 
;  If WndEvent = #PB_Event_CloseWindow 
;    Select EventWindowID() 
;      Case #ToolWindow 
;        Quit =#True 
;    EndSelect 
;  EndIf 
  
;Until Quit 

SetTitleBarButtonState(#ToolWindow, #False) 
Debug GetTitleBarButtonState(#ToolWindow) 

CreateThread(@test(), #ToolWindow) 

Quit=#False 
Repeat 
  WndEvent = WaitWindowEvent() 
  If WndEvent = #PB_Event_CloseWindow 
    Select EventWindowID() 
      Case #ToolWindow 
        Quit =#True 
    EndSelect 
  EndIf 
Until Quit 
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

ebs wrote:Drac,

Thanks for the fast response. Version 1.2 fixes the tooltip problem.

I noticed one other odd thing: All titlebar buttons, even one that's supposed to be blank, have a small rectangular outline near the bottom. I don't have a place to post an image, but the buttons have a small rectangular outline just above the bottom edge, similar to the Windows Minimize button. This is in addition to any image that is supposed to be on the button.

Can you (or anyone else) reproduce this?

Regards,
Eric
This is completely nominal for the moment!
In fact, it’s because I build the blank button by erasing the Windows Minimize one, this to have a new button similar to the others.
If the copied button color is not equal to the background color referenced into system configuration settings, you can see the ruse.
I don’t know if a button template already exists into windows system but if someone knows, tell me!
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

I have found a way to improve the button building according to DrawFrameControl API function.
I’m afraid that will limit the appearance of the button to the only standard format…
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

NOOOOOOOOOOO, someone stoled my nickname!!! 8O

hehehe
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

@ebs : I improve the way of painting the button :)
You can download this at the same address (it’s still v1.2).

Does the results is correct on XP ?
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Drac,

The button paints correctly with the new version (no horizontal bar).

However, when a window is moved by dragging the titlebar, the standard buttons (minimize, maximize/restore, and close)
will change from the XP style back to the older "classic" windows style.

Is that what you were referring to in your earlier message?

Regards,
Eric
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

Actually, the library doesn’t manage the Windows XP theme and if you disable it (come back to windows standard look), all works well…
Post Reply