// Constructor of the main class // of the extension TemplateExtension::TemplateExtension() { // Please, set the name of the extension // to make everything nice and tidy. name = "TemplateExtension"; // Here the commands from irc are // "linked" to the actual functions. SetCommandHandler( "PING", Pong ); }
bool VirtualDimension::CreateLangMenu() { LocalesIterator it; int count = 0; // languageCode from registry int currentLanguageCode = Locale::GetInstance().GetLanguage(); //Create the menu m_pLangMenu = CreatePopupMenu(); //Add the entries while(m_pLangMenu && it.GetNext()) { String name; HICON hicon; name = it.GetLanguage(&hicon, NULL); if (!name.empty()) { MENUITEMINFO iteminfo; int code = it.GetLanguageCode(); count++; iteminfo.cbSize = sizeof(MENUITEMINFO); iteminfo.fMask = MIIM_DATA|MIIM_STRING|MIIM_FTYPE|MIIM_BITMAP|MIIM_ID; iteminfo.dwTypeData = (LPTSTR)name.c_str(); iteminfo.fType = MFT_STRING; iteminfo.dwItemData = (ULONG_PTR)hicon; iteminfo.hbmpItem = HBMMENU_CALLBACK; iteminfo.wID = WM_VD_LANGUAGE+code; // in order to get WM_COMMAND msg InsertMenuItem(m_pLangMenu, WM_VD_LANGUAGE+code, FALSE, &iteminfo); if (code == currentLanguageCode) CheckMenuItem(m_pLangMenu,(UINT)code+WM_VD_LANGUAGE,MF_BYCOMMAND|MF_CHECKED); // then we connect any menu to the window proc SetCommandHandler(WM_VD_LANGUAGE+code, this, &VirtualDimension::OnCmdLanguageChange); SetSysCommandHandler(WM_VD_LANGUAGE+code, this, &VirtualDimension::OnCmdLanguageChange); } } return count > 1; }
bool VirtualDimension::Start(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; RECT pos; Settings settings; HWND hwndPrev; DWORD dwStyle; // If a previous instance is running, activate // that instance and terminate this one. hwndPrev = FindWindow(); if (hwndPrev != NULL) { SetForegroundWindow (hwndPrev); return false; } m_hInstance = hInstance; InitHotkeyControl(); InitHyperLinkControl(); // Register the window class RegisterClass(); // Bind the message handlers SetCommandHandler(IDM_ABOUT, this, &VirtualDimension::OnCmdAbout); SetSysCommandHandler(IDM_ABOUT, this, &VirtualDimension::OnCmdAbout); SetCommandHandler(IDM_CONFIGURE, this, &VirtualDimension::OnCmdConfigure); SetSysCommandHandler(IDM_CONFIGURE, this, &VirtualDimension::OnCmdConfigure); SetCommandHandler(IDM_EXIT, this, &VirtualDimension::OnCmdExit); SetSysCommandHandler(SC_CLOSE, this, &VirtualDimension::OnCmdExit); SetCommandHandler(IDM_LOCKPREVIEWWND, this, &VirtualDimension::OnCmdLockPreviewWindow); SetSysCommandHandler(IDM_LOCKPREVIEWWND, this, &VirtualDimension::OnCmdLockPreviewWindow); SetCommandHandler(IDM_SHOWCAPTION, this, &VirtualDimension::OnCmdShowCaption); SetSysCommandHandler(IDM_SHOWCAPTION, this, &VirtualDimension::OnCmdShowCaption); SetMessageHandler(WM_DESTROY, this, &VirtualDimension::OnDestroy); SetMessageHandler(WM_ENDSESSION, this, &VirtualDimension::OnEndSession); SetMessageHandler(WM_MOVE, this, &VirtualDimension::OnMove); SetMessageHandler(WM_WINDOWPOSCHANGING, this, &VirtualDimension::OnWindowPosChanging); SetMessageHandler(WM_DISPLAYCHANGE, this, &VirtualDimension::OnDisplayChange); SetMessageHandler(WM_SHOWWINDOW, this, &VirtualDimension::OnShowWindow); SetMessageHandler(WM_LBUTTONDOWN, this, &VirtualDimension::OnLeftButtonDown); SetMessageHandler(WM_LBUTTONUP, this, &VirtualDimension::OnLeftButtonUp); SetMessageHandler(WM_LBUTTONDBLCLK, this, &VirtualDimension::OnLeftButtonDblClk); SetMessageHandler(WM_RBUTTONDOWN, this, &VirtualDimension::OnRightButtonDown); SetMessageHandler(WM_MEASUREITEM, this, &VirtualDimension::OnMeasureItem); SetMessageHandler(WM_DRAWITEM, this, &VirtualDimension::OnDrawItem); m_autoHideTimerId = CreateTimer(this, &VirtualDimension::OnTimer); SetMessageHandler(WM_ACTIVATEAPP, this, &VirtualDimension::OnActivateApp); SetMessageHandler(WM_MOUSEHOVER, this, &VirtualDimension::OnMouseHover); SetMessageHandler(WM_MOUSELEAVE, this, &VirtualDimension::OnMouseLeave); SetMessageHandler(WM_NCHITTEST, this, &VirtualDimension::OnNCHitTest); SetMessageHandler(WM_VD_HOOK_MENU_COMMAND, this, &VirtualDimension::OnHookMenuCommand); SetMessageHandler(WM_VD_PREPARE_HOOK_MENU, this, &VirtualDimension::OnPrepareHookMenu); SetMessageHandler(WM_VD_CHECK_MIN_TO_TRAY, this, &VirtualDimension::OnCheckMinToTray); // compare the window's style m_hasCaption = settings.LoadSetting(Settings::HasCaption); dwStyle = WS_POPUP | WS_SYSMENU | (m_hasCaption ? WS_CAPTION : WS_DLGFRAME); // Reload the window's position settings.LoadSetting(Settings::WindowPosition, &pos); AdjustWindowRectEx(&pos, dwStyle, FALSE, WS_EX_TOOLWINDOW); // Dock the window to the screen borders m_dockedBorders = settings.LoadSetting(Settings::DockedBorders); DockWindow(pos); // Create the main window Create( WS_EX_TOOLWINDOW, m_szWindowClass, m_szTitle, dwStyle, pos.left, pos.top, pos.right - pos.left, pos.bottom - pos.top, NULL, NULL, hInstance); if (!IsValid()) return false; hWnd = *this; // Load some settings m_snapSize = settings.LoadSetting(Settings::SnapSize); m_autoHideDelay = settings.LoadSetting(Settings::AutoHideDelay); m_shrinked = false; m_tracking = false; //Ensure the window gets docked if it is close enough to the borders SetWindowPos(hWnd, NULL, pos.left, pos.top, pos.right - pos.left, pos.bottom - pos.top, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER); // Setup the system menu m_pSysMenu = GetSystemMenu(hWnd, FALSE); if (m_pSysMenu != NULL) { RemoveMenu(m_pSysMenu, SC_RESTORE, MF_BYCOMMAND); RemoveMenu(m_pSysMenu, SC_MINIMIZE, MF_BYCOMMAND); RemoveMenu(m_pSysMenu, SC_MAXIMIZE, MF_BYCOMMAND); RemoveMenu(m_pSysMenu, SC_MOVE, MF_BYCOMMAND); RemoveMenu(m_pSysMenu, SC_SIZE, MF_BYCOMMAND); RemoveMenu(m_pSysMenu, 0, MF_BYCOMMAND); AppendMenu(m_pSysMenu, MF_SEPARATOR, 0, NULL); AppendMenu(m_pSysMenu, MF_STRING, IDM_CONFIGURE, Locale::GetInstance().GetString(IDS_CONFIGURE)); //"C&onfigure" AppendMenu(m_pSysMenu, MF_STRING, IDM_LOCKPREVIEWWND, Locale::GetInstance().GetString(IDS_LOCKPREVIEWWND)); //"&Lock the window" AppendMenu(m_pSysMenu, MF_STRING, IDM_SHOWCAPTION, Locale::GetInstance().GetString(IDS_SHOWCAPTION)); //"S&how the caption" if (CreateLangMenu()) AppendMenu(m_pSysMenu, MF_STRING|MF_POPUP, (UINT_PTR)m_pLangMenu, Locale::GetInstance().GetString(IDS_LANGUAGEMENU)); //"L&anguage" AppendMenu(m_pSysMenu, MF_STRING, IDM_ABOUT, Locale::GetInstance().GetString(IDS_ABOUT)); //"&About" CheckMenuItem(m_pSysMenu, IDM_SHOWCAPTION, m_hasCaption ? MF_CHECKED : MF_UNCHECKED ); } // Lock the preview window as appropriate LockPreviewWindow(settings.LoadSetting(Settings::LockPreviewWindow)); // Bind to explorer explorerWrapper = new ExplorerWrapper(this); // Initialize the tray icon manager trayManager = new TrayIconsManager(); // Initialize tray icon trayIcon = new TrayIcon(hWnd); // Initialize transparency (set value two times, to make a fade-in) transp = new Transparency(hWnd); transp->SetTransparencyLevel(0); transp->SetTransparencyLevel(settings.LoadSetting(Settings::TransparencyLevel), true); // Initialize always on top state ontop = new AlwaysOnTop(hWnd); ontop->SetAlwaysOnTop(settings.LoadSetting(Settings::AlwaysOnTop)); // Create the tooltip tooltip = new ToolTip(hWnd); // Create mouse warp mousewarp = new MouseWarp(); // Create the windows manager winMan = new WindowsManager; // Create the desk manager settings.LoadSetting(Settings::WindowPosition, &pos); //use client position deskMan = new DesktopManager(pos.right - pos.left, pos.bottom - pos.top); // Retrieve the initial list of windows winMan->PopulateInitialWindowsSet(); //Update tray icon tooltip trayIcon->Update(); //Bind some additional message handlers (which need the desktop manager) SetMessageHandler(WM_SIZE, this, &VirtualDimension::OnSize); SetMessageHandler(WM_PAINT, deskMan, &DesktopManager::OnPaint); // Show window if needed if (m_isWndVisible = (settings.LoadSetting(Settings::ShowWindow) || !trayIcon->HasIcon())) { ShowWindow(hWnd, nCmdShow); Refresh(); } return true; }