How can i add titlebar buttons?

Just starting out? Need help? Post your questions and find answers here.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

How can i add titlebar buttons?

Post by sverson »

I look for something like this:

running on XP
Image

...and older versions
Image


;-) sverson
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

That's awesome, Im wondering about the answer to this as well. Since Im looking to a button that will sticky or unstick a window.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

I found it here: MyPhoneExplorer

The little one minimizes to tray.

;-) sverson
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

What do you want the buttons to do? I think I know what you want, but I'm not sure. I wrote this a while back, could you run it and see if that's what you want? If so, I'll post the code.

http://www.networkmaestro.com/TitleBar.exe

What the heck, it looks close enough to me. You'll need this icon file:

http://www.networkmaestro.com/pencilicons.zip

It contains one icon for the pushed version of the button and one for the up. Make them available to this code:

Code: Select all

; Yet another useless program by netmaestro 
; 
; because there just aren't enough useless programs 
; 

pathiconup$ = "d:\pencilup.ico"     ; Put your own path here 
pathicondn$ = "d:\pencildown.ico"   ; put your own path here 

Global pencilup=LoadImage_(GetModuleHandle_(0),pathiconup$,#IMAGE_ICON,0,0,#LR_LOADFROMFILE) 
Global pencildown=LoadImage_(GetModuleHandle_(0),pathicondn$,#IMAGE_ICON,0,0,#LR_LOADFROMFILE) 

Procedure ButtonAction()
  SetGadgetText(0, GetGadgetText(0)+"Pencil... ") 
EndProcedure

Procedure MouseOnButton() 
  GetCursorPos_(@pt.point) 
  If pt\x >= WindowX(0)+540 And pt\x <= WindowX(0)+560 
    If pt\y >=WindowY(0)+5 And pt\y <= WindowY(0)+25 
      ProcedureReturn 1 
    Else 
      ProcedureReturn 0 
    EndIf 
  EndIf 
EndProcedure 

Procedure ProcessTitleButtons() 
  If MouseOnButton() 
    While GetAsyncKeyState_(#VK_LBUTTON) & 32768 
      If MouseOnButton()
        DrawIconEx_(GetWindowDC_(WindowID(0)), 540,7, pencildown, 18, 18, 0, #Null, #DI_NORMAL ) 
      Else
        DrawIconEx_(GetWindowDC_(WindowID(0)), 540,7, pencilup, 18, 18, 0, #Null, #DI_NORMAL ) 
      EndIf
      Delay(1) 
    Wend 
    While WindowEvent():Wend 
    If MouseOnButton() 
      ButtonAction()
    EndIf 
    DrawIconEx_(GetWindowDC_(WindowID(0)), 540,7, pencilup, 18, 18, 0, #Null, #DI_NORMAL ) 
  EndIf 
EndProcedure 

Procedure CallBack(hwnd, msg, wparam, lparam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_PAINT,#WM_ACTIVATE,#WM_MOVE 
      DrawIconEx_(GetWindowDC_(WindowID(0)), 540,7, pencilup, 18, 18, 0, #Null, #DI_NORMAL ) 
    Case #WM_SYSCOMMAND 
      ProcessTitleButtons() 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

OpenWindow(0,0,0,640,480,"TitleBarButton Example by netmaestro",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget) 
SetWindowCallback(@CallBack()) 
CreateGadgetList(WindowID(0)) 
TextGadget(0,220,200,240,200,"") 

Repeat : Until WaitWindowEvent() = #WM_CLOSE 
    
End 
As you can see, it's a bit of work. You have to draw the pushed/unpushed buttons yourself and manage the events. But it really isn't that difficult. Of course, there could be a much better way to do it. I just don't know what it is.
Last edited by netmaestro on Tue Dec 26, 2006 2:27 pm, edited 5 times in total.
BERESHEIT
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Hmm, no extra buttons in the title bar in that sample.
** Edit: This post was created before the above post was edited. **
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

oops, sorry Shannara, I was loading the icons from my hard disk. They wouldn't have been available to the exe run from somewhere else. :oops:

I posted the source anyway and a link to the icons, so see if that works any better. Sorry.
BERESHEIT
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

netmaestro wrote:; Yet another useless program by netmaestro
;
; because there just aren't enough useless programs
;
lol. :D
Dare2 cut down to size
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

You may also take a look at an example from xgp with a question mark icon in the title bar for displaying context sensitive help:
http://www.purebasic.fr/english/viewtopic.php?t=22028
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

Thanks netmaestro.

I allready knew the "?" example (http://www.purebasic.fr/english/viewtopic.php?t=22028)
I want to add own (transparent) buttons like this.

What I need, is a way to add a non static button.

In your example the button is allways the same (not really a part of the window):
Image

Here the little button changes the same way, all others do:
Image
Window focus and/or system colors affect the button.
[EDIT]: I changed system colors from blue to green whlie the program was running!

Is there a way to manipulate the (windows) internal imagelist?

;-) sverson
Last edited by sverson on Thu Jun 29, 2006 3:29 pm, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

When you draw it, draw a white image if the title bar has not focus.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

@netmaestro

Just for information, your code does not work correctly with Windows 98 :
- the icons are not really in the titlebar : different titlebar heigth in Win98.
- sometimes the button doesn't react to a mouse click.
- sometimes the mouse cursor sticks to the button, and I can move the window by moving the mouse ; I have to click again to release the cursor.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I think you will have to use th XP theme library to do that, it should have some example on Google ;).
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

Fred wrote:I think you will have to use th XP theme library to do that, it should have some example on Google ;).
Thanks!

:wink: sverson
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Did you find out how to do this? I can extract the individual title bar buttons from the current theme, but I can't get them without glyphs.
Post Reply