c++ - Message-only window not receiving messages from tray icon -
I am trying to write a simple reusable class so that the functionality for the basic tray icon can be molded. This is my first "project" with C ++, and I'm having some problems: Message created for tray icon - only window does not receive any message in the icon tray And he has the right tooltip, but when I click on it, no message is sent in my invisible window. To check that the function Why does not the tray icon get any message from my window? This is what I wrote: And in this way I use the class: Thank you for your time. You want something like a message loop, do not block the call to do some input, try the canonical message loop. : WindowProcedure I added a
printf statement, and the output is that the build is called 4 times, but now more No, even though I click on the notification icon.
TrayIcon.h :
Square tray inkon {public: tray iacon (); ~ Trayicon (); Show zero (); /*...*/ fixed zero start (); Private: static LRESULT callback window precirer (HWW, UINT messaging, Varm vaporum, LAPRM LPARM); /*...*/};
TrayIcon.cpp :
// static RIIER int tray icon: _ idcounter = 1; Zero TrayIcon :: Initialize () // This method is called only once {// trunction registers the square for window WNDCLASSEX wx = {}; Wx.lpfnWndProc = TrayIcon :: WindowProcedure; Wx.lpszClassName = TRAYICON_WINDOW_CLASSNAME; Wx.cbSize = sizeof (WNDCLASSEX); RegisterClassEx (& amp; wx); } // constructor tray econo :: trichon () {// a hidden message-window only HWND hWnd = CreateWindowEx (0, TRAYICON_WINDOW_CLASSNAME, "TrekonWindo", 0, 0, 0, 0, 0, hwmsmax, faucet, zero, Zero);); Set Window Longprints (HWW, GWLP_USRDATA, (Long) this); // makes the notification icon NOTIFYICONDATA icon; Memc (& amp; icon, 0, size (NOTIFYICONDATA)); Icon.cbSize = sizeof (NOTIFYICONDATA); Icon.hWnd = hWnd; Icon.uID = TrayIcon :: _ idCounter ++; Icon.uCallbackMessage = WM_TRAYICON; // Set up our invented Windows message icon.uFlags = NIF_MESSAGE; This- & gt; _iconData = Icon; } // shows the tray icon zero TrayIcon :: Show () {// ... Shell_NotifyIcon (NIM_ADD, & amp; this-> _iconData); } // Processes of message received from the hidden window for each icon LRESULT callback: Window processing (HWNH HWD, UINT messaging, VARAM use, LAPRM LPARM) {tray icon * icon = (tray icon *) GetWindowLongPtr (HWD, GWLP_USRDATA); Printf ("called the window process. \ N \ r"); Return DefWindowProc (hwnd, message, wParam, lParam); }
int main () {// creates a new tray icon TrayIcon :: Initialize ( ); Tray icon * icon = new tray (); Icon-> SettailTip ("Foo Tooltip"); Icon & gt; SetIcon (...); Icon & gt; Show (); // User Wait for input zero * tmp; Cin & gt; & Gt; Tmp; Return 0; }
MSG msg; While (GetMessage (& msg, nullptr, 0, 0)) {translation message (& amp; msg); DispatchMessage (& amp; msg); }
Comments
Post a Comment