📄 dropbar.h
字号:
// DropBar.h
//
// @author christian oetterli
//
#ifndef __DROPBAR_H_
#define __DROPBAR_H_
#include "resource.h"
#include "CmdListener.h"
// special catch handler that displays an error message box.
#define catchItWithMsg catch (com_error &err) { errorMsg(&err); }
/////////////////////////////////////////////////////////////////////////////
// CDropBar
class ATL_NO_VTABLE CDropBar :
public CComObjectRootEx<CComSingleThreadModel>
, public CComCoClass<CDropBar, &CLSID_DropBar>
, public CComControl<CDropBar>
, public IDispatchImpl<IDropBar, &IID_IDropBar>
, public IDeskBand
, public IObjectWithSite
, public IPersistStream
, public IDropTarget
{
public:
CDropBar();
~CDropBar();
// declare own window class.
DECLARE_WND_CLASS(L"com.o3tt3rli.DropBar")
DECLARE_REGISTRY_RESOURCEID(IDR_DROPBAR)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CDropBar)
COM_INTERFACE_ENTRY(IDropTarget)
COM_INTERFACE_ENTRY(IDropBar)
COM_INTERFACE_ENTRY(IDeskBand)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IDockingWindow)
COM_INTERFACE_ENTRY(IObjectWithSite)
COM_INTERFACE_ENTRY(IPersist)
COM_INTERFACE_ENTRY(IPersistStream)
COM_INTERFACE_ENTRY(IOleWindow)
END_COM_MAP()
BEGIN_MSG_MAP(CDropBar)
CHAIN_MSG_MAP(CComControl<CDropBar>)
DEFAULT_REFLECTION_HANDLER()
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
END_MSG_MAP()
// command handlers.
HRESULT OnDraw(ATL_DRAWINFO& di);
LRESULT OnDestroy(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
LRESULT OnContextMenu(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
LRESULT OnMouseLeave(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
LRESULT OnMouseMove(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
LRESULT OnLButtonUp(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
LRESULT OnLButtonDown(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
LRESULT OnEraseBkgnd(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
// called whenever "Customize..." from the context menu is selected.
void onCustomize();
// forward mouse messages to this method.
void onToolsRelayEvent();
protected:
// Drop Bar
static CString NAME;
// creates a com object
// @param progId progId of the object
// @return object
IUnknownPtr createObject(CString progId);
// window that receives WM_COMMAND messages.
CCmdListener cmdListener;
// @return cmdListener.
CCmdListener &getCmdListener();
// site set upon IObjectWithSite::SetSite().
IInputObjectSitePtr site;
// tools for displaying tool tips.
CWindow tools;
// @return tools.
CWindow &getTools();
// notification handle. signaled when a file in users "My Documents" folder has changed.
HANDLE configFileChange;
// set configFileChange.
// @param newConfigFileChange new value.
void setConfigFileChange(HANDLE newConfigFileChange);
// @return configFileChange.
HANDLE getConfigFileChange() const;
// cached icons since last load of config.
CIcons icons;
// @return icons.
CIcons &getIcons();
// index of button that is hovered by the mouse during WM_MOUSEMOVE messages. -1 if none.
int lastButton;
// @return lastButton.
int getLastButton() const;
// sets the last button.
// @param newLastButton new value.
void setLastButton(int newLastButton);
// sets lastButton to -1.
void resetLastButton();
// @return true if button is the last button.
bool isLastButton(int button) const;
// @return true if there is a last button (lastButton != -1).
bool isLastButton() const;
// index of button that is pressed. -1 if none.
int pressedButton;
// @return pressedButton.
int getPressedButton() const;
// sets the pressed button.
// @param newPressedButton new value.
void setPressedButton(int newPressedButton);
// sets presssed button to -1.
void resetPressedButton();
// @return true if button is the pressed button.
bool isPressedButton(int button) const;
// @return true if there is a pressed button (pressedButton != -1).
bool isPressedButton() const;
// true if mouse is over the pressed button during WM_MOUSEMOVE messages.
bool isOverPressedButton;
// @return isOverPressedButton.
bool getIsOverPressedButton() const;
// sets the isOverPressedButton.
// @param newIsOverPressedButton new value.
void setIsOverPressedButton(bool newIsOverPressedButton = true);
// @return minimal height of Drop Bar window.
int minHeight() const;
// Drag points are given in screen coordinates. mouse move messages are given in
// client coordinates. this method converts screen coordinates to client coordinates.
// @param pDrag point in screen coordinates.
// @return point adjusted to client coordinates.
CPoint adjustDragPoint(CPoint pDrag);
// the last data object since DragEnter.
IDataObjectPtr dataObject;
// @return the last data object since DragEnter.
IDataObjectPtr getDataObject() const;
// sets the last data object since DragEnter.
// @param newDataObject new value.
void setDataObject(IDataObjectPtr newDataObject);
// sets the last data object to 0.
void resetDataObject();
// finals.
enum
{
BUTTONIDXTOTOOLID = 1 // add this number to a button index to obtain its tool id.
, DROPBARID = 22 // an id for the window.
, DROPRECTSPACE = 3 // increases a buttons rect with this value to allow a bigger area for droping files.
};
// bounds of buttons.
mutable CRects buttonBounds;
// calculates bounds of buttons.
// @param bounds surrounding bounds of buttons. if 0 the DropBars client rect will be used instead.
// @return vector with bounds of buttons.
const CRects &getButtonBounds() const;
// clears buttonBounds.
void clearButtonBounds();
// add a tool for the buttons.
void addTools();
// delete all tools.
void delTools();
// test over which button a point lies.
// @param p point to test.
// @return index of button over which the point lies or -1 if none.
int hitTestButton(CPoint p) const;
// gets all configured buttons as a node list.
// @return node list of buttons.
IXMLDOMNodeListPtr getButtons() const;
// the config xml document element.
mutable IXMLDOMNodePtr config;
// gets the document element of the config file.
// @return document element.
IXMLDOMNodePtr getConfig() const;
// loads the config file. if fails to load displays error message.
// and loads alternate default configuration.
void loadConfig();
// gets the full path name of the config file.
// that is getConfigPath() + "\dropBar.xml".
// @return full path of config file.
CString getConfigFile() const;
// gets the path where the config file resides. this is the users "My Documents" folder.
// @return path where config file resides.
CString getConfigPath() const;
// resets the DropBar. releases all cached attributes and reloads the config file.
void reset();
// sets that we receive WM_MOUSELEAVE messages when cursor leaves Drop Bar window.
void initMouseLeave();
// executes a scripts function.
// @param scriptNode a <script> node. its text is the script code to add.
// @param function name of function within script code. if that function does not exists this method does nothing.
// @param params parameters to pass to the function of 0 if function takes no parameters.
void execScript(IXMLDOMElementPtr scriptNode, CString function, CParams *params = 0);
// displays an error message box.
// @param err com_error that occured.
// @param msg message text to display.
void errorMsg(com_error *err = 0, LPCTSTR msg = 0) const;
// gets the dataObjects content as a HDROP. the dataObjects content must be of type CF_HDROP.
// @param dataObject objects thats beeing draged.
HDROP getHDROP();
// returns drop effect according dataObject.
// @param dataObject object thats beeing draged.
// @param p point.
// @return drop effect for dataObject.
DWORD dropEffect(CPoint p);
// check if a change has made to the config file and reload if so.
void checkConfig();
// last write-time of config file.
FILETIME lastConfigTime;
// @return last write-time of config file.
FILETIME getLastConfigTime() const;
// sets last write-time of config file.
// @param newLastConfigTime new value.
void setLastConfigTime(FILETIME newLastConfigTime);
// @return last-write time of config file.
FILETIME configTime() const;
// checks if given time is equal to the lastConfigTime.
// @param time time to compare.
// @return true if time and lastConfigTime are the same.
bool isLastConfigTime(FILETIME time) const;
// checks separator attribute of button.
// @param button index of button to test.
// @return true if button is a separator.
bool isSeparator(int button) const;
public:
// IDropBar
// brings the window identified by hWnd to the top.
// @param hWnd handle of window to bring to top.
STDMETHOD(BringWindowToTop)(OLE_HANDLE hWnd);
// IPersistStream
STDMETHOD(GetClassID)(LPCLSID classID);
STDMETHOD(IsDirty)(void);
STDMETHOD(Load)(LPSTREAM stream);
STDMETHOD(Save)(LPSTREAM stream, BOOL clearDirty);
STDMETHOD(GetSizeMax)(ULARGE_INTEGER *size);
// IOleWindow
STDMETHOD(GetWindow)(HWND *hwnd);
STDMETHOD(ContextSensitiveHelp)(BOOL enterMode);
// IObjectWithSite
STDMETHOD(SetSite)(IUnknown *newSite);
STDMETHOD(GetSite)(REFIID riid, void **site);
// IDockingWindow
STDMETHOD(CloseDW)(DWORD);
STDMETHOD(ResizeBorderDW)(LPCRECT border, IUnknown* toolbarSite, BOOL);
STDMETHOD(ShowDW)(BOOL show);
// IDeskBand
STDMETHOD(GetBandInfo)(DWORD bandID, DWORD viewMode, DESKBANDINFO* dbi);
// IDropTarget
STDMETHOD(DragEnter)(LPDATAOBJECT dataObject, DWORD keyState, POINTL p, LPDWORD effect);
STDMETHOD(DragOver)(DWORD keyState, POINTL p, LPDWORD effect);
STDMETHOD(DragLeave)();
STDMETHOD(Drop)(LPDATAOBJECT dataObject, DWORD keyState, POINTL p, LPDWORD effect);
};
#endif //__DROPBAR_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -