And what's stopping you from handling it? The notification will be sent
to the parent window (unless you use message reflection to handle it in
a class you derive from CCombobox).
You don't need to add it to the message map dynamically. #define the
control ID in resource.h and use the ID in the dynamic creation call and in
the message map ON_CBN_DROPDOWN. Add it to the message map by typing it in
before compiling.
--
Scott McPhillips [VC++ MVP]
"Scot T Brennecke" wrote:
I can't write msg map dynamically in BEGIN_MESSAGE_MAP() END_MESSAGE_MAP()
"Scot T Brennecke" wrote:
I can't write msg map dynamically in
BEGIN_MESSAGE_MAP()
.....
...
END_MESSAGE_MAP() block.
So tell me how I can capture msg ON_CBN_DROPDOWN. I am using CCombobox
object for creating combobox dynamically and this class had derived from
CDialog.
As already mentioned, you dont need to add it dynamically to
Begin_message_map. Define the ID at compile time and place it the
message map. At run time, simply create a combobox with this ID.
--
Ajay
First, not your question. You indicate you are creating a singly dynamic combobox. To
create it, you have to have an ID. If you have an ID, you can add a handler to the
message map at compile time; the fact that there is currently no control of that ID is
irrelevant. When it is finally created, if it sends a notification, the notification will
be sent.
Of course, there is a question of why you need to create it at runtime. This is often
done because "it isn't needed all the time", in which case the solution is to create it at
design time, and merely make it invisible until it is needed.
On the other hand, if you need to create a multitude of these, you can use
ON_CONTROL_RANGE in your message map.
Do not assume for any reason that the message map can only be manipulated by the class
wizards. You can always hand-edit anything you want into them.
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
but I don't know how many combo box will create in application. So what I
have to do now..
But one thing more, you have written that "If you have an ID, you can add a
handler to the message map at compile time." that is not clear.
How I can add a handler to the message map at compile time.
please tell me in detail.
thanks in advance
Just look at what the wizard does for a control on a dialog template, and do the
same things. There are three parts:
declaration in .h file
implementation in .cpp file
message map entry in .cpp file
--
David Wilkinson
Visual C++ MVP
#define DYNAMIC_COMBO_MIN 10000
#define DYNAMIC_COMBO_MAX 10100
and keep track of the IDs I assign. My range for ON_CONTROL_RANGE will be from
DYNAMIC_COMBO_MIN to DYNAMIC_COMBO_MAX.
Note: never assume you have a clue as to the dimensions of your combo box. If you have
hardwired integers into your code, your code is wrong. What I do is place an invisible
combo box on the dialog template, for example, tucked into one corner. I make it the size
I want. When the program runs, and I want to create a new combo box, I will do something
like
CRect proto;
c_PrototypeCombo.GetWindowRect(&proto);
ScreenToClient(&proto);
CRect combo;
combo.left = ... where you want to put it...;
combo.top = ... where you want to put it...;
combo.right = combo.left + proto.Width();
combo.bottom = combo.top + proto.Height();
...create the combo box
This means your combo box automatically matches the correct size for the screen,
resolution, default font, display driver version, and angular position of Mars that are
appropriate for the machine on which the program is currently executing (which can be the
same machine you developed it on, an hour later, with different settings). Sometimes, you
compute the width based on GetTextExtent of some suitably representative string. You may
also compute the height on the fly to ensure that you don't get some ugly situation in
which you had space for four items, it actually shows six, and the one the user needs is
*always* off-window and must be scrolled (scrolling is ugly in such situations and should
be avoided).
They way you add a handler to the message map at compile time is with a text editor!
There's nothing deep about that. Put the caret at the point you want to do the insertion.
Type.
joe