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
|
void setParent(HWND parent=GetForegroundWindow())
{
if (hwnd==NULL)
{
static int i=0;
i=i+1;
strCaption=strCaption + to_string(i);
WNDCLASS wc;
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
ZeroMemory(&wc, sizeof(WNDCLASS));
GetClassInfo(mod, TEXT("button"), &wc);
wc.hInstance = mod;
wc.lpszClassName = "CBUTTON";
// store the old WNDPROC of the EDIT window class
SetProp(parent, buttonpropname, (HANDLE)wc.lpfnWndProc);
// replace it with local WNDPROC
wc.lpfnWndProc = WndProcButton;
wc.hbrBackground = (HBRUSH) ((COLOR_WINDOW)+1);
// register the new window class, "ShEdit"
RegisterClass(&wc);
hwnd = CreateWindowEx(
WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_TRANSPARENT,
TEXT("button"),
strCaption.c_str(),
WS_CHILD | WS_VISIBLE | BS_TEXT | WS_TABSTOP | BS_NOTIFY,
0, 0, 60, 30,
parent,
NULL,
mod,
(LPVOID)this);
if (hwnd == NULL)
MessageBox(NULL, "error in create", "error", MB_OK);
if (SetProp(hwnd, buttonclassprop, (HANDLE)this) == 0)
MessageBox(NULL, "set class prop error", "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;
}
|