Controlling programs

This is a discussion on Controlling programs within the Windows Programming forums, part of the Platform Specific Boards category; Someone asked this question a few days ago. I wanted to know how to click the ok button in the ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    21

    Controlling programs

    Someone asked this question a few days ago.
    I wanted to know how to click the ok button in the windows login dialog.
    So I found out.
    Code:
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	HWND handle; //handle to a window
        printf("Waiting for login dialog\n");
        for(;;){ //main loop
            handle = FindWindow(NULL, "Enter Network Password"); //The window I'm looking for
    
            if(handle){
                printf("Login dialog found");
                SendMessage(handle, WM_COMMAND, 0x00000001, 0x000000c8); //see notes
                break; //exit loop
            }    
        }
        //exit(0);
    
    	return 0;
    }
    
    //Notes:
    // Using spy++ I viewed the messages sent to the login window.
    // I only care about the WM_COMMAND messages sent to this window
    // Seeing the message directed to a window object (say... a button 0xc8),
    // you can easly get the pram. 0x1 basicly tells 0xc8 that it has been clicked.
    // Very useful when you have a nat server on win98. CRASH

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    You do know that you can also search for child windows, correct?

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    21
    nope. Can you explain?

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    this looks very interesting. does it mean you can have a robot program control your computer? and can you use any window, provided you have the caption text?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    21
    if you know what messages to send... Yes

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    After you use FindWindow to get the handle of the parent window, you can use FindWindowEx to search through the child windows.

  7. #7
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Some help (maybe)...

    Here's some help (I think):

    After you use FindWindow() and find the dialog, then do this:

    HWND hOK = FindWindowEx(hMainHwnd, NULL, "button", "Ok");
    SendMessage(hOK, BM_CLICK, 0, 0);

    I think this should work. It finds the Ok button in the dialog and sends a button press to it. ('hMainHwnd' is the handle to the main dialog that you used FindWindow() on)

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by bennyandthejets
    this looks very interesting. does it mean you can have a robot program control your computer? and can you use any window, provided you have the caption text?
    Theoretically yes, practically no.

    Also, you cant use SendMessage and the like to manipulate the WinLogon dialog if that's what some of you are thinking.......M$ arent as stupid as you think.....there are mechanisms to stop your proggie messing with the logon process

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 06:32 AM
  2. I never Finish my programs :(
    By epidemic in forum C++ Programming
    Replies: 11
    Last Post: 04-02-2007, 12:35 PM
  3. Using other programs in mine
    By mramazing in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2006, 02:19 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 04:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM

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