00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00042
00043
00044 #ifndef _MBOWIN_H_
00045 #define _MBOWIN_H_
00046
00047 #include "Mbo.h"
00048 #include "MboThread.h"
00049 #include "MboIniData.h"
00050 #include <list>
00051
00052 #if defined(_MSC_VER)
00053 # pragma warning(push)
00054 # pragma warning(disable: 4251) // disable warning C4251: '...' : class '...' needs to have dll-interface to be used by clients of class '...'
00055 # pragma warning(disable: 4275) // non dll-interface class '...' used as base for dll-interface class '...'
00056 # ifndef _CPPRTTI
00057 # error You must compile using RTTI
00058 # endif // _CPPRTTI
00059 #endif // _MSC_VER
00060
00061 #define RGB_BLACK RGB( 0, 0, 0)
00062 #define RGB_BLUE RGB( 0, 0,128)
00063 #define RGB_GREEN RGB( 0,128, 0)
00064 #define RGB_CYAN RGB( 0,128,128)
00065 #define RGB_RED RGB(128, 0, 0)
00066 #define RGB_MAGENTA RGB(128, 0,128)
00067 #define RGB_BROWN RGB(128,128, 0)
00068 #define RGB_LTGRAY RGB(192,192,192)
00069 #define RGB_GRAY RGB(128,128,128)
00070 #define RGB_LTBLUE RGB( 0, 0,255)
00071 #define RGB_LTRED RGB(255, 0, 0)
00072 #define RGB_LTCYAN RGB( 0,255,255)
00073 #define RGB_LTGREEN RGB( 0,255, 0)
00074 #define RGB_LTMAGENTA RGB(255, 0,255)
00075 #define RGB_YELLOW RGB(255,255, 0)
00076 #define RGB_WHITE RGB(255,255,255)
00077
00078 #define RGB_HINT RGB(255,255,204)
00079
00080 namespace mbo
00081 {
00082
00088 static inline RECT NormalizeRect(RECT rect)
00089 {
00090 if (rect.left > rect.right)
00091 {
00092 LONG t = rect.left;
00093 rect.left = rect.right;
00094 rect.right = t;
00095 }
00096 if (rect.top > rect.bottom)
00097 {
00098 LONG t = rect.top;
00099 rect.top = rect.bottom;
00100 rect.bottom = t;
00101 }
00102 return rect;
00103 }
00104
00107 enum DRAW_MODE {
00108 DRAW_MODE_FILL,
00109 DRAW_MODE_TRANSPARENT,
00110 DRAW_MODE_HS_BDIAGONAL,
00111 DRAW_MODE_HS_CROSS,
00112 DRAW_MODE_HS_DIAGCROSS,
00113 DRAW_MODE_HS_FDIAGONAL,
00114 DRAW_MODE_HS_HORIZONTAL,
00115 DRAW_MODE_HS_VERTICAL
00116 };
00117
00118
00132 class MBO_API MboDrawWin
00133 : protected MboWinMsgHandler
00134 {
00135 public:
00136
00137 MboWinMsgHandler::GetHWND;
00138 MboWinMsgHandler::PostMessage;
00139
00159 explicit MboDrawWin(
00160 _IN int nSizeX = 400,
00161 _IN int nSizeY = 300,
00162 _IN const MboString& strWndClassName = "MboDrawWin",
00163 _IN bool bStart = true
00164 );
00165
00196 MboDrawWin(
00197 _IN int nSizeX,
00198 _IN int nSizeY,
00199 _IN int nMinSizeX,
00200 _IN int nMinSizeY,
00201 _IN int nMaxSizeX,
00202 _IN int nMaxSizeY,
00203 _IN const MboString& strWndClassName = "MboDrawWin",
00204 _IN bool bStart = true
00205 );
00206
00209 virtual ~MboDrawWin();
00210
00213 bool IsWindowVisible() const;
00214
00217 bool IsWindow() const;
00218
00221 bool IsWndSizeable() const;
00222
00225 bool IsWndSizingOrMoving() const;
00226
00236 virtual void WndShow(_IN bool bActive = true);
00237
00240 virtual void WndHide();
00241
00246 virtual void WndRestore();
00247
00262 virtual void WndSetSize(_IN int nSizeX, _IN int nSizeY);
00263
00272 virtual void WndSetPosition(_IN int nPosX, _IN int nPosY);
00273
00284 virtual void WndDraw();
00285
00291 virtual void OnWndSized();
00292
00302 virtual void DrawRect(
00303 _IN const RECT& rect,
00304 _IN COLORREF colInner,
00305 _IN COLORREF colOuter = RGB_BLACK,
00306 _IN DRAW_MODE enMode = DRAW_MODE_FILL
00307 );
00308
00321 virtual void DrawRect(
00322 _IN LONG nLeft,
00323 _IN LONG nTop,
00324 _IN LONG nRight,
00325 _IN LONG nBottom,
00326 _IN COLORREF colInner,
00327 _IN COLORREF colOuter = RGB_BLACK,
00328 _IN DRAW_MODE enMode = DRAW_MODE_FILL
00329 );
00330
00342 virtual void DrawLine(
00343 _IN LONG nX1,
00344 _IN LONG nY1,
00345 _IN LONG nX2,
00346 _IN LONG nY2,
00347 _IN int nPenWidth,
00348 _IN COLORREF colInner,
00349 _IN DRAW_MODE enMode = DRAW_MODE_FILL,
00350 _IN int fnPenStyle= PS_INSIDEFRAME
00351 );
00352
00362 virtual void DrawLine(
00363 _IN POINT pt1,
00364 _IN POINT pt2,
00365 _IN int nPenWidth,
00366 _IN COLORREF colInner,
00367 _IN DRAW_MODE enMode = DRAW_MODE_FILL,
00368 _IN int fnPenStyle= PS_INSIDEFRAME
00369 );
00370
00380 virtual void DrawEllipse(
00381 _IN const RECT& rect,
00382 _IN COLORREF colInner,
00383 _IN COLORREF colOuter = RGB_BLACK,
00384 _IN DRAW_MODE enMode = DRAW_MODE_FILL
00385 );
00386
00395 virtual void DrawCircle(
00396 _IN const POINT& ptCenter,
00397 _IN const LONG nRadius,
00398 _IN COLORREF colInner,
00399 _IN COLORREF colOuter = RGB_BLACK,
00400 _IN DRAW_MODE enMode = DRAW_MODE_FILL
00401 );
00402
00412 virtual void DrawCircle(
00413 _IN const LONG nCenterX,
00414 _IN const LONG nCenterY,
00415 _IN const LONG nRadius,
00416 _IN COLORREF colInner,
00417 _IN COLORREF colOuter = RGB_BLACK,
00418 _IN DRAW_MODE enMode = DRAW_MODE_FILL
00419 );
00420
00430 virtual void DrawPolygon(
00431 _IN const POINT* aptPoints,
00432 _IN int nNumPoints,
00433 _IN COLORREF colInner,
00434 _IN COLORREF colOuter = RGB_BLACK,
00435 _IN DRAW_MODE enMode = DRAW_MODE_FILL
00436 );
00437
00446 virtual void CalcTextRect(
00447 _IN _OUT RECT & rect,
00448 _IN const MboString& strText,
00449 _IN UINT uFormat = 0
00450 );
00451
00462 virtual void DrawText(
00463 _IN const RECT & rect,
00464 _IN const MboString& strText,
00465 _IN UINT uFormat = 0,
00466 _IN COLORREF colInner = RGB_BLACK,
00467 _IN COLORREF colOuter = RGB_WHITE,
00468 _IN DRAW_MODE enMode = DRAW_MODE_TRANSPARENT
00469 );
00470
00484 virtual void DrawText(
00485 _IN LONG nLeft,
00486 _IN LONG nTop,
00487 _IN LONG nRight,
00488 _IN LONG nBottom,
00489 _IN const MboString& strText,
00490 _IN UINT uFormat = 0,
00491 _IN COLORREF colInner = RGB_BLACK,
00492 _IN COLORREF colOuter = RGB_WHITE,
00493 _IN DRAW_MODE enMode = DRAW_MODE_TRANSPARENT
00494 );
00495
00503 virtual bool DrawBitmap(
00504 _IN int nLeft,
00505 _IN int nTop,
00506 _IN HBITMAP hBitmap
00507 );
00508
00516 virtual bool DrawBitmap(
00517 _IN int nLeft,
00518 _IN int nTop,
00519 _IN const MboString& strResId
00520 );
00521
00529 virtual bool DrawBitmap(
00530 _IN int nLeft,
00531 _IN int nTop,
00532 _IN UINT nResId
00533 );
00534
00542 virtual bool DrawIcon(
00543 _IN int nLeft,
00544 _IN int nTop,
00545 _IN HICON hIcon
00546 );
00547
00555 virtual bool DrawIcon(
00556 _IN int nLeft,
00557 _IN int nTop,
00558 _IN const MboString& strResId
00559 );
00560
00568 virtual bool DrawIcon(
00569 _IN int nLeft,
00570 _IN int nTop,
00571 _IN UINT nResId
00572 );
00573
00579 virtual bool WndSetIconBig(_IN UINT nResId);
00580
00586 virtual bool WndSetIconSmall(_IN UINT nResId);
00587
00597 virtual bool WndSetIconBoth(_IN UINT nResId);
00598
00611 virtual void DrawSetMode(
00612 _OUT HBRUSH & hBrush,
00613 _OUT HPEN & hPen,
00614 _IN COLORREF colInner,
00615 _IN COLORREF colOuter = RGB_BLACK,
00616 _IN DRAW_MODE enMode = DRAW_MODE_FILL,
00617 _IN int nPenWidth = 0,
00618 _IN int fnPenStyle= PS_SOLID
00619 );
00620
00637 virtual bool WndCreate();
00638
00642 virtual void WndClear();
00643
00657 virtual void OnWindowCreated();
00658
00672 virtual void OnButtonDown(_IN UINT nFlags, _IN int x, _IN int y);
00673
00687 virtual void OnButtonDblClk(_IN UINT nFlags, _IN int x, _IN int y);
00688
00702 virtual void OnButtonUp(_IN UINT nFlags, _IN int x, _IN int y);
00703
00706 virtual void WndDestroy();
00707
00710 virtual void WndUpdate();
00711
00727 virtual LRESULT ProcessMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
00728
00733 virtual void WndSetTitle(_IN const MboString& strTitle);
00734
00735 int GetPositionX() const;
00736 int GetPositionY() const;
00737 int GetSizeX() const;
00738 int GetSizeY() const;
00739 int GetMinSizeX() const;
00740 int GetMinSizeY() const;
00741 int GetMaxSizeX() const;
00742 int GetMaxSizeY() const;
00744 int GetWidth() const;
00745 int GetHeight() const;
00747 int GetScreenSizeX() const;
00748 int GetScreenSizeY() const;
00761 virtual void WndLoadExtent(
00762 _IN const CIniData & cIniData,
00763 _IN const MboString & strSection,
00764 _IN bool bWriteDefault = false
00765 );
00766
00777 virtual void WndSaveExtent(
00778 _IN CIniData & cIniData,
00779 _IN const MboString & strSection
00780 ) const;
00781
00782 protected:
00783
00786 virtual bool WndCalcMetrics();
00787
00793 virtual void WndRegisterHandle();
00794
00795 HDC m_hScrDC;
00796 HDC m_hMemDC;
00798 private:
00799 int m_nSizeX;
00800 int m_nSizeY;
00801 int m_nMinSizeX;
00802 int m_nMinSizeY;
00803 int m_nMaxSizeX;
00804 int m_nMaxSizeY;
00806 int m_nHeight;
00807 int m_nWidth;
00809 bool m_bInSizeMove;
00810 };
00811
00812 };
00813
00814 #ifdef _MSC_VER
00815 # pragma warning(pop)
00816 #endif
00817
00818 #endif // _MBOWIN_H_