From 76a258b41b4b7be20cd7568773cb9e0507220b21 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sun, 17 Aug 2003 14:19:03 +0000 Subject: [PATCH] Handling ofg iconized windows svn path=/trunk/; revision=5616 --- reactos/subsys/system/explorer/explorer.cpp | 14 +- reactos/subsys/system/explorer/explorer.dsp | 4 + reactos/subsys/system/explorer/explorer.dsw | 19 +- reactos/subsys/system/explorer/explorer.h | 10 +- .../system/explorer/taskbar/taskbar.cpp | 182 ++++++++++-------- .../subsys/system/explorer/taskbar/taskbar.h | 7 +- .../subsys/system/explorer/utility/window.cpp | 8 +- .../subsys/system/explorer/utility/window.h | 6 +- 8 files changed, 153 insertions(+), 97 deletions(-) diff --git a/reactos/subsys/system/explorer/explorer.cpp b/reactos/subsys/system/explorer/explorer.cpp index ae23ee1f795..16ce1d127c1 100644 --- a/reactos/subsys/system/explorer/explorer.cpp +++ b/reactos/subsys/system/explorer/explorer.cpp @@ -86,10 +86,8 @@ void explorer_show_frame(HWND hwndDesktop, int cmdshow) } -static void InitInstance(HINSTANCE hinstance) +static void InitInstance(HINSTANCE hInstance) { - g_Globals._hInstance = hinstance; - setlocale(LC_COLLATE, ""); // set collating rules to local settings for compareName @@ -97,9 +95,9 @@ static void InitInstance(HINSTANCE hinstance) WindowClass wcFrame(CLASSNAME_FRAME); - wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_EXPLORER)); + wcFrame.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EXPLORER)); wcFrame.hCursor = LoadCursor(0, IDC_ARROW); - wcFrame.hIconSm = (HICON)LoadImage(hinstance, + wcFrame.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_EXPLORER), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), @@ -133,7 +131,7 @@ static void InitInstance(HINSTANCE hinstance) } -int explorer_main(HINSTANCE hinstance, HWND hwndDesktop, int cmdshow) +int explorer_main(HINSTANCE hInstance, HWND hwndDesktop, int cmdshow) { // initialize COM and OLE OleInit usingCOM; @@ -144,7 +142,7 @@ int explorer_main(HINSTANCE hinstance, HWND hwndDesktop, int cmdshow) try { MSG msg; - InitInstance(hinstance); + InitInstance(hInstance); if (hwndDesktop) g_Globals._desktop_mode = true; @@ -197,6 +195,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL startup_desktop = TRUE; } + g_Globals._hInstance = hInstance; + HWND hwndDesktop = 0; if (startup_desktop) diff --git a/reactos/subsys/system/explorer/explorer.dsp b/reactos/subsys/system/explorer/explorer.dsp index 00c38cfce79..3bdb0e3f03f 100644 --- a/reactos/subsys/system/explorer/explorer.dsp +++ b/reactos/subsys/system/explorer/explorer.dsp @@ -332,6 +332,10 @@ SOURCE=.\res\toolbar.bmp # PROP Default_Filter "" # Begin Source File +SOURCE=.\taskbar\shellhook.h +# End Source File +# Begin Source File + SOURCE=.\taskbar\taskbar.cpp # End Source File # Begin Source File diff --git a/reactos/subsys/system/explorer/explorer.dsw b/reactos/subsys/system/explorer/explorer.dsw index 34bf5a90a43..d417101aa2f 100644 --- a/reactos/subsys/system/explorer/explorer.dsw +++ b/reactos/subsys/system/explorer/explorer.dsw @@ -3,7 +3,22 @@ Microsoft Developer Studio Workspace File, Format Version 6.00 ############################################################################### -Project: "explorer"=".\explorer.dsp" - Package Owner=<4> +Project: "explorer"=.\explorer.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name shellhook + End Project Dependency +}}} + +############################################################################### + +Project: "make_explorer"=.\make_explorer.dsp - Package Owner=<4> Package=<5> {{{ @@ -15,7 +30,7 @@ Package=<4> ############################################################################### -Project: "make_explorer"=".\make_explorer.dsp" - Package Owner=<4> +Project: "shellhook"=.\shellhook.dsp - Package Owner=<4> Package=<5> {{{ diff --git a/reactos/subsys/system/explorer/explorer.h b/reactos/subsys/system/explorer/explorer.h index 5ac7704d9c7..f1a6b878167 100644 --- a/reactos/subsys/system/explorer/explorer.h +++ b/reactos/subsys/system/explorer/explorer.h @@ -44,15 +44,15 @@ #define IDW_FIRST_CHILD 0xC000 /*0x200*/ -#define WM_TRANSLATE_MSG (WM_APP+2) -#define WM_GET_FILEWND_PTR (WM_APP+3) +#define WM_TRANSLATE_MSG (WM_APP+0x02) +#define WM_GET_FILEWND_PTR (WM_APP+0x03) -#define FRM_CALC_CLIENT (WM_APP+4) +#define FRM_CALC_CLIENT (WM_APP+0x04) #define Frame_CalcFrameClient(hwnd, prt) ((BOOL)SNDMSG(hwnd, FRM_CALC_CLIENT, 0, (LPARAM)(PRECT)prt)) -#define WM_OPEN_WINDOW (WM_APP+5) +#define WM_OPEN_WINDOW (WM_APP+0x05) -#define WM_GET_CONTROLWINDOW (WM_APP+6) +#define WM_GET_CONTROLWINDOW (WM_APP+0x06) #define CLASSNAME_FRAME TEXT("CabinetWClass") // same class name for frame window as in MS Explorer diff --git a/reactos/subsys/system/explorer/taskbar/taskbar.cpp b/reactos/subsys/system/explorer/taskbar/taskbar.cpp index d4e3d785e70..7f27c10bd41 100644 --- a/reactos/subsys/system/explorer/taskbar/taskbar.cpp +++ b/reactos/subsys/system/explorer/taskbar/taskbar.cpp @@ -226,6 +226,97 @@ TaskBar::TaskBar(HWND hwnd) _last_foreground_wnd = 0; } +TaskBar::~TaskBar() +{ + //DeinstallShellHook(); +} + +LRESULT TaskBar::Init(LPCREATESTRUCT pcs) +{ + super::Init(pcs); + + _htoolbar = CreateToolbarEx(_hwnd, + WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_TOP|//CCS_NORESIZE| + TBSTYLE_LIST|TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE|TBSTYLE_TRANSPARENT, + IDW_TASKTOOLBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON)); + + SendMessage(_htoolbar, TB_SETBUTTONWIDTH, 0, MAKELONG(16,160)); + //SendMessage(_htoolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS); + //SendMessage(_htoolbar, TB_SETDRAWTEXTFLAGS, DT_CENTER|DT_VCENTER, DT_CENTER|DT_VCENTER); + //SetWindowFont(_htoolbar, GetStockFont(ANSI_VAR_FONT), FALSE); + + _next_id = IDC_FIRST_APP; + + //InstallShellHook(_hwnd, WM_SHELLHOOK_NOTIFY); + + Refresh(); + + SetTimer(_hwnd, 0, 200, NULL); + + return 0; +} + +LRESULT TaskBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) +{ + switch(nmsg) { + case WM_CLOSE: + break; + + case WM_SIZE: + SendMessage(_htoolbar, WM_SIZE, 0, 0); + break; + + case WM_TIMER: + Refresh(); + return 0; + + case WM_SHELLHOOK_NOTIFY: { + int code = lparam; +/* + switch(code) { + case HSHELL_WINDOWCREATED: + case HSHELL_WINDOWDESTROYED: + case HSHELL_WINDOWACTIVATED: + case HSHELL_WINDOWREPLACED: + Refresh(); + break; + } */ + Refresh(); + break;} + + default: + return super::WndProc(nmsg, wparam, lparam); + } + + return super::WndProc(nmsg, wparam, lparam); +} + +int TaskBar::Command(int id, int code) +{ + TaskBarMap::iterator found = _map.find_id(id); + + if (found != _map.end()) { + HWND hwnd = found->first; + + if (hwnd==GetForegroundWindow() || hwnd==_last_foreground_wnd) { + ShowWindowAsync(hwnd, SW_MINIMIZE); + _last_foreground_wnd = 0; + } else { + // switch to selected application window + if (IsIconic(hwnd)) + ShowWindowAsync(hwnd, SW_RESTORE); + + SetForegroundWindow(hwnd); + + _last_foreground_wnd = hwnd; + } + + return 0; + } + + return super::Command(id, code); +} + // fill task bar with buttons for enumerated top level windows BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam) { @@ -264,16 +355,18 @@ BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam) ++entry._used; btn.idCommand = entry._id; + TCHAR title[BUFFER_LEN]; + + if (!GetWindowText(hwnd, title, BUFFER_LEN)) + title[0] = '\0'; + + //@@ refresh window titles + // create new toolbar buttons for new windows if (!last_id) { if (hwnd == GetForegroundWindow()) btn.fsState |= TBSTATE_PRESSED/*|TBSTATE_MARKED*/; - TCHAR title[BUFFER_LEN]; - - if (!GetWindowText(hwnd, title, BUFFER_LEN)) - title[0] = '\0'; - if (title[0]) btn.iString = (INT_PTR)title; @@ -282,81 +375,20 @@ BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam) SendMessage(pThis->_htoolbar, TB_INSERTBUTTON, entry._btn_idx, (LPARAM)&btn); } + + // move iconic windows out of sight + if (IsIconic(hwnd)) { + RECT rect; + GetWindowRect(hwnd, &rect); + + if (rect.bottom > 0) + SetWindowPos(hwnd, 0, -32000, -32000, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE); + } } return TRUE; } -LRESULT TaskBar::Init(LPCREATESTRUCT pcs) -{ - super::Init(pcs); - - _htoolbar = CreateToolbarEx(_hwnd, - WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_TOP|//CCS_NORESIZE| - TBSTYLE_LIST|TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE|TBSTYLE_TRANSPARENT, - IDW_TASKTOOLBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON)); - - SendMessage(_htoolbar, TB_SETBUTTONWIDTH, 0, MAKELONG(16,160)); - //SendMessage(_htoolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS); - //SendMessage(_htoolbar, TB_SETDRAWTEXTFLAGS, DT_CENTER|DT_VCENTER, DT_CENTER|DT_VCENTER); - //SetWindowFont(_htoolbar, GetStockFont(ANSI_VAR_FONT), FALSE); - - _next_id = IDC_FIRST_APP; - - Refresh(); - - SetTimer(_hwnd, 0, 1000, NULL); - - return 0; -} - -LRESULT TaskBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) -{ - switch(nmsg) { - case WM_CLOSE: - break; - - case WM_SIZE: - SendMessage(_htoolbar, WM_SIZE, 0, 0); - break; - - case WM_TIMER: // could be optimized by using WH_CBT hooks instead of timer - Refresh(); - return 0; - - default: - return super::WndProc(nmsg, wparam, lparam); - } - - return super::WndProc(nmsg, wparam, lparam); -} - -int TaskBar::Command(int id, int code) -{ - TaskBarMap::iterator found = _map.find_id(id); - - if (found != _map.end()) { - HWND hwnd = found->first; - - if (hwnd==GetForegroundWindow() || hwnd==_last_foreground_wnd) { - ShowWindow(hwnd, SW_MINIMIZE); - _last_foreground_wnd = 0; - } else { - // switch to selected application window - SetForegroundWindow(hwnd); - - if (IsIconic(hwnd)) - ShowWindow(hwnd, SW_RESTORE); - - _last_foreground_wnd = hwnd; - } - - return 0; - } - - return super::Command(id, code); -} - void TaskBar::Refresh() { for(TaskBarMap::iterator it=_map.begin(); it!=_map.end(); ++it) diff --git a/reactos/subsys/system/explorer/taskbar/taskbar.h b/reactos/subsys/system/explorer/taskbar/taskbar.h index 96b531547c9..331410f2f2f 100644 --- a/reactos/subsys/system/explorer/taskbar/taskbar.h +++ b/reactos/subsys/system/explorer/taskbar/taskbar.h @@ -26,6 +26,8 @@ // +//#include "shellhook.h" + #include #include @@ -34,6 +36,8 @@ #define TASKBAR_LEFT 60 //#define TASKBAR_AT_TOP +#define WM_SHELLHOOK_NOTIFY (WM_APP+0x10) + struct DesktopBar : public Window { @@ -74,6 +78,7 @@ struct TaskBar : public Window typedef Window super; TaskBar(HWND hwnd); + TaskBar::~TaskBar(); DesktopBar* _desktop_bar; @@ -87,7 +92,7 @@ protected: LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); int Command(int id, int code); - static BOOL CALLBACK EnumWndProc(HWND, LPARAM); + static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam); void Refresh(); }; diff --git a/reactos/subsys/system/explorer/utility/window.cpp b/reactos/subsys/system/explorer/utility/window.cpp index 0385695f0b6..615bf172abf 100644 --- a/reactos/subsys/system/explorer/utility/window.cpp +++ b/reactos/subsys/system/explorer/utility/window.cpp @@ -44,7 +44,7 @@ WindowClass::WindowClass(LPCTSTR classname, WNDPROC wndproc) } -HHOOK Window::s_hcbthook = 0; +HHOOK Window::s_hcbtHook = 0; Window::WINDOWCREATORFUNC Window::s_window_creator = NULL; const void* Window::s_new_info = NULL; @@ -84,11 +84,11 @@ Window* Window::create_mdi_child(HWND hmdiclient, const MDICREATESTRUCT& mcs, WI s_new_info = info; s_new_child_wnd = NULL; - s_hcbthook = SetWindowsHookEx(WH_CBT, CBTHookProc, 0, GetCurrentThreadId()); + s_hcbtHook = SetWindowsHookEx(WH_CBT, CBTHookProc, 0, GetCurrentThreadId()); HWND hwnd = (HWND) SendMessage(hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs); - UnhookWindowsHookEx(s_hcbthook); + UnhookWindowsHookEx(s_hcbtHook); Window* child = s_new_child_wnd; s_new_info = NULL; @@ -110,7 +110,7 @@ LRESULT CALLBACK Window::CBTHookProc(int code, WPARAM wparam, LPARAM lparam) s_new_child_wnd = child; } - return CallNextHookEx(s_hcbthook, code, wparam, lparam); + return CallNextHookEx(s_hcbtHook, code, wparam, lparam); } diff --git a/reactos/subsys/system/explorer/utility/window.h b/reactos/subsys/system/explorer/utility/window.h index 9be1868c699..ba7648e06a8 100644 --- a/reactos/subsys/system/explorer/utility/window.h +++ b/reactos/subsys/system/explorer/utility/window.h @@ -75,7 +75,7 @@ protected: static WINDOWCREATORFUNC s_window_creator; //TODO: protect for multithreaded access // MDI child creation - static HHOOK s_hcbthook; + static HHOOK s_hcbtHook; static LRESULT CALLBACK CBTHookProc(int code, WPARAM wparam, LPARAM lparam); }; @@ -126,7 +126,7 @@ struct WindowClass : public WNDCLASSEX }; -#define WM_DISPATCH_COMMAND (WM_APP+0) +#define WM_DISPATCH_COMMAND (WM_APP+0x00) #define SPLIT_WIDTH 5 @@ -140,7 +140,7 @@ struct MenuInfo HMENU _hMenuOptions; }; -#define FRM_GET_MENUINFO (WM_APP+1) +#define FRM_GET_MENUINFO (WM_APP+0x01) #define Frame_GetMenuInfo(hwnd) ((MenuInfo*)SNDMSG(hwnd, FRM_GET_MENUINFO, 0, 0))