Author Topic: How to receive mouse messages for the entire screen?  (Read 12382 times)

jj2007

  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Re: How to receive mouse messages for the entire screen?
« Reply #15 on: March 04, 2014, 04:04:08 AM »
Basically, 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

  • Guest
Re: How to receive mouse messages for the entire screen?
« Reply #16 on: March 14, 2014, 10:10:34 PM »
You need to handle raw input events. RegisterRawInputDevices + GetRawInputData. This is what some games use. Some firewalls might raise alarm regarding this.

Tedd

  • Member
  • ***
  • Posts: 353
  • Procrastinor Extraordinaire
Re: How to receive mouse messages for the entire screen?
« Reply #17 on: March 21, 2014, 03:05:39 AM »
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

  • Member
  • **
  • Posts: 87
Re: How to receive mouse messages for the entire screen?
« Reply #18 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 ...

jj2007

  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Re: How to receive mouse messages for the entire screen?
« Reply #19 on: March 25, 2014, 10:55:35 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

  • Member
  • ***
  • Posts: 353
  • Procrastinor Extraordinaire
Re: How to receive mouse messages for the entire screen?
« Reply #20 on: March 26, 2014, 06:12:04 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--

  • Administrator
  • Member
  • ******
  • Posts: 5940
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: How to receive mouse messages for the entire screen?
« Reply #21 on: March 26, 2014, 02:42:13 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

NoCforMe

  • Member
  • **
  • Posts: 87
Re: How to receive mouse messages for the entire screen?
« Reply #22 on: April 19, 2014, 07:08:36 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.