Winx-p.cpp

[目次 | 関数 | マクロ]

目次

関数一覧

マクロ一覧


   1|/**************************************************************************
   2|*  1. <<< Windows API by C++ (WinXpp) >>> 
   3|***************************************************************************/
   4|
   5|#include  <windows.h>
   6|#include  <WinInet.h>
   7|#define _WIN32_IE 0x0400
   8|#include  <shlobj.h>
   9|#include  <ComDef.h>
  10|#include  <shlwapi.h>
  11|
  12|#define  WINDOWSINC_INCLUDE_WINDOWS_H
  13|#ifdef  USES_MXP_AUTOINC
  14| #include  <winx.ah>  /* Auto include header, Look at mixer-... folder */
  15|#else
  16| #include  <all.h>
  17|#endif
  18|
  19|
  20|
  21|
  22| 
  23|/*------------------------------------------------------------------------*/
  24|/*  2. <<< ◆パス関係 >>>  */ 
  25|/*------------------------------------------------------------------------*/
  26|
  27| 
  28|/**************************************************************************
  29|  3. <<< [WinX_getShortCutTarget] ショートカット・ファイルのリンク先を取得する >>> 
  30|***************************************************************************/
  31|void  WinX_getShortCutTarget( const char* shortCut_path, char* target_path )
  32|{
  33|  IShellLink*    shell;
  34|  IPersistFile*  persis;
  35|  bool  bCo = false;
  36|  bool  bShell = false;
  37|  bool  bPersis = false;
  38|  WCHAR  wcLinkFile[MAX_PATH];
  39|  WIN32_FIND_DATA  dummy;
  40|  HRESULT  ret;
  41|
  42|  c_try {
  43|    CoInitialize( NULL );  bCo = true;
  44|    ret = CoCreateInstance( CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&shell );
  45|    if ( ret != S_OK )  error();
  46|    ret = shell->QueryInterface( IID_IPersistFile, (void **)&persis );
  47|    if ( ret != S_OK )  error();
  48|    MultiByteToWideChar( CP_ACP, 0, shortCut_path, -1, wcLinkFile, MAX_PATH );
  49|    ret = persis->Load( wcLinkFile, STGM_READ );
  50|    if ( ret != S_OK )  error();
  51|    shell->GetPath( target_path, MAX_PATH, &dummy, SLGP_UNCPRIORITY );
  52|  }
  53|  c_finally {
  54|    if ( bPersis )  persis->Release();
  55|		if ( bShell )  shell->Release();
  56|    if ( bCo )  CoUninitialize();
  57|	} c_end_finally;
  58|}
  59|
  60| 
  61|/**************************************************************************
  62|  4. <<< [WinX_createShortcut] ショートカットファイルを作成する >>> 
  63|【引数】
  64|  ・char*  path;         作成するショートカットファイルのパス(*.lnk)
  65|  ・char*  targetPath;   リンク先のファイルパス
  66|  ・char*  param;        targePath に続けて指定するコマンド列
  67|  ・char*  workPath;     作業用ディレクトリ・パス(カレント・ディレクトリ)
  68|  ・int    showFlags;    表示形態(SW_SHOWNORMAL など)
  69|  ・char*  iconPath;     アイコンのファイルパス
  70|  ・int    iIcon;        iconPath ファイルの中のアイコン番号
  71|  ・char*  description;  ショートカットの説明(ヒント表示、"" 指定可)
  72|【補足】
  73|・各引数については、Windows でショートカットを作成し、プロパティをさわって
  74|  理解してください。
  75|***************************************************************************/
  76|void  WinX_createShortcut( const char* path, const char* targetPath,
  77|  const char* param, const char* workPath, int showFlags,
  78|  const char* iconPath, int iIcon, const char* description )
  79|{
  80|  IShellLink*    link;
  81|  bool           bLink = false;
  82|  IPersistFile*  file;
  83|  bool           bFile = false;
  84|  WCHAR          ws[MAX_PATH];
  85|
  86|  c_try {
  87|
  88|    CoInitialize( NULL );
  89|
  90|    /* IShellLink I/F */
  91|    if ( FAILED( CoCreateInstance( CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
  92|        IID_IShellLink, (void**)&link ) ) )
  93|      WinX_throw(-1);
  94|    bLink = true;
  95|
  96|    /* 属性を設定する */
  97|    link->SetPath( targetPath );
  98|    link->SetArguments( param );
  99|    link->SetWorkingDirectory( workPath );
 100|    link->SetShowCmd( showFlags );
 101|    link->SetIconLocation( iconPath, iIcon );
 102|
 103|    /* IPersistFile I/F */
 104|    if ( FAILED( link->QueryInterface( IID_IPersistFile, (void**)&file ) ) )
 105|      WinX_throw(-1);
 106|
 107|    /* ファイルの作成 */
 108|    MultiByteToWideChar( CP_ACP, 0, path, -1, ws, MAX_PATH );
 109|    if ( FAILED( file->Save( ws, TRUE ) ) )
 110|      WinX_throw(-1);
 111|  }
 112|  c_finally {
 113|    if ( bFile )   file->Release();
 114|    if ( bLink )   link->Release();
 115|    CoUninitialize();
 116|  } c_end_finally;
 117|}
 118|
 119|
 120| 
 121|/**************************************************************************
 122|  5. <<< [WinX_openFolderSelDlg] フォルダ選択ダイアログを表示する >>> 
 123|【引数】
 124|  ・HWND  parent;    親ウィンドウ
 125|  ・char*  title;    説明文
 126|  ・char*  path;     (入力)デフォルトパス(出力)選択したフォルダパス
 127|  ・bool  返り値;     OK を押したかどうか(false=キャンセル)
 128|【補足】
 129|・path のサイズは、_MAX_PATH 以上にします。
 130|***************************************************************************/
 131|int _stdcall  WinX_openFolderSelDlgSub( HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData );
 132|
 133|
 134|bool  WinX_openFolderSelDlg( HWND parent, const char* title, char* path )
 135|{
 136|  BROWSEINFO   info;
 137|  ITEMIDLIST*  idl;
 138|
 139|  info.hwndOwner = parent;
 140|  info.pidlRoot = NULL;
 141|  info.pszDisplayName = path;
 142|  info.lpszTitle = title;
 143|  info.ulFlags = BIF_RETURNONLYFSDIRS;
 144|  info.lpfn = WinX_openFolderSelDlgSub;
 145|  info.lParam = (LPARAM)path;
 146|  info.iImage = 1;
 147|
 148|  idl = SHBrowseForFolder( &info );
 149|
 150|  if ( idl == NULL )  return  false;
 151|
 152|  SHGetPathFromIDList( idl, path );
 153|
 154|  CoTaskMemFree( idl );
 155|  return  true;
 156|}
 157|
 158|
 159|static int _stdcall  WinX_openFolderSelDlgSub( HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData )
 160|{
 161|  switch ( uMsg ) {
 162|    case BFFM_INITIALIZED:
 163|      SendMessage( hWnd, BFFM_SETSELECTION, TRUE, lpData );
 164|      break;
 165|  }
 166|  return  0;
 167|}
 168| 
 169|/*------------------------------------------------------------------------*/
 170|/*  6. <<< ◆エクスプローラメニュー関係 >>>  */ 
 171|/*------------------------------------------------------------------------*/
 172|
 173|
 174| 
 175|/**************************************************************************
 176|  7. <<< [WinX_flush] デスクトップやエクスプローラを最新の情報に更新する >>> 
 177|【補足】
 178|・デスクトップ、エクスプローラ、インターネット・エクスプローラを最新の情報に
 179|  更新します。
 180|・別のプロセスでフォルダウィンドウを開く設定になっているときは、デスクトップ
 181|  しか更新できません。(Windows の仕様?)
 182|***************************************************************************/
 183|void  WinX_flush()
 184|{
 185|  SHChangeNotify( SHCNE_ASSOCCHANGED, SHCNF_FLUSH, NULL, NULL );
 186|}
 187|
 188|
 189|#if 0
 190|
 191|void   WinX_reloadActiveDesktop()
 192|{
 193|//  IActiveDesktopPtr  pActiveDesktop( _uuidof( ActiveDesktop ) );
 194|//  pActiveDesktop->ApplyChanges( AD_APPLY_ALL );
 195|
 196|  HRESULT          hr;
 197|  IActiveDesktop*  pActiveDesktop;
 198|  COMPONENT        com;
 199|
 200|  CoInitialize( NULL );
 201|  hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
 202|              IID_IActiveDesktop, (void**)&pActiveDesktop);
 203|  if (! SUCCEEDED(hr))  error();
 204|
 205|  memset( &com, 0, sizeof(com) );
 206|  com.dwSize = sizeof(com);
 207|  hr = pActiveDesktop->GetDesktopItem( 0, &com, 0 );
 208|  if (! SUCCEEDED(hr))  error();
 209|
 210|  hr = pActiveDesktop->ModifyDesktopItem( &com, AD_APPLY_REFRESH );
 211|  if (! SUCCEEDED(hr))  error();
 212|
 213|  hr = pActiveDesktop->ApplyChanges( AD_APPLY_ALL );
 214|  if (! SUCCEEDED(hr))  error();
 215|
 216|  pActiveDesktop->Release();
 217|  CoUninitialize();
 218|}
 219|
 220|#endif
 221| 
 222|