need help passing keystroke to program

This is a discussion on need help passing keystroke to program within the C++ Programming forums, part of the General Programming Boards category; I need to write a program that will do the following: 1. open image file using mspaint.exe 2. Then pass ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    1

    need help passing keystroke to program

    I need to write a program that will do the following:

    1. open image file using mspaint.exe
    2. Then pass keystroke "cntrl-s" to mspaint.exe
    3. Then close mspaint.exe

    4. and repeat this process till all image files have been processed.


    Here is my code so far

    Code:
    #include <windows.h>
    #include <stdio.h>
    int main()
    {
    STARTUPINFO          si = { sizeof(si) };
    PROCESS_INFORMATION  pi;
    char                 szExe[] = "mspaint.exe";
    char                 buf[4444];
    
    if(CreateProcess(0, szExe, 0, 0, 0, 0, 0, 0, &si, &pi))
    {
       // optionally wait for process to finish
       //WaitForSingleObject(pi.hProcess, INFINITE);
    
       CloseHandle(pi.hProcess);
       CloseHandle(pi.hThread);
    }
    }


    I have no problem opening the images, but have not been able to automatically pass the keystoke "cntrl-s" to mspaint.

    I have looked at keyboard dumps and other functions but have not gotton far with this part of program. I have no formal coding education so I am a complete novice here. Any help or suggestions would be greatly appreciated.

    Douglas


  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    I would use FindWindow() to get the handle to the Paint window and then would use SendMessage().

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    You could try to reverse-engineer it. Since when clicking on menu items, the paint window will receive WM_COMMAND messages, you could generate and send them too. You can use Spy++ to spy for what messages the window gets and then you'll be able to control the window without hacks n' tricks. Pretty cool.
    Just don't expect it to work on newer versions of Paint. Hopefully it will, but again, it might not.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sending keystroke to a program
    By mvs in forum Windows Programming
    Replies: 1
    Last Post: 08-03-2006, 07:37 AM
  2. Passing PIDs to another program
    By DarrenY in forum C Programming
    Replies: 3
    Last Post: 06-02-2006, 02:04 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  4. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 08:48 AM
  5. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM

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