ImpossibleMushroom
ImpossibleMushroom

Reputation: 13

Exit not minimize a window?

I am trying to exit a window i've third DestroyWindow() and SendMessage() with WM_CLOSE and CloseWindow() the first two don't work and CloseWindow(); only minimizes it!

Example code of what i'm trying to do:

int main()
{
    HWND curwind;
    char ccurwind[256];
    HWND newwind;
    HWND wind2;
    Sleep(1000);
    printf("Destroying in 5...\n");
    Sleep(1000);
    printf("Destroying in 4...\n");
    Sleep(1000);
    printf("Destroying in 3...\n");
    Sleep(1000);
    printf("Destroying in 2...\n");
    Sleep(1000);
    printf("Destroying in 1...\n");
    curwind = GetForegroundWindow();
    GetWindowTextA(curwind, ccurwind, 256);
    //DestroyWindow(curwind);
    if (DestroyWindow(curwind) == 0) {
        printf("Failed with error: %s", GetLastError());
    }
    else {
        printf("\nDestroyed %s", ccurwind);
    }
    getch();
    return 0;
}

So basically close the window but not the process example scenario: I open a new tab on google in a new window this program will close that window but not the whole process. Is this possible and if so what function would i use?

Upvotes: 0

Views: 154

Answers (2)

user3629249
user3629249

Reputation: 16540

the function: DestroyWindow() should do the job.

From: 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms632682(v=vs.85).aspx'

Destroys the specified window. The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it. The function also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain (if the window is at the top of the viewer chain).

If the specified window is a parent or owner window, DestroyWindow automatically destroys the associated child or owned windows when it destroys the parent or owner window. The function first destroys child or owned windows, and then it destroys the parent or owner window.

DestroyWindow also destroys modeless dialog boxes created by the CreateDialog function.

Upvotes: 0

Anders
Anders

Reputation: 101746

Only the thread that owns the window is allowed to call DestroyWindow. SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0) is the same as closing the window with the system menu but it ultimately just sends WM_CLOSE.

A window can ignore WM_CLOSE and there is not much you can do about that.

If the window is in a process with a higher integrity level than you then UIPI will block your message.

Upvotes: 1

Related Questions