|
// バージョン情報ボックス用メッセージ ハンドラ
#include <lightbox.h>
class LboxCommdlg *Commdlg;
char szUrl[MAX_PATH];
char szBuffer[MAX_PATH];
void CreateShortcut( LPCSTR pszURL, LPCSTR pszShortCut ); // ユーザ関数宣言
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch( message ) {
case WM_INITDIALOG:
// インスタンスを作成
Commdlg = new LboxCommdlg( hDlg, hInst );
// 保存ダイアログのフィルタ
Commdlg->lpstrFilter = "インターネットショートカット,*.url";
// パス取得用バッファの初期化
szBuffer[0] = 0x00;
return TRUE;
case WM_COMMAND:
if( LOWORD(wParam) == IDCANCEL ) {
// インスタンス削除
delete Commdlg;
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
if( LOWORD(wParam) == IDOK ) {
// URL 文字列取得
GetDlgItemText( hDlg, IDC_EDIT1, szUrl, MAX_PATH );
// ショートカットのパスを取得
GetDlgItemText( hDlg, IDC_EDIT2, szBuffer, MAX_PATH );
// ユーザ関数呼び出し
CreateShortcut( szUrl, szBuffer );
}
if( LOWORD(wParam) == IDC_BUTTON1 ) {
// ショートカットのパスをダイアログで決定
if ( Commdlg->SaveFileName( szBuffer ) ) {
SetDlgItemText( hDlg, IDC_EDIT2, szBuffer );
}
}
break;
}
return FALSE;
}
// *********************************************************
// インターネットショートカット作成
// *********************************************************
#include <intshcut.h>
void CreateShortcut( LPCSTR pszURL, LPCSTR pszShortCut )
{
HRESULT hr;
IUniformResourceLocator *pUrl; // インスタンス用ポインタ変数
_bstr_t ShortCut( pszShortCut ); // ワイド文字列変換用
CoInitialize( NULL ); // COM ライブラリ初期化
// URL インスタンス作成
hr = CoCreateInstance(
CLSID_InternetShortcut,
NULL,
CLSCTX_INPROC_SERVER,
IID_IUniformResourceLocator,
(void**)&pUrl
);
if ( SUCCEEDED( hr ) ) {
// URL データセット
hr = pUrl->SetURL( pszURL, 0 );
if ( SUCCEEDED( hr ) ) {
// ショートカット保存処理
IPersistFile *pPf;
hr = pUrl->QueryInterface( IID_IPersistFile, (void **)&pPf );
if ( SUCCEEDED( hr ) ) {
hr = pPf->Save( ShortCut.operator wchar_t *(), TRUE );
pPf->Release();
}
}
// URL インスタンス解放
pUrl->Release();
}
CoUninitialize(); // COM ライブラリを閉じる
}
| |