Solved

hWnd to hDc is it possible?

Posted on 2001-08-07
10
1,361 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

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

Accepted Solution

by:
adg earned 300 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 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