Solved

hWnd to hDc is it possible?

Posted on 2001-08-07
10
1,358 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

809 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