Avatar of ray_marik
ray_marik
 asked on

get file path to image loaded on clipboard

How do I get local or actual file path to an image of type CF_BITMAP, CF_DIB, CF_TIFF, and CF_ENHMETAFILE currently loaded on the clipboard? I know how to get the actual image but I need to know the file path (If CF_HDROP is not specified as a loaded file type).
CC++

Avatar of undefined
Last Comment
ray_marik

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
mccarl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ray_marik

ASKER
Well, if it's CF_BITMAP and CF_HDROP loaded, there's a filename you can retrieve, so I would think you could retrieve a file name from other formats also loaded on clipboard along with CF_BITMAP, for example, OLE PRIVATE DATA or UniformResourceLocatorDataW.
mccarl

You said in the original post that
If CF_HDROP is not specified as a loaded file type
so that's what I was assuming.

How are these items getting on to the clipboard? Are you talking about, eg. hitting Ctrl+C on an image file in the filesystem? Or otherwise?
ray_marik

ASKER
What I was referring to is that a number of formats are loaded each time, not just what you normally would expect, ie for an image CF_BITMAP is specified but also something like CF_HDROP and a load of others.
Nevermind though, I guess it can't be done.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ray_marik

ASKER
I've requested that this question be deleted for the following reason:

No solution offered, cannot be done.
mccarl

Nevermind though, I guess it can't be done.

While that may well be he final outcome, but I hadn't really finished working this through with you. Are you able to answer the question that I asked?

How are these items getting on to the clipboard? Are you talking about, eg. hitting Ctrl+C on an image file in the filesystem? Or otherwise?
ray_marik

ASKER
"How are these items getting on to the clipboard? Are you talking about, eg. hitting Ctrl+C on an image file in the filesystem? Or otherwise?"

Right click, then copy.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mccarl

Right click, then copy.

But in what context? Right click on a file in the filesystem? Richt click on an image on a webpage? In a particular program, such as Word, Excel?
ray_marik

ASKER
Right clicking on images inside IE and loading to clipboard is the problem. I thought that was implied bec/ right clicking inside Win Explorer just passes the file as CF_HDROP, (in other words drag and drop and not of type CF_BITMAP).
mccarl

Ok, yeah, I was just making sure that that is the case before saying this...

I guess it can't be done

True, but not because of some limitation of the code or the clipboard, but simply because there is no file path to retrieve! Images in a browser are just image data retrieved from a URL, and they are at no point a file in the filesystem.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
mccarl

Moderators,

I don't believe that this should be deleted. I agree that there was no solution, but there is still a correct answer, "that there is no file path to retrieve". I believe that that is still worthy of an answer being accepted, and points awarded.
ray_marik

ASKER
There IS a file path to retrieve:

"Right clicking on images inside IE and loading to clipboard" should give a path and a file name leading to the original image inside the IE temp folder. That's how IE retrieves the images. We can argue till the cows come home but there is a file path and name to retrieve.
mccarl

> the original image inside the IE temp folder

What makes you think there is a physical file in the temp folder? Are talking about when you go to C:\Documents and Settings\XXXXX\Local Settings\Temporary Internet Files and you see entries in there for all the cached items, such as images, etc? That is just Windows trying to confuse you, it is presenting the browsers cahced items as though they are files but they aren't actually stored on the disk as files (I not saying that the info is not on the hard drive somewhere, just not as files and not in that directory). It is a view that Windows is making it "look" like there are physical files.

Here is some simple test code to illustrate my point... (go to your view of your Temporary Internet Files directory and pick out a file, put the path to that file as the constructor arg for file2, and put a path to a known file outside of the Temporary Internet Files directory for file1)

import java.io.File;
import java.io.IOException;

public class TestTemporaryInternetFileRetrieval {
	public static void main(String[] args) throws IOException {
		File file1 = new File("C:\\Documents and Settings\\XXXXX\\Local Settings\\test.txt");
		File file2 = new File("C:\\Documents and Settings\\XXXXX\\Local Settings\\Temporary Internet Files\\blank.gif");
		
		System.out.println("file1 exists: " + file1.exists() + " (" + file1.getAbsolutePath() + ")");
		System.out.println("file2 exists: " + file2.exists() + " (" + file2.getAbsolutePath() + ")");
	}
}

Open in new window


You should see that the file outside Temporary Internet Files "exists" and the one inside doesn't, ie. they aren't real files that can be accessed by a file path.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ray_marik

ASKER
IE caches image files inside temp folder for easier access later, that's the whole point.

In fact, back to the point I made in the second comment, assuming that CF_BIMAPT AND CF_HDROP are BOTH specified as loaded clipboard formats, then you can retrive the complete path to the image that points to the IE temp internet file. I have this code and it works as expected.

But what I was trying to do was get image path back to this IE temp folder assuming CF_BITMAP is specified but CF_HDROP is not, which is what happens with some images.

What I've ended up doing here is explain more to you than it's worth to me and my time. Judging by the Java code you cite for a C/C++ question and the fact you keep arguing to win 500 points, I'm led to believe that you do not understand clipboard and its formats and so I'm going to asks the moderators again to delete this question. You have not posted a solution and you do not deserve any points. Good day.