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
|
form()
{
++FormCount;
strCaption=strCaption + to_string(FormCount);
setParent(HWND_DESKTOP);
}
void setParent(HWND parent=HWND_DESKTOP)
{
WNDCLASS FormClass;
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
FormClass.hInstance = mod;
FormClass.lpszClassName = TEXT("form");
// replace it with local WNDPROC
FormClass.lpfnWndProc = WndProcForm;
FormClass.hbrBackground = (HBRUSH) ((COLOR_WINDOW)+1);
// register the new window class"
RegisterClass(&FormClass);
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
TEXT("form"),
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, mod, NULL);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
clrBackColor= GetBkColor(GetDC(HWND_DESKTOP));
clrTextColor = GetTextColor(GetDC(HWND_DESKTOP));
RECT a;
GetClientRect(hwnd,&a);
intTop=a.top;
intLeft=a.left;
intWidth=a.right-a.left;
intHeight=a.bottom-a.top;
}
//............
static LRESULT CALLBACK WndProcForm(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static POINT PreviousLocation, Location;
static bool Tracking = false;
static MouseButtons MBButtons;
static bool blControl=false;
static bool blShift=false;
static bool blResize=false;
static int xPos=0;
static int yPos=0;
static UINT_PTR timerid;
static bool blnDrag=false;
//preparing the message loop for be used in super class way
//Getting the parent procedure
WNDPROC oldproc = (WNDPROC)GetProp(HWND_DESKTOP, formpropname);
if (oldproc == NULL)
MessageBox(NULL, "Can't find old procedure", "error", MB_OK | MB_ICONEXCLAMATION);
//add the instance class to inst pointer
form *inst = (form*)GetProp(hwnd,formclassprop);
if (inst == NULL && msg == WM_NCCREATE)
{
inst = (form*)(((LPCREATESTRUCT)lParam)->lpCreateParams);
SetProp(hwnd, formclassprop, (HANDLE)inst);
}
if (inst == NULL)
MessageBox(NULL, "Can't find the instance pointer", "error", MB_OK);
//Working with messages
switch(msg)
{
case WM_CREATE:
{
inst->Create(inst->intLeft, inst->intTop);
}
break;
|