Solved

Another DC question.

Posted on 2004-10-28
169 Views
Last Modified: 2010-05-02
Hi!

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
'--------------------------------------------------------------------

Thanks!
0
Question by:dbrckovi
    3 Comments
     
    LVL 6

    Accepted Solution

    by:
    hi ,
    have a look at the article at this link
    http://www.officecomputertraining.com/vbtutorial/tutpages/page44.asp
    0
     
    LVL 11

    Author Comment

    by:dbrckovi
    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.
    0
     
    LVL 6

    Expert Comment

    by:Amritpal Singh
    welcome :))
    n e time
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    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…
    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…
    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…

    877 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now