Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy PictureBox content from another App

Status
Not open for further replies.

Unscruffed

Programmer
Apr 2, 2002
102
AU
Is it possible to get the Picture from a PictureBox control in another application and either copy it to a PictureBox, or save it as a file?

Be good. If you can't, don't get caught!
 
Clipboard.Clear
Clipboard.SetData Picture1.Image
MsgBox "Graph image copied to Windows Clipboard as a bitmap
 
If both applications are yours and you can modify the first one, use a winsock connection in both applications and use it to send the .Picture
In the sender you put the old picture into a Propertybag and send its contents.
In the receiver, after the data has arrived you put it into another propertybag and put it's contents into the new picture or image box
There are many threads in this forum explaining this and how to send a file using winsocks on the same computer.
You can also send it to a different computer on a LAN
 
Sorry for the delay in responding to your replies (which I thank you for). I've had to do some checking to find out exactly what I'm allowed to say in the forums (see the legal stuff below).

Unfortunately the source app is not mine. The app was written in VB6 though, so that's a start. I can get a "hwnd" for the source picturebox, but the "dc" is constantly changing, so "BitBlt" etc doesn't work.

The picture scrolls using scrollbars. I don't know if the picturebox actually loads the whole image and is moved by the bars, or if a section of the image is read then drawn when the scrollbars are moved. I think the later is more probable considering the size of the files.

The problem is that the existing image files are some kind of custom format that I can't load into an image editor or converter. I can't find anything that recognizes the file format. Therefore, it seems the only way I can source the image(s) is through the original GUI, then somehow save the image(s) and convert to a usable format as necessary.

The legal stuff:

1. The app was bought on a rather large multi user licence by the "company" that I drive for. Because the app is so difficult to use on a touch screen, the "company" (after I volunteered to give it a try) sought permission to make it's own customized GUI. Permission was granted, however assistance is very limited.

2. The permission granted by the authoring company allows the use or conversion of their data files, however they are unable to assist in this process.

3. Any converted or modified files must display as originally intended. (ie: convert as necessary, but all files must "look" the same as the original)

4. Any "programs" or "code" which uses the authors files (in original or modified form), must not be supplied in any way to a third party. All such items must remain the sole property of the licence holder.

It is point 4 that, unfortunately, makes life difficult for us part time programmers.

In the meantime, I'll keep prodding to be able to provide more info about what the app actually does. (There is a clue if you read between the lines.)

Be good. If you can't, don't get caught!
 
Sounds like the image is a map of the city??

If you just want to copy the existing pic to another app as you originally suggest, you could make a snapshot of the existing screen and use that. There are plenty of examples around that show you how to do this.
However if you want to make another GUI you will probably want to access the original image data into an image box - that could be a problem unless you can put the whole map into a huge image box and blow it up inside a frame to hide the unwanted edges.
You would then move it simply with the .move statement (with 0,0 being the left top corner of the frame) using large direction buttons on the touch screens instead of scroll bars.
Pity you cant get the original code and offer it back modified for touch screens to the company for others (for a small fee of course!) This would be the easy way and be to their own advantage!
You can easily zoom in by changing the Image1.Move left, top, width and height of the image box inside the frame.
 
Hi Ted. Yes, & well thought out.

The offer has been made, but apparently the "version" we have is now obsolete, and as such we are on our own. (Raises the question about about all the secrecy doesn't it?)

If we assume that the (we'll call it a "map" hehe) is of a city, then we may as well assume grids, pages etc in a book, right? If we then assume that this "imaginary" book has say 400 odd pages, and that a monitor generally displays about 1/3 of a page at a time, then we can see the conundrum. This is why I'm trying to avoid "screenshots" so to speek, and somehow obtain the map(s) by code.



Be good. If you can't, don't get caught!
 
>I can get a "hwnd" for the source picturebox, but the "dc" is constantly changing, so "BitBlt" etc doesn't work

If you can get an hWnd then you can get the hDC. The fact that it constantly changes should be irrelevant, since best practice suggests that you don't store the hDC but retrieve it from the hWnd at the exact point in time that you need to use it and then discard it as soon as you can.

At which point bitblitting should indeed be the way to grab the current contents of the foreign picturebox. However I don't see an easy way around the fact that it is pretty certain that the foreign application is itself only blitting in a small part of the image at a time, since this means that the whole image is likely only available in a private memory DC - which you cannot get access to.
 
Is it possible to identify the file that contains only the image? Surely it should be separate to the GUI app.

If it is a .bmp and you can load it all into a picture or image box at all (with stretch set to true) then you should be able to load just part of it as well (like severe cropping) as strongm says.

Then you could compose an entirely new front end with more suitable controls and not need to involve the original picture box.

I don't know if there is a limit to the size of an image?

You'd have to work out your own coordinate system of course using the "pixels per mile" or something like that.
 
The files have a "cmp" extension. I've hunted around and found that there are image files with this extension, but every editor I download that can edit that type of file, says the files are unrecognized.

With the "dc" issue, using "GetDC" then "BitBlt" straight away, does work. The problem I had was with the AutoRedraw on the destination, but that's sorted now. It's going to be a slow process, but it looks like this is the only way.

By the way, some of those cmp files are around 200mb in size. According to task manager, the app is only using about 20mb of mem max at any time. Certainly not loading the whole file, but whatever it is doing, it seems quick to draw for Vb.

Anyway, I should be right from here, so thanks for the help guys.

Be good. If you can't, don't get caught!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top