/// \brief Initializes a QnSend instance /// @param hWnd Owning window handle /// @param hInstance Owning instance handle QnSend(HWND hWnd, HINSTANCE hInstance) { _hWnd = hWnd; _hInstance = hInstance; _notifyIconVisible = false; if (WSAStartup(MAKEWORD(2, 2), &_wsaData) != 0) ExitProcess(ERROR_C); InitNotifyIconData(); AddNotifyIcon(); }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int iCmdShow ) { TCHAR className[] = TEXT( "tray icon class" ); WM_TASKBARCREATED = RegisterWindowMessageA("TaskbarCreated") ; WNDCLASSEX wnd = { 0 }; wnd.hInstance = hInstance; wnd.lpszClassName = className; wnd.lpfnWndProc = WndProc; wnd.style = CS_HREDRAW | CS_VREDRAW ; wnd.cbSize = sizeof (WNDCLASSEX); wnd.hIcon = LoadIcon (NULL, IDI_APPLICATION); wnd.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wnd.hCursor = LoadCursor (NULL, IDC_ARROW); wnd.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE ; if (!RegisterClassEx(&wnd)) { FatalAppExit( 0, TEXT("Couldn't register window class!") ); } g_hwnd = CreateWindowEx(0, className, TEXT( "Using the system tray" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, hInstance, NULL); InitNotifyIconData(); Shell_NotifyIcon(NIM_ADD, &g_notifyIconData); ZeroMQContext::init(); Exit exit; MSG msg ; while (!quit) { PeekMessage(&msg, 0, 0, 0, PM_REMOVE); exit.receive_input(); TranslateMessage(&msg); DispatchMessage(&msg); } Shell_NotifyIcon(NIM_DELETE, &g_notifyIconData); return msg.wParam; }
// // FUNCTION: InitInstance(HINSTANCE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } else g_hwnd = hWnd; InitNotifyIconData(); Minimize();//add the icon UpdateWindow(hWnd); return TRUE; }
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ WM_TASKBAR = RegisterWindowMessageA("TaskbarCreated"); /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof(WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(ICO1)); wincl.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(ICO1)); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ wincl.hbrBackground = (HBRUSH)(CreateSolidBrush(RGB(255, 255, 255))); /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx(&wincl)) return 503; /* The class is registered, let's create the program*/ Hwnd = CreateWindowEx( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ szClassName, /* Title Text */ 0, /* default window */ 0, /* Windows decides the position */ 0, /* where the window ends up on the screen */ 0, /* The programs width */ 0, /* and height in pixels */ HWND_MESSAGE, /* The window is a child-window to desktop */ NULL, /* No menu */ NULL, /* Program Instance handler */ NULL /* No Window Creation data */ ); /*Initialize the NOTIFYICONDATA structure only once*/ InitNotifyIconData(); /* Make the window visible on the screen */ ShowWindow(Hwnd, nCmdShow); // store address of hook proc HOOKPROC lpfnHookProc = &LowLevelKeyboardProc; // try to set hook KBHook = SetWindowsHookEx(WH_KEYBOARD_LL, lpfnHookProc, GetModuleHandle(NULL), 0); // if hook was not installed, get the last error code, and string and // show them both in a messagebox() if (KBHook == NULL) { char lpBuffer[50]; char* errorString = GetLastErrorString(); strcat_s(lpBuffer, errorString); MessageBox(HWND_DESKTOP, lpBuffer, "keyboard hook could not be installed!", MB_OK); } /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage(&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } // if there is a valid hook procedure, uninstall it if (KBHook) { // if unhookwindowshookex fails, show the last error as a string if (!UnhookWindowsHookEx(KBHook)) { char* errorString = GetLastErrorString(); MessageBox(HWND_DESKTOP, errorString, "Last Error", MB_OK); } } return messages.wParam; }