1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
   | #include <windows.h>
#include <Tlhelp32.h>
#include <stdio.h>
#include <string.h>
#include <commctrl.h>
BOOL Exe(HWND hwExe);
int main(int argc, char *argv[])
{
    static HWND hwExe;
   
    scanf("%s", &hwExe);
    Exe(hwExe);
    system("PAUSE");
}
/* Executer un processus. */
BOOL Exe(HWND hwExe)
{
     char * szBuffer;
     unsigned int uiSize;
     unsigned int uiCount;
     
     if((uiSize = SendMessage(hwExe,WM_GETTEXTLENGTH,0,0)) == 0) return FALSE;
     szBuffer = (char*)malloc(sizeof(char)*(uiSize+1));
     if(szBuffer == NULL){
                 return FALSE;
     }
     
     GetWindowText(hwExe,szBuffer,(uiSize+1));
     szBuffer[uiSize] = '\0';
     
     for(uiCount = 0 ; uiCount<uiSize ; uiCount++){
         if(szBuffer[uiCount] == ' '){ /* Si il y à un espace, c'est qu'il y a un argument. */
             char * szAppName;
             char * szArgument;
             
             szAppName = (char*)malloc(sizeof(char)*(uiCount+1));
             szArgument = (char*)malloc(sizeof(char)*(uiSize-uiCount)+1);
             
             sscanf(szBuffer,"%s %s",szAppName,szArgument);
             
             szAppName[uiCount] = '\0';
             szArgument[(uiSize-uiCount)] = '\0';
             
             ShellExecute(NULL,"open",szAppName,szArgument,NULL,SW_SHOWNORMAL);
             
             free(szAppName);
             free(szArgument);
             break;
         }else if(uiCount == (uiSize-1)){ /* Sinon. */
               ShellExecute(NULL,"open",szBuffer,0,NULL,SW_SHOWNORMAL);
         }
             
     }
     
     free(szBuffer);
} | 
Partager