?
Solved

Draw image to PictureBox given hDC

Posted on 2002-05-23
10
Medium Priority
?
1,045 Views
Last Modified: 2008-03-10
How do I load an image into a PictureBox only knowing that control's hDC?
0
Comment
Question by:dplambert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 7029859
if you don't mind messing w/ the clipboard you could do something like this:

put a richtextbox on your form (invisible if you want) and do the following:

Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
    hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As Long
Private Const WM_PASTE = &H302


Private Sub Command1_Click()

Dim p As StdPicture
Set p = LoadPicture("C:\my documents\badbaby.bmp")

Clipboard.Clear
Clipboard.SetData p
SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0

RichTextBox1.SelPrint (Picture1.hDC)


End Sub
0
 
LVL 3

Expert Comment

by:nichia
ID: 7029902
You may try the BitBlt API function to transfer an image from one hDC to another.  Example can be found here:
http://216.26.161.91/vbapi/ref/b/bitblt.html
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7030082
From where you are getting the image in first place?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Author Comment

by:dplambert
ID: 7030270
The source image will come from another PictureBox control.
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 300 total points
ID: 7030339
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
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source


Private Sub Command1_Click()
Picture1.ScaleMode = 3
Picture1.Picture = LoadPicture("C:\my documents\badbaby.bmp")

'' now write to picture2 hdc
BitBlt Picture2.hDC, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, _
       Picture1.hDC, 0, 0, SRCCOPY

End Sub

though you probably won't be able to get Picture2.ScaleWidth, Picture2.ScaleHeight since all you have is the hdc... but all that is is the destination width/height which you can set to whatever you want.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7030415
Stange. I don't understand why do you need to use hdc to put an image from one picture box to another since
Picture2.Picture = Picture1.Picture could do the job.
0
 
LVL 3

Author Comment

by:dplambert
ID: 7030487
Yeah, good point. I might just do that. I'm just trying to be consistent with the project style. All PictureBoxes are updated by passing a hDC to a DLL that handles the graphics. In a module, a call is made to the DLL and this method accepts a hDC. Under a certain case, I was going to use the hDC myself to put my own graphic in here, but I could do it that way too...
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 7030506
On Error Resume Next
For Each Control In Controls
    If Control.hDC = ThehDC Then
       Control.Picture = Picture1.Picture
    End If
Next
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7030525
OK. So bitblt form Bobbit could do the job.
0
 
LVL 3

Author Comment

by:dplambert
ID: 7030589
My research on the web also show this to be the "best" way for what I want to do too... Thanks...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question