-
Mouse Input
Hello everybody,
I have run into a difficult situation. My administrator has some C programs that he just converted from DJGPP to Dev. Since the conversion, he has been having some problems with mouse response in one certain situation. One of the projects starts another instance of itself. He has tried using spawnlp and system to start the second instance. The second instance will start up with no problem, but the mouse input will not work until he clicks off of the window and then back on the window. It is weird, because the scroll wheel on the mouse will work as soon as the second instance opens. I know this is pretty vague, but I will supply all the information I am able to. Anyone have any ideas what would cause mouse input to react that way???????? Here is a snippet from the program that starts another instance of itself. This program is not a true windows program, but it has been designed to have some window functionality. It might have some code that does not make sense, mostly for testing purposes:
Code:
case KEY_F3 :
// spawnlp ( _P_NOWAIT | _P_DETACH, "ragcalc.exe", "ragcalc.exe", NULL );
system ( "start ragcalc.exe" );
sleep ( 2000 );
enable_mouse ();
//mc_goto ( ptr );
break;
Thanks,
Kendal
-
When properly handled the scroll wheel does not need focus in a specific window to create messages. You should call SetFocus() for the window that needs to have focus.
-
The SetFocus() function requires a window handle. We are dealing with a console application that was custom built years ago to have window type functionality. Therefore, we are not using handles and such. Although, the console window does have the focus when it starts. You just have to click off the window and back on before it will start accepting mouse input. Any ideas?????????
Thanks,
Kendal
-
Use FindWindow() to get the HWND needed for SetFocus().
-
I am trying to build 2 test programs that use the SetFocus and FindWindow function. I will post the sample code below. It does not seem to be swapping focus. Is there something in my code that needs to change????????
main1.c
Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
system("start main2.exe");
system("PAUSE");
SetFocus(FindWindow(NULL,"F:\\Dev-Cpp\\Code\\Test Focus\\Main2.exe"));
system("PAUSE");
return 0;
}
Main2.c
Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
system("PAUSE");
SetFocus(FindWindow(NULL,"F:\\Dev-Cpp\\Code\\Test Focus\\main1.exe"));
system("PAUSE");
SetFocus(FindWindow(NULL,"F:\\Dev-Cpp\\Code\\Test Focus\\main1.exe"));
return 0;
}
Any Suggestions???????
Thanks,
Kendal
-
I just found that the SetFocus() does not work on whole windows only child windows, sorry. The function to use is SetForegroundWindow(HWND hwnd). That moves the window to the foreground and gives it mouse input now.
-
Also you need to use Sleep(int milliseconds) to delay the main program long enough to alow the other program to fully start or the call to SetForegroundWindow(HWND hwnd) will seem to fail when it hasn't.
-
Perfect. That is exactly what I needed.
Thanks a million,
Kendal