1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
button( const button &buttoninstance)
{
setParent(GetParent(buttoninstance.hwnd));
setHeight(buttoninstance.intHeight);
setLeft(buttoninstance.intLeft);
setTop(buttoninstance.intTop);
setWidth(buttoninstance.intWidth);
setTextAlignment(buttoninstance.intTextAlignment);
intMouseHover=buttoninstance.intMouseHover;
setAutoSize(buttoninstance.blnAutoSize);
setEnable(buttoninstance.blnEnable);
setTabStop(buttoninstance.blnTabStop);
setTextWrap(buttoninstance.blnTextWrap);
setTransparent(buttoninstance.blnTransparent);
setVisible(buttoninstance.blnVisible);
setBackColor(buttoninstance.clrBackColor);
setTextColor(buttoninstance.clrTextColor);
strCaption=buttoninstance.strCaption;
hCursor=buttoninstance.hCursor;
SetClassLong(hwnd, // window handle
GCL_HCURSOR, // change cursor
(LONG) hCursor);
//HFONT a=(HFONT)SendMessage(buttoninstance.hwnd, WM_GETFONT, 0, 0);
// setFont(a);
}
button & operator=( const button &buttoninstance)
{
setParent(GetParent(buttoninstance.hwnd));
setHeight(buttoninstance.intHeight);
setLeft(buttoninstance.intLeft);
setTop(buttoninstance.intTop);
setWidth(buttoninstance.intWidth);
setTextAlignment(buttoninstance.intTextAlignment);
intMouseHover=buttoninstance.intMouseHover;
setAutoSize(buttoninstance.blnAutoSize);
setEnable(buttoninstance.blnEnable);
setTabStop(buttoninstance.blnTabStop);
setTextWrap(buttoninstance.blnTextWrap);
setTransparent(buttoninstance.blnTransparent);
setVisible(buttoninstance.blnVisible);
setBackColor(buttoninstance.clrBackColor);
setTextColor(buttoninstance.clrTextColor);
strCaption=buttoninstance.strCaption;
hCursor=buttoninstance.hCursor;
SetClassLong(hwnd, // window handle
GCL_HCURSOR, // change cursor
(LONG) hCursor);
//HFONT a=(HFONT)SendMessage(buttoninstance.hwnd, WM_GETFONT, 0, 0);
//setFont(a);
return *this;
}
button(string caption="", HWND parent=WindowMain)
{
++ButtonCount;
if(caption=="")
strCaption=strCaption + to_string(ButtonCount);
else
strCaption=caption;
setParent(parent);
altkey=GettingAltKey(strCaption);
if(altkey!=-1)
RegisterHotKey(hwnd,altmessage,MOD_ALT,altkey);
}
void setParent(HWND parent=WindowMain)
{
if (hwnd==NULL)
{
WNDCLASS ButtonClass;
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
ZeroMemory(&ButtonClass, sizeof(WNDCLASS));
GetClassInfo(mod, TEXT("BUTTON"), &ButtonClass);
ButtonClass.hInstance = mod;
ButtonClass.lpszClassName = TEXT("CBUTTON");
ButtonClass.style=CS_DBLCLKS;
// store the old WNDPROC of the button window class
SetProp(parent, buttonpropname, (HANDLE)ButtonClass.lpfnWndProc);
// replace it with local WNDPROC
ButtonClass.lpfnWndProc = WndProcButton;
ButtonClass.hbrBackground = (HBRUSH)GetStockBrush(NULL_BRUSH);
// register the new window class"
RegisterClass(&ButtonClass);
hwnd = CreateWindowEx(
0,
TEXT("CBUTTON"),//these must be the same of ButtonClass.lpszClassName.. registed class
strCaption.c_str(),
WS_VISIBLE | WS_CHILD |WS_TABSTOP| BS_OWNERDRAW | BS_NOTIFY | WS_CLIPSIBLINGS, //onerdraw for add images
intLeft, intTop, intWidth, intHeight,
parent,
NULL,
mod,
this);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
if (SetProp(hwnd, buttonclassprop, (HANDLE)this) == 0)
MessageBox(NULL, "can't set the class property", "error", MB_OK);
clrBackColor= GetBkColor(GetDC(GetParent(hwnd)));
clrTextColor = GetTextColor(GetDC(hwnd));
}
else
{
SetParent(hwnd,parent);
}
/*RECT a;
GetClientRect(hwnd,&a);
intTop=a.top;
intLeft=a.left;
intWidth=a.right-a.left;
intHeight=a.bottom-a.top;
InvalidateRect(hwnd,NULL,true);//i add these line for fix that
UpdateWindow(hwnd);
SetWindowPos(hwnd, 0,intLeft , intTop, intWidth, intHeight,
SWP_NOZORDER|SWP_NOACTIVATE|
SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);*/
mousestoped.timerprocedure=[this]()
{
static POINT Location, PreviousLocation={0};
if(dcaButton==DrawControlsAction::MouseEnter)
{
GetCursorPos(&Location);
//testing is previous position is igual to location
//if they are the same, so the mouse is stop
if ((Location.x == PreviousLocation.x) && (Location.y == PreviousLocation.y))
{
MouseStoped();
}
else
{
MouseButtons MBButtons;
bool blControl=false;
bool blShift=false;
if(GetKeyState(MK_CONTROL) & 0x8000)
{
blControl=true;
}
if(GetKeyState(MK_SHIFT) & 0x8000)
{
blShift=true;
}
if(GetKeyState(MK_LBUTTON) & 0x8000)
{
MBButtons=Left;
dcaButton=DrawControlsAction::MouseClick;
InvalidateRect(hwnd,nullptr,FALSE);
}
else if(GetKeyState(MK_RBUTTON) & 0x8000)
MBButtons=Right;
else if(GetKeyState(MK_MBUTTON) & 0x8000)
MBButtons=Middle;
else if(GetKeyState(MK_XBUTTON1) & 0x8000)
MBButtons=X1;
else if(GetKeyState(MK_XBUTTON2) & 0x8000)
MBButtons=X2;
MouseMove(MBButtons,blControl,blShift,Location.x,Location.y);
}
}
InvalidateRect(hwnd,NULL,TRUE);
PreviousLocation = Location;
};
mousestoped.Interval=100;
mousestoped.Start();
setAutoSize(true);
}
|