|
-
Sep 9th, 2001, 06:54 AM
#1
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.
-
Sep 9th, 2001, 02:16 PM
#2
Fanatic Member
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:
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
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
'...............
Dim sp As StdPicture
Dim hDC As Long
Dim hOldBMP As Long
Set sp = LoadPicture("C:\Windows.bmp")
' create and get the handle to a new Device Context
hDC = CreateCompatibleDC(GetDC(hwnd_of_static_window))
' select the bitmap into the new DC
hOldBMP = SelectObject(hDC, sp.Handle)
' blt the image
' example assumes picture is 50 x 50 pixels, adjust the nHeight and nWidth _
parameters to fit your needs
BitBlt GetDC(hwnd_of_static_window), 0, 0, 50, 50, hDC, 0, 0, vbSrcCopy
' select the old dc back into the temporary DC and delete the DC
SelectObject hDC, hOldBMP
DeleteDC hDC
' ............
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Sep 10th, 2001, 11:08 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|