Results 1 to 16 of 16

Thread: [RESOLVED] Sending form behind desktop icons

  1. #1

    Thread Starter
    Banned
    Join Date
    Apr 2018
    Location
    https://t.me/pump_upp
    Posts
    79

    Resolved [RESOLVED] Sending form behind desktop icons

    My application is sent to the background (behind the desktop icons) beautifully with the following code:

    Code:
        Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        Private Const WS_EX_TRANSPARENT As Integer = &H20
        Const LWA_COLORKEY As Int32 = 1
        Const LWA_ALPHA As Int32 = 2
        Const GWL_EXSTYLE As Int32 = (-20)
        Const WS_EX_LAYERED As Int32 = 524288
        Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32) As Int32
        Private Declare Function apiSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32
        Private Declare Function apiSetLayeredWindowAttributes Lib "user32" Alias "SetLayeredWindowAttributes" (ByVal hWnd As Int32, ByVal crKey As Int32, ByVal bAlpha As Byte, ByVal dwFlags As Int32) As Int32
        Private nhwnd As Int32
    I have a second form that is sent to each non-primary screen. It has the exact same code, but it doesn't move to the back as expected. As in, icons are hidden behind the form and when right-clicking, the Windows Explorer context menu doesn't show.

    I have searched for any resolution, but I can't even find where I found the above code again.

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: Sending form behind desktop icons

    Quote Originally Posted by Amerigoware View Post
    My application is sent to the background (behind the desktop icons) beautifully with the following code:
    I'm having trouble visualizing what you mean by this. Can you post a screenshot of what it looks like?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Sending form behind desktop icons

    Quote Originally Posted by Niya View Post
    I'm having trouble visualizing what you mean by this. Can you post a screenshot of what it looks like?
    Sounds much like a desktop widget, so the form is basically embedded in the desktop window, so it is displayed behind app shortcuts instead of in front of them.

  4. #4

    Thread Starter
    Banned
    Join Date
    Apr 2018
    Location
    https://t.me/pump_upp
    Posts
    79

    Re: Sending form behind desktop icons


  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Sending form behind desktop icons

    Quote Originally Posted by Amerigoware View Post
    My application is sent to the background (behind the desktop icons) beautifully with the following code:
    It isn't, because that code is nothing but declarations. There's no actual calls to the declared functions. You probably ought to show us how exactly you're calling those functions.

    It's also rather strange that you have two functions declared that map to SetWindowLongA. The first one looks wrong for VB.NET, because Windows API functions almost universally use 32-bit numbers, which is Long in VB6 and Integer in VB.NET.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Sending form behind desktop icons

    Quote Originally Posted by Amerigoware View Post
    We can't see that attachment. The Insert Image function on the basic editor has a bug. Click the Go Advanced button and then use Manage Attachments.

  7. #7

    Thread Starter
    Banned
    Join Date
    Apr 2018
    Location
    https://t.me/pump_upp
    Posts
    79

    Re: Sending form behind desktop icons

    Sorry.

    I was actually looking through the code for the calls to the declared functions in order to put them in the second form. The only thing I can find is:

    Code:
        Protected Overrides ReadOnly Property CreateParams() As CreateParams
            Get
                Const WS_EX_TRANSPARENT As Integer = &H20
                Dim params As CreateParams = MyBase.CreateParams
                params.ExStyle = params.ExStyle Or WS_EX_TRANSPARENT
                Return params
            End Get
        End Property
    and
    Code:
        Private Sub Transparency(ByVal hwnd As Int32, ByVal sOpacity As Int32)
            Dim Ret As Int32 = apiGetWindowLong(hwnd, GWL_EXSTYLE)  'Set the window style to 'Layered'
            Ret = Ret Or WS_EX_LAYERED
            apiSetWindowLong(hwnd, GWL_EXSTYLE, Ret)
            apiSetLayeredWindowAttributes(hwnd, 0, sOpacity, LWA_ALPHA) 'Set the opacity of the layered window
            Application.DoEvents()
        End Sub
    I put both of these in the secondary form, but it still doesn't work.

    I realize the code is probably crap at best as it is copied from here and there, but it works on form 1.
    Attached Images Attached Images  

  8. #8

    Thread Starter
    Banned
    Join Date
    Apr 2018
    Location
    https://t.me/pump_upp
    Posts
    79

    Re: Sending form behind desktop icons

    To clarify; the primary screen is the one with the rainbow background. The secondary screen(s) displays a slideshow that should also be embedded in the desktop.

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: Sending form behind desktop icons

    You know that code you're using doesn't actually put Forms behind anything. All it does is make Forms translucent.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10

    Thread Starter
    Banned
    Join Date
    Apr 2018
    Location
    https://t.me/pump_upp
    Posts
    79

    Re: Sending form behind desktop icons

    Yes, translucent and click-through, so effectively behind everything else.

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: Sending form behind desktop icons

    It won't actually be behind, It's still in front. Nonetheless, I don't think that's the problem.

    Quote Originally Posted by Amerigoware View Post
    I was actually looking through the code for the calls to the declared functions in order to put them in the second form. The only thing I can find is:

    Code:
        Protected Overrides ReadOnly Property CreateParams() As CreateParams
            Get
                Const WS_EX_TRANSPARENT As Integer = &H20
                Dim params As CreateParams = MyBase.CreateParams
                params.ExStyle = params.ExStyle Or WS_EX_TRANSPARENT
                Return params
            End Get
        End Property
    and
    Code:
        Private Sub Transparency(ByVal hwnd As Int32, ByVal sOpacity As Int32)
            Dim Ret As Int32 = apiGetWindowLong(hwnd, GWL_EXSTYLE)  'Set the window style to 'Layered'
            Ret = Ret Or WS_EX_LAYERED
            apiSetWindowLong(hwnd, GWL_EXSTYLE, Ret)
            apiSetLayeredWindowAttributes(hwnd, 0, sOpacity, LWA_ALPHA) 'Set the opacity of the layered window
            Application.DoEvents()
        End Sub
    I put both of these in the secondary form, but it still doesn't work.

    I realize the code is probably crap at best as it is copied from here and there, but it works on form 1.
    That code doesn't actually do anything. By the looks of it, it's incomplete. It seems to be missing a call to the Transparency function which should actually make the Form translucent.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: Sending form behind desktop icons

    I’ve done something like this before with the SetParent API using the desktop Handle - which is 0

    Code:
    Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Last edited by .paul.; Jun 20th, 2022 at 01:00 AM.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Sending form behind desktop icons

    Quote Originally Posted by .paul. View Post
    I’ve done something like this before with the SetParent API using the desktop Handle - which is 0

    Code:
    Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    That would actually put the form behind the desktop shortcuts, which is why it is important to describe the situation as it actually is.

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: Sending form behind desktop icons

    Quote Originally Posted by jmcilhinney View Post
    That would actually put the form behind the desktop shortcuts, which is why it is important to describe the situation as it actually is.
    A Form that is completely translucent, allowing click-thru, but also visible? That’s not so easy…

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Sending form behind desktop icons

    Quote Originally Posted by .paul. View Post
    A Form that is completely translucent, allowing click-thru, but also visible? That’s not so easy…
    What I'm saying is that the OP said that they were putting the form behind the desktop shortcuts when they weren't, but you code will. They are two different things so, if we're to help fix something, we need to know which it is. I'm criticising the OP, not you. It's always important to describe what you're actually doing, not just what you think it effectively amounts to.

  16. #16

    Thread Starter
    Banned
    Join Date
    Apr 2018
    Location
    https://t.me/pump_upp
    Posts
    79

    Re: Sending form behind desktop icons

    I'm sorry to have bothered you all. I forgot to set the opacity. It's working now.
    Also, I had forgotten what the code was actually doing (making translucent and click-through) and described what the end result appears to be.

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