August 22, 2019, 12:13:37 pm

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Sub classing a single control.

Started by Andy, December 20, 2018, 05:02:33 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

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.

:)


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

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

Code Select
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.

Code Select
SetWindowSubclass(w1.hwnd, &subclassProc, subclassID, 0)

Brian

December 21, 2018, 03:31:50 am #2 Last Edit: December 21, 2018, 04:43:16 am by Brian Pugh
Works for me! Well done again, Fasecero

Brian

Andy

Yes, thanks Fasecro!

Just tried it this morning and works great.

Andy.
:)

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

December 22, 2018, 03:13:19 am #4 Last Edit: December 22, 2018, 04:27:17 am by Andy
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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.