static LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { POINT pt; NOTIFYICONDATA nid; RECT rect; char *txt; #if 0 if(message!=WM_CTLCOLORSTATIC && message!=WM_TIMER) log(LOG_DEBUG, "Window message: %d", message); #endif switch (message) { case WM_CREATE: if (options.option.taskbar) /* taskbar update enabled? */ SetTimer(hwnd, 0x29a, 1000, NULL); /* 1-second timer */ return TRUE; case WM_SIZE: GetClientRect(hwnd, &rect); MoveWindow(EditControl, 0, 0, rect.right, rect.bottom, TRUE); UpdateWindow(EditControl); return TRUE; case WM_SETFOCUS: txt=log_txt(); SetWindowText(EditControl, txt); free(txt); SetFocus(EditControl); return TRUE; case WM_TIMER: update_taskbar(); return TRUE; case WM_CLOSE: set_visible(0); return TRUE; case WM_DESTROY: DestroyMenu(hmainmenu); DestroyMenu(htraymenu); ZeroMemory(&nid, sizeof(nid)); nid.cbSize=sizeof(NOTIFYICONDATA); nid.hWnd=hwnd; nid.uID=1; nid.uFlags=NIF_TIP; /* not really sure what to put here, but it works */ Shell_NotifyIcon(NIM_DELETE, &nid); /* this removes the icon */ PostQuitMessage(0); KillTimer(hwnd, 0x29a); return TRUE; case WM_COMMAND: switch(wParam) { case IDM_ABOUT: DialogBox(ghInst, "AboutBox", hwnd, (DLGPROC)about_proc); break; case IDM_LOG: set_visible(!visible); break; case IDM_CLOSE: set_visible(0); break; case IDM_EXIT: DestroyWindow(hwnd); break; case IDM_SAVEAS: save_file(hwnd); break; case IDM_SETUP: MessageBox(hwnd, "Function not implemented", options.win32_name, MB_ICONERROR); break; }; return TRUE; case UWM_SYSTRAY: switch (lParam) { case WM_RBUTTONUP: /* track a popup menu */ /* http://support.microsoft.com/support/kb/articles/Q135/7/88.asp */ GetCursorPos(&pt); SetForegroundWindow(hwnd); TrackPopupMenu(hpopup, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL); PostMessage(hwnd, WM_NULL, 0, 0); /* see above */ break; case WM_LBUTTONDBLCLK: /* switch log window visibility */ set_visible(!visible); break; } return TRUE; } return DefWindowProc(hwnd, message, wParam, lParam); }
static LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { NOTIFYICONDATA nid; POINT pt; RECT rect; LPTSTR txt; #if 0 if(message!=WM_CTLCOLORSTATIC && message!=WM_TIMER) s_log(LOG_DEBUG, "Window message: %d", message); #endif switch (message) { case WM_CREATE: if (options.option.taskbar) /* taskbar update enabled? */ SetTimer(hwnd, 0x29a, 1000, NULL); /* 1-second timer */ #ifdef _WIN32_WCE /* create command bar */ hwndCB=CommandBar_Create(ghInst, hwnd, 1); if(!hwndCB) error_box(TEXT("CommandBar_Create")); if(!CommandBar_InsertMenubar(hwndCB, ghInst, IDM_MAINMENU, 0)) error_box(TEXT("CommandBar_InsertMenubar")); if(!CommandBar_AddAdornments(hwndCB, 0, 0)) error_box(TEXT("CommandBar_AddAdornments")); #endif /* create child edit window */ EditControl=CreateWindow(TEXT("EDIT"), NULL, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY, 0, 0, 0, 0, hwnd, (HMENU)IDE_EDIT, ghInst, NULL); #ifndef _WIN32_WCE SendMessage(EditControl, WM_SETFONT, (WPARAM)GetStockObject(OEM_FIXED_FONT), MAKELPARAM(FALSE, 0)); /* no need to redraw right, now */ #endif /* NOTE: there's no return statement here -> proceeding with resize */ case WM_SIZE: GetClientRect(hwnd, &rect); #ifdef _WIN32_WCE MoveWindow(EditControl, 0, CommandBar_Height(hwndCB), rect.right, rect.bottom-CommandBar_Height(hwndCB), TRUE); #else MoveWindow(EditControl, 0, 0, rect.right, rect.bottom, TRUE); #endif UpdateWindow(EditControl); /* CommandBar_Show(hwndCB, TRUE); */ return TRUE; case WM_SETFOCUS: txt=log_txt(); SetWindowText(EditControl, txt); free(txt); SetFocus(EditControl); return TRUE; case WM_TIMER: update_taskbar(); return TRUE; case WM_CLOSE: set_visible(0); return TRUE; case WM_DESTROY: #ifdef _WIN32_WCE CommandBar_Destroy(hwndCB); #else if(hmainmenu) DestroyMenu(hmainmenu); #endif if(htraymenu) DestroyMenu(htraymenu); ZeroMemory(&nid, sizeof(nid)); nid.cbSize=sizeof(NOTIFYICONDATA); nid.hWnd=hwnd; nid.uID=1; nid.uFlags=NIF_TIP; /* not really sure what to put here, but it works */ Shell_NotifyIcon(NIM_DELETE, &nid); /* this removes the icon */ PostQuitMessage(0); KillTimer(hwnd, 0x29a); return TRUE; case WM_COMMAND: switch(wParam) { case IDM_ABOUT: DialogBox(ghInst, TEXT("AboutBox"), hwnd, (DLGPROC)about_proc); break; case IDM_LOG: set_visible(!visible); break; case IDM_CLOSE: set_visible(0); break; case IDM_EXIT: DestroyWindow(hwnd); break; case IDM_SAVEAS: save_file(hwnd); break; case IDM_SETUP: MessageBox(hwnd, TEXT("Function not implemented"), win32_name, MB_ICONERROR); break; } return TRUE; case UWM_SYSTRAY: /* a taskbar event */ switch (lParam) { #ifdef _WIN32_WCE case WM_LBUTTONDOWN: /* no right mouse button on Windows CE */ GetWindowRect(GetDesktopWindow(), &rect); /* no cursor position */ pt.x=rect.right; pt.y=rect.bottom-25; #else case WM_RBUTTONDOWN: GetCursorPos(&pt); #endif SetForegroundWindow(hwnd); TrackPopupMenuEx(hpopup, TPM_BOTTOMALIGN, pt.x, pt.y, hwnd, NULL); PostMessage(hwnd, WM_NULL, 0, 0); break; #ifndef _WIN32_WCE case WM_LBUTTONDBLCLK: /* switch log window visibility */ set_visible(!visible); break; #endif } return TRUE; } return DefWindowProc(hwnd, message, wParam, lParam); }