// Vance Thrift and Biller File Utility 2 // // Douglas Thrift // // $Id: Chooser.cxx,v 1.10 2003/09/05 01:57:00 douglas Exp $ #include "Chooser.h" Chooser::Chooser() { shortcut = false; choice = none; number = count++; choosers.insert(pair(number, this)); } Chooser::~Chooser() { choosers.erase(number); } Mode Chooser::choose(HWND parent) { DialogBoxParam(gui.instance, MAKEINTRESOURCE(IDD_CHOICE), parent, Chooser::window, number); desktop(); return choice; } unsigned Chooser::count = 0; map Chooser::choosers; map Chooser::windows; INT_PTR Chooser::window(HWND dialog, UINT msg, WPARAM w, LPARAM l) { map::iterator itor = windows.find(dialog); Chooser* data = itor->second; switch (msg) { case WM_INITDIALOG: center(dialog); SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); { map::iterator itor = choosers.find(l); windows.insert(pair(dialog, itor->second)); } break; case WM_COMMAND: switch (LOWORD(w)) { case IDC_CHOICE_DISC: data->choice = disc; if (debug) cerr << "choice = disc\n"; EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); EnableWindow(GetDlgItem(dialog, IDOK), TRUE); break; case IDC_CHOICE_SCAN: data->choice = scan; if (debug) cerr << "choice = scan\n"; EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); EnableWindow(GetDlgItem(dialog, IDOK), TRUE); break; case IDC_CHOICE_ALWAYS: data->shortcut = !data->shortcut; if (debug) cerr << "shortcut = " << data->shortcut << "\n"; break; case IDCANCEL: data->choice = none; case IDOK: EndDialog(dialog, w); return TRUE; default: break; } break; } return FALSE; } void Chooser::desktop(void) { if (!shortcut || choice == none) return; IShellLink* link; CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)(&link)); string name; link->SetPath(program.c_str()); link->SetIconLocation(program.c_str(), 0); link->SetDescription(programName.c_str()); switch (choice) { case disc: name = "Disc Browse"; link->SetArguments("-disc"); break; case scan: name = "Scan Utility"; link->SetArguments("-scan"); break; } IPersistFile* file; link->QueryInterface(IID_IPersistFile, (LPVOID*)(&file)); char* desktop = new char[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT, desktop); wstring path = toWide(string(desktop) + "\\" + name + ".lnk"); if (debug) cerr << "path = " << toAnsi(path) << "\n"; file->Save(path.c_str(), TRUE); file->Release(); link->Release(); delete [] desktop; }