Re: Add a picture on screen?
While I can't figure out why someone would need/want to do this. I've played around with transparent windows. And I can give you a start.
Create a new project and copy and paste this code. It will make the form transparent.
VB Code:
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
Private Sub Form_Load()
'pass sub form name, level form 0 to 255, zero being invisible
MakeTransparent Me, 100
End Sub
Public Sub MakeTransparent(F As Form, Level As Byte)
Dim rtn As Long
rtn = GetWindowLong(F.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong F.hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes F.hwnd, 0, Level, LWA_ALPHA
End Sub
This code will make it always on top. Add to form or a module, and call with MakeTop FormName,True to enable, MakeTop FormName,False to disable.
VB Code:
'in declaration section of form or module
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
'in main section of form or module
'ex. MakeTop form1,True
Public Sub MakeTop(FormName As Form, WindowState As Boolean)
Dim wFlags As Long
Dim posFlag As Long
Const Swp_Nosize = &H1
Const SWP_Nomove = &H2
Const Hwnd_TopMost = -1
Const Hwnd_NoTopMost = -2
wFlags = SWP_Nomove Or Swp_Nosize
If WindowState = True Then
SetWindowPos FormName.hwnd, Hwnd_TopMost, 0, 0, 0, 0, wFlags
Else
SetWindowPos FormName.hwnd, Hwnd_NoTopMost, 0, 0, 0, 0, wFlags
End If
End Sub
Now, even if the form is transparent. It's still going to receive the mouse clicks and retain focus. So, you still need to figure that part out.
Re: Add a picture on screen?
Thanks for these ideas...
But now I would prefer using no form and drawing only on the desk dc, paint only pixels... :D . I know using APIs for catching and playing with DCs. But if I managed to draw continously on screen throught Timers, this way draws a flickering image... Is a way to avoid these flashes?
Re: Add a picture on screen?
I don't know what you're drawing. But the only advice I can give is to draw to another DC and then BitBlt to the desktop. But then, you probably knew that.
Maybe, there's a way with DirectX. But, I've never played with DirectX.