-
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?
-
July 6th, 2014, 05:35 AM
#2
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 .....................
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 6th, 2014, 05:42 AM
#3
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 ..................... "
because these message is for my button\others controls class's prodedure
-
July 6th, 2014, 07:29 AM
#4
Re: [win32] - creating the form super class
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 ..................... "
What are SetProp/GetProp?
Are they your own functions? Then set a breakpoint, debug and see what and why goes wrong!
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!
Victor Nijegorodov
-
July 6th, 2014, 07:33 AM
#5
Re: [win32] - creating the form super class
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
-
July 6th, 2014, 07:39 AM
#6
Re: [win32] - creating the form super class
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?
Victor Nijegorodov
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
|