Capturing mouse input outside a dialog
-
I am trying to create a dialog MFC application that reads the cursor position anywhere on the screen, finds the colour of the pixel at that location and reports the information back to the dialog application. I have tried SetCapture and I must be doing something wrong because the cursor location stops reporting as soon as the cursor leaves the client area of the dialog. I have also looked at the "Screen Color Picker" by Florin Vasilescu. That uses an OnTimer function that allows me to read the screen location, but does not report mouse actions (LBUTTONDOWN) so that I can read the pixel at the cursor location. I have also tried using SetWindowsHookEx and defining the MouseProc (as described by Vesi in the CodeGuru article "Modal dialog and outside mouse control". That wasn't successful. If I use the WH_JOURNALRECORD hook ID as described there appears to be an indeterminate delay between any mouse (or keyboard) action and interaction with screen objects. If I use the WH_MOUSE no mouse actions are detected. Could someone help me with how to either properly set SetCapture() or point me to where I might discover how to read mouse actions outside the dialog box? I'm happy to supply code, but at this point it's a bit of a mess since I've been trying everything. Thanks for any help you may be able to provide. Much appreciated.
-
I am trying to create a dialog MFC application that reads the cursor position anywhere on the screen, finds the colour of the pixel at that location and reports the information back to the dialog application. I have tried SetCapture and I must be doing something wrong because the cursor location stops reporting as soon as the cursor leaves the client area of the dialog. I have also looked at the "Screen Color Picker" by Florin Vasilescu. That uses an OnTimer function that allows me to read the screen location, but does not report mouse actions (LBUTTONDOWN) so that I can read the pixel at the cursor location. I have also tried using SetWindowsHookEx and defining the MouseProc (as described by Vesi in the CodeGuru article "Modal dialog and outside mouse control". That wasn't successful. If I use the WH_JOURNALRECORD hook ID as described there appears to be an indeterminate delay between any mouse (or keyboard) action and interaction with screen objects. If I use the WH_MOUSE no mouse actions are detected. Could someone help me with how to either properly set SetCapture() or point me to where I might discover how to read mouse actions outside the dialog box? I'm happy to supply code, but at this point it's a bit of a mess since I've been trying everything. Thanks for any help you may be able to provide. Much appreciated.
rbrunton wrote:
I am trying to create a dialog MFC application that reads the cursor position anywhere on the screen, finds the colour of the pixel at that location and reports the information back to the dialog application.
This sounds like Pixie. I've used it a few times, and it does what I needed it to do.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
rbrunton wrote:
I am trying to create a dialog MFC application that reads the cursor position anywhere on the screen, finds the colour of the pixel at that location and reports the information back to the dialog application.
This sounds like Pixie. I've used it a few times, and it does what I needed it to do.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
Thanks David, I'll check it out as a tool, but I'm really looking to find out how to accomplish the task; essentially a programming learning experience.
PS - Pixie doesn't seem to address the key problem. Instead of using a left-mouse click to grab the colour at the particular location, pixie require keyboard shortcuts - Ctrl+Alt+c to copy HTML, Ctrl_Alt_X for to bring up the standard windows color dialog and Ctrl+Alt+Z to display a larger background of the color at the cursor. I would like to accomplish the selection with the left-mouse click as that seems a little more "natural" in a windows environment and then have the result in the main dialog screen of the application to manipulate it into various formats (HEX, RGB, HTML, etc.)
-
I am trying to create a dialog MFC application that reads the cursor position anywhere on the screen, finds the colour of the pixel at that location and reports the information back to the dialog application. I have tried SetCapture and I must be doing something wrong because the cursor location stops reporting as soon as the cursor leaves the client area of the dialog. I have also looked at the "Screen Color Picker" by Florin Vasilescu. That uses an OnTimer function that allows me to read the screen location, but does not report mouse actions (LBUTTONDOWN) so that I can read the pixel at the cursor location. I have also tried using SetWindowsHookEx and defining the MouseProc (as described by Vesi in the CodeGuru article "Modal dialog and outside mouse control". That wasn't successful. If I use the WH_JOURNALRECORD hook ID as described there appears to be an indeterminate delay between any mouse (or keyboard) action and interaction with screen objects. If I use the WH_MOUSE no mouse actions are detected. Could someone help me with how to either properly set SetCapture() or point me to where I might discover how to read mouse actions outside the dialog box? I'm happy to supply code, but at this point it's a bit of a mess since I've been trying everything. Thanks for any help you may be able to provide. Much appreciated.
-
I am trying to create a dialog MFC application that reads the cursor position anywhere on the screen, finds the colour of the pixel at that location and reports the information back to the dialog application. I have tried SetCapture and I must be doing something wrong because the cursor location stops reporting as soon as the cursor leaves the client area of the dialog. I have also looked at the "Screen Color Picker" by Florin Vasilescu. That uses an OnTimer function that allows me to read the screen location, but does not report mouse actions (LBUTTONDOWN) so that I can read the pixel at the cursor location. I have also tried using SetWindowsHookEx and defining the MouseProc (as described by Vesi in the CodeGuru article "Modal dialog and outside mouse control". That wasn't successful. If I use the WH_JOURNALRECORD hook ID as described there appears to be an indeterminate delay between any mouse (or keyboard) action and interaction with screen objects. If I use the WH_MOUSE no mouse actions are detected. Could someone help me with how to either properly set SetCapture() or point me to where I might discover how to read mouse actions outside the dialog box? I'm happy to supply code, but at this point it's a bit of a mess since I've been trying everything. Thanks for any help you may be able to provide. Much appreciated.
May be you just want to capture the mouse position, and you have no problem in finding the colour, then you can set a new Timer, then in the OnTimer function, you may try GetCursorPos() to retrieve the mouse's position. If you want to capture other mouse's action like mouse click... then take a look at global hook, as described in this Mouse and KeyBoard Hooking utility with VC++[^]