Click here to Skip to main content
15,918,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCListCtrl arrow key navigation Pin
dennisV13-Aug-02 7:59
dennisV13-Aug-02 7:59 
GeneralRe: CListCtrl arrow key navigation Pin
Shog913-Aug-02 8:53
sitebuilderShog913-Aug-02 8:53 
GeneralRe: CListCtrl arrow key navigation Pin
dennisV13-Aug-02 9:04
dennisV13-Aug-02 9:04 
GeneralRe: CListCtrl arrow key navigation Pin
Shog913-Aug-02 9:10
sitebuilderShog913-Aug-02 9:10 
GeneralRe: CListCtrl arrow key navigation Pin
dennisV13-Aug-02 9:32
dennisV13-Aug-02 9:32 
GeneralRe: CListCtrl arrow key navigation Pin
Shog913-Aug-02 9:36
sitebuilderShog913-Aug-02 9:36 
GeneralKill a screensaver... Pin
Matt Eckerson13-Aug-02 7:49
Matt Eckerson13-Aug-02 7:49 
GeneralRe: Kill a screensaver... Pin
Alexander Wiseman13-Aug-02 8:35
Alexander Wiseman13-Aug-02 8:35 
Hello,

There is a nice little function which simulates a mouse event (by sending a mouse message to the active window) called 'mouse_event'. Sending a MOUSE_MOVE message to a screen saver would make it kill itself, because it automatically closes itself wheenever there is any mouse activity.

MSDN said that on Windows NT and 2000, 'mouse_event' has been superseded by 'SendInput', so here is the information for both functions (you might want to check the OS, so you can use the correct function):

'mouse_event':
VOID mouse_event(
DWORD dwFlags,         // motion and click options
DWORD dx,              // horizontal position or change
DWORD dy,              // vertical position or change
DWORD dwData,          // wheel movement
ULONG_PTR dwExtraInfo  // application-defined information
}


dwFlags: look up this function on MSDN to see all the options; the one you want is MOUSEEVENTF_MOVE, to simulate a mouse movement. MOUSEEVENTF_ABSOLUTE can be combined with this flag (e.g. MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE) to let you specify absolute coordinates in 'dx' and 'dy'.

dx: if MOUSEEVENTF_ABSOLUTE is set in the firest parameter, this specifies the absolute position along the 'x' axis of the mouse. Othwerwise, this specifies how many points you want to move along the 'x' axis.

dy: same as 'dx' only for the 'y' axis

dwData: this specifies mouse wheel movement; you don't need to worry about this, because you won't be using the MOUSEEVENTF_WHEEL option. Just set it to 0 or NULL.

dwExtraInfo: used to send a value with the message. Set this to 0 or NULL for your purposes.

'SetInput':
UINT SetInput(
UINT nInputs,     // count of input events
LPINPUT pInputs,  // array of input events
int cbSize        // size of structure
}


nInputs: number of input events (mouse events) that you want to send

pInputs: a pointer to an array of INPUT structures. An input structure looks like this:
typedef struct tagINPUT {
  DWORD   type;
  union {
      MOUSEINPUT      mi;
      KEYBDINPUT      ki;
      HARDWAREINPUT   hi;
  };
} INPUT, *PINPUT;

For your purposes, you want to use the 'mi' variable, so you would set 'type' equal to INPUT_MOUSE. The MOUSEINPUT structure contains almost identical variables to the 'mouse_event' function. To send a movement command, you would set the 'dwFlags' variable of the structure to: MOUSEEVENTF_MOVE or MOUSEEVENTF_ABSOLUTE, and the 'dx' and 'dy' variables to the coordinates of your choice. Every other variable can be filled with 0 or NULL.

cbSize: size of the structure. Set this equal to sizeof(INPUT), which gives you the size, in bytes, of an INPUT structure.

Here are sample calls to each function:

'mouse_event' sample call:
//Send MOUSE_MOVE message to the active window
//If it is a screensaver window, it will kill itself automatically)
//The mouse will be moved to the coordinates (0,0) on the screen
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE, 0, 0, NULL, NULL);


'SetInput' sample call:
//Send MOUSE_MOVE message to the active window
//If it is a screensaver window, it will kill itself automatically)

//Initialize an INPUT structure:
INPUT myInput;
myInput.type = INPUT_MOUSE;  //we're sending mouse commands

//Initialize our MOUSEINPUT structure:
MOUSEINPUT mouseInput;
mouseInput.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
mouseInput.dx = 0;
mouseInput.dy = 0;
mouseInput.mouseData = NULL;
mouseInput.time = 0;
mouseInput.dwExtraInfo = NULL;


//Put our MOUSEINPUT structure into our INPUT structure:
myInput.mi = mouseInput;

//Call SetInput:
//The mouse will be moved to the coordinates (0,0) on the screen
SetInput(1, &myInput, sizeof(INPUT));


SetInput is a pain to call, and since you are only moving the mouse, you could get away with calling mouse_event across all platforms.

Hope that helps you out!
Big Grin | :-D

Sincerely,
Alexander Wiseman

Est melior esse quam videri
It is better to be than to seem
GeneralRe: Kill a screensaver... Pin
Matt Eckerson13-Aug-02 10:42
Matt Eckerson13-Aug-02 10:42 
GeneralRe: Kill a screensaver... Pin
Alexander Wiseman13-Aug-02 10:47
Alexander Wiseman13-Aug-02 10:47 
GeneralRe: Kill a screensaver... Pin
Matt Eckerson17-Aug-02 12:26
Matt Eckerson17-Aug-02 12:26 
GeneralISAPI File Writing Pin
John Pepper13-Aug-02 7:26
John Pepper13-Aug-02 7:26 
GeneralRe: ISAPI File Writing Pin
Jason Henderson13-Aug-02 9:14
Jason Henderson13-Aug-02 9:14 
GeneralRe: ISAPI File Writing Pin
John Pepper13-Aug-02 9:30
John Pepper13-Aug-02 9:30 
GeneralRe: ISAPI File Writing Pin
Jason Henderson13-Aug-02 15:59
Jason Henderson13-Aug-02 15:59 
GeneralRe: ISAPI File Writing Pin
Tomasz Sowinski13-Aug-02 9:20
Tomasz Sowinski13-Aug-02 9:20 
GeneralRe: ISAPI File Writing Pin
John Pepper13-Aug-02 9:28
John Pepper13-Aug-02 9:28 
GeneralRe: ISAPI File Writing Pin
John Pepper13-Aug-02 9:24
John Pepper13-Aug-02 9:24 
GeneralRe: ISAPI File Writing Pin
John Pepper13-Aug-02 9:35
John Pepper13-Aug-02 9:35 
GeneralRe: ISAPI File Writing Pin
John Pepper13-Aug-02 10:37
John Pepper13-Aug-02 10:37 
QuestionFTP Add-in for Visual Studio? Pin
Paul Tomsic13-Aug-02 7:01
Paul Tomsic13-Aug-02 7:01 
AnswerRe: FTP Add-in for Visual Studio? Pin
Daniel Turini13-Aug-02 7:34
Daniel Turini13-Aug-02 7:34 
GeneralRe: FTP Add-in for Visual Studio? Pin
Paul Tomsic13-Aug-02 7:58
Paul Tomsic13-Aug-02 7:58 
GeneralRe: FTP Add-in for Visual Studio? Pin
Daniel Turini13-Aug-02 8:53
Daniel Turini13-Aug-02 8:53 
AnswerRe: FTP Add-in for Visual Studio? Pin
Shog913-Aug-02 8:55
sitebuilderShog913-Aug-02 8:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.