News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

superclassing controls in dialogbox

Started by shaldan, April 06, 2006, 11:09:26 AM

Previous topic - Next topic

shaldan

Just looking through Iczelion's superclassing examples I would like to ask:

I have dialog box defined in resource with 10 edits and would like to superclass edits to filter some input.

What are the steps needed to superclass these controls ?
Subclassing is clear, but has to be done one cotrol by one .. ..... but superclassing ... At this moment I do not how .. :))

thanks


hutch--

To try and avoid the terminology, when you write a subclass procedure, you supply the address of the procedure and use SetWindowLong() but this can be used for more than one control, as long as the subclass does similar things to each control that calls it. Character filtering in usually done with the WM_CHAR message on an accept or throw away basis and if you are very careful writing the subclass, you can distinguis between controls by the handle arg passed to it but its easy to make a mess of this.

Usually a subclass procedure is so small that its safer and clearer to make one for each control unless you know for sure that two or more controls do identical things. For a subclass procedure you need the proper window handle for the control which you normally get with the GetDlgItem() function using the parent window handle and the control ID as arguments.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

shaldan

thanks Hutch .. hope i am not reading your answer badly ...

but I asked about SUPERclassing. Subclassing edit control in dialogbox I made easily by myself  ... it is greatly explained by Iczelion ..
I know I can use it ... I was just curious about superclassing,
because i have no idea how to do that when using for example 10 edits in dialog box ... I know I can subclass them all and it is not problem at all, but I would like to know, if it even possible to superclass them and how to do that ...

again thanks ...

hutch--

 :bg

I treid to warn you its a terminology issue. If you can write a reliable subclass rountine, set the address of more than one control to the same subclass. As only one control can have the focus at one, the two controls don't overlap with their use of the same subclass.

I warned you that it can get messy if you have different control types using the same subclass though so its better to makea common subclass for buttons then a common subclass for edit controls and so on.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

shaldan

i can see it is perhaps the terminology problem, because I still have feelings we are talking about subclassing :)))))))
(understand that all I "know" about superclassing and subclassing is from Iczelions tutorials :))

I ask different. How can I use Iczelions SUPERclassing example, when using dialogbox ? :)



....
mov wc.cbSize,sizeof WNDCLASSEX
        invoke GetClassInfoEx,NULL,addr EditClass,addr wc
        push wc.lpfnWndProc
        pop OldWndProc
        mov wc.lpfnWndProc, OFFSET EditWndProc
        push hInstance
        pop wc.hInstance
        mov wc.lpszClassName,OFFSET OurClass
        invoke RegisterClassEx, addr wc

.....
here Iczelion superclassed normal edit class and then creates 6 edits in loop:


invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR OurClass,NULL,\
                 WS_CHILD+WS_VISIBLE+WS_BORDER,20,\
                 edi,300,25,hWnd,ebx,\
                 hInstance,NULL
..

I think this I understand .. he created "modified" edit class and then based on this class he created 6 "new" edits and each edit has the same extra behavior, that is filtering ability handled by EditWndProc. But here he uses normal window and then CreateWindowEx.
But how can I do that, when edits are in dialogbox, that is in resource ? :))
Or better ask: you wrote "set the address of more than one control to the same subclass" .. how can I do that with dialogbox AT ONCE for six contols in dialog box like in iczelion example ? :))

reeeeaaallllyy thanks for patience :)))

hutch--

Is basically like this, a dialog box uses the system dialog engine that in fact uses CreateWindowEx() to create the windows anyway. If you use CreateWindowEx() you use a WndProc style message handler for one OR MORE windows (controls are windows) and do whatever processing you require.

Now when you use a dialog box with resource style controls, you don't immediately have a message handling procedure for any of the controls so you must write a subclass for them, either individually or collectively. Now a subclass is similar but not the same as a WndProc style procedure as it must have an address intercepted and passed to the subclass which in turn must return back to the true message handler for the control after it has finished.

Now this is a different technique to that in Iczelions tutorial. The trick is to avoid the limitations of the terminology of super or sub classing and see what either procedure is doing. It reduces down to a procedure that processes messages for one or more windows. The differences are how the window is created and how its address is made available to the OS so it know what address to point messages for a particular window to.

If you have a current version of the masm32 project, have a look in the example code exampl01 in a directory called FILTINPT which shows you ow to do multiple subclassing. The only diference is with what you want to do is you set the SAME ADDRESS to different edit controls.

You SUPERCLASS the control by adding functionality to it and by using a subclass in this context, producing filtered input is the functionality you are adding.

What makes a control a superclass is how you package it for reuse and if part of the design is added functionality, you attach the subclass procedure to it so that when you call you custom control function, it is ALREADY subclassed to do what you need.

This is often done in a DLL for higher level languages but in assembler you can just write and reuse the code within an app.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

shaldan

great .. I think I got it ... thank you very much  :U

hutch--

Here is a small example of how to do what you are after, its simple numbers only filtering with a single subclass that works on all 3 edit controls. This is the basic mechanics of superclassing a control.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

shaldan

thank you Hutch ..

Now I can see for sure, that the only problem was really in my understanding of the word: SUPERCLASSING .. .. because nearly the same example you gave me I wrote myself before I asked .. the only difference is that I have 2 controls and filter hex numbers :)

thanks again for your time ...