1

Okey. Here's what I want to do:

I have a windows application that sorts a folder specified by the user. I want to take a screenshot of this folder before sorting, and then again when my program has finished sorting the folder.

I know how to take a screenshot of an active window using the following link:

Capture screenshot of active window?

However, what happens if I want to take screenshot of an unopened location?

Meening, that I want to take a screenshot of a folder that is not opened at all. Is it even possible?

If yes, then how would I go about achieving this?

One way I guess would be to make the program open the folder -> take screenshot -> close it -> sort folder -> open folder -> take new screenshot -> Show on screen

This isn't a very elegant solution though.

Can anyone shed some light on this issue? Thank you for your time!

Community
  • 1
  • 1
AlexanderN
  • 2,610
  • 1
  • 26
  • 42
  • Sort a folder ? what kind of folder ? – Steve B May 03 '12 at 12:34
  • @SteveB A normal directory. Its sorts just fine. I just need to take screehshots for before and after. – AlexanderN May 03 '12 at 12:35
  • 1
    I don't understand... the OS sorts the folder. Are you talking about a file system folder ? – Steve B May 03 '12 at 12:37
  • a screenshot is a picture of what IS actually shown... I don't think it's possible – asdasdad May 03 '12 at 12:40
  • *Why* do you want a screenshot? What do you mean by "sort the folder"? – Roger Lipscombe May 03 '12 at 12:40
  • @SteveB By sorting I mean moving the files in the chosen directory into folders(Movies, Images, etc). But that is not important. Because the sorting works like it should. I need to know if its possible to either take a screenshot of an unopened folder window or if its possible to open the folder windows and take a screenshot without the user seeing it. – AlexanderN May 03 '12 at 12:41
  • @RogerLipscombe Hey, read the comment above :) – AlexanderN May 03 '12 at 12:42
  • 1
    Why bothering with a screenshot ? Just build a visual report (draw an image, populate a treeview, etc.) – Steve B May 03 '12 at 12:44
  • @SteveB I thought that it might be easier. I was sadly mistaken.. – AlexanderN May 03 '12 at 12:59

4 Answers4

2

Depends on what you actually want to do, if your intent is to check the contents of the "folder" and "subfolders" before and after the sort operation, I will suggest you use the command prompt to generate the list of contents in a text file. you can use the dir command for this like so:

DIR /S /B "Path\To\Folder" > "Path\to\text\File.txt"
Surya Pratap
  • 495
  • 8
  • 17
1

You can't take a snapshot of something that isn't drawn on the screen. You need to open the folder, take the snapshot and close the folder.

Icarus
  • 63,293
  • 14
  • 100
  • 115
1

First think of the purpose of the screenshot. You might be able to log the order of objects inside the folder before and after sorting them. Then you can use your logdata to produce an textual or graphical output showing a folder like image with the contents in presorted order.

If you take a screenshot how do you handle objects that do not fit inside the folder? With the above solution you will get information even of files not visible in an open folder.

Otherwise there will be no way to get a real screenshot of anything that is not on the screen. Opening the folder would be the easiest and only way then.

Tarion
  • 16,283
  • 13
  • 71
  • 107
1

You could position the folder window outside of the bounds of his/her screen. Then take a screenshot of that window region.

You can determine the screen width and height and position (if you position a second screen to the left of your primary screen you start position of your screen is negative) using the following code:

System.Windows.SystemParameters.VirtualScreenWidth;  //Total width of screen
System.Windows.SystemParameters.VirtualScreenHeight; //Total height of screen
System.Windows.SystemParameters.VirtualScreenLeft;   //Start x location of screen
System.Windows.SystemParameters.VirtualScreenTop;    //Start y location of screen

And by placing your folder window outside of this region and then take a screen shot of that folder should do the trick. (Not sure not tested)

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(folderWidth, folderHeight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.CopyFromScreen(folderX, folderY, 0, 0, folderSize);
bitmap.Save(aRandomFileStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Code provided as is... No warrenties if it works.

SynerCoder
  • 12,493
  • 4
  • 47
  • 78