Another DC question.

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!
LVL 11
dbrckoviAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dbrckoviAuthor Commented:
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
Amritpal SinghCommented:
welcome :))
n e time
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.