How to add an extra button to the WindowTitle?

Just starting out? Need help? Post your questions and find answers here.
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 »

Mine's steady at 33 all the time now, thanks to Sparkie!
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Fluid Byte wrote:@Trond: Please update your system respectivley use the XP theme feature. Then you would know that this code certainly corectly places/sizes the button but lacks XP skinning representation.
Please update your system to not use the XP theme feature. Then you would know that netmaestro's code lacks a normal representation.
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 »

does not...
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

?
Image

Edit: By the way, emule's implementation fails miserably with another theme than the default XP one. Another minimize button is displayed almost on top of the normal minimize button. So, you don't want it like emule. :wink:
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Trond wrote:Please update your system to not use the XP theme feature. Then you would know that netmaestro's code lacks a normal representation.
ROFL Trond! I expected something like that. :roll:

Well, don't get me wrong here. I don't want to force you to use something you dislike (although there is no argument for it) but you have to use the skinning feature in order to make your code compatible with XP themes.

@netmaestro: Trond is right here. You are using plain images so it will look like on the screenshot he posted when XP theming is disabled.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Actually I knew the the code I used didn't look good with themes, but, as you said, netmaestros doesn't look good without themes. I have tried to make it theme compatible, but it's almost impossible. Remember that there's no guarantee that the user uses the default XP theme.
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 »

It's easy to make my code work themed or not. The last code I posted handles sizing correctly and all you have to do is provide 3 icon images for themed and 3 for unthemed and use the appropriate set for the environment you find.
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Since it's so easy, will you show us?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Remember that there's no guarantee that the user uses the default XP theme.
Exactly! That's what I also pointed out. Addding an extra button for themed/non-themed applications involves messing around with the "Visual Styles Reference".
The last code I posted handles sizing correctly and all you have to do is provide 3 icon images for themed and 3 for unthemed and use the appropriate set for the environment you find.
Not a chance! As stated before people can use different XP skins so you need to access the current theme data and obtain the appropriate images to create an extra window button.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
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 »

No problem, I'll post some code after I get back that shows the method. It isn't difficult at all to clone the current look of the window, whatever theme or color it is. But if you're looking to make the button look exactly like a button would from somebody's theme engine, that's not a reasonable goal. For my purposes it's enough make a button that fits in nicely and doesn't stick out like a sore thumb. This will do that.
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

netmaestro wrote:from somebody's theme engine
Not if they are using their personal theme engine. But if they are using the theme engine that ships with Windows XP.
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 »

Agreed then that the parameters of the challenge are that the buttons fit in with the themes that ship with Windows XP, and react in real time with changes to the theme as they occur. Deal?
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It should be any theme as long as the Windows XP theme engine is used. But that's very hard.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Gahh! I was messing around with the XP Theme API since yesterday only to come to a conclusion wich Trond already pointed out:
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.
I am reffering to this thread: http://www.purebasic.fr/english/viewtopic.php?t=22476

So drawing the the individual caption buttons is pretty simple (compile with Unicode enabled):

Code: Select all

#WP_MINBUTTON = 15
#WP_MAXBUTTON = 17
#WP_CLOSEBUTTON = 18

Global HTHEME.l

Procedure WindowCallback(hWnd.l,uMsg.l,wParam.l,lParam.l)
    Select uMsg
 		Case #WM_PAINT
		hdc = BeginPaint_(hwnd,ps.PAINTSTRUCT)
		
		SetRect_(pRect.RECT,10,10,26,26)
		DrawThemeBackground_(HTHEME,hdc,#WP_MINBUTTON,1,pRect,0)
		OffsetRect_(pRect,18,0)		
		DrawThemeBackground_(HTHEME,hdc,#WP_MAXBUTTON,1,pRect,0)
		OffsetRect_(pRect,18,0)		
		DrawThemeBackground_(HTHEME,hdc,#WP_CLOSEBUTTON,1,pRect,0)
				
		EndPaint_(hwnd,ps)
    EndSelect
     
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0,0,0,200,80,"",#WS_OVERLAPPEDWINDOW | 1)

SetWindowCallback(@WindowCallback())

HTHEME = OpenThemeData_(WindowID(0),"Window")

While WaitWindowEvent() ! 16 : Wend

CloseThemeData_(HTHEME)
But as stated before it seems to be impossible to draw a plain window button without the corresponding gylph (the symbols on the button). Thus there is no way drawing a custom symbol on a theme template image.

Furthermore I deeply searched the internet and noticed (as pointed out by large communities like codeguru.com) that the XP Theme API is poorly documented. For example try to search for "WP_SMALLSYSBUTTON" (wich is a part constant) on Google. You get exactly 2 matches! Well, all we got are 3 includes: uxtheme.h, Schemadef.h and Tmschema.h + SDK Documentaion but as said before some information is simply missing.

I already thought about using a quick hack and just try to duplicate the image portion wich is not covered by the glyph. But a different theme may use differently sized gylphs so this ain't a real solution.

If anyone knows a way to draw a raw window button without a gylph please let me know!
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

nice, works also without unicode:

Code: Select all

#WP_MINBUTTON = 15
#WP_MAXBUTTON = 17
#WP_CLOSEBUTTON = 18

Global HTHEME.l

Procedure WindowCallback(hWnd.l,uMsg.l,wParam.l,lParam.l)
    Select uMsg
       Case #WM_PAINT
      hdc = BeginPaint_(hwnd,ps.PAINTSTRUCT)
      
      SetRect_(pRect.RECT,10,10,26,26)
      DrawThemeBackground_(HTHEME,hdc,#WP_MINBUTTON,1,pRect,0)
      OffsetRect_(pRect,18,0)      
      DrawThemeBackground_(HTHEME,hdc,#WP_MAXBUTTON,1,pRect,0)
      OffsetRect_(pRect,18,0)      
      DrawThemeBackground_(HTHEME,hdc,#WP_CLOSEBUTTON,1,pRect,0)
            
      EndPaint_(hwnd,ps)
    EndSelect
     
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0,0,0,200,80,"",#WS_OVERLAPPEDWINDOW | 1)

SetWindowCallback(@WindowCallback())

Win.s = Space(12)
PokeS(@Win, "Window", -1, #PB_Unicode)
HTHEME = OpenThemeData_(WindowID(0),Win)

While WaitWindowEvent() ! 16 : Wend

CloseThemeData_(HTHEME)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply