Problem with Highlighting, Timers and WordXP

D

DanielH

Hello,

I have a very strange problem:

When using a Timer in a Word-Plugin which sets or gets the
HighlightColorIndex-Value of a range, everything that will be typed in Word
will appear two or three times.


This source-code can be used to reproduce this problem:

Connect.cpp:

STDMETHODIMP
CConnect::OnDisconnection(AddInDesignerObjects::ext_DisconnectMode
/*RemoveMode*/, SAFEARRAY ** /*custom*/ )
{
m_pApplication = NULL;
m_pAddInInstance = NULL;
return S_OK;
}

STDMETHODIMP CConnect::OnAddInsUpdate (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}

void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
Word::_ApplicationPtr pApp = Word::_ApplicationPtr(&(*g_pApplication));
Word::_DocumentPtr pDoc = pApp->GetActiveDocument();
Word::WordsPtr pWords = pDoc->GetWords();
if (pWords->GetCount() > 3)
{
Word::RangePtr pWord = pWords->Item(2);
OutputDebugStr("Hi there\n");
pWord->PutHighlightColorIndex(Word::wdYellow);
}

}

STDMETHODIMP CConnect::OnConnection(IDispatch *pApplication,
AddInDesignerObjects::ext_ConnectMode /*ConnectMode*/, IDispatch *pAddInInst,
SAFEARRAY ** /*custom*/ )
{
pApplication->QueryInterface(__uuidof(IDispatch), (LPVOID*)&m_pApplication);
pAddInInst->QueryInterface(__uuidof(IDispatch), (LPVOID*)&m_pAddInInstance);

g_pApplication = m_pApplication;

return S_OK;
}

STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*custom*/ )
{
SetTimer(NULL, NULL, 1000, TimerProc);
return S_OK;
}

STDMETHODIMP CConnect::OnBeginShutdown (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}


This problem also occurs on Word2000. This is very urgent, please help.

Any help, hints, solutions and work-arounds are GREATLY appreciated.


Kind regards,

Daniel Hilgarth
 

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