Results 1 to 4 of 4

Thread: Add a picture on screen?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    Add a picture on screen?

    Hello,

    I'm searching to draw a picture on screen. My picture would be always on top and you can follow to click under the element as if my picture doesn't exist. It's simply graphic, an image, no form or other thing...

    Does exit a way to perform that? Can we think we can make a transparent picture as we can see what happen under the picture?


    Thanks

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    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:
    1. Private Declare Function GetWindowLong Lib "user32" Alias _
    2.     "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    3.    
    4. Private Declare Function SetWindowLong Lib "user32" Alias _
    5.     "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
    6.     ByVal dwNewLong As Long) As Long
    7.    
    8. Private Declare Function SetLayeredWindowAttributes Lib "user32" _
    9.     (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, _
    10.      ByVal dwFlags As Long) As Long
    11.  
    12. Const WS_EX_LAYERED = &H80000
    13. Const GWL_EXSTYLE = (-20)
    14. Const LWA_ALPHA = &H2
    15. Const LWA_COLORKEY = &H1
    16.  
    17.  
    18. Private Sub Form_Load()
    19.     'pass sub form name, level form 0 to 255, zero being invisible
    20.     MakeTransparent Me, 100
    21. End Sub
    22.  
    23.  
    24. Public Sub MakeTransparent(F As Form, Level As Byte)
    25.    Dim rtn As Long
    26.    rtn = GetWindowLong(F.hwnd, GWL_EXSTYLE)
    27.    rtn = rtn Or WS_EX_LAYERED
    28.    SetWindowLong F.hwnd, GWL_EXSTYLE, rtn
    29.    SetLayeredWindowAttributes F.hwnd, 0, Level, LWA_ALPHA
    30. 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:
    1. 'in declaration section of form or module
    2. Private Declare Function SetWindowPos Lib "user32" _
    3. (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
    4. ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
    5. ByVal cy As Long, ByVal wFlags As Long) As Long
    6.  
    7. 'in main section of form or module
    8. 'ex. MakeTop form1,True
    9. Public Sub MakeTop(FormName As Form, WindowState As Boolean)
    10.     Dim wFlags As Long
    11.     Dim posFlag As Long
    12.  
    13.     Const Swp_Nosize = &H1
    14.     Const SWP_Nomove = &H2
    15.     Const Hwnd_TopMost = -1
    16.     Const Hwnd_NoTopMost = -2
    17.    
    18.     wFlags = SWP_Nomove Or Swp_Nosize
    19.  
    20.     If WindowState = True Then
    21.         SetWindowPos FormName.hwnd, Hwnd_TopMost, 0, 0, 0, 0, wFlags
    22.     Else
    23.         SetWindowPos FormName.hwnd, Hwnd_NoTopMost, 0, 0, 0, 0, wFlags
    24.     End If
    25. 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.
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    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... . 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?

  4. #4
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    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.
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

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