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
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).
Re: minimize an Excel window using c++
that works very good.
thank you very much!!