Results 1 to 12 of 12

Thread: [RESOLVED] SetParent and Opacity

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Resolved [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?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: SetParent and Opacity

    i think you'll find only top level windows can use transparency

  3. #3

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: SetParent and Opacity

    regions?

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: SetParent and Opacity

    Quote Originally Posted by JuggaloBrotha View Post
    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

  6. #6

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: SetParent and Opacity

    Quote Originally Posted by .paul. View Post
    regions?
    What do you mean by regions?

    Quote Originally Posted by Edgemeal View Post
    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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: SetParent and Opacity

    Quote Originally Posted by JuggaloBrotha View Post
    What do you mean by regions?
    reshaping the form so it just shows the areas you want visible

  8. #8

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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).
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  9. #9
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    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.
    Last edited by BlindSniper; Sep 24th, 2011 at 03:00 AM.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  10. #10
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: SetParent and Opacity

    Quote Originally Posted by JuggaloBrotha View Post
    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!

  11. #11

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: SetParent and Opacity

    Quote Originally Posted by Edgemeal View Post
    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?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  12. #12

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width