?
Solved

hWnd to hDc is it possible?

Posted on 2001-08-07
10
Medium Priority
?
1,372 Views
Last Modified: 2010-07-27
I have a commercial ocx that displays images. I want to superimpose another image over the top using my own ocx.

What I would like is to have the new image as a background.

Is it possible ?

If so how?
0
Comment
Question by:mulga
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6359489
Yes.
Public Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6359713
You should use the ReleaseDC function after you are done using the device context.

Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hWnd As Long, ByVal hDC As Long) As Long



From Microsoft:
============================

The GetDC function retrieves a common, class, or private DC depending on the class style specified for the specified window. For common DCs, GetDC assigns default attributes to the DC each time it is retrieved. For class and private DCs, GetDC leaves the previously assigned attributes unchanged.

After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do not have to be released. ReleaseDC must be called from the same thread that called GetDC. The number of DCs is limited only by available memory.

Windows 95/98: There are only 5 common DCs available per thread, thus failure to release a DC can prevent other applications from accessing one.
0
 

Author Comment

by:mulga
ID: 6360181
Thanks for the comments. I can use the GetDC/ReleaseDC Ok and it shows the image. What I want is more ambitious, is it possible to show both images at the same time, ie one as a backdrop of the other. When I write either of the images the other gets zapped.
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 16

Expert Comment

by:Richie_Simonetti
ID: 6360296
You mean merging both in one?
0
 
LVL 3

Accepted Solution

by:
adg earned 1200 total points
ID: 6361762
Something like this?  Click on the small picture box to copy the pixels to the left.

Option Explicit
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 Sub Form_Resize()
    Dim i As Integer
    Randomize Timer
    Picture1.Move 0, 0, ScaleWidth / 2, ScaleHeight
    Picture2.Move ScaleWidth / 2, 0, ScaleWidth / 4, ScaleHeight / 4
    Picture1.ScaleMode = vbTwips
    Picture2.ScaleMode = vbTwips
    For i = 1 To 100
        Picture1.Circle (Rnd * ScaleWidth / 2, Rnd * ScaleHeight), 100, vbRed
    Next i
    For i = 1 To 10
        Picture2.Line (Rnd * ScaleWidth / 4, Rnd * ScaleHeight / 4)-(Rnd * ScaleWidth / 4, Rnd * ScaleHeight / 4), vbGreen, B
    Next i
    Picture1.ScaleMode = vbPixels
    Picture2.ScaleMode = vbPixels
End Sub

Private Sub Picture2_Click()
    Dim x1 As Long
    x1 = Picture2.ScaleWidth / 2
    Picture1.AutoRedraw = False
    BitBlt Picture1.hdc, x1, x1, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture2.hdc, 0, 0, vbSrcCopy
End Sub
0
 

Author Comment

by:mulga
ID: 6361997
Yes, I want to merge. One image is displayed on screen and the other is held in memory, it is an aerial photo pulled from disc. The image on screen is displayed in an OCX control that doesn't have a hDc but I can get an hDc from GetDC etc.
There are other things that I need to do but I won't worry about them if it is not possible to merge.

0
 
LVL 3

Expert Comment

by:adg
ID: 6362189
Sorry, I'm not sure if your responding to Richie_Simonetti or me or both.  Can I ask you a few questions?  

1. When you say you want to merge, do you mean copying a smaller bitmap on top of a larger one?  If so, is the smaller image rectangular?

2. The above example draws some circles and lines and then copies the lines on on top of the circles, leaving the circles as a background. I used pictureboxes since I don't have access to your commercial control.  Is there some way I could modify the example to make it more useful to you?  

3. When you say the other image is being held in memory, is it a GDI bitmap or something else?

0
 

Author Comment

by:mulga
ID: 6362755
The bitmap in memory (aerial photo)is a simple GDI and I can convert it if neccessary. I want the background of the aerial photo to show as a background and the commercial OCX to appear as well.
I can show either in the DC but not both together.
 
0
 

Author Comment

by:mulga
ID: 6363010
The bitmap in memory (aerial photo)is a simple GDI and I can convert it if neccessary. I want the background of the aerial photo to show as a background and the commercial OCX to appear as well.
I can show either in the DC but not both together.
 
0
 
LVL 3

Expert Comment

by:adg
ID: 6365161
Sounds good.  That's what my example does.  It takes a smaller bitmap and blits it onto a larger bitmap so they both show. The larger one is the background for the smaller.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

801 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