News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to receive mouse messages for the entire screen?

Started by NoCforMe, March 01, 2014, 02:35:15 PM

Previous topic - Next topic

jj2007

Quote from: qWord on March 04, 2014, 12:33:16 AM
Quote from: jj2007 on March 03, 2014, 07:00:06 PMBasically, you paint rectangles on a window that doesn't paint its background.
That method does no longer work due to the desktop window manager (vista+), which compose the final image from buffers - the applications no longer draw directly to the screen DC.

It works perfectly under Win7, provided you are using a "classic" theme. With Aero, you get indeed white rectangles instead of frames.

hool

You need to handle raw input events. RegisterRawInputDevices + GetRawInputData. This is what some games use. Some firewalls might raise alarm regarding this.

Tedd

1. Take a snapshot of the whole screen
2. Capture the mouse pointer
3. Create a popup window (with on-top state) to cover the screen
4. Bitblt the screenshot to your window
5. Change the pointer shape (crosshair?) to give some user feedback, and allow the user to drag an outline, or whatever else
6. Respond to the click and save the image portion to file
7. Destroy your popup window, and free your resources (bitmaps, DCs, etc)
8. Release the mouse pointer

Easy?
Potato2

NoCforMe

@Tedd: With all due respect, that sounds like a ... klugey solution at best.

In my original post I mentioned how a piece of commercial software I use (Paint Shop Pro) has this functionality built in. Is anyone here familiar with this program? I'm still using their version  7.00, which by now is pretty ancient, but still works fine  for me. I'll bet (though I'd have to try it) that it would still work under Vista, perhaps even Windows 7, including the nifty screen-lasso function.

Also, regarding the solution suggested by Dave (I think) earlier, ugh: hadn't figured on having to write a DLL for my little app. I've never written one and frankly don't really have any desire to do so ...
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on March 25, 2014, 10:04:45 AM.. (Paint Shop Pro) has this functionality built in. Is anyone here familiar with this program? I'm still using their version  7.00, which by now is pretty ancient, but still works fine  for me. I'll bet (though I'd have to try it) that it would still work under Vista, perhaps even Windows 7, including the nifty screen-lasso function.

Version 4.18 works fine under Windows 7...

Tedd

Quote from: NoCforMe on March 25, 2014, 10:04:45 AM
@Tedd: With all due respect, that sounds like a ... klugey solution at best.

In my original post I mentioned how a piece of commercial software I use (Paint Shop Pro) has this functionality built in. Is anyone here familiar with this program? I'm still using their version  7.00, which by now is pretty ancient, but still works fine  for me. I'll bet (though I'd have to try it) that it would still work under Vista, perhaps even Windows 7, including the nifty screen-lasso function.

Also, regarding the solution suggested by Dave (I think) earlier, ugh: hadn't figured on having to write a DLL for my little app. I've never written one and frankly don't really have any desire to do so ...
Windows doesn't provide a direct way to do this, and you're trying to copy the contents of other windows - any solution is going to be some kind of kludge. This is the cleanest way I could think to do it.

I have just tried with PSP7 and it works almost the same way minus the intermediate popup window - the capture rectangle is drawn directly on to the screen (xor-ed so that xor-ing again will remove it), with the hope that you won't to interact with any other windows during that time (you still can via the keyboard), and the snapshot is actually taken with the next click. This is a fairly hacky-but-it-works-in-most-cases approach.

For an immediate capture (full-screen, window, static area), you can obviously just take the snapshot directly from the screen, but in the case of capturing a user-drawn rectangle I did suggest taking the snapshot first and then using it on a popup window for a few reasons:
- you're going to be drawing some kind of interface on top of everything else, which shouldn't interfere with any other windows' contents (even in the case of xor-ing simple lines, this leaves artefacts if their window contents change during that time);
- it should avoid problems caused by composition rendering on later windows version (untested whether it would be a problem, but it doesn't hurt either);
- it makes sense to capture what was on the screen when the capture was requested, and not some seconds later after a rectangle has been drawn around the..... oops, it's changed and now I missed it.

Any less kludgey magic solutions welcome.
Potato2

hutch--

Tedd is right, doing a BitBlt() on the screen (with or without the calling window) then chop out the bit you want that you mark out with the mouse rectangle. From memory you just BitBlt() the rect area that is marked out with the mouse reading the mouse down then up messages.

NoCforMe

Quote from: Tedd on March 26, 2014, 06:12:04 AM
I have just tried with PSP7 and it works almost the same way minus the intermediate popup window - the capture rectangle is drawn directly on to the screen (xor-ed so that xor-ing again will remove it), with the hope that you won't to interact with any other windows during that time (you still can via the keyboard), and the snapshot is actually taken with the next click. This is a fairly hacky-but-it-works-in-most-cases approach.

For an immediate capture (full-screen, window, static area), you can obviously just take the snapshot directly from the screen [...]

Ackshooly, that's exactly what I want. Take a snapshot of the screen as it is at the time of lassoing, then size an area. No concern about subsequent changes to window contents.

Actually, I don't even want the contents of the screen: I only want to be able to draw a lasso and determine the size of the lassoed area.  Like PSP 7 does, I can indicate the size directly on the screen (I think by creating a cursor that's an image of the size string--x X y--so no other interface or popup windows needed). This isn't perfect--with my browser (Opera), it left some garbage on the screen during the capture--but it would work well enough for my purposes.

So can you tell me how to do that? I don't know how to access the screen, nor how to conduct mouse operations outside of my client windows. Oh, and the way PSP works,  when you capture the screen, the PSP client windows completely disappear.

This might in itself be klugey, but it would satisfy the requirements of my little project.
Assembly language programming should be fun. That's why I do it.