20. august 2004 - 23:22
Der er
5 kommentarer og 1 løsning
Fjern (hide) icon fra systray
Hej Jeg har længe søgt på nettet efter noget kode til at fjerne (hide) og unhide ikoner i systrayen. Kunne være meget rart at kunne gemme forskellige programmers systray ikoner væk. Nogen af jer der har et bud?
Annonceindlæg fra FPT Software
20. august 2004 - 23:43
#1
21. august 2004 - 09:37
#2
Det ser meget rigtigt ud. Ligenu har jeg en meget ugly ikke OO function til at finde hwnd vha. strcmp i window title. Nogen af jer der evt. har en OO function til dette?
22. august 2004 - 01:35
#3
Jeg ved ikke om dette er OO'et nok: #include <windows.h> #include <iostream> #include <string> class FindWindowClass { public: FindWindowClass(std::string aTitle) : Title(aTitle), HWnd(0) {} bool Run() { EnumWindows(EnumWindowsProc, (LPARAM )this); if(HWnd != 0) { return true; } return false; }; HWND GetHWnd() const {return HWnd; } const std::string &GetTitle() const {return Title; } private: std::string Title; HWND HWnd; static BOOL CALLBACK EnumWindowsProc(HWND aHWnd, LPARAM aLParam) { FindWindowClass *Me = (FindWindowClass *)aLParam; char Buf[1024] = ""; GetWindowText(aHWnd, Buf, sizeof(Buf)); std::string S(Buf); if(S.find(Me->Title) != std::string::npos) { Me->HWnd = aHWnd; Me->Title = S; return false; } return true; } }; int main(int argc, char *argv[]) { SetConsoleTitle(""); // Prevent the Finder to find the console window itself FindWindowClass Finder(argv[1]); if(Finder.Run()) { std::cout << "Did find a window: " << std::hex << (unsigned int )Finder.GetHWnd() << std::endl << Finder.GetTitle() << std::endl; } else std::cout << "Did not find the window" << std::endl; } Man bør måske checke om der skulle findes mere end et windue med den rigtige titel.
23. august 2004 - 16:21
#4
Jeg har følgende lille setup til at finde forskellige vinduer osv. #include <windows.h> using namespace std; char buf [MAX_PATH]={0}; char bufB [MAX_PATH]={0}; BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { GetWindowText(hwnd,buf,MAX_PATH); GetClassName(hwnd,bufB,MAX_PATH); printf("\nWindowText:"); printf(buf); printf("\nClassName:"); printf(bufB); if ( strstr(bufB,"Connections Tray") != NULL ) { //ShowWindow(hwnd,SW_SHOW); //Shell_NotifyIcon(NIM_DELETE, &FNid); CloseWindow(hwnd); return FALSE; } else { return TRUE; } } int main(int argc,char *argv[]) { BOOL w = EnumWindows(EnumWindowsProc,0); } Når jeg prøver at lukke "Connections Tray" giver windows mig en alvorlig fejl... Jeg er egentligt heller ikke interesseret i at lukke Connections Tray, med blot skjule/evt. slette ikoner derfra. bertel... takker foreløbigt for det fine OO eksempel ;)
23. august 2004 - 23:51
#5
Jeg lavede en funktion, ja jeg ved godt det ikke er ret OO'et: void Remove(HWND aHWnd) { NOTIFYICONDATA NotifyIconData; memset(&NotifyIconData, 0, sizeof(NOTIFYICONDATA)); NotifyIconData.cbSize = sizeof(NOTIFYICONDATA); NotifyIconData.hWnd = aHWnd; NotifyIconData.uID = 123; Shell_NotifyIcon(NIM_DELETE, &NotifyIconData); } Den fjerner ikonet fra sys-tray'et. Problemet er blot at finde det rigtige id (123 i eksemplet). Jeg har ikke fundet nogen metode til at finde dette nummer :-( Man kan selvfølgelig prøve fra en ende af, der er kun ca 65000 muligheder ;-)
24. august 2004 - 10:27
#6
;)
Kurser inden for grundlæggende programmering