 |
|
 |
I cam across this on my search for adding a Help button to the Windows Title Bar, as the standard one doesn't show when maximise/minimise buttons are visible. Using this class I have got the Help button showing fine and it even mimics the help when clicked (changes cursor to ? and allows control to be clicked). It even throws the HelpRequested event, Great! However the control that is passed to the Helprequested event in the sender object is the form and not the control clicked. Any idea how I and sort this out?
|
|
|
|
 |
|
 |
The short answer is: it will be difficult.
The constructor of WinTrayButton you would have to add another method that would take your form type as an argument so that you can access its controls:
Public Sub New(ByVal parent As YourForm)
AddHandler parent.HandleCreated, AddressOf Me.OnHandleCreated
AddHandler parent.HandleDestroyed, AddressOf Me.OnHandleDestroyed
AddHandler parent.TextChanged, AddressOf Me.OnTextChanged
AddHandler MinTrayBtnStateChanged, AddressOf Me.StateChange
AddHandler MinTrayBtnHelpClicked, AddressOf Me.Helpbtnclicked
Me.parent = parent
End Sub 'New
Then you would have to check with Me.parent, if it is of YourForm type, then you can also alter the helpbutton click events after you are first able to track which button is getting clicked.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
 |
|
 |
I was wondering if it would be possible to have the user click a button, then show the system menu, with or without transparency. I'm making a custom skiined form, and the only missing piece is the system menu. As the form doesn't have a border style, it doesn't even appear on the right-clicked taskbar button. Any help is greatly appreciated.
Thanks, bobert
|
|
|
|
 |
|
 |
It is very possible to get the system menu for the window without actually having the toolbar. Unfortunately I am too busy right now to get you a code snippet, however you may want to look into WinAPI and sending messages to emulate the system menu. I believe their is another article on the CodeProject site that might delve into emulating the system menu, for that matter you could even create a new menu that emulates it.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
 |
|
 |
Okay, thanks for your quick reply. I'll look into that even though I hate using API. Thanks for this awesome little program again.
Thanks,
Bobert
|
|
|
|
 |
|
 |
Great article Tom! But how do I add tooltip support for your WinTrayButtons like the system buttons have?
|
|
|
|
 |
|
 |
To be honest that is probably a bit more complicated than what it would be worth. In order to have tooltip support you would have to listen to the wndproc for mouse over events. Since .NET tooltips do not support the non-client area of the window, you would have to create the tooltips through the WinAPI. It may be possible to use .NET tooltips (within the client area, but still under the button) by manually showing the tooltip after handling the mouse over events in the wndproc. Its location would have to be hard coded.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
 |
|
 |
Hi,
This is the application to insert custom button and menu on title bar of own window.
But I want to use same functionality with external window (insert custom button on title bar of external window (open window)). Is it same source code useful for this functionality or need to change something.
I have the open window or target windows handle and I want insert custom button on that windows title bar.
Please help me!!!!!
Thanks and Regards
Varsha
|
|
|
|
 |
|
 |
You can use this project as a general guideline for enumerating through windows, however this project will not work for external windows throughout the operating system.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
 |
|
 |
I want to add buttons on every (Win 32) window when user opens.
So can you suggest me any Hook or any idea?
please help me out?
Thanks in advance
Shahid Hazoor
shahid_hazoor@hotmail.com
|
|
|
|
 |
|
 |
Absolutely no trnsparency and no buttons in VISTA SP1 !
|
|
|
|
 |
|
 |
This program was written for Windows XP at the time, and Microsoft has since messed up the menu system in Vista. However, I have just used the code for another article that I wrote that uses ToolStrips/MenuStrips of .NET 2.0+, and the transparency is working for that program. The article that has mention of the transparency for the new menus can be found here[^]
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
 |
|
 |
First of all: great article on title bar buttons in WXP
Is there any way to make the title bar button work in VB.NET (2.0+) on Windows Vista? Or did M$ mess up too much?
thanks in advance
Rudy
|
|
|
|
 |
|
 |
I hate to say it, but M$ did a bit to much meddling with their interface for this to work under Vista. However, it is easier to customize a programs interface with Vista with the WPF of .NET 3.x.
Please be sure to vote for the article
Regards,
Thomas Stockwell
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
 |
|
 |
Hi, i wonder if its possible to make a button with some very general action and add it to the title of every application launched (possibly filtering dialog boxes or toolwindows)
|
|
|
|
 |
|
 |
Buttons will be more difficult, but you can look into PowerMenu for how to add menu items to all windows' system menus. (Google it )
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
 |
|
 |
This is a very good project, and it works just fine.
I've commented out the lines that show the icons on the button, and I see a horizontal line, like the minimize button.
I have some questions:
How can I change the text of the button ?
Is it possible to add something else than a button on the titlebar (e.g. a textbox) ?
|
|
|
|
 |
|
 |
It is possible to add other items to the toolbar, but this is as close to that as I have come. I do not know how AOL has been able to add the icons/textboxes to its windows (the one thing AOL has done correctly), but it shows that it is possible.
At the moment I did a quick glance through the code (as I have not dealt with this project for ages ), to add text to the actual button appearance you would have to make the rectangle for the button wider, then where the icons were drawn you would g.DrawString(...) instead of g.DrawImage(...) for the icon.
If you try to add more than a button to the window with this aproach like a textbox or something, keep in mind of all the events that you will have to handle with API commands. The button events are fairly easy to understand basically just mouseclicks, but for textboxes you may need to handle a lot more. Good luck if you try .
If this doesn't help please post back.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
 |
|
 |
After some time of clicking and moving mouse over the form it hangs, draws nonsenses and after a while disappears. I've looked in the Task Manager and voila - the aplication is consuming GDI objects (very fast) and after a while when it reaches a system maximum (10000) it crashes.
And second thing - the transparent menus are really really sloooooow... when I click on the menu, it draws the border and transparent window (without any text on it) and after a pretty long while (about 3 seconds) it draws the texts. The problem is not in my computer, because as the first it is high-end computer and as the second I have tried that on more computers and the behavior was exactly the same.
|
|
|
|
 |
|
 |
I am still looking into the 1st bug, but the second-I am not sure if I can fix the problem. On my computer the menu does not take 3 seconds to load completely, but it does take longer than normal menus when shown (I would say less than a second to show with text but still longer than it would otherwise). At the moment I do not see a way to shorten the time for the menu.
I will coninue to look into both bugs, but I do not think I can change the second 'bug'. The first bug I believe is being caused by the excessive calling of the uxtheme API, I will try to work around the API and try to limit how many times it is being called. Hopefully that will solve the problem.
Thanks for the feedback.
|
|
|
|
 |
|
 |
Well, I don't think so. I haven't looked in the code, but I don't think that this is problem in calling the uxtheme.dll. I think that there must be some problem like not calling ReleaseDC after GetDC or something similar.
|
|
|
|
 |
|
 |
I figured that out when I changed how many calls to opentheme API. I'll look into the ReleaseDC function some more. With this article or one of my other articles I was having problems with the function so I tried avoiding it, but may become a bad habit. I'll continue to look into it.
|
|
|
|
 |
|
 |
At the moment I have no software that can help in trying to fix this problem. I have altered the code for the DrawButton function so that is uses the ReleaseDC API call. The code that reduces how fast the GC builds up you can replace the function with the following code. As said his will not fix the GC problem it will just reduce slightly the effect.
Private Declare Function ReleaseDC Lib "user32.dll" ( _
ByVal hwnd As Int32, _
ByVal hdc As Int32) As Int32
Private Sub DrawButton(ByVal g As Graphics, ByVal state As state)
Dim windowTheme As IntPtr = openThemeData(Me.Handle, "Window")
Dim btn_width As Integer = GetSystemMetrics(SM_CXSIZE)
Dim btn_height As Integer = GetSystemMetrics(SM_CYSIZE)
Dim pos As Point
Select Case parent.FormBorderStyle
Case FormBorderStyle.SizableToolWindow, FormBorderStyle.FixedToolWindow
pos = New Point(wnd_size.Width - ((bindex - 1) * btn_width / 1.5) - 12 - (btn_width - 18), 5)
Case FormBorderStyle.None
Case Else
pos = New Point(wnd_size.Width - ((bindex - 1) * btn_width) - 12 - (btn_width - 18), 5)
End Select
' real button size
btn_width -= 2
btn_height -= 4
Dim hDC As IntPtr
Select Case parent.FormBorderStyle
Case FormBorderStyle.SizableToolWindow, FormBorderStyle.FixedToolWindow
'small caption button
hDC = g.GetHdc()
If bhelpbutton = True Then
Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 23, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 23, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 23, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 23, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
End Select
ElseIf bimageonly = False Then
Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 15, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 15, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 15, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 15, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
End Select
End If
ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
hDC = New IntPtr(GetWindowDC(parent.Handle.ToInt32))
g = Graphics.FromHdc(hDC) 'm.HWnd));
If bhelpbutton = False Then
If Not bimagelist Is Nothing Then
If bimagelist.Images.Count = 1 Then
If state <> state.Disabled Then
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Else
ControlPaint.DrawImageDisabled(g, bimagelist.Images(0), pos.X, pos.Y, Color.Transparent)
End If
ElseIf bimagelist.Images.Count = 4 Then
Select Case state
Case state.Disabled
g.DrawImage(bimagelist.Images(3), pos.X, pos.Y)
Case state.Hot
g.DrawImage(bimagelist.Images(1), pos.X, pos.Y)
Case state.Normal
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Case state.Pushed
g.DrawImage(bimagelist.Images(2), pos.X, pos.Y)
End Select
ElseIf bimagelist.Images.Count > 0 And bimagelist.Images.Count <> 4 Then
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
End If
End If
End If
g.Dispose()
ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
Case FormBorderStyle.None
'draw nothing because their is not title bar to draw to
Case Else
hDC = g.GetHdc
'regular size caption button
If bhelpbutton = True Then
Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 23, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 23, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 23, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 23, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
End Select
ElseIf bimageonly = False Then
Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 15, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 15, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 15, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 15, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
End Select
End If
ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
hDC = New IntPtr(GetWindowDC(parent.Handle.ToInt32))
g = Graphics.FromHdc(hDC) 'm.HWnd));
If bhelpbutton = False Then
If Not bimagelist Is Nothing Then
'offset x, y values to center image in button
pos.Offset(Math.Sqrt(btn_width) - 1, Math.Sqrt(btn_height) - 1)
If bimagelist.Images.Count = 1 Then
If state <> state.Disabled Then
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Else
ControlPaint.DrawImageDisabled(g, bimagelist.Images(0), pos.X, pos.Y, Color.Transparent)
End If
ElseIf bimagelist.Images.Count = 4 Then
Select Case state
Case state.Disabled
g.DrawImage(bimagelist.Images(3), pos.X, pos.Y)
Case state.Hot
g.DrawImage(bimagelist.Images(1), pos.X, pos.Y)
Case state.Normal
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Case state.Pushed
g.DrawImage(bimagelist.Images(2), pos.X, pos.Y)
End Select
ElseIf bimagelist.Images.Count > 0 Then
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
End If
End If
End If
g.Dispose()
ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
End Select
System.GC.GetTotalMemory(True)
End Sub 'DrawButton
|
|
|
|
 |
|
 |
Hi!
I get a System.InvalidOperation Exception when I click on the Stylelist ListBox.
What should I do to fix it ¿
|
|
|
|
 |
|
 |
Do you have the proper system requirements. This articles code can only be run on WinXP or higher operating system. If you do have WinXP or higher then would you mind giving me the stacktrace for the exception. This will help me isolate where the problem is occuring.
Regards,
1tg46
Check out 3D Game Development with Dark Basic Professional [^]programming.
|
|
|
|
 |
|