[Webinar] Streamline your web hosting managementRegister Today

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

Copy picture between applications

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
Amnon
Asked:
Amnon
  • 5
  • 3
  • 3
  • +3
1 Solution
 
BabyFaceCommented:
I don't understand your question...
0
 
MirkwoodCommented:
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
 
AmnonAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
MirkwoodCommented:
That will hardly be faster...
0
 
BabyFaceCommented:
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
 
MirkwoodCommented:
passing hdc between application works.
Well not on my machine (NT)
0
 
AmnonAuthor Commented:
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
 
SLECommented:
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
 
AmnonAuthor Commented:
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
 
BabyFaceCommented:
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
 
pakosCommented:
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
 
AmnonAuthor Commented:
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
 
AmnonAuthor Commented:
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
 
wyllikerCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now