0dc125401dd38d660149e147d1427e65148f9ff3
[reactos.git] / rosapps / winfile / run.c
1 /*
2 * ReactOS Task Manager
3 *
4 * run.c
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <process.h>
31 #include <stdio.h>
32
33 #include <shellapi.h>
34
35 #include "main.h"
36 #include "run.h"
37
38
39 typedef void (WINAPI *RUNFILEDLG)(
40 HWND hwndOwner,
41 HICON hIcon,
42 LPCSTR lpstrDirectory,
43 LPCSTR lpstrTitle,
44 LPCSTR lpstrDescription,
45 UINT uFlags);
46
47 //
48 // Flags for RunFileDlg
49 //
50
51 #define RFF_NOBROWSE 0x01 // Removes the browse button.
52 #define RFF_NODEFAULT 0x02 // No default item selected.
53 #define RFF_CALCDIRECTORY 0x04 // Calculates the working directory from the file name.
54 #define RFF_NOLABEL 0x08 // Removes the edit box label.
55 #define RFF_NOSEPARATEMEM 0x20 // Removes the Separate Memory Space check box (Windows NT only).
56
57
58 // Show "Run..." dialog
59 void OnFileRun(void)
60 {
61 HMODULE hShell32;
62 RUNFILEDLG RunFileDlg;
63 OSVERSIONINFO versionInfo;
64 WCHAR wTitle[40];
65 WCHAR wText[256];
66 CHAR szTitle[40] = "Create New Task";
67 CHAR szText[256] = "Type the name of a program, folder, document, or Internet resource, and Task Manager will open it for you.";
68
69 hShell32 = LoadLibrary(_T("SHELL32.DLL"));
70 RunFileDlg = (RUNFILEDLG)(FARPROC)GetProcAddress(hShell32, (CHAR*)((long)0x3D));
71 if (RunFileDlg) {
72 versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
73 GetVersionEx(&versionInfo);
74 if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
75 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTitle, -1, wTitle, 40);
76 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szText, -1, wText, 256);
77 RunFileDlg(Globals.hMainWnd, 0, NULL, (LPCSTR)wTitle, (LPCSTR)wText, RFF_CALCDIRECTORY);
78 } else {
79 RunFileDlg(Globals.hMainWnd, 0, NULL, szTitle, szText, RFF_CALCDIRECTORY);
80 }
81 }
82 FreeLibrary(hShell32);
83 }
84
85
86 /*
87 typedef struct _SHELLEXECUTEINFO{
88 DWORD cbSize;
89 ULONG fMask;
90 HWND hwnd;
91 LPCTSTR lpVerb;
92 LPCTSTR lpFile;
93 LPCTSTR lpParameters;
94 LPCTSTR lpDirectory;
95 int nShow;
96 HINSTANCE hInstApp;
97
98 // Optional members
99 LPVOID lpIDList;
100 LPCSTR lpClass;
101 HKEY hkeyClass;
102 DWORD dwHotKey;
103 union {
104 HANDLE hIcon;
105 HANDLE hMonitor;
106 };
107 HANDLE hProcess;
108 } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO;
109 */
110
111 BOOL OpenTarget(HWND hWnd, TCHAR* target)
112 {
113 BOOL result = FALSE;
114 SHELLEXECUTEINFO shExecInfo;
115
116 memset(&shExecInfo, 0, sizeof(shExecInfo));
117 shExecInfo.cbSize = sizeof(shExecInfo);
118 shExecInfo.fMask = 0;
119 shExecInfo.hwnd = hWnd;
120 shExecInfo.lpVerb = NULL;
121 shExecInfo.lpFile = target;
122 shExecInfo.lpParameters = NULL;
123 shExecInfo.lpDirectory = NULL;
124 shExecInfo.nShow = SW_SHOW;
125 shExecInfo.hInstApp = 0;
126
127 result = ShellExecuteEx(&shExecInfo);
128
129
130 return result;
131 }