/* リンク あらかじめ、CoInitialize(NULL); を実行しておくこと */ BOOL SymLink(LPCSTR src, LPSTR dest, LPCSTR arg) { IShellLink *shellLink; IPersistFile *persistFile; Wstr wsrc(src), wdest(dest), warg(arg); BOOL ret = FALSE; char buf[MAX_PATH_U8]; if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void **)&shellLink))) { shellLink->SetPath((char *)wsrc.Buf()); shellLink->SetArguments((char *)warg.Buf()); GetParentDirU8(src, buf); shellLink->SetWorkingDirectory((char *)U8toWs(buf)); if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) { if (SUCCEEDED(persistFile->Save(wdest.s(), TRUE))) { ret = TRUE; GetParentDirU8(WtoU8(wdest.s()), buf); ::SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH|SHCNF_FLUSH, U8toAs(buf), NULL); } persistFile->Release(); } shellLink->Release(); } return ret; }
/* メインダイアログ用 WM_INITDIALOG 処理ルーチン */ BOOL TUninstDlg::EvCreate(LPARAM lParam) { char title[256], title2[256]; GetWindowText(title, sizeof(title)); ::wsprintf(title2, "%s ver%s", title, GetVersionStr()); SetWindowText(title2); GetWindowRect(&rect); int cx = ::GetSystemMetrics(SM_CXFULLSCREEN), cy = ::GetSystemMetrics(SM_CYFULLSCREEN); int xsize = rect.right - rect.left, ysize = rect.bottom - rect.top; ::SetClassLong(hWnd, GCL_HICON, (LONG)::LoadIcon(TApp::GetInstance(), (LPCSTR)SETUP_ICON)); MoveWindow((cx - xsize)/2, (cy - ysize)/2, xsize, ysize, TRUE); Show(); // 現在ディレクトリ設定 char resetupDir[MAX_PATH_U8]; GetModuleFileNameU8(NULL, resetupDir, sizeof(resetupDir)); GetParentDirU8(resetupDir, resetupDir); SetDlgItemTextU8(RESETUP_EDIT, resetupDir); if (runasWnd) { ::SendMessage(runasWnd, IPMSG_QUIT_MESSAGE, 0, 0); CheckDlgButton(DELPUBKEY_CHECK, 1); PostMessage(WM_COMMAND, IDOK, 0); } return TRUE; }
/* BrowseDlg用 WM_COMMAND 処理 */ BOOL TBrowseDirDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl) { switch (wID) { case MKDIR_BUTTON: { char dirBuf[MAX_PATH_U8], path[MAX_PATH_U8]; TInputDlg dlg(dirBuf, this); if (dlg.Exec() != IDOK) return TRUE; MakePath(path, fileBuf, dirBuf); if (CreateDirectoryU8(path, NULL)) { strcpy(fileBuf, path); dirtyFlg = TRUE; PostMessage(WM_CLOSE, 0, 0); } } return TRUE; case RMDIR_BUTTON: if (RemoveDirectoryU8(fileBuf)) { GetParentDirU8(fileBuf, fileBuf); dirtyFlg = TRUE; PostMessage(WM_CLOSE, 0, 0); } return TRUE; } return FALSE; }
/* BrowseDlg用サブクラス生成 */ BOOL TBrowseDirDlg::AttachWnd(HWND _hWnd) { BOOL ret = TSubClass::AttachWnd(_hWnd); dirtyFlg = FALSE; // ディレクトリ設定 DWORD attr = GetFileAttributesU8(fileBuf); if (attr == 0xffffffff || (attr & FILE_ATTRIBUTE_DIRECTORY) == 0) GetParentDirU8(fileBuf, fileBuf); SendMessageW(BFFM_SETSELECTIONW, TRUE, (LPARAM)U8toWs(fileBuf)); SetWindowText(IPMSG_FULLNAME); // ボタン作成 RECT tmp_rect; ::GetWindowRect(GetDlgItem(IDOK), &tmp_rect); POINT pt = { tmp_rect.left, tmp_rect.top }; ::ScreenToClient(hWnd, &pt); int cx = (pt.x - 30) / 2, cy = tmp_rect.bottom - tmp_rect.top; ::CreateWindowU8(BUTTON_CLASS, GetLoadStrU8(IDS_MKDIR), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 10, pt.y, cx, cy, hWnd, (HMENU)MKDIR_BUTTON, TApp::GetInstance(), NULL); ::CreateWindowU8(BUTTON_CLASS, GetLoadStrU8(IDS_RMDIR), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 18 + cx, pt.y, cx, cy, hWnd, (HMENU)RMDIR_BUTTON, TApp::GetInstance(), NULL); HFONT hDlgFont = (HFONT)SendDlgItemMessage(IDOK, WM_GETFONT, 0, 0L); if (hDlgFont) { SendDlgItemMessage(MKDIR_BUTTON, WM_SETFONT, (UINT)hDlgFont, 0L); SendDlgItemMessage(RMDIR_BUTTON, WM_SETFONT, (UINT)hDlgFont, 0L); } return ret; }
/* リンクファイル削除 */ BOOL DeleteLink(LPCSTR path) { char dir[MAX_PATH_U8]; if (!DeleteFileU8(path)) return FALSE; GetParentDirU8(path, dir); ::SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH|SHCNF_FLUSH, U8toA(dir), NULL); return TRUE; }
/* ファイルの保存されているドライブ識別 */ UINT GetDriveTypeEx(const char *file) { if (file == NULL) return GetDriveType(NULL); if (IsUncFile(file)) return DRIVE_REMOTE; char buf[MAX_PATH_U8]; int len = strlen(file), len2; strcpy(buf, file); do { len2 = len; GetParentDirU8(buf, buf); len = strlen(buf); } while (len != len2); return GetDriveTypeU8(buf); }