Mouse Input

This is a discussion on Mouse Input within the C Programming forums, part of the General Programming Boards category; Hello everybody, I have run into a difficult situation. My administrator has some C programs that he just converted from ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    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

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    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.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    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

  4. #4
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Use FindWindow() to get the HWND needed for SetFocus().
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    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

  6. #6
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    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.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  7. #7
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    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.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Perfect. That is exactly what I needed.

    Thanks a million,
    Kendal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 09:52 AM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  3. Mouse Input
    By bumfluff in forum C++ Programming
    Replies: 7
    Last Post: 11-11-2005, 12:23 AM
  4. Making a mouse hover button, API style
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 05-27-2004, 06:17 AM
  5. Win32 Console App- Mouse input
    By Trauts in forum Windows Programming
    Replies: 2
    Last Post: 04-29-2003, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21