-
July 6th, 2014, 04:08 AM
#1
[win32] - creating the form super class
i'm trying build the form super class without sucess
i can't get the old procedure
Code:
void setParent(HWND parent=GetDesktopWindow())
{
WNDCLASSEX FormClass;
char classname[]="form";
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
FormClass.cbSize = sizeof(WNDCLASSEX);
FormClass.style = 0;
FormClass.lpfnWndProc = WndProcForm;
FormClass.cbClsExtra = 0;
FormClass.cbWndExtra = 0;
FormClass.hInstance = mod;
FormClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
FormClass.hCursor = LoadCursor(NULL, IDC_ARROW);
FormClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
FormClass.lpszMenuName = NULL;
FormClass.lpszClassName = classname;
FormClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// register the new window class"
RegisterClassEx(&FormClass);
SetProp(hwnd, formpropname, (HANDLE)FormClass.lpfnWndProc);
hwnd = CreateWindowEx(0, classname, "The title of my window", WS_OVERLAPPEDWINDOW | WS_TABSTOP, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, parent, NULL, mod, (LPVOID) this);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
SetProp(hwnd, formclassprop, (HANDLE)this);
ShowWindow(hwnd, SW_NORMAL);
UpdateWindow(hwnd);
clrBackColor= GetBkColor(GetDC(parent));
clrTextColor = GetTextColor(GetDC(parent));
RECT a;
GetClientRect(hwnd,&a);
intTop=a.top;
intLeft=a.left;
intWidth=a.right-a.left;
intHeight=a.bottom-a.top;
}
//window procedure:
//preparing the message loop for be used in super class way
//Getting the parent procedure
WNDPROC oldproc = (WNDPROC)GetProp(GetDesktopWindow(), 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);
why i can't get the old procedure?
why i can't get the inst pointer?
and see these message:
Code:
case WM_COMMAND:
{
SendMessage(hwnd,WM_COMMAND,wParam,lParam);
}
break;
why the windows(OS) give me an error and close my application, when i click on button?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|