Results 1 to 3 of 3

Thread: Drawing an image on a static window

  1. #1
    Tygur
    Guest

    Drawing an image on a static window

    I have a static window I made with CreateWindowEx. And I have an image stored in either a StdPicture variable or a picturebox. I want to draw the image onto the static window.

    Can anyone give me the code for that? I can probably do it myself, but I don't have the time right now.

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    You need to use BitBlt, but to use BitBlt you need to have a Source DC to blit from, something like this should (where hwnd_of_static_window is the window handle of the window created with CreateWindowEX)....

    VB Code:
    1. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
    2. Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
    3. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    4. Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
    5. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    6. Private Declare Function BitBlt Lib "gdi32" (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 dwRop As Long) As Long
    7.  
    8. '...............
    9.  Dim sp As StdPicture
    10.  Dim hDC As Long
    11.  Dim hOldBMP As Long
    12.  
    13.  Set sp = LoadPicture("C:\Windows.bmp")
    14.  
    15.  ' create and get the handle to a new Device Context
    16.  hDC = CreateCompatibleDC(GetDC(hwnd_of_static_window))
    17.  
    18.  ' select the bitmap into the new DC
    19.  hOldBMP = SelectObject(hDC, sp.Handle)
    20.  
    21.  ' blt the image
    22.  ' example assumes picture is 50 x 50 pixels, adjust the nHeight and nWidth _
    23.    parameters to fit your needs
    24.  BitBlt GetDC(hwnd_of_static_window), 0, 0, 50, 50, hDC, 0, 0, vbSrcCopy
    25.  
    26.  ' select the old dc back into the temporary DC and delete the DC
    27.  SelectObject hDC, hOldBMP
    28.  DeleteDC hDC
    29.  
    30. ' ............
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3
    Tygur
    Guest
    I figured I ought to tell you what happened. Before starting this thread,
    I already did try it myself, but it wasn't working and I couldn't figure
    out why (by the way, I was using BitBlt). So I decided to compare it to
    somebody else's code to look for any differences. Your code was very
    similar to mine, and it didn't work either.

    It turned out that my problem wasn't in the code that actually put the
    image on the window. It was in the code that created it. Apparently, you
    need to make a static window with the SS_USERITEM style set if you want to
    put an image on it, otherwise it won't work.

    This is just FYI, just in case somebody else runs into the same problem.

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