log off button in start menu

svn path=/trunk/; revision=5626
This commit is contained in:
Martin Fuchs 2003-08-17 23:14:23 +00:00
parent 54a2b50917
commit b5aac7eb36
20 changed files with 407 additions and 110 deletions

View file

@ -29,6 +29,7 @@
#include "desktop.h"
#include "../externals.h"
#include "../explorer_intres.h"
static BOOL (WINAPI*SetShellWindow)(HWND);
@ -118,7 +119,8 @@ DesktopWindow::~DesktopWindow()
LRESULT DesktopWindow::Init(LPCREATESTRUCT pcs)
{
super::Init(pcs);
if (super::Init(pcs))
return 1;
HRESULT hr = Desktop()->CreateViewObject(_hwnd, IID_IShellView, (void**)&_pShellView);
/* also possible:
@ -230,17 +232,13 @@ LRESULT DesktopWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
HWND create_desktop_window(HINSTANCE hInstance)
{
WindowClass wcDesktop(_T("Progman"), CS_DBLCLKS);
IconWindowClass wcDesktop(_T("Progman"), IDI_REACTOS, CS_DBLCLKS);
wcDesktop.hbrBackground = (HBRUSH)(COLOR_BACKGROUND+1);
wcDesktop.hIcon = LoadIcon(0, IDI_APPLICATION);
ATOM desktopClass = wcDesktop.Register();
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
return Window::Create(WINDOW_CREATOR(DesktopWindow),
WS_EX_TOOLWINDOW, (LPCTSTR)(int)desktopClass, _T("Program Manager"), WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN,
WS_EX_TOOLWINDOW, (LPCTSTR)(int)wcDesktop.Register(), _T("Program Manager"), WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN,
0, 0, width, height, 0);
}

View file

@ -62,6 +62,17 @@ ResString::ResString(UINT nid)
}
ResIcon::ResIcon(UINT nid)
{
_hicon = LoadIcon(g_Globals._hInstance, MAKEINTRESOURCE(nid));
}
SmallIcon::SmallIcon(UINT nid)
{
_hicon = (HICON)LoadImage(g_Globals._hInstance, MAKEINTRESOURCE(nid), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
}
void explorer_show_frame(HWND hwndDesktop, int cmdshow)
{
if (g_Globals._hMainWnd)
@ -90,28 +101,15 @@ static void InitInstance(HINSTANCE hInstance)
{
setlocale(LC_COLLATE, ""); // set collating rules to local settings for compareName
// register frame window class
WindowClass wcFrame(CLASSNAME_FRAME);
wcFrame.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EXPLORER));
wcFrame.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_EXPLORER),
IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
g_Globals._hframeClass = wcFrame.Register();
g_Globals._hframeClass = IconWindowClass(CLASSNAME_FRAME,IDI_EXPLORER).Register();
// register child windows class
WindowClass(CLASSNAME_CHILDWND, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
// register tree windows class
WindowClass(CLASSNAME_WINEFILETREE, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
g_Globals._cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
}
@ -125,8 +123,6 @@ int explorer_main(HINSTANCE hInstance, HWND hwndDesktop, int cmdshow)
CommonControlInit usingCmnCtrl(ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES|ICC_BAR_CLASSES);
try {
MSG msg;
InitInstance(hInstance);
if (hwndDesktop)
@ -142,21 +138,7 @@ int explorer_main(HINSTANCE hInstance, HWND hwndDesktop, int cmdshow)
explorer_show_frame(hwndDesktop, cmdshow);
}
while(GetMessage(&msg, 0, 0, 0)) {
if (g_Globals._hMainWnd && SendMessage(g_Globals._hMainWnd, WM_TRANSLATE_MSG, 0, (LPARAM)&msg))
continue;
TranslateMessage(&msg);
try {
DispatchMessage(&msg);
} catch(COMException& e) {
HandleException(e, g_Globals._hMainWnd);
}
}
return msg.wParam;
return Window::MessageLoop();
} catch(COMException& e) {
HandleException(e, g_Globals._hMainWnd);
}

View file

@ -401,6 +401,14 @@ SOURCE=.\globals.h
# End Source File
# Begin Source File
SOURCE=.\res\icon1.ico
# End Source File
# Begin Source File
SOURCE=.\res\logoff.ico
# End Source File
# Begin Source File
SOURCE=.\shell\mainframe.cpp
# End Source File
# Begin Source File
@ -417,6 +425,10 @@ SOURCE=.\shell\pane.h
# End Source File
# Begin Source File
SOURCE=.\res\reactos.ico
# End Source File
# Begin Source File
SOURCE=.\shell\shellbrowser.cpp
# End Source File
# Begin Source File

View file

@ -41,7 +41,6 @@
#define IDW_FIRST_CHILD 0xC000 /*0x200*/
#define WM_TRANSLATE_MSG (WM_APP+0x02)
#define WM_GET_FILEWND_PTR (WM_APP+0x03)
#define FRM_CALC_CLIENT (WM_APP+0x04)
@ -58,12 +57,6 @@
#define CLASSNAME_WINEFILETREE TEXT("WFS_Tree")
struct ResString : public String
{
ResString(UINT nid);
};
#include "shell/mainframe.h"
#include "shell/pane.h"
#include "shell/filechild.h"

View file

@ -3,19 +3,22 @@
// Used by explorer_intres.rc
//
#define IDS_TITLE 1
#define IDI_EXPLORER 100
#define IDB_TOOLBAR 101
#define IDA_EXPLORER 101
#define ID_ACTIVATE 101
#define IDB_DRIVEBAR 102
#define IDB_IMAGES 103
#define IDD_EXECUTE 103
#define IDR_MAINFRAME 104
#define IDM_MAINFRAME 105
#define ID_EXECUTE 105
#define IDM_WINEFILE 107
#define IDB_STARTMENU 120
#define IDI_STARTMENU 121
#define IDS_START 2
#define IDS_LOGOFF 3
#define IDI_REACTOS 100
#define IDI_EXPLORER 101
#define IDI_STARTMENU 102
#define IDB_TOOLBAR 103
#define IDA_EXPLORER 104
#define ID_ACTIVATE 105
#define IDB_DRIVEBAR 106
#define IDB_IMAGES 107
#define IDD_EXECUTE 108
#define IDR_MAINFRAME 109
#define IDM_MAINFRAME 110
#define ID_EXECUTE 111
#define IDM_WINEFILE 112
#define IDI_LOGOFF 124
#define ID_VIEW_NAME 401
#define ID_VIEW_ALL_ATTRIBUTES 402
#define ID_VIEW_SELECTED_ATTRIBUTES 403
@ -47,7 +50,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 122
#define _APS_NEXT_RESOURCE_VALUE 125
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101

View file

@ -90,8 +90,10 @@ END
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_REACTOS ICON DISCARDABLE "res/reactos.ico"
IDI_EXPLORER ICON DISCARDABLE "res/explorer.ico"
IDI_STARTMENU ICON DISCARDABLE "res/startmenu.ico"
IDI_LOGOFF ICON DISCARDABLE "res/logoff.ico"
/////////////////////////////////////////////////////////////////////////////
//
@ -117,7 +119,7 @@ BEGIN
MENUITEM "&Drucken...", 102
MENUITEM "Zuord&nen...", 103
MENUITEM SEPARATOR
MENUITEM "Ver&zeichnis erstellen...", 111
MENUITEM "Ver&zeichnis erstellen...", ID_EXECUTE
MENUITEM "&Suchen...", 104
MENUITEM "Dateien aus&wählen...", 116
MENUITEM SEPARATOR
@ -238,6 +240,8 @@ END
STRINGTABLE DISCARDABLE
BEGIN
IDS_TITLE "Reactos Explorer"
IDS_START "Start"
IDS_LOGOFF "Logoff"
END
#endif // German (Germany) resources
@ -304,7 +308,7 @@ BEGIN
MENUITEM "&Print...", 102
MENUITEM "Associate...", 103
MENUITEM SEPARATOR
MENUITEM "Cr&eate Directory...", 111
MENUITEM "Cr&eate Directory...", ID_EXECUTE
MENUITEM "Searc&h...", 104
MENUITEM "&Select Files...", 116
MENUITEM SEPARATOR

View file

@ -38,3 +38,28 @@ extern struct ExplorerGlobals
bool _desktop_mode;
} g_Globals;
struct ResString : public String
{
ResString(UINT nid);
};
struct ResIcon
{
ResIcon(UINT nid);
operator HICON() const {return _hicon;}
protected:
HICON _hicon;
};
struct SmallIcon
{
SmallIcon(UINT nid);
operator HICON() const {return _hicon;}
protected:
HICON _hicon;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View file

@ -475,7 +475,7 @@ int FileChildWindow::Notify(int id, NMHDR* pnmh)
}
BOOL CALLBACK ExecuteDialog::WndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
BOOL CALLBACK ExecuteDialog::WndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
{
static struct ExecuteDialog* dlg;

View file

@ -88,9 +88,9 @@ public:
};
struct ExecuteDialog { // TODO: integrate with Window class
struct ExecuteDialog { // TODO: integrate dialogs with Window class
TCHAR cmd[MAX_PATH];
int cmdshow;
static BOOL CALLBACK WndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
static BOOL CALLBACK WndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
};

View file

@ -36,7 +36,7 @@
MainFrame::MainFrame(HWND hwnd)
: Window(hwnd)
: super(hwnd)
{
_hMenuFrame = GetMenu(hwnd);
_hMenuWindow = GetSubMenu(_hMenuFrame, GetMenuItemCount(_hMenuFrame)-2);
@ -322,7 +322,7 @@ int MainFrame::Command(int id, int code)
case ID_EXECUTE: {
ExecuteDialog dlg = {{0}, 0};
if (DialogBoxParam(g_Globals._hInstance, MAKEINTRESOURCE(IDD_EXECUTE), _hwnd, ExecuteDialog::WndProg, (LPARAM)&dlg) == IDOK) {
if (DialogBoxParam(g_Globals._hInstance, MAKEINTRESOURCE(IDD_EXECUTE), _hwnd, ExecuteDialog::WndProc, (LPARAM)&dlg) == IDOK) {
HINSTANCE hinst = ShellExecute(_hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
if ((int)hinst <= 32)

View file

@ -26,9 +26,9 @@
//
struct MainFrame : public Window
struct MainFrame : public PreTranslateWindow
{
typedef Window super;
typedef PreTranslateWindow super;
MainFrame(HWND hwnd);
~MainFrame();

View file

@ -73,7 +73,8 @@ ShellBrowserChild::~ShellBrowserChild()
LRESULT ShellBrowserChild::Init(LPCREATESTRUCT pcs)
{
super::Init(pcs);
if (super::Init(pcs))
return 1;
_hWndFrame = GetParent(pcs->hwndParent);

View file

@ -38,16 +38,15 @@
#define IDC_START 0x1000
#define IDC_LOGOFF 0x1001
#define IDC_FIRST_APP 0x2000
#define IDC_FIRST_MENU 0x3000
HWND InitializeExplorerBar(HINSTANCE hInstance)
{
RECT rect;
WindowClass wcExplorerBar(CLASSNAME_EXPLORERBAR);
wcExplorerBar.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
rect.left = -2; // hide left border
#ifdef TASKBAR_AT_TOP
rect.top = -2; // hide top border
@ -58,7 +57,8 @@ HWND InitializeExplorerBar(HINSTANCE hInstance)
rect.bottom = rect.top + TASKBAR_HEIGHT + 2;
return Window::Create(WINDOW_CREATOR(DesktopBar), WS_EX_PALETTEWINDOW,
(LPCTSTR)(int)wcExplorerBar.Register(), TITLE_EXPLORERBAR, WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE,
(LPCTSTR)(int)BtnWindowClass(CLASSNAME_EXPLORERBAR).Register(), TITLE_EXPLORERBAR,
WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE,
rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, 0);
}
@ -67,6 +67,7 @@ DesktopBar::DesktopBar(HWND hwnd)
: super(hwnd)
{
_hwndTaskBar = 0;
_hwndStartMenu = 0;
}
DesktopBar::~DesktopBar()
@ -78,19 +79,17 @@ DesktopBar::~DesktopBar()
LRESULT DesktopBar::Init(LPCREATESTRUCT pcs)
{
super::Init(pcs);
if (super::Init(pcs))
return 1;
// create start button
new PictureButton(Button(_hwnd, TEXT("Start"), 2, 2, STARTBUTTON_WIDTH, TASKBAR_HEIGHT-10, IDC_START,
WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_OWNERDRAW),
LoadIcon(g_Globals._hInstance, MAKEINTRESOURCE(IDI_STARTMENU)));
new PictureButton(Button(_hwnd, ResString(IDS_START), 2, 2, STARTBUTTON_WIDTH, TASKBAR_HEIGHT-8, IDC_START,
WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_OWNERDRAW),
ResIcon(IDI_STARTMENU));
// create task bar
WindowClass wcTaskBar(CLASSNAME_TASKBAR);
wcTaskBar.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
_hwndTaskBar = Window::Create(WINDOW_CREATOR(TaskBar), 0,
(LPCTSTR)(int)wcTaskBar.Register(), TITLE_TASKBAR, WS_CHILD|WS_VISIBLE,
(LPCTSTR)(int)BtnWindowClass(CLASSNAME_TASKBAR).Register(), TITLE_TASKBAR, WS_CHILD|WS_VISIBLE,
TASKBAR_LEFT, 0, ClientRect(_hwnd).right-TASKBAR_LEFT, TASKBAR_HEIGHT, _hwnd);
TaskBar* taskbar = static_cast<TaskBar*>(Window::get_window(_hwndTaskBar));
@ -101,6 +100,19 @@ LRESULT DesktopBar::Init(LPCREATESTRUCT pcs)
}
void DesktopBar::create_startmenu()
{
WindowRect my_pos(_hwnd);
static BtnWindowClass wcStartMenu(CLASSNAME_STARTMENU);
_hwndStartMenu = Window::Create(WINDOW_CREATOR(StartMenu), 0,
(LPCTSTR)(int)wcStartMenu.Register(), TITLE_STARTMENU,
WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN|WS_VISIBLE,
my_pos.left, my_pos.top-STARTMENU_HEIGHT, STARTMENU_WIDTH, STARTMENU_HEIGHT, _hwnd);
}
LRESULT DesktopBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
{
switch(nmsg) {
@ -149,8 +161,11 @@ LRESULT DesktopBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
int DesktopBar::Command(int id, int code)
{
if (id == IDC_START)
DestroyWindow(_hwnd);
switch(id) {
case IDC_START:
create_startmenu();
break;
}
return 0;
}
@ -199,7 +214,6 @@ static HBITMAP create_bitmap_from_icon(HICON hicon, HWND hwnd, HBRUSH hbrush_bkg
}
TaskBarEntry::TaskBarEntry()
{
_id = 0;
@ -234,7 +248,8 @@ TaskBar::~TaskBar()
LRESULT TaskBar::Init(LPCREATESTRUCT pcs)
{
super::Init(pcs);
if (super::Init(pcs))
return 1;
_htoolbar = CreateToolbarEx(_hwnd,
WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_TOP|
@ -289,7 +304,7 @@ LRESULT TaskBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
return super::WndProc(nmsg, wparam, lparam);
}
return super::WndProc(nmsg, wparam, lparam);
return 0;
}
int TaskBar::Command(int id, int code)
@ -458,3 +473,56 @@ TaskBarMap::iterator TaskBarMap::find_id(int id)
return end();
}
StartMenu::StartMenu(HWND hwnd)
: super(hwnd)
{
}
StartMenu::~StartMenu()
{
}
LRESULT StartMenu::Init(LPCREATESTRUCT pcs)
{
if (super::Init(pcs))
return 1;
ClientRect clnt(_hwnd);
SetWindowFont(*new PictureButton(Button(_hwnd, ResString(IDS_LOGOFF), 2, clnt.bottom-STARTMENU_LINE_HEIGHT, clnt.right-2, STARTMENU_LINE_HEIGHT,
IDC_LOGOFF, WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_OWNERDRAW),
ResIcon(IDI_LOGOFF)),
GetStockFont(DEFAULT_GUI_FONT), FALSE);
return 0;
}
LRESULT StartMenu::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
{
/*@@
switch(nmsg) {
default:
return super::WndProc(nmsg, wparam, lparam);
}
return 0;
*/
return super::WndProc(nmsg, wparam, lparam);
}
int StartMenu::Command(int id, int code)
{
switch(id) {
case IDC_LOGOFF:
DestroyWindow(GetParent(_hwnd));
break;
case IDCANCEL:
DestroyWindow(_hwnd);
break;
}
return super::Command(id, code);
}

View file

@ -28,15 +28,16 @@
//#include "shellhook.h"
#include <map>
#include <set>
#define TASKBAR_HEIGHT 30
#define STARTBUTTON_WIDTH 90
#define TASKBAR_LEFT 100
#define TASKBAR_HEIGHT 30
#define STARTBUTTON_WIDTH 60
#define TASKBAR_LEFT 70
//#define TASKBAR_AT_TOP
#define STARTMENU_WIDTH 150
#define STARTMENU_HEIGHT 400
#define STARTMENU_LINE_HEIGHT 30
#define WM_SHELLHOOK_NOTIFY (WM_APP+0x10)
@ -46,6 +47,9 @@
#define CLASSNAME_TASKBAR _T("MSTaskSwWClass")
#define TITLE_TASKBAR _T("Running Applications")
#define CLASSNAME_STARTMENU _T("ReactosStartmenuClass")
#define TITLE_STARTMENU _T("Start Menu")
struct DesktopBar : public OwnerDrawParent<Window>
{
@ -59,7 +63,10 @@ protected:
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
int Command(int id, int code);
void create_startmenu();
HWND _hwndTaskBar;
HWND _hwndStartMenu;
};
@ -90,7 +97,7 @@ struct TaskBar : public Window
typedef Window super;
TaskBar(HWND hwnd);
TaskBar::~TaskBar();
~TaskBar();
DesktopBar* _desktop_bar;
@ -108,3 +115,16 @@ protected:
void Refresh();
};
struct StartMenu : public OwnerDrawParent<Dialog>
{
typedef OwnerDrawParent<Dialog> super;
StartMenu(HWND hwnd);
~StartMenu();
protected:
LRESULT Init(LPCREATESTRUCT pcs);
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
int Command(int id, int code);
};

View file

@ -108,6 +108,14 @@ struct ClientRect : public RECT
}
};
struct WindowRect : public RECT
{
WindowRect(HWND hwnd)
{
GetWindowRect(hwnd, this);
}
};
struct TextColor
{

View file

@ -27,6 +27,7 @@
#include "utility.h"
#include "shellclasses.h"
#include "window.h"
#include "../globals.h"
@ -43,6 +44,16 @@ WindowClass::WindowClass(LPCTSTR classname, UINT style_, WNDPROC wndproc)
lpszClassName = classname;
lpfnWndProc = wndproc;
_atomClass = 0;
}
IconWindowClass::IconWindowClass(LPCTSTR classname, UINT nid, UINT style, WNDPROC wndproc)
: WindowClass(classname, style, wndproc)
{
hIcon = ResIcon(nid);
hIconSm = SmallIcon(nid);
}
@ -51,8 +62,8 @@ Window::WINDOWCREATORFUNC Window::s_window_creator = NULL;
const void* Window::s_new_info = NULL;
HWND Window::Create(WINDOWCREATORFUNC creator,
DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
HWND Window::Create(WINDOWCREATORFUNC creator, DWORD dwExStyle,
LPCTSTR lpClassName, LPCTSTR lpWindowName,
DWORD dwStyle, int x, int y, int w, int h,
HWND hwndParent, HMENU hMenu, LPVOID lpParam)
{
@ -64,8 +75,8 @@ HWND Window::Create(WINDOWCREATORFUNC creator,
hwndParent, hMenu, g_Globals._hInstance, 0/*lpParam*/);
}
HWND Window::Create(WINDOWCREATORFUNC creator, const void* info,
DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
HWND Window::Create(WINDOWCREATORFUNC creator, const void* info, DWORD dwExStyle,
LPCTSTR lpClassName, LPCTSTR lpWindowName,
DWORD dwStyle, int x, int y, int w, int h,
HWND hwndParent, HMENU hMenu, LPVOID lpParam)
{
@ -190,7 +201,7 @@ int Window::Notify(int id, NMHDR* pnmh)
SubclassedWindow::SubclassedWindow(HWND hwnd)
: Window(hwnd)
: super(hwnd)
{
_orgWndProc = SubclassWindow(_hwnd, WindowWndProc);
@ -205,7 +216,7 @@ LRESULT SubclassedWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
ChildWindow::ChildWindow(HWND hwnd)
: Window(hwnd)
: super(hwnd)
{
_left_hwnd = 0;
_right_hwnd = 0;
@ -356,6 +367,98 @@ void ChildWindow::resize_children(int cx, int cy)
}
WindowSet Window::s_pretranslate_windows;
void Window::register_pretranslate(HWND hwnd)
{
s_pretranslate_windows.insert(hwnd);
}
void Window::unregister_pretranslate(HWND hwnd)
{
s_pretranslate_windows.erase(hwnd);
}
BOOL Window::pretranslate_msg(LPMSG pmsg)
{
for(WindowSet::const_iterator it=Window::s_pretranslate_windows.begin(); it!=s_pretranslate_windows.end(); ++it)
if (SendMessage(*it, WM_TRANSLATE_MSG, 0, (LPARAM)pmsg))
return TRUE;
return FALSE;
}
WindowSet Window::s_dialogs;
void Window::register_dialog(HWND hwnd)
{
s_dialogs.insert(hwnd);
}
void Window::unregister_dialog(HWND hwnd)
{
s_dialogs.erase(hwnd);
}
BOOL Window::dispatch_dialog_msg(MSG* pmsg)
{
for(WindowSet::const_iterator it=Window::s_dialogs.begin(); it!=s_dialogs.end(); ++it)
if (IsDialogMessage(*it, pmsg))
return TRUE;
return FALSE;
}
PreTranslateWindow::PreTranslateWindow(HWND hwnd)
: super(hwnd)
{
register_pretranslate(hwnd);
}
PreTranslateWindow::~PreTranslateWindow()
{
unregister_pretranslate(_hwnd);
}
Dialog::Dialog(HWND hwnd)
: super(hwnd)
{
register_dialog(hwnd);
}
Dialog::~Dialog()
{
unregister_dialog(_hwnd);
}
int Window::MessageLoop()
{
MSG msg;
while(GetMessage(&msg, 0, 0, 0)) {
if (pretranslate_msg(&msg))
continue;
if (dispatch_dialog_msg(&msg))
continue;
TranslateMessage(&msg);
try {
DispatchMessage(&msg);
} catch(COMException& e) {
HandleException(e, g_Globals._hMainWnd);
}
}
return msg.wParam;
}
Button::Button(HWND parent, LPCTSTR text, int left, int top, int width, int height,
UINT id, DWORD flags, DWORD ex_flags)
{
@ -452,8 +555,8 @@ LRESULT PictureButton::WndProc(UINT message, WPARAM wparam, LPARAM lparam)
if (dis->itemState & ODS_DISABLED)
style |= DFCS_INACTIVE;
POINT iconPos = {dis->rcItem.left+2, dis->rcItem.top+2};
RECT textRect = {dis->rcItem.left+2, dis->rcItem.top+2, dis->rcItem.right-4, dis->rcItem.bottom-4};
POINT iconPos = {dis->rcItem.left+2, (dis->rcItem.top+dis->rcItem.bottom-16)/2};
RECT textRect = {dis->rcItem.left+16+2, dis->rcItem.top+2, dis->rcItem.right-4, dis->rcItem.bottom-4};
if (dis->itemState & ODS_SELECTED) {
style |= DFCS_PUSHED;

View file

@ -26,6 +26,13 @@
//
#include <map>
#include <set>
typedef set<HWND> WindowSet;
struct Window
{
Window(HWND hwnd)
@ -45,8 +52,8 @@ struct Window
typedef Window* (*WINDOWCREATORFUNC)(HWND, const void*);
static HWND Create(WINDOWCREATORFUNC creator,
DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
static HWND Create(WINDOWCREATORFUNC creator, DWORD dwExStyle,
LPCTSTR lpClassName, LPCTSTR lpWindowName,
DWORD dwStyle, int x, int y, int w, int h,
HWND hwndParent=0, HMENU hMenu=0, LPVOID lpParam=0);
@ -61,6 +68,17 @@ struct Window
static Window* 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();
protected:
HWND _hwnd;
@ -77,11 +95,16 @@ protected:
// MDI child creation
static HHOOK s_hcbtHook;
static LRESULT CALLBACK CBTHookProc(int code, WPARAM wparam, LPARAM lparam);
static WindowSet s_pretranslate_windows;
static WindowSet s_dialogs;
};
struct SubclassedWindow : public Window
{
typedef Window super;
SubclassedWindow(HWND);
protected:
@ -121,12 +144,37 @@ struct WindowClass : public WNDCLASSEX
ATOM Register()
{
return RegisterClassEx(this);
if (!_atomClass)
_atomClass = RegisterClassEx(this);
return _atomClass;
}
operator ATOM() const {return _atomClass;}
protected:
ATOM _atomClass;
};
// window class with gray background color
struct BtnWindowClass : public WindowClass
{
BtnWindowClass(LPCTSTR classname, UINT style=0, WNDPROC wndproc=Window::WindowWndProc)
: WindowClass(classname, style, wndproc)
{
hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
}
};
// window class with gray background color
struct IconWindowClass : public WindowClass
{
IconWindowClass(LPCTSTR classname, UINT nid, UINT style=0, WNDPROC wndproc=Window::WindowWndProc);
};
#define WM_DISPATCH_COMMAND (WM_APP+0x00)
#define WM_TRANSLATE_MSG (WM_APP+0x01)
#define SPLIT_WIDTH 5
@ -140,7 +188,7 @@ struct MenuInfo
HMENU _hMenuOptions;
};
#define FRM_GET_MENUINFO (WM_APP+0x01)
#define FRM_GET_MENUINFO (WM_APP+0x02)
#define Frame_GetMenuInfo(hwnd) ((MenuInfo*)SNDMSG(hwnd, FRM_GET_MENUINFO, 0, 0))
@ -171,6 +219,25 @@ protected:
};
struct PreTranslateWindow : public Window
{
typedef Window super;
PreTranslateWindow(HWND);
~PreTranslateWindow();
};
struct Dialog : public Window
{
typedef Window super;
Dialog(HWND);
~Dialog();
};
// create button controls
struct Button
{
Button(HWND parent, LPCTSTR text, int left, int top, int width, int height,
@ -183,9 +250,10 @@ protected:
};
// control message routing for colloered and owner drawn controls
/*
// control color message routing for ColorStatic and HyperlinkCtrl
#define WM_DISPATCH_CTLCOLOR (WM_APP+0x07)
#define WM_DISPATCH_DRAWITEM (WM_APP+0x08)
template<typename BASE> struct CtlColorParent : public BASE
{
@ -211,8 +279,13 @@ template<typename BASE> struct CtlColorParent : public BASE
}
}
};
*/
// owner draw message routing for ColorButton and PictureButton
#define WM_DISPATCH_DRAWITEM (WM_APP+0x08)
// for ColorButton and PictureButton
template<typename BASE> struct OwnerDrawParent : public BASE
{
typedef BASE super;
@ -240,6 +313,9 @@ template<typename BASE> struct OwnerDrawParent : public BASE
}
};
// Subclass button controls to paint colored text labels.
// The owning window should use the OwnerDrawParent template to route woner draw messages to the buttons.
struct ColorButton : public SubclassedWindow
{
typedef SubclassedWindow super;
@ -253,6 +329,10 @@ protected:
COLORREF _textColor;
};
// Subclass button controls to paint pictures left to the labels.
// The buttons should have set the style bit BS_OWNERDRAW.
// The owning window should use the OwnerDrawParent template to route woner draw messages to the buttons.
struct PictureButton : public SubclassedWindow
{
typedef SubclassedWindow super;

View file

@ -1462,7 +1462,7 @@ struct ExecuteDialog {
};
static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
static BOOL CALLBACK ExecuteDialogWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
{
static struct ExecuteDialog* dlg;
@ -1755,7 +1755,7 @@ LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam
memset(&dlg, 0, sizeof(struct ExecuteDialog));
if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProc, (LPARAM)&dlg) == IDOK) {
HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
if ((int)hinst <= 32)