#17 ProXicT
Hmm, tak jsem to zkusil v trial verzi osmiček a chová se to stejně jako ve Win7...
Přidal jsem tam automatické skrývání na timer, popř. ruční na horkou klávesu a skrývá a obnovuje to ikony bez problému.
#include "stdafx.h"
#define _STR_TRIDA L"MojeOkno"
HWND _hwnd;
HWND _hwnd_ikony;
NOTIFYICONDATA _nid;
void on_timer()
{
HWND h = GetForegroundWindow();
wchar_t trida[250];
wchar_t text[250];
if (GetClassNameW(h, trida, sizeof(trida)/sizeof(wchar_t)) == 0)
return;
_nid.uFlags = NIF_INFO;
_nid.uFlags = NIF_INFO | NIF_SHOWTIP;
StringCbPrintf(text, sizeof(text), L"HWND: %X\nTřída: %s", (int)h, trida);
StringCbCopyN(_nid.szInfo, sizeof(_nid.szInfo), text, sizeof(_nid.szInfo) - sizeof(wchar_t));
Shell_NotifyIconW(NIM_MODIFY, &_nid);
if ((lstrcmpi(trida, L"Progman") == 0) || (lstrcmpi(trida, L"Shell_TrayWnd") == 0))
ShowWindow(_hwnd_ikony, SW_HIDE);
else
{
ShowWindow(_hwnd_ikony, SW_RESTORE);
ShowWindow(_hwnd_ikony, SW_SHOW);
}
}
LRESULT CALLBACK window_proc(HWND hwnd, UINT zprava, WPARAM wparam, LPARAM lparam)
{
switch (zprava)
{
case WM_HOTKEY:
if (IsWindowVisible(_hwnd_ikony))
ShowWindow(_hwnd_ikony, SW_HIDE);
else
{
ShowWindow(_hwnd_ikony, SW_RESTORE);
ShowWindow(_hwnd_ikony, SW_SHOW);
}
break;
case WM_TIMER:
on_timer();
break;
case WM_CLOSE:
{
UnregisterHotKey(_hwnd, 1);
ShowWindow(_hwnd_ikony, SW_RESTORE);
ShowWindow(_hwnd_ikony, SW_SHOW);
memset(&_nid, 0, sizeof(_nid));
_nid.cbSize = sizeof(NOTIFYICONDATA);
_nid.hWnd = hwnd;
_nid.uID = 1;
Shell_NotifyIconW(NIM_DELETE, &_nid);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_APP + 1:
if (LOWORD(lparam) == WM_LBUTTONUP)
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
return DefWindowProc(hwnd, zprava, wparam, lparam);
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int)
{
_hwnd_ikony = FindWindow(L"Progman", NULL);
if (_hwnd_ikony)
_hwnd_ikony = FindWindowEx(_hwnd_ikony, NULL, L"SHELLDLL_DefView", NULL);
if (_hwnd_ikony)
_hwnd_ikony = FindWindowEx(_hwnd_ikony, NULL, L"SysListView32", NULL);
if (!_hwnd_ikony)
return 0;
MSG msg;
WNDCLASSEX wc;
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = window_proc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_INFORMATION);
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszClassName = _STR_TRIDA;
wc.hIconSm = LoadIcon(NULL, IDI_INFORMATION);
if (!RegisterClassEx(&wc))
return 0;
_hwnd = CreateWindowEx(0, _STR_TRIDA, L"Test", WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
memset(&_nid, 0, sizeof(_nid));
_nid.cbSize = sizeof(_nid);
_nid.hIcon = LoadIcon(NULL, IDI_INFORMATION);
_nid.hWnd = _hwnd;
_nid.uID = 1;
_nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
_nid.uFlags |= NIF_SHOWTIP;
_nid.uCallbackMessage = WM_APP + 1;
_nid.uVersion = NOTIFYICON_VERSION_4;
StringCbCopyNW(_nid.szTip, sizeof(_nid.szTip), L"Test plochy", sizeof(_nid.szTip) - sizeof(wchar_t));
if (!Shell_NotifyIconW(NIM_ADD, &_nid))
return 0;
_nid.uVersion = NOTIFYICON_VERSION_4;
if (!Shell_NotifyIconW(NIM_SETVERSION, &_nid))
return 0;
SetTimer(_hwnd,1, 5000, NULL);
on_timer();
RegisterHotKey(_hwnd, 1, 0, VK_SCROLL);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Radek Chalupa
- vývoj software na zakázku
- školení programování (C/C++, WinAPI, ATL, COM, ActiveX, C#, NET Framework, MFC)
http://www.radekchalupa.cz