Windows-Beenden-Dialog



  • Hi zusammen,
    gibt es api-funktion mit der man das Windows-Beenden-Dialog aufruft?

    danke



  • ich möchte mal behaupten ja.
    Werde zuhause mal nachschauen.



  • Hi,
    folgender Code würde funktionieren, wenn du es jetzt noch schafst auf hDesktop den Tastatur Fokus zu setzen... 😉
    viel Spass... 🕶

    // includes
    #include <windows.h>
    
    // api entry point
    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
        // private
        HWND    hDesktop;
    
        // get the desktop
        hDesktop = GetDesktopWindow();
        if(hDesktop==NULL)
            MessageBox(0, "error", ":(", 0);
    
        // send ALT+F4 to window
        keybd_event(VK_MENU,0,0,0);
        keybd_event(VK_F4,0,0,0);
        keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
        keybd_event(VK_F4,0,KEYEVENTF_KEYUP,0);
        return 0;
    }
    

    cu para
    😃



  • Das hilft mir auch nicht weiter, (genauso kann ich die maus proggen dass sie ueber den bildschirm bis zum "Start-Button" geht dann auf Beenden usw... hehehe) leider brauche ich die orginal-funktion dafuer... aber trozdem thx.



  • Es gibt da eine funktion ExitWindows und ExitWindowsEx
    Dann gibt es noch das hier: (Borland Win32HLP)

    Windows NT only
    
    The following example uses the InitiateSystemShutdown function to begin the system shutdown process on the computer on which is user is logged on. The application must first enable the SE_SHUTDOWN_NAME privilege. 
    
    HANDLE hToken;              // handle to process token  
    TOKEN_PRIVILEGES tkp;       // pointer to token structure  
    
    BOOL fResult;               // system shutdown flag 
    
    // Get the current process token handle so we can get shutdown 
    // privilege. 
    
    if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
        ErrorHandler("OpenProcessToken failed."); 
    
    // Get the LUID for shutdown privilege. 
    
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
    
            &tkp.Privileges[0].Luid); 
    
    tkp.PrivilegeCount = 1;  // one privilege to set    
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
    
    // Get shutdown privilege for this process. 
    
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
        (PTOKEN_PRIVILEGES) NULL, 0); 
    
    // Cannot test the return value of AdjustTokenPrivileges. 
    
    if (GetLastError() != ERROR_SUCCESS) 
        ErrorHandler("AdjustTokenPrivileges enable failed."); 
    
    // Display the shutdown dialog box and start the time-out countdown. 
    
    fResult = InitiateSystemShutdown( 
        NULL,                                  // shut down local computer 
        "Click on the main window and press \
         the Escape key to cancel shutdown.",  // message to user 
        20,                                    // time-out period 
        FALSE,                                 // ask user to close apps 
        TRUE);                                 // reboot after shutdown 
    
    if (!fResult) 
    { 
        ErrorHandler("InitiateSystemShutdown failed."); 
    
    } 
    
    // Disable shutdown privilege. 
    
    tkp.Privileges[0].Attributes = 0; 
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES) NULL, 0); 
    
    if (GetLastError() != ERROR_SUCCESS) 
    {
        ErrorHandler("AdjustTokenPrivileges disable failed."); 
    } 
    
    If the AbortSystemShutdown function is executed in the time-out period specified by InitiateSystemShutdown, the system does not shut down. In this example, the user can prevent the system from shutting down by clicking on the application's main window and pressing the ESC key. The example processes the keystroke by calling AbortSystemShutdown. 
    
    HANDLE hToken;              // handle to process token  
    TOKEN_PRIVILEGES tkp;       // pointer to token structure  
    
    BOOL fResult;               // system shutdown flag 
    
    case WM_KEYDOWN: 
    
        // Process only the Escape key. 
    
        if (wParam != VK_ESCAPE) 
        { 
            break; 
        } 
    
        // Get the current process token handle  so we can get shutdown 
        // privilege. 
    
        if (!OpenProcessToken(GetCurrentProcess(), 
                TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
    
        {
            ErrorHandler("OpenProcessToken failed."); 
        }
    
        // Get the LUID for shutdown privilege. 
    
        LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
                &tkp.Privileges[0].Luid); 
    
        tkp.PrivilegeCount = 1;  // one privilege to set    
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
    
        // Get shutdown privilege for this process. 
    
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES)NULL, 0); 
    
        // Cannot test the return value of AdjustTokenPrivileges. 
    
        if (GetLastError() != ERROR_SUCCESS) 
        {
            ErrorHandler("AdjustTokenPrivileges enable failed."); 
        }
    
        // Prevent the system from shutting down. 
    
        fResult = AbortSystemShutdown(NULL); 
    
        if (!fResult) 
        { 
            ErrorHandler("AbortSystemShutdown failed."); 
        } 
    
        // Disable shutdown privilege. 
    
        tkp.Privileges[0].Attributes = 0; 
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
    
            (PTOKEN_PRIVILEGES) NULL, 0); 
    
        if (GetLastError() != ERROR_SUCCESS) 
        {
            ErrorHandler("AdjustTokenPrivileges disable failed."); 
        }
    
        break;
    


  • IMO kommt dieser Dialog auch dann wenn der Explorer beendet wird...



  • Tja, und wie geht das nun in Windows 9x?



  • ExitWindowsEx(EWX_POWEROFF, 0);
    


  • Das beendet allerdings Windows direkt und ruft nicht den Beenden-Dialog auf!



  • Genau!



  • Genau!



  • wo bleiben die profis?



  • HIER!!!

    Bastel' dir einfach 'n eigenen Beenden-Dialog mit MFC oder VCL.

    [ Dieser Beitrag wurde am 26.11.2002 um 15:30 Uhr von nEo SkYwAlKeR editiert. ]



  • Falls du das ganze für NT/2K/XP brauchst kannst du dir mal das hier anschauen:
    Displaying the Shutdown Dialog Box (MSDN)



  • flenders
    dein link ist doch das gleiche was DocJunioR oben gepostet hat...

    nEo SkYwAlKeR
    darum gehts nicht... ist mir klar das selber machen kann... ich moechte einfach nur wissen ob es fertige funktionen dafuer gibt!



  • @ toom.

    Da wird Dir wirklich nix bleiben als einfach einen Dialog zu schreiben. Win95/98 sieht sowas einfach nicht vor.



  • Hi,

    ich glaube das es da doch was gibt. Ich habe mal aus Spaß, unter Windows XP den Programm Manager von Windows 95 gestartet. Dort gab es im Menü eine Option "Beenden". Als ich das aufgerufen hatte, kam der Windows XP Beenden-Dialog. Vielleicht gibt es da ja auch eine undokumentiere Funktion. 😕



  • Das ist allerdings möglich.
    Immerhin gibt es in der Referenz auch immer mal wieder Funktionen bei denen steht

    Diese Funktion ist nicht implementiert.



  • Hi nochmal,

    ich habe gerade einfach mal in google nach "shutdown dialog" gesucht und bin auf ein paar VB-Beispiele gefunden, die die Funktion "SHShutDownDialog" benutzen. Die Funktion ist anscheinend nicht dokumentiert und muss wohl per GetProcAddress aus der shell32.dll geladen werden. Ich werd's gleich mal ausprobieren...



  • typedef LONG (CALLBACK *SHUTDOWNDLG) (LONG);
    
    HINSTANCE hDll = LoadLibrary("shell32.dll");
    SHUTDOWNDLG SHShutDownDialog;
    if(hDll != 0)
    {
       SHShutDownDialog = (SHUTDOWNDLG)GetProcAddress(hDll, (LPSTR)60);
       SHShutDownDialog(0);
    }
    FreeLibrary(hDll);
    

    Hehe, war schneller. 😉

    [ Dieser Beitrag wurde am 26.11.2002 um 23:07 Uhr von WebFritzi editiert. ]


Anmelden zum Antworten