ReactOS  0.4.15-dev-341-g17c5fb8
FlatButton Struct Reference

#include <window.h>

Inheritance diagram for FlatButton:
Collaboration diagram for FlatButton:

Public Types

typedef OwnerdrawnButton super
 
- Public Types inherited from OwnerdrawnButton
typedef SubclassedWindow super
 
- Public Types inherited from SubclassedWindow
typedef Window super
 
- Public Types inherited from Window
typedef map< HWND, Window * > WindowMap
 
typedef Window *(* CREATORFUNC) (HWND)
 
typedef Window *(* CREATORFUNC_INFO) (HWND, const void *)
 

Public Member Functions

 FlatButton (HWND hwnd)
 
 FlatButton (HWND owner, int id)
 
- Public Member Functions inherited from OwnerdrawnButton
 OwnerdrawnButton (HWND hwnd)
 
- Public Member Functions inherited from SubclassedWindow
 SubclassedWindow (HWND)
 
- Public Member Functions inherited from Window
 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)
 
 Window (INT cx, INT cy, BOOL fAutoHide=FALSE)
 
virtual ~Window ()
 
virtual LRESULT CALLBACK WindowProcDx (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void DoAction ()
 

Protected Member Functions

LRESULT WndProc (UINT nmsg, WPARAM wparam, LPARAM lparam)
 
virtual void DrawItem (LPDRAWITEMSTRUCT dis)
 
- Protected Member Functions inherited from SubclassedWindow
virtual int Command (int id, int code)
 
virtual int Notify (int id, NMHDR *pnmh)
 
- Protected Member Functions inherited from Window
virtual LRESULT Init (LPCREATESTRUCT pcs)
 
void OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
 
void OnPaint (HWND hwnd)
 
void OnRButtonDown (HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
 
void OnKey (HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
 
void OnAppBarCallback (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
BOOL AppBar_Register (HWND hwnd)
 
BOOL AppBar_UnRegister (HWND hwnd)
 
BOOL AppBar_SetAutoHide (HWND hwnd, BOOL fHide)
 
BOOL AppBar_AutoHide (HWND hwnd)
 
BOOL AppBar_NoAutoHide (HWND hwnd)
 
BOOL AppBar_SetSide (HWND hwnd, UINT uSide)
 
void AppBar_SetAlwaysOnTop (HWND hwnd, BOOL fOnTop)
 
void AppBar_Hide (HWND hwnd)
 
void AppBar_UnHide (HWND hwnd)
 
void AppBar_SetAutoHideTimer (HWND hwnd)
 
void AppBar_SetAutoUnhideTimer (HWND hwnd)
 
void AppBar_Size (HWND hwnd)
 
void AppBar_QueryPos (HWND hwnd, LPRECT lprc)
 
void AppBar_QuerySetPos (UINT uEdge, LPRECT lprc, PAPPBARDATA pabd, BOOL fMove)
 
void AppBar_PosChanged (PAPPBARDATA pabd)
 
BOOL OnCreate (HWND hwnd, LPCREATESTRUCT lpCreateStruct)
 
void OnActivate (HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized)
 
void OnWindowPosChanged (HWND hwnd, const LPWINDOWPOS lpwpos)
 
void OnSize (HWND hwnd, UINT state, int cx, int cy)
 
void OnMove (HWND hwnd, int x, int y)
 
void OnNCDestroy (HWND hwnd)
 
void OnTimer (HWND hwnd, UINT id)
 
UINT OnNCHitTest (HWND hwnd, int x, int y)
 
void OnLButtonDown (HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
 
void OnMouseMove (HWND hwnd, int x, int y, UINT keyFlags)
 
void OnLButtonUp (HWND hwnd, int x, int y, UINT keyFlags)
 

Protected Attributes

COLORREF _textColor
 
COLORREF _activeColor
 
bool _active
 
- Protected Attributes inherited from SubclassedWindow
WNDPROC _orgWndProc
 
- Protected Attributes inherited from Window
HWND m_hwnd
 
BOOL m_fAutoHide
 
BOOL m_fOnTop
 
BOOL m_fHiding
 
UINT m_uSide
 
LONG m_cxWidth
 
LONG m_cyHeight
 
LONG m_cxSave
 
LONG m_cySave
 
BOOL m_fAppBarRegd
 
BOOL m_fMoving
 
BOOL m_bDragged
 
POINT m_ptDragOn
 
RECT m_rcAppBar
 
RECT m_rcDrag
 

Additional Inherited Members

- Static Public Member Functions inherited from Window
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 More...
 
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 ()
 
static BOOL DoRegisterClass (HINSTANCE hInstance)
 
static HWND DoCreateMainWnd (HINSTANCE hInstance, LPCTSTR pszText, INT cx, INT cy, DWORD style=WS_POPUP|WS_THICKFRAME|WS_CLIPCHILDREN, DWORD exstyle=WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_TOPMOST, BOOL fAutoHide=FALSE)
 
static INT DoMainLoop ()
 
static WindowGetAppbarData (HWND hwnd)
 
static LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static DWORD WINAPI ActionThreadFunc (LPVOID args)
 
- Public Attributes inherited from Window
IAccessible IAccessible_iface
 
IOleWindow IOleWindow_iface
 
IEnumVARIANT IEnumVARIANT_iface
 
LONG ref
 
- Static Protected Member Functions inherited from SubclassedWindow
static LRESULT CALLBACK SubclassedWndProc (HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
 
- Static Protected Member Functions inherited from Window
static Windowcreate_controller (HWND hwnd)
 create controller for a new window More...
 
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 inherited from Window
static WindowMap s_wnd_map
 
static const voids_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

Subclass button controls to paint colored text labels. The owning window should use the OwnerDrawParent template to route owner draw messages to the buttons.

Definition at line 692 of file window.h.

Member Typedef Documentation

◆ super

Definition at line 694 of file window.h.

Constructor & Destructor Documentation

◆ FlatButton() [1/2]

FlatButton::FlatButton ( HWND  hwnd)
inline

Definition at line 696 of file window.h.

697  : super(hwnd), _active(false) {}
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
OwnerdrawnButton super
Definition: window.h:694
bool _active
Definition: window.h:708

◆ FlatButton() [2/2]

FlatButton::FlatButton ( HWND  owner,
int  id 
)
inline

Definition at line 699 of file window.h.

700  : super(GetDlgItem(owner, IDOK)), _active(false) {}
#define IDOK
Definition: winuser.h:824
OwnerdrawnButton super
Definition: window.h:694
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
bool _active
Definition: window.h:708

Member Function Documentation

◆ DrawItem()

void FlatButton::DrawItem ( LPDRAWITEMSTRUCT  dis)
protectedvirtual

Implements OwnerdrawnButton.

Definition at line 1050 of file window.cpp.

1051 {
1053 
1054  if (dis->itemState & ODS_DISABLED)
1055  style |= DFCS_INACTIVE;
1056 
1057  RECT textRect = {dis->rcItem.left+2, dis->rcItem.top+2, dis->rcItem.right-4, dis->rcItem.bottom-4};
1058 
1059  if (dis->itemState & ODS_SELECTED) {
1060  style |= DFCS_PUSHED;
1061  ++textRect.left; ++textRect.top;
1063  }
1064 
1066 
1067  // highlight the button?
1068  if (_active)
1069  DrawEdge(dis->hDC, &dis->rcItem, EDGE_ETCHED, BF_RECT);
1070  else if (GetWindowStyle(_hwnd) & BS_FLAT) // Only with BS_FLAT there will be drawn a frame to show highlighting.
1071  DrawEdge(dis->hDC, &dis->rcItem, EDGE_RAISED, BF_RECT|BF_FLAT);
1072 
1073  TCHAR txt[BUFFER_LEN];
1074  int txt_len = GetWindowText(_hwnd, txt, BUFFER_LEN);
1075 
1076  if (dis->itemState & (ODS_DISABLED|ODS_GRAYED)) {
1078 
1079  if (gray) {
1080  {
1081  TextColor lcColor(dis->hDC, GetSysColor(COLOR_BTNHIGHLIGHT));
1082  RECT shadowRect = {textRect.left+1, textRect.top+1, textRect.right+1, textRect.bottom+1};
1083  DrawText(dis->hDC, txt, txt_len, &shadowRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
1084  }
1085 
1086  BkMode mode(dis->hDC, TRANSPARENT);
1087  TextColor lcColor(dis->hDC, gray);
1088  DrawText(dis->hDC, txt, txt_len, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
1089  } else {
1090  int old_r = textRect.right;
1091  int old_b = textRect.bottom;
1093  int x = textRect.left + (old_r-textRect.right)/2;
1094  int y = textRect.top + (old_b-textRect.bottom)/2;
1095  int w = textRect.right-textRect.left;
1096  int h = textRect.bottom-textRect.top;
1099  GrayString(dis->hDC, GetSysColorBrush(COLOR_GRAYTEXT), MyDrawText, (LPARAM)txt, txt_len, x, y, w, h);
1100  }
1101  } else {
1102  TextColor lcColor(dis->hDC, _active? _activeColor: _textColor);
1103  DrawText(dis->hDC, txt, txt_len, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
1104  }
1105 
1106  if (dis->itemState & ODS_FOCUS) {
1107  RECT rect = {
1108  dis->rcItem.left+3, dis->rcItem.top+3,
1109  dis->rcItem.right-dis->rcItem.left-4, dis->rcItem.bottom-dis->rcItem.top-4
1110  };
1111  if (dis->itemState & ODS_SELECTED) {
1112  ++rect.left; ++rect.top;
1113  ++rect.right; ++rect.bottom;
1114  }
1115  DrawFocusRect(dis->hDC, &rect);
1116  }
1117 }
#define BF_FLAT
Definition: winuser.h:471
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
#define DFCS_INACTIVE
Definition: winuser.h:502
LONG top
Definition: windef.h:307
#define ODS_FOCUS
Definition: winuser.h:2524
COLORREF _textColor
Definition: window.h:706
#define COLOR_BTNHIGHLIGHT
Definition: winuser.h:925
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
LONG left
Definition: windef.h:306
LONG right
Definition: windef.h:308
DWORD WINAPI GetSysColor(_In_ int)
& rect
Definition: startmenu.cpp:1413
#define DrawText
Definition: winuser.h:5746
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define GetWindowText
Definition: winuser.h:5773
#define GetWindowStyle(hwnd)
Definition: windowsx.h:290
#define BF_RECT
Definition: winuser.h:462
#define DFCS_PUSHED
Definition: winuser.h:503
#define DT_CALCRECT
Definition: winuser.h:526
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
#define TRANSPARENT
Definition: wingdi.h:949
RECT textRect
Definition: startmenu.cpp:1392
#define BUFFER_LEN
Definition: utility.h:97
LONG_PTR LPARAM
Definition: windef.h:208
#define DT_VCENTER
Definition: winuser.h:543
char TCHAR
Definition: xmlstorage.h:189
#define ODS_DISABLED
Definition: winuser.h:2522
DWORD COLORREF
Definition: windef.h:300
#define EDGE_ETCHED
Definition: winuser.h:452
#define ODS_GRAYED
Definition: winuser.h:2521
#define COLOR_GRAYTEXT
Definition: winuser.h:922
#define COLOR_BTNFACE
Definition: winuser.h:918
GLenum mode
Definition: glext.h:6217
#define EDGE_RAISED
Definition: winuser.h:450
#define BS_FLAT
Definition: winuser.h:280
#define DT_SINGLELINE
Definition: winuser.h:540
#define DFCS_BUTTONPUSH
Definition: winuser.h:501
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
bool _active
Definition: window.h:708
#define ODS_SELECTED
Definition: winuser.h:2520
LONG bottom
Definition: windef.h:309
#define DT_CENTER
Definition: winuser.h:527
COLORREF _activeColor
Definition: window.h:707
#define GrayString
Definition: winuser.h:5777
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
Arabic default style
Definition: afstyles.h:93
static BOOL CALLBACK MyDrawText(HDC hdc, LPARAM data, int cnt)
Definition: window.cpp:885
HBRUSH WINAPI GetSysColorBrush(_In_ int)
static RECT s_MyDrawText_Rect
Definition: window.cpp:883

◆ WndProc()

LRESULT FlatButton::WndProc ( UINT  nmsg,
WPARAM  wparam,
LPARAM  lparam 
)
protectedvirtual

Reimplemented from OwnerdrawnButton.

Definition at line 1119 of file window.cpp.

1120 {
1121  switch(nmsg) {
1122  case WM_MOUSEMOVE: {
1123  bool active = false;
1124 
1125  if (IsWindowEnabled(_hwnd)) {
1126  DWORD pid_foreground;
1127  HWND hwnd_foreground = GetForegroundWindow(); //@@ may be better look for WM_ACTIVATEAPP ?
1128  GetWindowThreadProcessId(hwnd_foreground, &pid_foreground);
1129 
1130  if (GetCurrentProcessId() == pid_foreground) {
1132  ClientRect clntRect(_hwnd);
1133 
1134  // highlight the button?
1135  if (pt.x>=clntRect.left && pt.x<clntRect.right && pt.y>=clntRect.top && pt.y<clntRect.bottom)
1136  active = true;
1137  }
1138  }
1139 
1140  if (active != _active) {
1141  _active = active;
1142 
1143  if (active) {
1144  TRACKMOUSEEVENT tme = {sizeof(tme), /*TME_HOVER|*/TME_LEAVE, _hwnd/*, HOVER_DEFAULT*/};
1145  _TrackMouseEvent(&tme);
1146  }
1147 
1148  InvalidateRect(_hwnd, NULL, TRUE);
1149  }
1150 
1151  return 0;}
1152 
1153  case WM_LBUTTONUP: {
1155  ClientRect clntRect(_hwnd);
1156 
1157  // no more in the active rectangle?
1158  if (pt.x<clntRect.left || pt.x>=clntRect.right || pt.y<clntRect.top || pt.y>=clntRect.bottom)
1159  goto cancel_press;
1160 
1161  goto def;}
1162 
1163  case WM_CANCELMODE:
1164  cancel_press: {
1165  TRACKMOUSEEVENT tme = {sizeof(tme), /*TME_HOVER|*/TME_LEAVE|TME_CANCEL, _hwnd/*, HOVER_DEFAULT*/};
1166  _TrackMouseEvent(&tme);
1167  _active = false;
1168  ReleaseCapture();}
1169  // fall through
1170 
1171  case WM_MOUSELEAVE:
1172  if (_active) {
1173  _active = false;
1174 
1175  InvalidateRect(_hwnd, NULL, TRUE);
1176  }
1177 
1178  return 0;
1179 
1180  default: def:
1181  return super::WndProc(nmsg, wparam, lparam);
1182  }
1183 }
#define TRUE
Definition: types.h:120
#define pt(x, y)
Definition: drawing.c:79
#define GET_X_LPARAM(lp)
Definition: windowsx.h:274
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
Definition: window.cpp:865
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
#define WM_MOUSELEAVE
Definition: commctrl.h:4971
DWORD WINAPI GetWindowThreadProcessId(HWND, PDWORD)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI IsWindowEnabled(_In_ HWND)
BOOL WINAPI _TrackMouseEvent(TRACKMOUSEEVENT *ptme)
Definition: commctrl.c:1207
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WM_CANCELMODE
Definition: winuser.h:1617
#define TME_CANCEL
Definition: commctrl.h:4980
#define TME_LEAVE
Definition: commctrl.h:4977
#define WM_LBUTTONUP
Definition: winuser.h:1759
#define WM_MOUSEMOVE
Definition: winuser.h:1757
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:275
bool _active
Definition: window.h:708
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2889
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
static UINT WPARAM wparam
Definition: combo.c:716

Member Data Documentation

◆ _active

bool FlatButton::_active
protected

Definition at line 708 of file window.h.

Referenced by DrawItem(), and WndProc().

◆ _activeColor

COLORREF FlatButton::_activeColor
protected

Definition at line 707 of file window.h.

Referenced by DrawItem().

◆ _textColor

COLORREF FlatButton::_textColor
protected

Definition at line 706 of file window.h.

Referenced by DrawItem().


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