1. define a window class name and hotkey id constant
in MainFrame.h
#define ID_NEW_TAB_FIRST 1000
#define MAINFRAME_WNDCLASS
L"Console2_WndClass"
#define MAINFRAME_HOTKEY 0x2300
2. use the window class:
class MainFrame
: public CTabbedFrameImpl<MainFrame>
, public CUpdateUI<MainFrame>
, public CMessageFilter
, public CIdleHandler
{
public:
DECLARE_FRAME_WND_CLASS
(MAINFRAME_WNDCLASS, IDR_MAINFRAME)
3. declare a WM_HOTKEY handler
MESSAGE_HANDLER(WM_HOTKEY, OnHotkey);
LRESULT OnHotkey(UINT /*uMsg*/, WPARAM wParam,
LPARAM /*lParam*/, BOOL& bHandled);
4. provide an implementation
LRESULT MainFrame::OnHotkey(UINT /*uMsg*/, WPARAM
wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
if(wParam != MAINFRAME_HOTKEY)
{
bHandled = FALSE;
return 0;
}
static HWND hLastConsoleWnd = NULL;
HWND hNextConsoleWnd = ::FindWindowEx(NULL,
hLastConsoleWnd, MAINFRAME_WNDCLASS, NULL);
if(hNextConsoleWnd == NULL)
{
hNextConsoleWnd = m_hWnd;
}
hLastConsoleWnd = hNextConsoleWnd;
::SetForegroundWindow(hLastConsoleWnd);
return 0;
}
5. register the hotkey in OnCreate
::RegisterHotKey(m_hWnd, MAINFRAME_HOTKEY,
MOD_WIN, 'C');
at the moment, it doesnt work with consoles pinned to
the desktop, because i didnt managed to set keyboard
focus into a window with parent set to GetShellWindow
() :(
Logged In: YES
user_id=1545227
yeah, and also it is not a bad idea to call OpenIcon
(hLastConsoleWnd); before calling SetForegroundWindow :))))