|

Introduction
This article will go over some of the least documented (in VB.NET) principles, Transparent Menus and System Title Buttons. This article will discuss how to wrap UxTheme.dll and window events to make a window caption button, and how to hook system menus to make them appear transparent. Please keep in mind that this code is meant for Windows XP, as that is the operating system that I am using, their is no guarantee that this code will work on other Windows operating systems.
Background
Transparent Menu Background: C++ Transparent Menu article was one of the first places on the web that came up when I Googled 'transparent menus' about a year ago. I tried for months to try and convert it to VB.NET but alas with no success. That is until I ran across Flat Visual Studio Style Menus article which shined new hope on the subject, I will explain why later in this article.
Window Titlebar Button Background: This has also been a hard topic to find documentation on, but alas The Code Project had the answer again with MinTrayButton article. This article was written in C# and so was fairly easy to convert to VB.NET. However a drawback was that it did not support XP theming. So I had to modify the code so that it used the Uxtheme.dll to do all the drawing of the caption buttons.
Transparent menu code
As I said this code is based on the article Flat Visual Studio Style Menus. In the code for the article, it had a hook which hooked all system menus of a form and made them appear flat by hooking the menu window and painting a new border on the menu window. Well I took just the hook portion of the flat menu code and added code where it hooked the WM_NCPAINT event. Select case m.msg
...
Case WM_NCPAINT
Dim dwstyle As Integer = GetWindowLong(hwnd, GWL_EXSTYLE)
SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED Or dwstyle)
SetWindowPos(hwnd, -1, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOACTIVATE _
Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE)
SetLayeredWindowAttributes(hwnd.ToInt32, 0, 150, LWA_ALPHA)
DrawBorder(hwnd, IntPtr.Zero)
...
End Select
With this code it gets the window handle of the menu popup from the wparameter of the WndProc function. I could then use SetWindowLong and SetLayeredWindowAttributes to set the menu window to appear transparent. This did work and I used the 'DrawBorder' function from the original article code to draw a flat border around the code. I did have to modify the function so that the border drew half-ways properly. A drawback of the current DrawBorder function is that when the mouse goes over a menu item the left border of the menu item will disappear.
Using Transparent menu code
To use the code in your project just copy the component to your project and declare a variable for the TransMenuLib component. Then, in your 'Sub Main' routine include the hooking and unhooking functions. Like:
TransMenuLib.Hook(Process.GetCurrentProcess)
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New Form1)
TransMenuLib.Unhook()
WinTrayButton code
To understand the basics of the code I would suggest that you look at the article that this code is based on: MinTrayButton. I will however explain the parts that I have added.
As most Windows programmers know, Windows XP is using the theming engine of UxTheme.dll to draw everything with a UI in the operating system. This also includes caption buttons, which have a total of four states that are painted by UxTheme. The states of Hot, Normal, Pressed, and Disabled are used to show the user if the button is easily accessible or not. I have changed the drawing of the original C# code so that all these states are used. However UxTheme did not have a Windows caption button that did not already have an icon on it, so I decided to use the button that had the smallest icon, the minimize button. This way I could then put an icon over the minimize icon in the minimize button. In the UxTheme.dll the MinButton's part number is 15 and its states are numbers 1-4. However this leads to another solution to a common problem 'What if I want to have a help button in the titlebar when the default buttons (min/max/close) will cover up the form.helpbutton property?'. I have took this into consideration and I have added code so that either the minimize button or the help button can be drawn from UxTheme. The part number in UxTheme for the help button is 23 and its states are the same as those of any of the caption buttons (states 1-4). Private Sub DrawButton(ByVal g As Graphics, ByVal state As state)
Select Case parent.FormBorderStyle
Case FormBorderStyle.SizableToolWindow, FormBorderStyle.FixedToolWindow
If bhelpbutton = True Then
Select Case state
Case state.Normal
drawThemeBackground(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 23, 1, New RECT(New Rectangle(pos.X, _
pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 23, 2, New RECT(New Rectangle(pos.X, pos.Y, _
btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 23, 3, New RECT(New Rectangle(pos.X, pos.Y, _
btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 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(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 15, 1, New RECT(New Rectangle(pos.X, pos.Y, _
btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 15, 2, New RECT(New Rectangle(pos.X, pos.Y, _
btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 15, 3, New RECT(New Rectangle(pos.X, pos.Y, _
btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(openThemeData(Me.Handle, "Window"), _
g.GetHdc, 15, 4, New RECT(New Rectangle(pos.X, pos.Y, _
btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
End Select
End If
g = Graphics.FromHdc(New IntPtr(GetWindowDC(parent.Handle.ToInt32)))
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 Then
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
End If
End If
End If
g.Dispose()
...
End Select
End Sub
Now the other area where I changed the original code a lot is the WndProc subroutine. I have had to change the code to include WinTrayButton clicks, and state changes. This is also the area where I added code to draw the WinTrayButton only when it was necessary. <System.Security.Permissions.PermissionSet(_
System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As Message)
......
If m.Msg = WM_ACTIVATE OrElse m.Msg = WM_SIZE OrElse m.Msg = _
WM_SYNCPAINT OrElse m.Msg = WM_NCCREATE OrElse _
m.Msg = WM_NCPAINT OrElse m.Msg = WM_NCACTIVATE _
OrElse m.Msg = WM_NCHITTEST OrElse m.Msg = WM_PAINT Then
If m.Msg = WM_SIZE Then
wnd_size = New Size(New Point(m.LParam.ToInt32))
End If
Dim pnt As New Point(m.LParam.ToInt32)
If drawn = False Then
RaiseEvent MinTrayBtnStateChanged(Me, sstate)
End If
If parent.Enabled = False Or bEnabled = False Then
SetState(state.Disabled)
Else
If MouseinBtn(pnt) = False Then
If Not parent.ActiveForm Is parent Then
Checkstate(state.Disabled)
Else
Checkstate(state.Normal)
End If
Else
Checkstate(state.Hot)
End If
End If
End If
MyBase.WndProc(m)
End Sub
The Checkstate function that you see used in this WndProc function checks to make sure that the caption button state is not already the state used in the parameter. The Checkstate function does this by checking to make sure the state of the button is not already the newstate. Public Function Checkstate(ByVal newstate As state)
If sstate <> newstate Then
sstate = newstate
RaiseEvent MinTrayBtnStateChanged(Me, sstate)
End If
End Function
The last part that I will discuss about the WinTrayButton is its help function. You are allowed to set the button so that you can have a help button displayed. When the help button is displayed there will be no icon appearing over the button and a different event is sent when the help button is clicked. When the help button is clicked it will act the same as any help button. I added this feature because the default form control only allows the help button when the only button in the window caption bar is a close button.
Using WinTrayButton code
This code is a little more time consuming to use, this is because the WinTrayButton is not an inherent of a component but of a native window. This means that you cannot edit the object directly using the IDE Design Mode, but you have to manually type in the code for everything. It is fairly easy to do once you know how to do it. Basically declare the object as WithEvents and edit the button's properties in the Form.Load event. Friend WithEvents wintraybtn As WinTrayButton = New WinTrayButton(Me)
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
wintraybtn.ButtonImageList = b4imagelist
wintraybtn.ButtonMenuText = "Tray Button Menu"
End Sub
History
- September 2, 2005 - Initial version.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 33 (Total in Forum: 33) (Refresh) | FirstPrevNext |
|
|
 |
|
|
 |
|
|
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[ ^]
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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 StudiosDiscounted or Free Software for Students: DreamSpark - downloads.channel8.msdn.com MSDN Academic Alliance - www.msdnaa.com
|
| Sign In·View Thread·PermaLink | 4.20/5 (2 votes) |
|
|
|
 |
|
|
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)
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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) ?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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[ ^]
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi! I get a System.InvalidOperation Exception when I click on the Stylelist ListBox.
What should I do to fix it ¿
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Good job integrating the Windows theme support! I found one bug however: when you call GetWindowDC you forget to call ReleaseDC...
-- modified at 6:58 Tuesday 4th April, 2006
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Is the bug or exception an acutal error where a .NET program debug window appears? Or is this just a bug based on the logic of how the control is written.
If their is a .NET error message then I will look into the problem, however from my more recent experience in VC#.NET I have had problems when calling ReleaseDC which resulted in memory shortage (the program spiked to using 97,000+kb in the task manager when program quit). If the bug is not an error message than I would just leave it unless you are getting a major problem with it. If you find a work around that works, I would be glad to include it in the article.
Regards, 1tg46
Check out 3D Game Development with Dark Basic Professional [^]programming.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I actually got a System.InvalidOperationException or something like that... and the message is object used elsewhere. I was able to solve the problem by doing a Graphics.ReleaseHdc ie going through the .net and not calling the API directly.
System.IntPtr HDC = User32.GetWindowDC(owner.Handle); Graphics g = Graphics.FromHdc(HDC);
If(!IsOldOS()) { DrawButton(g); g.ReleaseHdc(HDC); } else DrawButton_OldOS(g);
g.Dispose();
IsOldOS = procedure to check the version of windows. I have the OS check for windows 2000 and older versions. In that case I draw the button (drawnlines, etc...) instead of using the themes API.
And for some weird reason, I need to release the HDC when using themes API (without it I would get the Exception mentionned above), but when actually drawing the button myself (for old OS) and NOT using the themes API releasing the HDC causes an exception.
Hope this helps.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have know idea why that is. And how you get the graphics handle is how I normally would do it in my programming also. I have know idea why this problem is occurring.
Sorry, 1tg46
At least you found out how to work around the problem. If I could see the actual error message and source for the error I may be able to fix part of the program, but until then I can't really do anything.
Check out 3D Game Development with Dark Basic Professional [^]programming.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello :
I have to use only for putting button on title bar. When i remove code of transparent menu it does not work
Thanks
Fayaz
|
| Sign In·View Thread· | | | | | |