Handling ofg iconized windows
authorMartin Fuchs <fuchs.martin@gmail.com>
Sun, 17 Aug 2003 14:19:03 +0000 (14:19 +0000)
committerMartin Fuchs <fuchs.martin@gmail.com>
Sun, 17 Aug 2003 14:19:03 +0000 (14:19 +0000)
svn path=/trunk/; revision=5616

reactos/subsys/system/explorer/explorer.cpp
reactos/subsys/system/explorer/explorer.dsp
reactos/subsys/system/explorer/explorer.dsw
reactos/subsys/system/explorer/explorer.h
reactos/subsys/system/explorer/taskbar/taskbar.cpp
reactos/subsys/system/explorer/taskbar/taskbar.h
reactos/subsys/system/explorer/utility/window.cpp
reactos/subsys/system/explorer/utility/window.h

index ae23ee1..16ce1d1 100644 (file)
@@ -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)
index 00c38cf..3bdb0e3 100644 (file)
@@ -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
index 34bf5a9..d417101 100644 (file)
@@ -3,7 +3,7 @@ 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>
 {{{
@@ -11,11 +11,26 @@ Package=<5>
 
 Package=<4>
 {{{
+    Begin Project Dependency
+    Project_Dep_Name shellhook
+    End Project Dependency
 }}}
 
 ###############################################################################
 
-Project: "make_explorer"=".\make_explorer.dsp" - Package Owner=<4>
+Project: "make_explorer"=.\make_explorer.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "shellhook"=.\shellhook.dsp - Package Owner=<4>
 
 Package=<5>
 {{{
index 5ac7704..f1a6b87 100644 (file)
 #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
index d4e3d78..7f27c10 100644 (file)
@@ -226,65 +226,9 @@ TaskBar::TaskBar(HWND hwnd)
        _last_foreground_wnd = 0;
 }
 
- // fill task bar with buttons for enumerated top level windows
-BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam)
+TaskBar::~TaskBar()
 {
-       TaskBar* pThis = (TaskBar*)lparam;
-
-       DWORD style = GetWindowStyle(hwnd);
-       DWORD ex_style = GetWindowExStyle(hwnd);
-
-       if ((style&WS_VISIBLE) && !(ex_style&WS_EX_TOOLWINDOW) &&
-               !GetParent(hwnd) && !GetWindow(hwnd,GW_OWNER)) {
-               TBBUTTON btn = {-2/*I_IMAGENONE*/, 0, TBSTATE_ENABLED/*|TBSTATE_ELLIPSES*/, BTNS_BUTTON, {0, 0}, 0, 0};
-
-               TaskBarMap::iterator found = pThis->_map.find(hwnd);
-               int last_id = 0;
-
-               if (found != pThis->_map.end()) {
-                       last_id = found->second._id;
-
-                       if (!last_id)
-                               found->second._id = pThis->_next_id++;
-               } else {
-                       HICON hicon = get_window_icon(hwnd);
-                       HBITMAP hbmp = create_bitmap_from_icon(hicon, pThis->_htoolbar, GetSysColorBrush(COLOR_BTNFACE));
-
-                       TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
-                       int bmp_idx = SendMessage(pThis->_htoolbar, TB_ADDBITMAP, 1, (LPARAM)&ab);
-
-                       TaskBarEntry bmp = {pThis->_next_id++, hbmp, bmp_idx, 0, 0};
-
-                       pThis->_map[hwnd] = bmp;
-                       found = pThis->_map.find(hwnd);
-               }
-
-               TaskBarEntry& entry = found->second;
-
-               ++entry._used;
-               btn.idCommand = entry._id;
-
-                // 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;
-
-                       btn.iBitmap = entry._bmp_idx;
-                       entry._btn_idx = SendMessage(pThis->_htoolbar, TB_BUTTONCOUNT, 0, 0);
-
-                       SendMessage(pThis->_htoolbar, TB_INSERTBUTTON, entry._btn_idx, (LPARAM)&btn);
-               }
-       }
-
-       return TRUE;
+       //DeinstallShellHook();
 }
 
 LRESULT TaskBar::Init(LPCREATESTRUCT pcs)
@@ -303,9 +247,11 @@ LRESULT TaskBar::Init(LPCREATESTRUCT pcs)
 
        _next_id = IDC_FIRST_APP;
 
+       //InstallShellHook(_hwnd, WM_SHELLHOOK_NOTIFY);
+
        Refresh();
 
-       SetTimer(_hwnd, 0, 1000, NULL);
+       SetTimer(_hwnd, 0, 200, NULL);
 
        return 0;
 }
@@ -320,10 +266,24 @@ LRESULT TaskBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
                SendMessage(_htoolbar, WM_SIZE, 0, 0);
                break;
 
-         case WM_TIMER:        // could be optimized by using WH_CBT hooks instead of timer
+         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);
        }
@@ -339,14 +299,14 @@ int TaskBar::Command(int id, int code)
                HWND hwnd = found->first;
 
                if (hwnd==GetForegroundWindow() || hwnd==_last_foreground_wnd) {
-                       ShowWindow(hwnd, SW_MINIMIZE);
+                       ShowWindowAsync(hwnd, SW_MINIMIZE);
                        _last_foreground_wnd = 0;
                } else {
                         // switch to selected application window
-                       SetForegroundWindow(hwnd);
-
                        if (IsIconic(hwnd))
-                               ShowWindow(hwnd, SW_RESTORE);
+                               ShowWindowAsync(hwnd, SW_RESTORE);
+
+                       SetForegroundWindow(hwnd);
 
                        _last_foreground_wnd = hwnd;
                }
@@ -357,6 +317,78 @@ int TaskBar::Command(int id, int code)
        return super::Command(id, code);
 }
 
+ // fill task bar with buttons for enumerated top level windows
+BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam)
+{
+       TaskBar* pThis = (TaskBar*)lparam;
+
+       DWORD style = GetWindowStyle(hwnd);
+       DWORD ex_style = GetWindowExStyle(hwnd);
+
+       if ((style&WS_VISIBLE) && !(ex_style&WS_EX_TOOLWINDOW) &&
+               !GetParent(hwnd) && !GetWindow(hwnd,GW_OWNER)) {
+               TBBUTTON btn = {-2/*I_IMAGENONE*/, 0, TBSTATE_ENABLED/*|TBSTATE_ELLIPSES*/, BTNS_BUTTON, {0, 0}, 0, 0};
+
+               TaskBarMap::iterator found = pThis->_map.find(hwnd);
+               int last_id = 0;
+
+               if (found != pThis->_map.end()) {
+                       last_id = found->second._id;
+
+                       if (!last_id)
+                               found->second._id = pThis->_next_id++;
+               } else {
+                       HICON hicon = get_window_icon(hwnd);
+                       HBITMAP hbmp = create_bitmap_from_icon(hicon, pThis->_htoolbar, GetSysColorBrush(COLOR_BTNFACE));
+
+                       TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
+                       int bmp_idx = SendMessage(pThis->_htoolbar, TB_ADDBITMAP, 1, (LPARAM)&ab);
+
+                       TaskBarEntry bmp = {pThis->_next_id++, hbmp, bmp_idx, 0, 0};
+
+                       pThis->_map[hwnd] = bmp;
+                       found = pThis->_map.find(hwnd);
+               }
+
+               TaskBarEntry& entry = found->second;
+
+               ++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*/;
+
+                       if (title[0])
+                               btn.iString = (INT_PTR)title;
+
+                       btn.iBitmap = entry._bmp_idx;
+                       entry._btn_idx = SendMessage(pThis->_htoolbar, TB_BUTTONCOUNT, 0, 0);
+
+                       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;
+}
+
 void TaskBar::Refresh()
 {
        for(TaskBarMap::iterator it=_map.begin(); it!=_map.end(); ++it)
index 96b5315..331410f 100644 (file)
@@ -26,6 +26,8 @@
  //
 
 
+//#include "shellhook.h"
+
 #include <map>
 #include <set>
 
@@ -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();
 };
index 0385695..615bf17 100644 (file)
@@ -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);
 }
 
 
index 9be1868..ba7648e 100644 (file)
@@ -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))