[RESOLVED] SetParent and Opacity
I've recently gotten over the hurdle of a Borderless form that doesn't show in the Taskbar to not be hidden when the user clicks the Show Desktop button in windows by using the SetParent API to make the windows all children of the desktop, but now I can't change the Opacity of the form, it throws an exception:
Code:
System.ComponentModel.Win32Exception was unhandled
ErrorCode=-2147467259
Message="The parameter is incorrect"
NativeErrorCode=87
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Form.UpdateLayered()
at System.Windows.Forms.Form.set_Opacity(Double value)
at ReminderNotes.NoteBase.set_Opacity(Double value) in C:\Users\IBM_ADMIN\Desktop\Program Stuffs\ReminderNotes\ReminderNotes\NoteBase.vb:line 255
at ReminderNotes.NoteForm.TransparencyToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\IBM_ADMIN\Desktop\Program Stuffs\ReminderNotes\ReminderNotes\NoteForm.vb:line 254
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at ReminderNotes.MainModule.Main() in C:\Users\IBM_ADMIN\Desktop\Program Stuffs\ReminderNotes\ReminderNotes\MainApp.vb:line 62
InnerException:
Here's the code I have:
Code:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> _
Public Shared Function SetParent(ByVal child As IntPtr, ByVal parent As IntPtr) As Integer
End Function
Public Sub New()
MyBase.New()
MyBase.FormBorderStyle = Windows.Forms.FormBorderStyle.None
MyBase.ShowInTaskbar = False
MyBase.Size = New Size(180I, 165I)
MyBase.MinimumSize = New Size(180I, 120I)
MyBase.AutoScroll = True
SetParent(Me.Handle, FindWindow("progman", Microsoft.VisualBasic.vbNullString))
End Sub
Private Sub TransparencyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Opacity values are stored as "1", "0.9", etc in the tag property
Me.Opacity = CDbl(CType(sender, ToolStripMenuItem).Tag.ToString)
End Sub
Any ideas on how to keep the windows children of the desktop but still allow the opacity to be something other than 1.0?
Re: SetParent and Opacity
i think you'll find only top level windows can use transparency
Re: SetParent and Opacity
Don't suppose you know of a work around to still avoid the Show Desktop minimizing and still allow the opacity to be changed would ya?
Re: SetParent and Opacity
Re: SetParent and Opacity
Quote:
Originally Posted by
JuggaloBrotha
Don't suppose you know of a work around to still avoid the Show Desktop minimizing and still allow the opacity to be changed would ya?
What if you reset the parent, change opacity then set the parent back, might be some flicker tho...?
Code:
Private Sub ChangeOpacity(ByVal opacity As Double)
SetParent(Me.Handle, IntPtr.Zero)
Me.Opacity = opacity
SetParent(Me.Handle, FindWindow("progman", Microsoft.VisualBasic.vbNullString))
'Me.Refresh() ' < needed ?
End Sub
Re: SetParent and Opacity
Quote:
Originally Posted by
.paul.
regions?
What do you mean by regions?
Quote:
Originally Posted by
Edgemeal
What if you reset the parent, change opacity then set the parent back, might be some flicker tho...?
Code:
Private Sub ChangeOpacity(ByVal opacity As Double)
SetParent(Me.Handle, IntPtr.Zero)
Me.Opacity = opacity
SetParent(Me.Handle, FindWindow("progman", Microsoft.VisualBasic.vbNullString))
'Me.Refresh() ' < needed ?
End Sub
I guess I hadn't thought of that, I'll fiddle with the idea tomorrow.
Re: SetParent and Opacity
Quote:
Originally Posted by
JuggaloBrotha
What do you mean by regions?
reshaping the form so it just shows the areas you want visible
Re: SetParent and Opacity
Well after playing around with the ideas in here, I did manage to make it so the opacity can be changed and the form is a child of the Desktop's ListView, however if I change the opacity then the whole thing disappears completely (even if I set the Opacity to 0.9).
Re: SetParent and Opacity
If you have the same problem as here, I have recently made a better version, so that it looks like the buttons are on the desktop.
EDIT: And I seemingly don't have that on my pc any more.
I used BitBlt to create a image of what is behind the app, I then set that image to form background image and It looked like the buttons were on the background. It would probably be easier with regions, But I don't know how to use them.
Re: SetParent and Opacity
Quote:
Originally Posted by
JuggaloBrotha
Well after playing around with the ideas in here, I did manage to make it so the opacity can be changed and the form is a child of the Desktop's ListView, however if I change the opacity then the whole thing disappears completely (even if I set the Opacity to 0.9).
I tried the same under Win7 using the desktop listview and had same thing happen.. the form just disappears when I changed the opacity, weird! Maybe look into making vista/win7 widget/gadget or whatever they are called? I mainly target XP OS so really don't have a clue. Good Luck!
Re: SetParent and Opacity
Quote:
Originally Posted by
Edgemeal
I tried the same under Win7 using the desktop listview and had same thing happen.. the form just disappears when I changed the opacity, weird! Maybe look into making vista/win7 widget/gadget or whatever they are called? I mainly target XP OS so really don't have a clue. Good Luck!
Problem is, XP doesn't support gadgets, the target audience with this is XP and newer.
That and Vista (as far as I know) doesn't let you move gadgets around freely, they're locked into that side bar thing.
Can VS 2008 allow you to make Vista/7 gadget apps?
Re: [RESOLVED] SetParent and Opacity
I ended up including a 'Bring to front' menu item and when the user clicks it, it'll loop through all the note form's and call it's BringToFront() method. It would be nice if the form could do that automatically after the Show Desktop action is taken but I'll think about that at a later time.