Click here to Skip to main content
15,923,087 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionPNG image in Dialog Pin
tamila_tamila17-May-10 7:07
tamila_tamila17-May-10 7:07 
AnswerRe: PNG image in Dialog Pin
jeron117-May-10 7:14
jeron117-May-10 7:14 
GeneralRe: PNG image in Dialog Pin
tamila_tamila18-May-10 1:00
tamila_tamila18-May-10 1:00 
QuestionVisual studio debugger yellow arrow cursor/owner draw control Pin
ForNow17-May-10 6:56
ForNow17-May-10 6:56 
AnswerRe: Visual studio debugger yellow arrow cursor/owner draw control Pin
Chris Losinger17-May-10 9:31
professionalChris Losinger17-May-10 9:31 
GeneralRe: Visual studio debugger yellow arrow cursor/owner draw control Pin
ForNow17-May-10 13:00
ForNow17-May-10 13:00 
Questionserial port I/O and console focus strange behavior Pin
pkcinna17-May-10 4:52
pkcinna17-May-10 4:52 
AnswerRe: serial port I/O and console focus strange behavior Pin
Aescleal17-May-10 8:53
Aescleal17-May-10 8:53 
GeneralRe: serial port I/O and console focus strange behavior Pin
pkcinna17-May-10 9:45
pkcinna17-May-10 9:45 
GeneralRe: serial port I/O and console focus strange behavior Pin
pkcinna17-May-10 11:15
pkcinna17-May-10 11:15 
QuestionHow to receive a notification when the app window is activated. Pin
sashoalm17-May-10 4:42
sashoalm17-May-10 4:42 
AnswerRe: How to receive a notification when the app window is activated. Pin
Code-o-mat17-May-10 4:49
Code-o-mat17-May-10 4:49 
GeneralRe: How to receive a notification when the app window is activated. Pin
sashoalm17-May-10 5:05
sashoalm17-May-10 5:05 
QuestionProblem with CreateFileMapping() window7/Vista. Pin
janaswamy uday17-May-10 2:38
janaswamy uday17-May-10 2:38 
QuestionMFC CreateInstance from CWinThread Pin
IAmRami17-May-10 2:28
IAmRami17-May-10 2:28 
AnswerRe: MFC CreateInstance from CWinThread Pin
Code-o-mat17-May-10 2:43
Code-o-mat17-May-10 2:43 
GeneralRe: MFC CreateInstance from CWinThread Pin
IAmRami17-May-10 3:31
IAmRami17-May-10 3:31 
GeneralRe: MFC CreateInstance from CWinThread Pin
Code-o-mat17-May-10 3:48
Code-o-mat17-May-10 3:48 
GeneralRe: MFC CreateInstance from CWinThread Pin
IAmRami19-May-10 22:05
IAmRami19-May-10 22:05 
QuestionHow to get all instances of Excel.exe Pin
KTTransfer17-May-10 2:17
KTTransfer17-May-10 2:17 
AnswerRe: EnumWindowsProc( ) , EnumProcessModules , FindWindow( ), Pin
Software_Developer17-May-10 3:00
Software_Developer17-May-10 3:00 
AnswerRe: How to get all instances of Excel.exe Pin
sashoalm17-May-10 5:07
sashoalm17-May-10 5:07 
GeneralRe: How to get all instances of Excel.exe Pin
KTTransfer17-May-10 18:12
KTTransfer17-May-10 18:12 
GeneralRe: How to get all instances of Excel.exe Pin
sashoalm17-May-10 23:33
sashoalm17-May-10 23:33 
This code might help you. Call get_Application function of the obtained document IDispatch to get its application's IDispatch.

void COffCntrDispCtrl::GetDocDispatch()
{
    // No need, if we already have it.
    if(m_pDocDisp != NULL) return;

    // Get a BindCtx.
    IBindCtx *pbc;
    HRESULT hr = CreateBindCtx(0, &pbc);
    if(FAILED(hr)) {
        DoErr("CreateBindCtx()", hr);
        return;
    }

    // Get running-object table.
    IRunningObjectTable *prot;
    hr = pbc->GetRunningObjectTable(&prot);
    if(FAILED(hr)) {
        DoErr("GetRunningObjectTable()", hr);
        pbc->Release();
        return;
    }

    // Get enumeration interface.
    IEnumMoniker *pem;
    hr = prot->EnumRunning(&pem);
    if(FAILED(hr)) {
        DoErr("EnumRunning()", hr);
        prot->Release();
        pbc->Release();
        return;
    }

    // Start at the beginning.
    pem->Reset();

    // Churn through enumeration.
    ULONG fetched;
    IMoniker *pmon;
    int n = 0;
    while(pem->Next(1, &pmon, &fetched) == S_OK) {

        // Get DisplayName.
        LPOLESTR pName;
        pmon->GetDisplayName(pbc, NULL, &pName);
        // Convert it to ASCII.
        char szName[512];
        WideCharToMultiByte(CP_ACP, 0, pName, -1, szName, 512, NULL,
        NULL);

        // Compare it against the name we got in SetHostNames().
        if(!strcmp(szName, m_szDocName)) {

            DoMsg("Found document in ROT!");

            // Bind to this ROT entry.
            IDispatch *pDisp;
            hr = pmon->BindToObject(pbc, NULL, IID_IDispatch, (void
            **)&pDisp);
            if(!FAILED(hr)) {
                // Remember IDispatch.
                m_pDocDisp = pDisp;

                // Notice...
                sprintf(buf, "Document IDispatch = %08lx",
                m_pDocDisp);
                DoMsg(buf);
            }
            else {
                DoErr("BindToObject()", hr);
            }
        }

        // Release interfaces.
        pmon->Release();

        // Break out if we obtained the IDispatch successfully.
        if(m_pDocDisp != NULL) break;
    }

    // Release interfaces.
    pem->Release();
    prot->Release();
    pbc->Release();
}

void COffCntrDispCtrl::TestDispatch()
{
    ASSERT(m_pDocDisp);

    COleDispatchDriver doc(m_pDocDisp);
    DISPID dispID = 0;
    unsigned short *ucPtr = L"Name";

    // Get DISPID for Name.
    HRESULT hr = m_pDocDisp->GetIDsOfNames(IID_NULL, &ucPtr, 1,
    LOCALE_USER_DEFAULT, &dispID);
    ASSERT(!FAILED(hr));


    // Get Name property.
    CString name;
    doc.GetProperty(dispID, VT_BSTR, &name);

    AfxMessageBox(
        CString("Document name is ") + name,
        MB_SETFOREGROUND
    );
}

There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal

GeneralRe: How to get all instances of Excel.exe Pin
T210211-Jan-11 22:00
T210211-Jan-11 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.