Page 1 of 1
How can i add titlebar buttons?
Posted: Wed Jun 28, 2006 1:00 am
by sverson
I look for something like this:
running on XP
...and older versions

sverson
Posted: Wed Jun 28, 2006 2:01 am
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.
Posted: Wed Jun 28, 2006 2:26 am
by sverson
I found it here:
MyPhoneExplorer
The little one minimizes to tray.

sverson
Posted: Wed Jun 28, 2006 5:31 am
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.
Posted: Wed Jun 28, 2006 5:56 am
by Shannara
Hmm, no extra buttons in the title bar in that sample.
** Edit: This post was created before the above post was edited. **
Posted: Wed Jun 28, 2006 6:03 am
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.
I posted the source anyway and a link to the icons, so see if that works any better. Sorry.
Posted: Wed Jun 28, 2006 6:28 am
by Dare
netmaestro wrote:; Yet another useless program by netmaestro
;
; because there just aren't enough useless programs
;
lol.

Posted: Wed Jun 28, 2006 9:39 am
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
Posted: Thu Jun 29, 2006 3:01 pm
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):
Here the little button changes the same way, all others do:

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
Posted: Thu Jun 29, 2006 3:04 pm
by Trond
When you draw it, draw a white image if the title bar has not focus.
Posted: Thu Jun 29, 2006 4:08 pm
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.
Posted: Thu Jun 29, 2006 4:13 pm
by Fred
I think you will have to use th XP theme library to do that, it should have some example on Google

.
Posted: Fri Jun 30, 2006 4:27 pm
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!

sverson
Posted: Thu Jul 27, 2006 6:15 pm
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.