Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Another DC question.

Posted on 2004-10-28
Medium Priority
Last Modified: 2010-05-02

I'm going crazy with these DC's (Device Context). As soon as I think I understand how it works, I found out that I'm wrong.

So, please can someone explain:
 - how DC's work?
 - how to create my own DC which will hold the picture loaded in PictureBox control, so later I can work with this DC the same as if I would work with PictureBox'es DC.

This is what I'm trying but it just won't work. Why?
 - create two pictureboxes and assign some pictures to them
 - create two command buttons
 - paste this code:
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 Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
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 Const SRCCOPY = &HCC0020

Dim NewDC As Long
Dim NewBMP As Long

Private Sub Command1_Click()
    BitBlt Picture2.hdc, 0, 0, 15, 23, Picture1.hdc, 0, 0, SRCCOPY
End Sub

Private Sub Command2_Click()
    NewDC = CreateCompatibleDC(Picture1.hdc)
    NewDC = CreateCompatibleBitmap(Picture1.Picture.Handle, 15, 23)
    NewBMP = SelectObject(NewDC, Picture1.Picture.Handle)

    BitBlt NewDC, 0, 0, 15, 23, Picture1.hdc, 0, 0, SRCCOPY
    BitBlt Picture2.hdc, 0, 0, 15, 23, NewDC, 0, 0, SRCCOPY
End Sub

Private Sub Form_Load()
    Command1.Caption = "Working"
    Command2.Caption = "Not working! Why?"
End Sub

Question by:dbrckovi
  • 2

Accepted Solution

Amritpal Singh earned 2000 total points
ID: 12431560
hi ,
have a look at the article at this link
LVL 11

Author Comment

ID: 12431842
Thank you.

I realized what was the problem thanks to your link. My way of thinking was correct, but I didn't notice few errors in the syntax.

Expert Comment

by:Amritpal Singh
ID: 12431865
welcome :))
n e time

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

577 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