IonicWind Software

IWBasic => General Questions => Topic started by: Andy on December 20, 2018, 05:02:33 AM

Title: Sub classing a single control.
Post by: Andy on December 20, 2018, 05:02:33 AM
Now I know we've done this before for edit controls etc... but what about this combo box.

This is Fasecero's example of a combo box created by using the CreateWindowExW command, and in this example the whole window is sub classed.

That's great for the combo box, but not for the button controls, they become "unresponsive" to a click.

Now I understand why, and I can work around it by changing the sub routine "subclassProc" and add in a
CASE MyButton section which makes the buttons work again.

E.g.

CASE MyButton
        DoSomething

But what if you have a lot of buttons, and each button has a lot of code?

if, in the section "OnInit" we comment out SetWindowSubclass(w1.hwnd, &subclassProc, subclassID, COMBO_1)
the button works again, but we cannot detect which combo box item is selected.

So how do we change this example to only sub class the combo box?

BTW I named the example "close" for no real reason.

Thanks,
Andy.

:)


Title: Re: Sub classing a single control.
Post by: fasecero on December 20, 2018, 03:21:04 PM
It's a tongue twister but I will try to explain it. subclassProc was bad designed. It's a mistake I can't stop doing it again and again. subclassProc is always called before w1_handler, and the message from the button is not forwarded to w1_handler bacause DefSubclassProc is never called

Fixed subclass procedure

SUB subclassProc(hWnd:INT,uMsg:INT,wParam:INT,lParam:INT,uIdSubclass:UINT_PTR,dwRefData:DWORD_PTR),INT
SELECT uMsg
CASE WM_COMMAND
SELECT LOWORD(wParam)
CASE COMBO_1
SELECT HIWORD(wParam)
CASE CBN_SELCHANGE ' the user has selected another index
OnIndexChange(lParam)
ENDSELECT
ENDSELECT
ENDSELECT

RETURN DefSubclassProc(hWnd, uMsg, wParam, lParam)
ENDSUB


Also, the last parameter of SetWindowSubclass does not need to be COMBO_1 and you can pass a 0.

SetWindowSubclass(w1.hwnd, &subclassProc, subclassID, 0)
Title: Re: Sub classing a single control.
Post by: Brian on December 21, 2018, 03:31:50 AM
Works for me! Well done again, Fasecero

Brian
Title: Re: Sub classing a single control.
Post by: Andy on December 21, 2018, 03:45:02 AM
Yes, thanks Fasecro!

Just tried it this morning and works great.

Andy.
:)

Title: Re: Sub classing a single control Explained.
Post by: Andy on December 22, 2018, 03:13:19 AM
Hi,

I thought I would spend some time documenting / explaining Fasecero's Unicode combo box example.

Hopefully as you read through the code, it will help you understand better what is being done here and why.

Read the code first, then compile / run, and select a couple of items from the combo box, finally close the program.

You can then read the text file 1.txt (in the same folder) which should show you how a combo box works.

Going through the code like this helped me to understand it better - hope it helps someone too!

Andy.
:)