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.
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
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.
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.
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.
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.
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
It won't actually be behind, It's still in front. Nonetheless, I don't think that's the problem.
Originally Posted by Amerigoware
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.
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
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.
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.