I try to create a window, which is hidden when it is minimized. The Window should be hidden, when it's minimized. Where is my problem? What prevents ShowWindow from working?
#define _WIN32_WINNT 0x0600
#include <Windows.h>
#include <CommCtrl.h>
#pragma comment(lib,"ComCtl32.lib")
#include <tchar.h>
#include <stdlib.h>
#include <string>
#include "resource.h"
#pragma comment(linker, \
"\"/manifestdependency:type='Win32' "\
"name='Microsoft.Windows.Common-Controls' "\
"version='6.0.0.0' "\
"processorArchitecture='*' "\
"publicKeyToken='6595b64144ccf1df' "\
"language='*'\"")
//Fenster des Dialogs
HWND hDialog;
INT_PTR CALLBACK Func(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
switch(uMsg) {
case WM_SYSCOMMAND:
if(wParam==SC_MINIMIZE) {
ShowWindow(hDialog,SW_HIDE);
}
break;
case WM_CLOSE:
DestroyWindow(hwndDlg);
return TRUE;
case WM_DESTROY:
DeregisterShellHookWindow(hDialog);
PostQuitMessage(0);
return TRUE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
InitCommonControls();
hDialog=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,Func);
SendMessage(hDialog,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(NULL,(LPCWSTR)IDI_APPLICATION));
RegisterShellHookWindow(hDialog);
ShowWindow(hDialog,SW_SHOWNORMAL);
MSG msg={0};
BOOL ret=0;
while((ret = GetMessage(&msg, 0, 0, 0)) != 0) {
if(ret==-1) {
break;
}
if(!IsDialogMessage(hDialog,&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
Using ShowWindow and returning TRUE in Func if wParam equals SC_MINIMIZE or SC_RESTORE (with SW_HIDE or SW_RESTORE as nCmdShow) works.