How to add combobox to a com add-in for ms office

S

santosh

Hi
I am developing an add-in for MS WORD in which
I am adding a toolbar which contains a button and combobox using COM in
visual c++ .
For that I'm using a sample addin in msdn "comaddin.exe".
this is the link for downloading 'comaddin.exe'
http://support.microsoft.com/?kbid=230689

I modified the code to add one combobox.
like this.


STDMETHODIMP CMyAddin::OnStartupComplete(LPSAFEARRAY* custom)

{

......................

.......................

/***********************************************************************************/

/* Code For adding ComboBox */

/***********************************************************************************/



vtParam.vt = VT_BSTR;

vtParam.bstrVal = ::SysAllocString(L"ComboBox1");

hr = CallMethod(vtCtrls.pdispVal, L"Item", &vtComboBox, 1, &vtParam);

VariantClear(&vtParam);



if (FAILED(hr)) {

vtParam.vt = VT_I4; vtParam.lVal = COMBOBOX;

hr = CallMethod(vtCtrls.pdispVal, L"Add", &vtComboBox, 1, &vtParam);

if (FAILED(hr)) goto cleanup;



//I tried this method for populating the listBox but it is not working.

I TRIED THIS METHOD FOR POPULATING THE LIST BOX BUT IT IS NOT WORKING


vtParam.vt = VT_BSTR;

vtParam.bstrVal = ::SysAllocString(L"String1; String2;String3");

hr = PutProperty(vtComboBox.pdispVal, L"Data", &vtParam);

if (FAILED(hr)) goto cleanup;



CAN SOMEONE PLEASE SUGGEST ANY SOLUTION TO THIS PROBLEM.I ALSO WANT TO
HANDLE TEXT CHANGE EVENT OF COMBOBOX AND BUTTON CLICK

(FOR MORE THAN ONE BUTTON IT FIRES SAME EVENT). IS THERE ANY METHOD TO FIRE
DIFFERENT EVENTS FOR DIFFERENT BUTTONS.

RIGHT NOW I HAVE WRITTEN DIFFERENT CLASSES FOR ALL BUTTONS FOR HANDLING
"CLICK" EVENTS. BUT I DONT WANT TO DO THIS AND SEARCHING

FOR SOME BETTER SOLUTION

PLEASE HELP, ITS URGENT



Santosh
 
C

Cindy M -WordMVP-

Hi Santosh,
//I tried this method for populating the listBox but it is not working.

I TRIED THIS METHOD FOR POPULATING THE LIST BOX BUT IT IS NOT WORKING


vtParam.vt = VT_BSTR;

vtParam.bstrVal = ::SysAllocString(L"String1; String2;String3");

hr = PutProperty(vtComboBox.pdispVal, L"Data", &vtParam);
I don't really understand C++ syntax very well, but... An Office ComboBox
doesn't have a "Data" property. You have to insert the list entries one
at a time, using the .AddItem method.

You have to define "OnClick" events for each button. Again, I don't know
the syntax for C++. For C# one needs to use "delegates".

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top