こんにちわ
先日エクスプローラのツールバーを非表示にするには?
という質問でお世話になった者です
タイトルのとおりなのですが、先日使っていたマシンと違うマシンでエクスプローラ実行処理をしましたところ、処理がものすごく重くなり、応答なしを頻繁に起こすようになってしまいました。
この現象はマシンスペックが足りないため起こってしまうのでしょうか?
それとも他に原因があるのでしたら教えていただけないでしょうか?
環境は先日と同じくVC++6.0 MFC WinXP ProsSP2です
おそらく
> while ( ( pExplorer = this->FindWindow( _T( "ExploreWClass" ), NULL ) ) == NULL );
> while ( !pExplorer->IsWindowVisible() );
が問題なんでしょう。
クラス名が CabinetWClass か ExploreWClass なので環境によって違うかもしれませんし。
それと、前回の回答後よく考えたのですが、この処理って本当に必要なんでしょうか?
一度「標準のボタン」のチェックをはずせば、次回から表示されなくなるし、
起動後ユーザが手動で表示させてしまえば意味なくなるし。
対策としては、
案1.CabinetWClass と ExploreWClass でFindWindowする。(取れるまで無限ループ)
案2.ShellExecuteではなくShellExecuteExで起動し、WaitForInputIdleで待ってから、
CabinetWClass と ExploreWClass でFindWindowする。(1回)
参考過去ログ:http://madia.world.coocan.jp/cgi-bin/Vcbbs/wwwlng.cgi?print+200603/06030036.txt
案3.SHDocVw::ShellWindowsをつかって、ハンドルを取得する。
(一番確実に取れるが、COMなので扱いにくい上に若干遅い。)
一応案3ので試したコード
#import <SHDocVw.dll>
#import <Shell32.dll>
・
・
・
void CXXXXDlg::OnButton1()
{
// TODO: この位置にコントロール通知ハンドラ用のコードを追加してください
const LPCTSTR path = _T( "E:\\" ); // 任意のパス
TCHAR cmd[ 256 ];
_stprintf( cmd, _T( "/e,/root=\"%s\"" ), path );
if ( ( int )::ShellExecute( 0, _T( "open" ), _T( "explorer" ), cmd, NULL, SW_SHOW ) >= 32 )
{
CWnd* pExplorer = NULL;
HRESULT hr = ::CoInitialize( NULL );
if ( FAILED( hr ) ) return;
SHDocVw::IShellWindowsPtr sw = NULL;
try
{
hr = sw.CreateInstance( __uuidof( SHDocVw::ShellWindows ) );
if ( FAILED( hr ) ) _com_issue_error( hr );
for ( long i = 0; i < sw->Count; ++i )
{
if ( SHDocVw::IWebBrowser2Ptr ie = sw->Item( i ) )
{
if ( Shell32::IShellFolderViewDualPtr view = ie->GetDocument() )
{
Shell32::Folder2Ptr pFolder = view->Folder;
Shell32::FolderItemPtr pFolderItem = pFolder->Self;
_bstr_t sPath = pFolderItem->Path;
if ( !_wcsicmp( sPath, ( _bstr_t )path ) )
{
pExplorer = CWnd::FromHandle( ( HWND )ie->HWND );
while ( ie->Visible == VARIANT_FALSE );
// ie->ToolBar = VARIANT_FALSE;
break;
}
}
}
}
}
catch ( _com_error& e )
{
hr = e.Error();
}
sw.Release();
::CoUninitialize();
if ( FAILED( hr ) ) return;
if ( pExplorer == NULL ) return;
CWnd* pWork = pExplorer->GetDlgItem( 0xA005 );
if ( pWork )
{
CWnd* pReBar = pWork->GetDlgItem( 0xA005 );
if ( pReBar )
{
CWnd* pToolBar = pReBar->GetDlgItem( 0xA000 );
if ( pToolBar && pToolBar->IsWindowVisible() )
{
pExplorer->SendMessage( WM_COMMAND, ( WPARAM )0xA204, ( LPARAM )0L );
}
}
}
}
}
行コメントになっているのが、前回のレスで行ったやつ。
ツイート | ![]() |