minimize an Excel window using c++
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: minimize an Excel window using c++

  1. #1
    Join Date
    Sep 2013
    Posts
    10

    minimize an Excel window using c++

    I'm trying to minimize an Excel window using c++. but it doesn't work.
    Code:
     
    //Save the PID
    HWND hWnd = FindWindowA(NULL, (LPCSTR)pXlApp);  
    GetWindowThreadProcessId(hWnd, &proccesID);
    
    // Make it visible 
    {
    VARIANT x;
    x.vt = VT_I4;
    x.lVal = isVisible;
    AutoWrap(DISPATCH_PROPERTYPUT, NULL, pXlApp, L"Visible", 1, x);
    }
    Here I tried this:
    Code:
     
    {
    SetForegroundWindow((HWND)(((ULONG) hWnd) | 0x01) );
    BringWindowToTop(hWnd);
    ShowWindow(hWnd, SW_MINIMIZE);      
    }
    and this:
    Code:
     
    {
    ShowWindow(hWnd, SW_MINIMIZE);      
    }
    amd i have also tried WINDOWPLACEMENT and other things, and anything works.

    I checked the HWND is not null, but is not visible....
    Code:
     
    bool visible=IsWindowVisible(hWnd);
    and visible=false, but the window is Visible (I see the Excel file)

    Do you know why?

    Could you help me?? Thank you

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: minimize an Excel window using c++

    Probably, you got anoter window handle. Just use Spy++ to see if that's true.
    And/or try this:
    Code:
        HWND hWnd = ::FindWindow(_T("XLMAIN"), NULL);
        if(NULL != hWnd)
        {
            if(! ::IsIconic(hWnd))
            {
                ::ShowWindowAsync(hWnd, SW_MINIMIZE);
            }
        }
    Also verify with Spy++ if the main window class name is "XLMAIN" or another one (may differ in other Excel version).
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Sep 2013
    Posts
    10

    Re: minimize an Excel window using c++

    that works very good.
    thank you very much!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center