Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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!
0
dbrckovi
Asked:
dbrckovi
  • 2
1 Solution
 
Amritpal SinghCommented:
hi ,
have a look at the article at this link
http://www.officecomputertraining.com/vbtutorial/tutpages/page44.asp
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now