Sorry, I know this sounds pretty impossible, but is there a way I could check to see what windows would be displaying under my application were it not there? Thanks.
Printable View
Sorry, I know this sounds pretty impossible, but is there a way I could check to see what windows would be displaying under my application were it not there? Thanks.
Yes, but it may take a good amount of code using APIs. You would enumerate
the windows checking the z order position and window areas that would
overlap your apps form. Sounds like a real pain to code.
Why do you want to get what is behind your form? Maybe there is a better solution.
Are you trying to get the desktop display behind your form for some kind of
transparency?
ZOrder may change at any given moment: user may activate or deactivate any window when they want regardless so handle that your app stored a few seconds ago might not be valid any longer.
Yes, thats a good point ;). I kind of think that the poster wants to do something like a transparency thing.
I suppose it would be transparent, is that easier? I don't want the whole form to be transparent though, just the body of the form. So i'd want to keep the title bar and the small bit around the edges that gives it a 3d effect.
Here is an example of alpha blending (transparency) for Windows 2000+
VB Code:
Option Explicit 'Add a slider control to your form. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _ (ByVal lpLibFileName As String) As Long Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _ ByVal lpProcName As String) As Long Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, _ ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long Private Const GWL_EXSTYLE = (-20) Private Const WS_EX_LAYERED = &H80000 Private Const LWA_ALPHA = &H2 Public Sub AlphaBlendForm(ByVal lHwnd As Long, ByVal intTranslucenceLevel As Integer) If APIExists("SetLayeredWindowAttributes", "User32") Then SetWindowLong lHwnd, GWL_EXSTYLE, WS_EX_LAYERED SetLayeredWindowAttributes lHwnd, 0, intTranslucenceLevel, LWA_ALPHA Else MsgBox "Your OS does not support Alpha Blending.", vbExclamation, "Alpha Blend" End If End Sub Public Function APIExists(ByVal pstrFunctionName As String, ByVal pstrDllName As String) As Boolean Dim lngHandle As Long Dim lngAddr As Long lngHandle = LoadLibrary(pstrDllName) If Not (lngHandle = 0) Then lngAddr = GetProcAddress(lngHandle, pstrFunctionName) FreeLibrary lngHandle End If APIExists = Not (lngAddr = 0) End Function Private Sub Form_Load() Slider1.Max = 255 Slider1.Min = 10 Slider1.LargeChange = 5 AlphaBlendForm Me.Hwnd, 255 'MAX VALUE = OPAIC/ MIN VALUE = 0 CAN'T SEE Slider1.Value = 255 End Sub Private Sub Slider1_Scroll() AlphaBlendForm Me.Hwnd, Slider1.Value End Sub
I'm on windows 98 :cry:
yeah on Win 2k and XP it's easy using layers but on win98 there are two ways that I know of. I placed both ways into one function for your choice.
VB Code:
Option Explicit Public Enum iMode AlphaBlendingDLL = 1 msimg32DLL = 2 End Enum Public Type BLENDFUNCTION BlendOp As Byte BlendFlags As Byte SourceConstantAlpha As Byte AlphaFormat As Byte End Type Public Declare Function AlphaBlending Lib "Alphablending.dll" _ (ByVal destHDC As Long, ByVal XDest As Long, ByVal YDest As Long, _ ByVal destWidth As Long, ByVal destHeight As Long, ByVal srcHDC As Long, _ ByVal xSrc As Long, ByVal ySrc As Long, ByVal srcWidth As Long, ByVal srcHeight As Long, ByVal AlphaSource As Long) As Long Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public Declare Function AlphaBlend Lib "msimg32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long, ByVal blendFunct As Long) As Boolean Public Sub Blend(Destination As Object, Source As Object, Amount As Integer, in_iMode As iMode) Dim bl As BLENDFUNCTION Dim bl_lng As Long If in_iMode = AlphaBlendingDLL Then AlphaBlending Destination.hDC, -Destination.Left - 1, -Destination.Top - 1, Source.ScaleWidth, Source.ScaleHeight, Source.hDC, 0, 0, Source.ScaleWidth, Source.ScaleHeight, Amount ElseIf in_iMode = msimg32DLL Then bl.SourceConstantAlpha = Amount CopyMemory bl_lng, bl, 4 Destination.Cls AlphaBlend Destination.hDC, -Destination.Left - 1, -Destination.Top - 1, Source.ScaleWidth, Source.ScaleHeight, _ Source.hDC, 0, 0, Source.ScaleWidth, Source.ScaleHeight, bl_lng End If Destination.Refresh End Sub
Use Blend PictureDestination, PictureSource, 120, AlphaBlendingDLL for the 1st method
Use Blend PictureDestination, PictureSource, 120, msimg32DLL for the 2nd method
Make sure all pictureboxes are set to autoredraw and are scaled in pixels. Also you SHOULD have msimg32.dll on your pc, but you might not have Alphablending.dll, so i'll attach it. Put the Alphablending.dll into your system folder. Also source and destination could be a form, not a picturebox but make sure autoredraw is on and form is scaled to pixels.