views:

251

answers:

2

Hi!

I've got a code (which works fine) for piloting word with C++ Builder. It's useful for reaching different bookmarks in the document.

Variant vNom, vWDocuments, vWDocument, vMSWord, vSignets, vSignet;
    vNom = WideString("blabla.doc");
    try
    {
        vMSWord = Variant::GetActiveObject("Word.Application");
    }
    catch(...)
    {
        vMSWord = Variant::CreateObject("Word.Application");
    }
    vMSWord.OlePropertySet("Visible", true);
    vWDocuments = vMSWord.OlePropertyGet("Documents");
    vWDocument = vWDocuments.OleFunction("Open", vNom);
    vSignets = vWDocument.OlePropertyGet("BookMarks");
    if (vSignets.OleFunction("Exists", signet))
    {
        vSignet = vSignets.OleFunction("Item", signet);
        vSignet.OleFunction("Select");
    }

But once the document is opened, the user can no longer see when an other bookmark has been reached, since the application stays in background.

Does anyone know how i can do to make Word displayed in the foreground, or to light-up the document in the taskbar?

Thanks!

A: 

There is a simple trick to do that (using Win32 API):

ShowWindow(hwnd, SW_MINIMIZE);
ShowWindow(hwnd, SW_RESTORE);

You must find the hwnd of word using the EnumWindows function.

RED SOFT ADAIR
Yes it works, thanks a lot!
Getz
A: 

I use the "FindWindow" method:

HWND hwnd = FindWindowA(NULL,"blabla.doc - Microsoft Word");
    ShowWindow(hwnd, SW_MINIMIZE);
    ShowWindow(hwnd, SW_RESTORE);
Getz