Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes

Window Struct Reference

Class Window is the base class for several C++ window wrapper classes. More...

#include <window.h>

Inheritance diagram for Window:
Inheritance graph
[legend]
Collaboration diagram for Window:
Collaboration graph
[legend]

List of all members.

Classes

struct  StaticWindowData
 structure for managing critical sections as static class information in struct Window More...

Public Types

typedef map< HWND, Window * > WindowMap
typedef Window *(* CREATORFUNC )(HWND)
typedef Window *(* CREATORFUNC_INFO )(HWND, const void *)

Public Member Functions

 Window (HWND hwnd)
virtual ~Window ()
LRESULT SendParent (UINT nmsg, WPARAM wparam=0, LPARAM lparam=0)
LRESULT PostParent (UINT nmsg, WPARAM wparam=0, LPARAM lparam=0)

Static Public Member Functions

static HWND Create (CREATORFUNC creator, DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int w, int h, HWND hwndParent=0, HMENU hMenu=0)
static HWND Create (CREATORFUNC_INFO creator, const void *info, DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int w, int h, HWND hwndParent=0, HMENU hMenu=0)
static Windowcreate_mdi_child (const ChildWndInfo &info, const MDICREATESTRUCT &mcs, CREATORFUNC_INFO creator)
static LRESULT CALLBACK WindowWndProc (HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
static INT_PTR CALLBACK DialogProc (HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
static Windowget_window (HWND hwnd)
 get window controller from window handle
template<typename CLASS >
static CLASS * get_window (HWND hwnd)
static void register_pretranslate (HWND hwnd)
static void unregister_pretranslate (HWND hwnd)
static BOOL pretranslate_msg (LPMSG pmsg)
static void register_dialog (HWND hwnd)
static void unregister_dialog (HWND hwnd)
static BOOL dispatch_dialog_msg (LPMSG pmsg)
static int MessageLoop ()
static void CancelModes ()

Protected Member Functions

virtual LRESULT Init (LPCREATESTRUCT pcs)
virtual LRESULT WndProc (UINT nmsg, WPARAM wparam, LPARAM lparam)
virtual int Command (int id, int code)
virtual int Notify (int id, NMHDR *pnmh)

Static Protected Member Functions

static Windowcreate_controller (HWND hwnd)
 create controller for a new window
static StaticWindowDataGetStaticWindowData ()
static LRESULT CALLBACK MDICBTHookProc (int code, WPARAM wparam, LPARAM lparam)
static LRESULT CALLBACK PropSheetCBTHookProc (int code, WPARAM wparam, LPARAM lparam)

Static Protected Attributes

static WindowMap s_wnd_map
static const void * s_new_info = NULL
static CREATORFUNC s_window_creator = NULL
static HHOOK s_hcbtHook = 0
static WindowSet s_pretranslate_windows
static WindowSet s_dialogs

Detailed Description

Class Window is the base class for several C++ window wrapper classes.

Window objects are allocated from the heap. They are automatically freed when the window gets destroyed.

Definition at line 58 of file window.h.


Member Typedef Documentation

Definition at line 66 of file window.h.

typedef Window*(* Window::CREATORFUNC_INFO)(HWND, const void *)

Definition at line 67 of file window.h.

Definition at line 64 of file window.h.


Constructor & Destructor Documentation

Window::Window ( HWND  hwnd )

Definition at line 74 of file window.cpp.

References WindowHandle::_hwnd, GetStaticWindowData(), and s_wnd_map.

 :  WindowHandle(hwnd)
{
    Lock lock(GetStaticWindowData()._map_crit_sect);    // protect access to s_wnd_map

    s_wnd_map[_hwnd] = this;
}

Here is the call graph for this function:

Window::~Window (  ) [virtual]

Definition at line 82 of file window.cpp.

References WindowHandle::_hwnd, GetStaticWindowData(), and s_wnd_map.

{
    Lock lock(GetStaticWindowData()._map_crit_sect);    // protect access to s_wnd_map

    s_wnd_map.erase(_hwnd);
}

Here is the call graph for this function:


Member Function Documentation

void Window::CancelModes (  ) [static]

Reimplemented in NotifyArea.

Definition at line 298 of file window.cpp.

{
    PostMessage(HWND_BROADCAST, WM_CANCELMODE, 0, 0);
}
int Window::Command ( int  id,
int  code 
) [protected, virtual]
HWND Window::Create ( CREATORFUNC_INFO  creator,
const void *  info,
DWORD  dwExStyle,
LPCTSTR  lpClassName,
LPCTSTR  lpWindowName,
DWORD  dwStyle,
int  x,
int  y,
int  w,
int  h,
HWND  hwndParent = 0,
HMENU  hMenu = 0 
) [static]

Definition at line 105 of file window.cpp.

References ExplorerGlobals::_hInstance, g_Globals, GetStaticWindowData(), s_new_info, and s_window_creator.

{
    Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info

    s_window_creator = (CREATORFUNC) creator;
    s_new_info = info;

    return CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle,
                            x, y, w, h,
                            hwndParent, hMenu, g_Globals._hInstance, 0/*lpParam*/);
}

Here is the call graph for this function:

HWND Window::Create ( CREATORFUNC  creator,
DWORD  dwExStyle,
LPCTSTR  lpClassName,
LPCTSTR  lpWindowName,
DWORD  dwStyle,
int  x,
int  y,
int  w,
int  h,
HWND  hwndParent = 0,
HMENU  hMenu = 0 
) [static]

Definition at line 90 of file window.cpp.

References ExplorerGlobals::_hInstance, g_Globals, GetStaticWindowData(), s_new_info, and s_window_creator.

Referenced by MDIShellBrowserChild::WndProc().

{
    Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info

    s_window_creator = creator;
    s_new_info = NULL;

    return CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle,
                            x, y, w, h,
                            hwndParent, hMenu, g_Globals._hInstance, 0/*lpParam*/);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Window * Window::create_controller ( HWND  hwnd ) [static, protected]

create controller for a new window

Definition at line 223 of file window.cpp.

References GetStaticWindowData(), s_new_info, and s_window_creator.

Referenced by DialogProc(), MDICBTHookProc(), PropSheetCBTHookProc(), and WindowWndProc().

{
    if (s_window_creator) { // protect for recursion and create the window object only for the first window
        Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info

        const void* info = s_new_info;
        s_new_info = NULL;

        CREATORFUNC window_creator = s_window_creator;
        s_window_creator = NULL;

        if (info)
            return CREATORFUNC_INFO(window_creator)(hwnd, info);
        else
            return CREATORFUNC(window_creator)(hwnd);
    }

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Window * Window::create_mdi_child ( const ChildWndInfo info,
const MDICREATESTRUCT &  mcs,
CREATORFUNC_INFO  creator 
) [static]

Definition at line 121 of file window.cpp.

References ChildWndInfo::_hmdiclient, WindowHandle::_hwnd, get_window(), GetStaticWindowData(), HWND, MDICBTHookProc(), s_hcbtHook, s_new_info, and s_window_creator.

Referenced by ChildWindow::create(), and FileChildWindow::create().

{
    Lock lock(GetStaticWindowData()._create_crit_sect); // protect access to s_window_creator and s_new_info

    s_window_creator = (CREATORFUNC) creator;
    s_new_info = &info;

    s_hcbtHook = SetWindowsHookEx(WH_CBT, MDICBTHookProc, 0, GetCurrentThreadId());

    HWND hwnd = (HWND) SendMessage(info._hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);

     // end hook in case it's not already done
    if (s_hcbtHook)
        UnhookWindowsHookEx(s_hcbtHook);

    Window* child = get_window(hwnd);
    s_new_info = NULL;

    if (child && (!hwnd || !child->_hwnd))
        child = NULL;

    return child;
}

Here is the call graph for this function:

Here is the caller graph for this function:

INT_PTR CALLBACK Window::DialogProc ( HWND  hwnd,
UINT  nmsg,
WPARAM  wparam,
LPARAM  lparam 
) [static]

Reimplemented in PropSheetPageDlg.

Definition at line 720 of file window.cpp.

References Command(), create_controller(), get_window(), Init(), NFR_CURRENT, Notify(), and WndProc().

Referenced by Dialog::DoModal().

{
    Window* pThis = get_window(hwnd);

    if (pThis) {
        switch(nmsg) {
          case WM_COMMAND:
            pThis->Command(LOWORD(wparam), HIWORD(wparam));
            return TRUE;    // message has been processed

          case WM_NOTIFY:
            pThis->Notify(wparam, (NMHDR*)lparam);
            return TRUE;    // message has been processed

          case WM_NOTIFYFORMAT:
            SetWindowLong(hwnd, DWLP_MSGRESULT, NFR_CURRENT);   // set return value NFR_CURRENT
            return TRUE;    // message has been processed

          case WM_NCDESTROY:
            delete pThis;
            return TRUE;    // message has been processed

          default:
            return pThis->WndProc(nmsg, wparam, lparam);
        }
    } else if (nmsg == WM_INITDIALOG) {
        pThis = create_controller(hwnd);

        if (pThis)
            return pThis->Init(NULL);
    }

    return FALSE;   // message has not been processed
}

Here is the call graph for this function:

Here is the caller graph for this function:

static BOOL Window::dispatch_dialog_msg ( LPMSG  pmsg ) [static]

Referenced by PropertySheetDialog::DoModal(), MessageLoop(), and StartMenuRoot::TrackStartmenu().

Here is the caller graph for this function:

Window * Window::get_window ( HWND  hwnd ) [static]

get window controller from window handle

Definition at line 206 of file window.cpp.

References GetStaticWindowData(), and s_wnd_map.

Referenced by create_mdi_child(), DialogProc(), MDICBTHookProc(), PropSheetCBTHookProc(), and WindowWndProc().

{
    {
        Lock lock(GetStaticWindowData()._map_crit_sect);    // protect access to s_wnd_map

        WindowMap::const_iterator found = s_wnd_map.find(hwnd);

        if (found!=s_wnd_map.end())
            return found->second;
    }

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename CLASS >
static CLASS* Window::get_window ( HWND  hwnd ) [inline, static]

Definition at line 87 of file window.h.

References get_window().

Referenced by get_window().

{return static_cast<CLASS*>(get_window(hwnd));}

Here is the call graph for this function:

Here is the caller graph for this function:

Window::StaticWindowData & Window::GetStaticWindowData (  ) [static, protected]

Definition at line 66 of file window.cpp.

Referenced by Create(), create_controller(), create_mdi_child(), Dialog::DoModal(), get_window(), Window(), and ~Window().

{
    static StaticWindowData s_initialized_data;

    return s_initialized_data;
}

Here is the caller graph for this function:

LRESULT Window::Init ( LPCREATESTRUCT  pcs ) [protected, virtual]
LRESULT CALLBACK Window::MDICBTHookProc ( int  code,
WPARAM  wparam,
LPARAM  lparam 
) [static, protected]

Definition at line 145 of file window.cpp.

References create_controller(), get_window(), HWND, and s_hcbtHook.

Referenced by create_mdi_child().

{
    if (code == HCBT_CREATEWND) {
        UnhookWindowsHookEx(s_hcbtHook);    // use the hook only for the first created window
        s_hcbtHook = 0;

        HWND hwnd = (HWND)wparam;

         // create Window controller and associate it with the window handle
        Window* child = get_window(hwnd);

        if (!child)
            child = create_controller(hwnd);
    }

    return CallNextHookEx(s_hcbtHook, code, wparam, lparam);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int Window::MessageLoop (  ) [static]

Definition at line 624 of file window.cpp.

References dispatch_dialog_msg(), HandleException(), and pretranslate_msg().

Referenced by explorer_main().

{
    MSG msg;

    while(GetMessage(&msg, 0, 0, 0)) {
        try {
            if (pretranslate_msg(&msg))
                continue;

            if (dispatch_dialog_msg(&msg))
                continue;

            TranslateMessage(&msg);

            try {
                DispatchMessage(&msg);
            } catch(COMException& e) {
                HandleException(e, 0);
            }
        } catch(COMException& e) {
            HandleException(e, 0);
        }
    }

    return msg.wParam;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int Window::Notify ( int  id,
NMHDR *  pnmh 
) [protected, virtual]
LRESULT Window::PostParent ( UINT  nmsg,
WPARAM  wparam = 0,
LPARAM  lparam = 0 
)

Definition at line 662 of file window.cpp.

References WindowHandle::_hwnd, and HWND.

{
    HWND parent = GetParent(_hwnd);

    if (!parent)
        return 0;

    return PostMessage(parent, nmsg, wparam, lparam);
}
BOOL Window::pretranslate_msg ( LPMSG  pmsg ) [static]

Definition at line 592 of file window.cpp.

References PM_TRANSLATE_MSG, and s_pretranslate_windows.

Referenced by PropertySheetDialog::DoModal(), MessageLoop(), and StartMenuRoot::TrackStartmenu().

{
    for(WindowSet::const_iterator it=Window::s_pretranslate_windows.begin(); it!=s_pretranslate_windows.end(); ++it)
        if (SendMessage(*it, PM_TRANSLATE_MSG, 0, (LPARAM)pmsg))
            return TRUE;

    return FALSE;
}

Here is the caller graph for this function:

LRESULT CALLBACK Window::PropSheetCBTHookProc ( int  code,
WPARAM  wparam,
LPARAM  lparam 
) [static, protected]

Definition at line 188 of file window.cpp.

References create_controller(), get_window(), HWND, and s_hcbtHook.

{
    if (code == HCBT_CREATEWND) {
        HWND hwnd = (HWND)wparam;

         // create Window controller and associate it with the window handle
        Window* child = get_window(hwnd);

        if (!child)
            child = create_controller(hwnd);
    }

    return CallNextHookEx(s_hcbtHook, code, wparam, lparam);
}

Here is the call graph for this function:

void Window::register_dialog ( HWND  hwnd ) [static]

Definition at line 604 of file window.cpp.

References s_dialogs.

Referenced by Dialog::Dialog(), and DialogWindow::DialogWindow().

{
    s_dialogs.insert(hwnd);
}

Here is the caller graph for this function:

void Window::register_pretranslate ( HWND  hwnd ) [static]

Definition at line 582 of file window.cpp.

References s_pretranslate_windows.

Referenced by FindProgramDlg::FindProgramDlg(), PreTranslateWindow::PreTranslateWindow(), and TrayNotifyDlg::TrayNotifyDlg().

{
    s_pretranslate_windows.insert(hwnd);
}

Here is the caller graph for this function:

LRESULT Window::SendParent ( UINT  nmsg,
WPARAM  wparam = 0,
LPARAM  lparam = 0 
)

Definition at line 652 of file window.cpp.

References WindowHandle::_hwnd, and HWND.

Referenced by StartMenu::CloseStartMenu(), NotifyArea::Command(), StartMenu::WndProc(), and StartMenu::~StartMenu().

{
    HWND parent = GetParent(_hwnd);

    if (!parent)
        return 0;

    return SendMessage(parent, nmsg, wparam, lparam);
}

Here is the caller graph for this function:

void Window::unregister_dialog ( HWND  hwnd ) [static]

Definition at line 609 of file window.cpp.

References s_dialogs.

Referenced by Dialog::~Dialog(), and DialogWindow::~DialogWindow().

{
    s_dialogs.erase(hwnd);
}

Here is the caller graph for this function:

void Window::unregister_pretranslate ( HWND  hwnd ) [static]

Definition at line 587 of file window.cpp.

References s_pretranslate_windows.

Referenced by FindProgramDlg::~FindProgramDlg(), PreTranslateWindow::~PreTranslateWindow(), and TrayNotifyDlg::~TrayNotifyDlg().

{
    s_pretranslate_windows.erase(hwnd);
}

Here is the caller graph for this function:

LRESULT CALLBACK Window::WindowWndProc ( HWND  hwnd,
UINT  nmsg,
WPARAM  wparam,
LPARAM  lparam 
) [static]

Definition at line 250 of file window.cpp.

References Command(), create_controller(), get_window(), Init(), NFR_CURRENT, Notify(), and WndProc().

{
    Window* pThis = get_window(hwnd);

    if (!pThis)
        pThis = create_controller(hwnd);

    if (pThis) {
        switch(nmsg) {
          case WM_COMMAND:
            return pThis->Command(LOWORD(wparam), HIWORD(wparam));

          case WM_NOTIFY:
            return pThis->Notify(wparam, (NMHDR*)lparam);

          case WM_NOTIFYFORMAT:
            return NFR_CURRENT;

          case WM_CREATE:
            return pThis->Init((LPCREATESTRUCT)lparam);

          case WM_NCDESTROY:
            delete pThis;
            return 0;

          default:
            return pThis->WndProc(nmsg, wparam, lparam);
        }
    }
    else
        return DefWindowProc(hwnd, nmsg, wparam, lparam);
}

Here is the call graph for this function:

LRESULT Window::WndProc ( UINT  nmsg,
WPARAM  wparam,
LPARAM  lparam 
) [protected, virtual]

Member Data Documentation

WindowSet Window::s_dialogs [static, protected]

Definition at line 138 of file window.h.

Referenced by register_dialog(), and unregister_dialog().

HHOOK Window::s_hcbtHook = 0 [static, protected]

Definition at line 133 of file window.h.

Referenced by create_mdi_child(), MDICBTHookProc(), and PropSheetCBTHookProc().

const void * Window::s_new_info = NULL [static, protected]

Definition at line 119 of file window.h.

Referenced by Create(), create_controller(), create_mdi_child(), and Dialog::DoModal().

Definition at line 137 of file window.h.

Referenced by pretranslate_msg(), register_pretranslate(), and unregister_pretranslate().

Window::CREATORFUNC Window::s_window_creator = NULL [static, protected]

Definition at line 120 of file window.h.

Referenced by Create(), create_controller(), create_mdi_child(), and Dialog::DoModal().

Window::WindowMap Window::s_wnd_map [static, protected]

Definition at line 117 of file window.h.

Referenced by get_window(), Window(), and ~Window().


The documentation for this struct was generated from the following files:

ROS Explorer Source Code Documentation
generated on 02.01.2013 by doxygen

ROS Explorer Homepage