Disable CCheckListBox items without access to code that calls AddString

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Disable CCheckListBox items without access to code that calls AddString

I need to be able to disable the items on a CCheckListBox but I can't change the code that calls AddString. I know I can use the CCheckListBox::Enable function to disable an item if I have an index but I don't have the index which would be provided by AddString. I've tried intercepting the LB_ADDSTRING message and then looping through the items in the control but the string has not been added at this point so the last item in the list is never disabled. I used Spy++ to see what messages were being sent and I noticed that LB_GETTEXT was sent so I tried intercepting this message (ugly hack) but this caused my app to hang - I assume because of the number of times the message is sent. Is there a way to disable the items?

Correct, I want to disable all items. I already tried setting up a for loop when I intercept the LB_ADDSTRING message but the item hasn't been added to the list at this point so it isn't included in the loop and isn't disabled.

The strings are added in my code but I want to create a generic solution that can be used by all dialogs to reduce maintenance and risk of coding error.

I have a hook that receives the messages and then passes them to this function. CMyDialog is the base class of the dialog which contains the CCheckListBox. I've verified that the LB_ADDSTRING message is received in this function. I've left out some of the code between the hook and this function to make this easier to show. I've verified that the part that is left out is working correctly.

I'm trying to disable all items in the control. I have multiple dialogs in my application and I need to provide a generic solution that will disable all items in any Arjay:
CCheckListBox in any of these dialogs based on a condition. So sometimes they need to be disabled and sometimes they need to be enabled. I don't want to write code to disable the items in each dialog because 1) I'll have to do this in a large number of dialogs; 2) it will increase the risk of someone breaking the functionality; 3) it will have to be added to dialogs that are created in the future. If I put this behavior in the base class it will be inherited by all existing dialogs and future dialogs (assuming they're derived), there will be no maintenance effort, and there will be a consistent solution instead of different for each dialog.

I cannot rely on the action that causes the AddString because it will be different in each dialog.

GCDEF:
I tried deriving a new class from CChecklistBox but couldn't figure out what to override. AddString is not in the list of overrides. Deriving a new class would also require a change in each dialog which I'm trying to avoid (though a small change that I'm willing to make at this point).

I tried deriving a new class from CChecklistBox but couldn't figure out what to override.

Just implement a new method in the derived class that will disable all the items in the control.
Then use your derived class instead of the CChecklistBox everywhere in your application/project.
Now if you'd like to disable all items in some of the controls you would only need to call the implemented method for disable all items!

Edit: I forgot to add (presuming it is obvious) that you would have to add control member variables of the implemented derived class for all the controls you would enable/disable)

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.