Hi,
Please look at my attached C++ and VB programs.
Can anyone explain why the icon looks terrible in C++ and fine in VB?
Can it be because of the way I load the icon? I commented out
other methods I used that didn't seem to work.
thanks
Printable View
Hi,
Please look at my attached C++ and VB programs.
Can anyone explain why the icon looks terrible in C++ and fine in VB?
Can it be because of the way I load the icon? I commented out
other methods I used that didn't seem to work.
thanks
They both look same for me:D
Well, the systray has to be 16X16. I have both sizes in my icon
file, but I think ExtractIcon is defaulting to 32X32.
Who has the code for ExtractIconEx?
Why can't you use NOTIFYTRAYICON structure?
Is this what you mean? if so, this is the code in the project I posted.
You have to have some way to set the icon, even if you use
NOTIFYTRAYICON. I can't get MAKEINTRESOURCE to work.
I only get a blank icon in the system tray.
Code:#include <windows.h>
// main icon identifier
#define IDI_ICONMAIN 1001
// Main Window Handle
HWND hwndMain;
// for system tray
NOTIFYICONDATA nid;
// The window procedure
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam){
switch(message)
{
case WM_DESTROY:
{
Shell_NotifyIcon(NIM_DELETE, &nid);
DestroyWindow(hwndMain);
PostQuitMessage(0);
break;
}
default:
{
return DefWindowProc(hwnd, message, wParam, lParam);
break;
}
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszArgument, int nCmdShow){
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hInstance;
wincl.lpszClassName = "systray";
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = ExtractIcon(NULL,"systray.exe",0);
wincl.hIconSm = ExtractIcon(NULL,"systray.exe",0);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
if(!RegisterClassEx(&wincl)) return 0;
hwndMain = CreateWindowEx(
0,
"systray",
"systray",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, //| WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
250,
120,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);
nid.cbSize = sizeof(nid);
nid.hIcon = ExtractIcon(NULL,"systray.exe",0);//LoadIcon(NULL,IDI_WINLOGO); LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICONMAIN));
nid.hWnd = hwndMain;
strcpy(nid.szTip, "systray\0");
nid.uCallbackMessage = WM_RBUTTONDOWN;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
nid.uID = 2;
Shell_NotifyIcon(NIM_ADD, &nid);
ShowWindow(hwndMain,nCmdShow);
while(GetMessage(&messages, NULL, 0, 0)){
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
Always use this to load a 16X16 icon:
Code:HICON hIconSm;
hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_ICONMAIN),
IMAGE_ICON, 16, 16, 0);