[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Another DC question.

Posted on 2004-10-28
3
Medium Priority
?
170 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
Comment
Question by:dbrckovi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
Amritpal Singh earned 2000 total points
ID: 12431560
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
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.
0
 
LVL 6

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

649 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