Enter the Superclass where you want to add functionality to a bunch of controls..
You get the properties for a class (in our case the edit window class) modify a few properties, and register the new class.
You call GetClassInfoEx 2 things: the name of the class you want to Superclass and a pointer to a WNDCLASSEX structure. GetClassInfoEx will fill that structure.
Next, modify WNDCLASSEX, there are 2 members you must modify - hInstance and lpszClassName and in our example we modify lpfnWndProc
hInstance will be the handle to your app you get from GetModuleHandle
lpszClassName will be the name of your new class
lpfnWndProc will be the address of our callback proc
Step by step...
Get the class info for the Edit window class
mov wc.cbSize, sizeof WNDCLASSEX invoke GetClassInfoEx, NULL, offset szWndClsEdit, addr wc
next change a few things, then register our new superclassed edit control:
push wc.lpfnWndProc pop lpEditWndProc mov wc.lpfnWndProc, offset WndProcEdit push hInst pop wc.hInstance ;##### Change the cursor for our edit windows invoke LoadCursor, NULL, IDC_UPARROW mov wc.hCursor, eax mov wc.lpszClassName, offset szWndClsSuperEdit invoke RegisterClassEx, addr wc
As with subclassing, we need to save the original address for the edit window proc so we can pass on the messages, #1 and #2
#3 we are telling windows to use our Window proc for all controls created with our class name not needed, but makes our life easier for our task
#4 - 5 we are setting the hInstance for the control, this is a must
I decided to change the cursor for our class to an up arrow #7-8
#9 we give our class a name this is a must
Then we register our class.. That is it, now you can CreateWindowEx with our new classname! Instead of having to create multiple procs to handle each edit control, all controls created with our classname, will use the same callback proc.
in the attached sample, I create 4 edit controls that only accept numbers
xor ebx, ebx mov edi, 5 .while ebx < 4 invoke CreateWindowEx, WS_EX_CLIENTEDGE, offset szWndClsSuperEdit, NULL, WS_CHILD or WS_VISIBLE or WS_TABSTOP, 5, edi, 285, 20, hWin, ebx, hInst, 0 mov dword ptr [hEditHandles + 4 * ebx], eax add edi, 50 inc ebx .endw
As you can see, superclassing a control is easier than subclassing if you want a bunch of controls with the same properties..
Number of downloads: 305