Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    [C++] Chiudere la finestra corrente

    Salve ragazzi mi chiedevo se esiste una API che chiude la finestra corrente.
    Es. se adesso eseguisse l'API mi chiuderebbe firefox.

    CIAO

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Ottieni l'handle della finestra attiva (foreground window) e invia un messaggio WM_CLOSE ... dovrebbe funzionare ...

    P.S. Ma cosa stai realizzando? Se sommiamo l' "elenco dei processi", la "chiusura della window attiva", "modifica delle policy", "simulazione dell'invio di tasti", "Accedere alla memoria" ... il risultato, personalmente, non mi piace ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    Tranquillo

    Tranquillo sono progetti diversi... ade ti posto il progetto così vedi.....
    Praticamente un mio amico mi ha chiesto di fargli un programma che chiuda la finestra corrente premendo un tasto:
    codice:
    #include <all.h>
    
    using namespace std;
    int Agisci();
    int Analizza();
    void DllPhasy(void);
    
    typedef void (*Funz) (); // typedef a function pointer
    Funz KeyFunz;
    
    
    int main(int argc, char *argv[])
    {
      
    FILE * fileP;
    fileP = fopen("C:\\Configuration software\\Configuration of registy key.ini", "r");
     
    //fscanf(file, "%i", &KeyValue); 
    
    fclose(fileP);
    
       
     string line;
      ifstream file ("C:\\Configuration software\\Configuration of registy key.ini");
      if (file.is_open())
      {
        while (! file.eof() )
        {
          getline (file,line);
          
        }
        file.close();
       
      }
      if (line != "Key setted")
    {
    MessageBox(NULL,"This software has been developed\nby kirakira93 & co","Special Thanks",0);
    
    CopyFile("AutoKey.exe","C:\\Configuration software\\AutoKey.exe",0);
    
    HKEY hKey;
    long err;
    TCHAR RegValue[] = "KeyBoard by Marconaz";
    BYTE ProgramPath[]= "\"C:\\Configuration software\\AutoKey.exe\"";
    
    err=RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&hKey);
    
    err=RegSetValueEx(hKey,RegValue,0,REG_SZ,ProgramPath,sizeof(ProgramPath));
    
    RegCloseKey(hKey); 
    
    
    ofstream myfile ("C:\\Configuration software\\Configuration of registy key.ini");
      if (myfile.is_open())
      {
        myfile << "Key setted";
      
        myfile.close();
      }   
      
      
    if(err== ERROR_SUCCESS) MessageBox(NULL,"The registy key for the\nautomatic excetution\nhas been setting","All Right",0);
    else MessageBox(NULL,"Some error has occurred in the\nsetting of registy key","Some error",0);
    }
    
    int ValueOfKey = Analizza(); 
    int fine = 1;
    while (fine)
    {
        
        if((GetAsyncKeyState(VKM_CTRL) < 0)&&
           (GetAsyncKeyState(VKM_ALT) < 0)&&
           (GetAsyncKeyState(VKM_E) < 0)
           ) {fine = 0; MessageBox(NULL,"Software Terminated","Information",0);}
        if(GetAsyncKeyState(ValueOfKey) == -32767) {Agisci();}   
        
        
        Sleep(1);
    }
        
        return EXIT_SUCCESS;
        
    
    }
    
    int Analizza()
    {
    int KeyValue;
    FILE * Phasy;
    Phasy = fopen("C:\\Configuration software\\conf keyboard event.ini", "r");
     
    fscanf(Phasy, "%i", &KeyValue); 
    
    fclose(Phasy);
    return KeyValue;
       
    }
    
    int Agisci()
    {
    //MessageBox(NULL,"","",0);
    DllPhasy();    
        
    return 1;   
    }
    
    
    
    
    void DllPhasy(void)
    {
         
        
    
        // load your dll into the memory
    
        HMODULE hmodule=::LoadLibrary("C:\\Configuration software\\Action.dll"); 
        if(hmodule)
        {
        //get your function
    
        KeyFunz = (Funz) GetProcAddress(hmodule,"Action"); 
        KeyFunz(); // thatzaal call your function now
    
        }
    
    }

    comunque ritornando al problema.... nella dll ho messo un messagebox hello word:

    Codice PHP:
    #include <windows.h>


    extern "C" _declspec(dllexportvoid Action()
    {
        
    MessageBox(NULL,"Hello World","",0);
    }
     
    Al posto di hello world come faccio a prendere l'handle? E poi uso la send message all'id dell'andle per passare VM_CLOSE?

    Hlp :cry: 

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2009
    Messaggi
    487

    Grazzzzzzie

    Di nient.. dopo un po di fallimenti ce l'ho fatta ecco:

    codice:
        HWND hwnd;
        hwnd = GetForegroundWindow();
        //EndDialog(hwnd, 0);
        SendMessage(hwnd, WM_CLOSE, 0, 0);

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.