Windows default context menu not captured correctly?

Aug 19, 2010 at 9:44 PM
Hi all, I need to capture images of a window when the user right-clicks on a text box, and the default Windows context menu is displayed. I was able to capture my own defined ContextMenu using TestAPI, but when I tried to capture the default Windows context menus, they are not captured. Can anyone confirm if TestAPI should be able to capture the default Windows context menus? Maybe my timing is off, capturing in the wrong event or something, but I want to be sure this should work before I pursue that too much further. Thank you for any suggestions you can provide! Jon
Aug 20, 2010 at 1:09 AM


Yes, TestApi is able to capture any screen content (incl. context windows). I'd advise you to capture a screen rectangle (the screen rectangle of your context menu -- because context menus are typically implemented as top-level windows) and add a bit of a wait before the capture (unless ideally you have a synchronization event you can wait on) to make sure the menu has been displayed. That should work.


Aug 21, 2010 at 10:56 PM

If a screen rectangle is captured, how do you figure out which part of the rectangle is the menu and which part isn't? Similarly, what if the menu extends beyond the borders of the window. Capturing the screen as a rectangle would include pixels from windows running behind the desired window. How do you handle a case like that?

Aug 23, 2010 at 6:02 AM


If you use a screen capture (i.e. Snapshot.FromRectangle(...)) for capturing the menu, you should first figure out the bounding rectangle of the menu in screen coordinates and feed that into the FromRectangle method. But I am pretty sure things will work fine if you just use Snapshot.FromWindow(hwndOfYourMenu). If you decide to capture the whole screen then I'd suggest placing a window with a known pattern under your window to obscure any other desktop or window variations. This is one of the techniques we used to test the glass window borders in Vista.