Flush current work
[desktopswitcher.git] / rundialog.cpp
blob3f070e6aca13815356535c1b3af7768edf19ea3c
1 // $Id: rundialog.cpp,v 1.1 2002/05/29 22:06:50 nedko Exp $
2 //
3 // Desktop Switcher
4 // Copyright (C) 2000,2001,2002 Nedko Arnaudov <nedko@users.sourceforge.net>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "ph.h"
21 #include "switcher.h"
22 #include "RunDialog.h"
23 #include "resource.h"
25 CRunDialog::CRunDialog(const char *pszDefault)
27 strcpy(m_FilenameBuffer,pszDefault);
29 HRESULT hr = S_OK;
30 m_pMRU = new CMRUList(RUN_MRU_MAX, RUN_MRU_KEY, hr);
31 if (FAILED(hr))
33 delete m_pMRU;
34 m_pMRU = NULL;
38 CRunDialog::~CRunDialog()
42 const char * CRunDialog::DoModal(HWND hwnd)
44 if (DialogBoxParam(_Module.GetModuleInstance(),MAKEINTRESOURCE(IDD_DIALOG_RUN),hwnd,DialogProc,(LPARAM)this) == IDOK)
45 return m_FilenameBuffer;
46 else
47 return NULL;
50 int __stdcall CRunDialog::DialogProc(HWND hwndDlg, UINT nMsg, WPARAM wParam, LPARAM lParam)
52 CRunDialog *pThis = (CRunDialog *)GetWindowLong(hwndDlg,GWL_USERDATA);
53 switch(nMsg)
55 case WM_INITDIALOG:
57 SetForegroundWindow(hwndDlg);
58 pThis = (CRunDialog *)lParam;
59 SetWindowLong(hwndDlg,GWL_USERDATA,(LPARAM)pThis);
60 HWND hwndCombo = GetDlgItem(hwndDlg,IDC_COMBO_COMMAND);
61 if (hwndCombo && pThis->m_pMRU)
63 for (unsigned int i = 0; i < pThis->m_pMRU->GetCount(); i ++)
64 SendMessage(hwndCombo,CB_INSERTSTRING,-1,(LPARAM)pThis->m_pMRU->GetEntry(i));
66 SendMessage(hwndCombo,CB_SETCURSEL,0,0);
67 SendMessage(hwndCombo,CB_SETDROPPEDWIDTH,600,0);
69 return TRUE;
70 case WM_COMMAND:
71 switch(LOWORD(wParam))
73 case IDC_BUTTON_BROWSE:
75 OPENFILENAME ofn;
76 ofn.lStructSize = sizeof(OPENFILENAME);
77 ofn.hwndOwner = hwndDlg;
78 ofn.hInstance = NULL;
79 ofn.lpstrFilter = "Executable Files (*.exe;*.com;*.bat)\0*.exe;*.com;*.bat\0All Files (*.*)\0*.*\0";
80 ofn.lpstrCustomFilter = NULL;
81 ofn.nMaxCustFilter = 0;
82 ofn.nFilterIndex = 1;
83 pThis->m_FilenameBuffer[0] = 0;
84 ofn.lpstrFile = pThis->m_FilenameBuffer;
85 ofn.nMaxFile = MAX_FILENAME_SIZE;
86 ofn.lpstrFileTitle = NULL;
87 ofn.nMaxFileTitle = 0;
88 ofn.lpstrInitialDir = NULL;
89 ofn.lpstrTitle = "Please select file to run";
90 ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
91 ofn.nFileOffset = 0;
92 ofn.nFileExtension = 0;
93 ofn.lpstrDefExt = NULL;
94 ofn.lCustData = (LPARAM)pThis;
95 ofn.lpfnHook = NULL;
96 ofn.lpTemplateName = NULL;
97 #if (_WIN32_WINNT >= 0x0500)
98 ofn.pvReserved = NULL;
99 ofn.dwReserved = 0;
100 ofn.FlagsEx = 0;
101 #endif
102 if (GetOpenFileName(&ofn))
103 SetWindowText(GetDlgItem(hwndDlg,IDC_COMBO_COMMAND),pThis->m_FilenameBuffer);
105 return TRUE;
106 case IDOK:
107 if (!GetWindowText(GetDlgItem(hwndDlg,IDC_COMBO_COMMAND),pThis->m_FilenameBuffer,MAX_FILENAME_SIZE))
109 strcpy(pThis->m_FilenameBuffer,"cmd");
111 else if (pThis->m_pMRU)
113 VERIFY(SUCCEEDED(pThis->m_pMRU->Add(pThis->m_FilenameBuffer)));
115 case IDCANCEL:
116 EndDialog(hwndDlg,LOWORD(wParam));
117 return TRUE;
119 default:
120 return FALSE;