Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy picture between applications

Posted on 1999-07-11
14
Medium Priority
?
225 Views
Last Modified: 2010-05-02
Hi,
I have two VB applications.
Both have picture box with picture inside and the AutoRedraw property is true.
I want that one application will copy its picture to the other (I have the destination picture box hWnd).

I'm doing the following:

DesDC = GetDC(DestHwnd)
BitBlt(DestHwnd, 0, 0, 1000, 1000, SourceDC, 0, 0, SRCCOPY)

The result is that the picture was copied but after moving
some window above the destination picture box is presenting
the old picture (not the one that I copied),
It's just like the AutoRedraw property of the destination
picture box is false (altough it was set to true).
Does anyone know how to copy the picture so the AutoRedraw will present the new picture and not the previous one ?

Thanks.

0
Comment
Question by:Amnon
[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
  • 5
  • 3
  • 3
  • +3
14 Comments
 
LVL 1

Expert Comment

by:BabyFace
ID: 1523495
I don't understand your question...
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1523496
First application does the Command1 code
Second application does the Command2 code


Private Sub Command1_Click()
    Clipboard.SetData Picture1.Picture
End Sub

Private Sub Command2_Click()
    Picture2.Picture = Clipboard.GetData
End Sub

0
 

Author Comment

by:Amnon
ID: 1523497
I've tried this before but it was too slow.
I have to pass many picture between those applications
(one application is connected to a camera) and each picture
is about 0.5 MB and need to be stretched in the destination
applications.
I want economize the time it takes to pass the picture to
the clipboard and from the clipboard and copy the picture
directly to the destination.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1523498
That will hardly be faster...
0
 
LVL 1

Expert Comment

by:BabyFace
ID: 1523499
I don't know exactly what you are doing, but this is a method I've tried and it works!

In app 1 you have a picturebox(no borders, autoredraw set to true), and a CommandButton.

In app2 you have a picturebox(same properties as above, but with a picture).
During app2 activation, Debug.Print Picture1.hDC, run the program.

Remember the hdc in the debug window, and then goto App 1, Command1_Click.
Type this:
BitBlt Picture1.hDC, 0, 0, 100, 100, [Debug's hdc goes here...], 0, 0, vbSrcCopy
    Picture1.Refresh

This should copy the picture from App2 to App1
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1523500
passing hdc between application works.
Well not on my machine (NT)
0
 

Author Comment

by:Amnon
ID: 1523501
BabyFace hello,

Your method wotks only if app#1 copy the picture from app#2
to its own PictureBox but not if app#1 copy its picture
to app#2 PictureBox as I need.

Thanks.

0
 
LVL 2

Expert Comment

by:SLE
ID: 1523502
What about saving the picture from the first app in a common (shared) path and then loading it into your second app from file?
0
 

Author Comment

by:Amnon
ID: 1523503
SLE Hello,
This option is much to slow, the picture is coming from
camera and should,sometimes, be updated a few time in one second while other processes runing in background.

Thanks
0
 
LVL 1

Expert Comment

by:BabyFace
ID: 1523504
If you know the hdc of the picturebox in app #2, you can do this from app #1:

BitBlt [Debug's hdc goes here...], 0, 0, 100, 100, Picture2.hDC, 0, 0, vbSrcCopy
0
 

Expert Comment

by:pakos
ID: 1523505
why don't u use the capture screen (or a prefixed area of the screen) to a temp file and load it from the second app?

0
 

Author Comment

by:Amnon
ID: 1523506
If I'll do the following :
BitBlt [Debug's hdc goes here...], 0, 0, 100, 100, Picture2.hDC, 0, 0, vbSrcCopy

The picture will be copied but if I'll move another window
above it, the picture will be deleted even if
AutoRedraw = True.
0
 

Author Comment

by:Amnon
ID: 1523507
If I'll do the following :
BitBlt [Debug's hdc goes here...], 0, 0, 100, 100, Picture2.hDC, 0, 0, vbSrcCopy

The picture will be copied but if I'll move another window
above it, the picture will be deleted even if
AutoRedraw = True.

I need to copy the picture to the Background image (or someything like that) of the picture box, in this way
every paint event of the picture box will paint the copied
picture.

0
 
LVL 4

Accepted Solution

by:
wylliker earned 400 total points
ID: 1523508
The important thing to realize is that the behavior you see with AutoRedraw=True is absolutely correct.  You are simply copying bits to the screen.

The picture control is 'bound' to the bitmap specified by the Picture1.Picture property which takes a bitmap handle returned by LoadPicture, or any other way of handing off a bitmap handle.

It will always redraw the bitmap it knows about regardless of the copying of bits you have done.

Now, if I am not mistaken (and I have been and may now be) Bitmap Handles and Bitmaps themselves are 'global' in windows, in that they are in the GDI space common to all applications.  So a handle to a bitmap should be transferable across application boundaries.

If you set up a DDE conversation between the applications you can use LinkPoke with picture boxes since, as the VB help points out (confirming my assumption above):

If object is a PictureBox, LinkPoke transfers the contents of the Picture property to the source.

So your first app could poke the Picture property (handle) of it's picture control to the second app's Picture Control.  This will result in the transfer of just the handle not the entire half MB file.


Alternatively, if you didn't need every 'frame' from the first app, the second app could poll using LinkRequest in conjunction with a timer.  Experiment, see what works best for your app.

If you need help setting up the DDE conversation, post up a new question for 20 or 30 points, there are many who could run that out for you - or read the help info and have at it!





0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 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