[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?
Re: [win32] - creating the form super class
Code:
SetProp(hwnd, formpropname, (HANDLE)FormClass.lpfnWndProc);
You can't set a window property until the window has been created in the following line! You also should test RegistrClassEX() and SetProp() for return errors.
Code:
case WM_COMMAND:
{
SendMessage(hwnd,WM_COMMAND,wParam,lParam);
}
break;
You are handling the WM_COMMAND message and you send a WM_COMMAND message which then gets handled as a WM_COMMAND message which sends a WM_COMMAND message which ..................... :eek:
Re: [win32] - creating the form super class
hello 2kaud thanks for answer me.
"You can't set a window property until the window has been created in the following line! You also should test RegistrClassEX() and SetProp() for return errors."
my mistake, but i continue with problems: i don't get the inst and oldproc correctly :(
"You are handling the WM_COMMAND message and you send a WM_COMMAND message which then gets handled as a WM_COMMAND message which sends a WM_COMMAND message which ..................... :eek:"
because these message is for my button\others controls class's prodedure
Re: [win32] - creating the form super class
Quote:
Originally Posted by
Cambalinho
hello
2kaud thanks for answer me.
"You can't set a window property until the window has been created in the following line! You also should test RegistrClassEX() and SetProp() for return errors."
my mistake, but i continue with problems:
i don't get the inst and oldproc correctly :(
"You are handling the WM_COMMAND message and you send a WM_COMMAND message which then gets handled as a WM_COMMAND message which sends a WM_COMMAND message which ..................... :eek:"
What are SetProp/GetProp?
Are they your own functions? Then set a breakpoint, debug and see what and why goes wrong!
Quote:
Originally Posted by
Cambalinho
Code:
SetProp(hwnd, formclassprop, (HANDLE)this);
What is this here? I do not see any calss in your code snippets.
PS: please use quote tags for quatation of other posts!
Re: [win32] - creating the form super class
Quote:
Originally Posted by
VictorN
What are SetProp/GetProp?
Are they your own functions? Then set a breakpoint, debug and see what and why goes wrong!
What is this here? I do not see any calss in your code snippets.
PS: please use quote tags for quatation of other posts!
i didn't show all the class, because it's very big.
the SetProp/GetProp are API functions
Re: [win32] - creating the form super class
Quote:
Originally Posted by
Cambalinho
the SetProp/GetProp are API functions
Well, then do you check their return values?
Why don't you call GetLastError if SetProp fails?