You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by mt...@apache.org on 2003/02/21 22:07:24 UTC
cvs commit: jakarta-commons-sandbox/daemon/src/native/nt/procrun procgui.c procrun.c procrun.h procrun.rc procrun.vcproj
mturk 2003/02/21 13:07:24
Modified: daemon/src/native/nt/procrun procgui.c procrun.c procrun.h
procrun.rc procrun.vcproj
Log:
Added nice About box for WINAPP mode.
Revision Changes Path
1.4 +126 -10 jakarta-commons-sandbox/daemon/src/native/nt/procrun/procgui.c
Index: procgui.c
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/nt/procrun/procgui.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- procgui.c 21 Feb 2003 12:14:21 -0000 1.3
+++ procgui.c 21 Feb 2003 21:07:24 -0000 1.4
@@ -108,16 +108,16 @@
int ac_use_dlg = 0;
int ac_use_show = 0;
HINSTANCE ac_instance;
-
+static procrun_t *ac_env = NULL;
static HICON ac_main_icon;
static HICON ac_try_icon;
static UINT ac_taskbar_created;
-static HWND ac_main_hwnd;
+HWND ac_main_hwnd;
static HWND ac_list_hwnd;
static HWND ac_console_hwnd = NULL;
static char *ac_stdout_lines[MAX_LISTCOUNT + 1];
char *ac_cmdline;
-RECT ac_winpos = {0, 0, 640, 480};
+RECT ac_winpos = {-1, 0, 640, 480};
void ac_add_list_string(const char *str, int len)
{
@@ -126,11 +126,14 @@
int i;
if (str) {
- if (nqueue < MAX_LISTCOUNT) {
- ac_stdout_lines[nqueue++] = strdup(str);
+ if (nqueue > MAX_LISTCOUNT - 1) {
+ free(ac_stdout_lines[0]);
+ /* TODO: improve performance */
+ for (i = 1; i < MAX_LISTCOUNT; i++)
+ ac_stdout_lines[i - 1] = ac_stdout_lines[i];
+ --nqueue;
}
- else
- return;
+ ac_stdout_lines[nqueue++] = strdup(str);
nlen = max(nlen, len);
}
if (!ac_list_hwnd || !nqueue)
@@ -150,7 +153,7 @@
nqueue = 0;
}
-static void ac_show_try_icon(HWND hwnd, DWORD message, const char *tip)
+void ac_show_try_icon(HWND hwnd, DWORD message, const char *tip)
{
NOTIFYICONDATA nid;
@@ -209,6 +212,7 @@
menu = CreatePopupMenu();
if (menu) {
if (ac_use_dlg) {
+ ac_append_menu_item(menu, IDM_ABOUT, "About", 0, 1);
ac_append_menu_item(menu, IDM_CONSOLE, "Open Console Monitor", 1, 1);
ac_append_menu_item(menu, 0, "", 0, 1);
}
@@ -225,6 +229,38 @@
}
}
+static int ac_copy_to_clipboard()
+{
+ HGLOBAL hglbcopy;
+ DWORD sel, i;
+ char buf[MAX_PATH + 2], *str;
+ int *si;
+
+ if (!OpenClipboard(ac_main_hwnd))
+ return -1;
+ EmptyClipboard();
+
+ sel = SendMessage(ac_list_hwnd, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
+ if (sel != LB_ERR && sel > 0) {
+ si = (int *)malloc(sel * sizeof(int));
+ hglbcopy = GlobalAlloc(GMEM_MOVEABLE,
+ (MAX_PATH + 2) * sel);
+ str = GlobalLock(hglbcopy);
+ str[0] = '\0';
+ SendMessage(ac_list_hwnd, LB_GETSELITEMS, (WPARAM)sel, (LPARAM)si);
+ for (i = 0; i < sel; i++) {
+ SendMessage(ac_list_hwnd, LB_GETTEXT, (WPARAM)si[i], (LPARAM)buf);
+ strcat(buf, "\n");
+ strcat(str, buf);
+ }
+ GlobalUnlock(hglbcopy);
+ SetClipboardData(CF_TEXT, hglbcopy);
+
+ free(si);
+ }
+ return 0;
+}
+
static void ac_center_window(HWND hwnd)
{
RECT rc, rw;
@@ -254,6 +290,55 @@
SetWindowPos(hwnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
}
+static void ac_calc_center()
+{
+ RECT rWorkArea;
+ BOOL bResult;
+
+
+ /* Get the limits of the 'workarea' */
+ bResult = SystemParametersInfo(
+ SPI_GETWORKAREA,
+ sizeof(RECT),
+ &rWorkArea,
+ 0);
+ if (!bResult) {
+ rWorkArea.left = rWorkArea.top = 0;
+ rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
+ rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
+ }
+
+ /* Calculate new X and Y position*/
+ ac_winpos.left = (rWorkArea.right - ac_winpos.right) / 2;
+ ac_winpos.top = (rWorkArea.bottom - ac_winpos.bottom) / 2;
+}
+
+LRESULT CALLBACK ac_about_dlg_proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ HWND hrich;
+ HRSRC rsrc;
+ HGLOBAL glob;
+ char *txt;
+
+ switch (message) {
+ case WM_INITDIALOG:
+ ac_center_window(hDlg);
+ hrich = GetDlgItem(hDlg, IDC_RICHEDIT21);
+ rsrc = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_RTFLIC), "RTF");
+ glob = LoadResource(GetModuleHandle(NULL), rsrc);
+ txt = (char *)LockResource(glob);
+ SendMessage(hrich, WM_SETTEXT, 0, (LPARAM)txt);
+ return TRUE;
+
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
+ EndDialog(hDlg, LOWORD(wParam));
+ return TRUE;
+ }
+ break;
+ }
+ return FALSE;
+}
LRESULT CALLBACK ac_console_dlg_proc(HWND hdlg, UINT message, WPARAM wparam, LPARAM lparam)
{
@@ -268,13 +353,19 @@
status_bar = CreateStatusWindow(0x0800 /* SBT_TOOLTIPS */
| WS_CHILD | WS_VISIBLE,
ac_cmdline, hdlg, IDC_STATBAR);
+
if (!ac_use_try) {
LONG w = GetWindowLong(hdlg, GWL_STYLE);
w &= ~WS_MINIMIZEBOX;
SetWindowLong(hdlg, GWL_STYLE, w);
}
+
+ if (ac_winpos.left < 0)
+ ac_calc_center();
+
SetWindowPos(hdlg, HWND_TOP, ac_winpos.left, ac_winpos.top,
- ac_winpos.right, ac_winpos.bottom, 0);
+ ac_winpos.right, ac_winpos.bottom, SWP_SHOWWINDOW);
+
GetWindowRect(status_bar, &r);
GetClientRect(hdlg, &m);
MoveWindow(ac_list_hwnd, 0, 0, m.right - m.left, m.bottom - abs((r.top - r.bottom)), TRUE);
@@ -300,6 +391,24 @@
break;
}
break;
+ case WM_COMMAND:
+ switch (LOWORD(wparam)) {
+ case IDM_MENU_EXIT:
+ EndDialog(hdlg, TRUE);
+ ac_list_hwnd = NULL;
+ ac_console_hwnd = NULL;
+ SetEvent(g_env->m->events[0]);
+ PostQuitMessage(CONWRAP_SUCCESS);
+ break;
+ case IDM_MENU_EDIT:
+ ac_copy_to_clipboard();
+ break;
+ case IDM_MENU_ABOUT:
+ DialogBox(ac_instance, MAKEINTRESOURCE(IDD_ABOUTBOX),
+ hdlg, (DLGPROC)ac_about_dlg_proc);
+ break;
+ }
+ break;
case WM_QUIT:
case WM_CLOSE:
GetWindowRect(hdlg, &ac_winpos);
@@ -368,6 +477,11 @@
DialogBox(ac_instance, MAKEINTRESOURCE(IDD_DLGCONSOLE),
hwnd, (DLGPROC)ac_console_dlg_proc);
break;
+ case IDM_ABOUT:
+ DialogBox(ac_instance, MAKEINTRESOURCE(IDD_ABOUTBOX),
+ hwnd, (DLGPROC)ac_about_dlg_proc);
+ break;
+
}
default:
return DefWindowProc(hwnd, message, wparam, lparam);
@@ -404,6 +518,7 @@
0, 0, 0, 0, 0,
NULL, NULL, instance, NULL);
+
return hwnd;
}
@@ -412,7 +527,7 @@
{
DWORD rv = 0;
MSG msg;
- procrun_t *env = (procrun_t *)param;
+ procrun_t *env = ac_env = (procrun_t *)param;
char cname[MAX_LOADSTRING];
if (!param || !env->m->service.name)
@@ -437,6 +552,7 @@
DispatchMessage(&msg);
}
}
+ ac_main_hwnd = NULL;
SetEvent(env->m->events[0]);
return rv;
}
1.10 +27 -1 jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.c
Index: procrun.c
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- procrun.c 21 Feb 2003 12:13:39 -0000 1.9
+++ procrun.c 21 Feb 2003 21:07:24 -0000 1.10
@@ -118,11 +118,13 @@
extern int ac_use_show;
extern RECT ac_winpos;
extern HINSTANCE ac_instance;
+extern HWND ac_main_hwnd;
+void ac_show_try_icon(HWND hwnd, DWORD message, const char *tip);
#endif
#ifdef _DEBUG
-static void dbprintf(char *format, ...)
+void dbprintf(char *format, ...)
{
va_list args;
char tid[4096 + 128];
@@ -478,6 +480,11 @@
ac_use_dlg = 1;
ac_use_show = 1;
}
+ else if (STRN_COMPARE(arg, PROC_ARG_GUID_PROCESS)) {
+ mode = PROCRUN_CMD_GUID_PROCESS;
+ ac_use_dlg = 1;
+ ac_use_show = 1;
+ }
#endif
else if (STRN_COMPARE(arg, PROC_ARG_STOP_SERVICE)) {
proc->service.name = pool_strdup(proc->pool, arg +
@@ -2360,6 +2367,7 @@
case PROCRUN_CMD_GUID_SERVICE:
{
DWORD gi;
+ LoadLibrary("riched32.dll");
CreateThread(NULL, 0, gui_thread, g_env, 0, &gi);
}
#else
@@ -2405,6 +2413,20 @@
dispatch_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)service_main;
rv = (StartServiceCtrlDispatcher(dispatch_table) == FALSE);
break;
+#ifdef PROCRUN_WINAPP
+ case PROCRUN_CMD_GUID_PROCESS:
+ {
+ DWORD gi;
+ ac_use_try = 1;
+ LoadLibrary("riched32.dll");
+ CreateThread(NULL, 0, gui_thread, g_env, 0, &gi);
+ }
+ env->m->service.name = argv[0];
+ env->m->service.description = argv[2];
+ rv = procrun_redirect(argv[2], envp, env);
+ break;
+
+#endif
default:
/* Run the process
* We can be master or called by env.
@@ -2427,6 +2449,10 @@
/* clean up... */
cleanup:
+#ifdef PROCRUN_WINAPP
+ if (ac_main_hwnd)
+ ac_show_try_icon(ac_main_hwnd, NIM_DELETE, NULL);
+#endif
procrun_destroy_jvm(env->m);
inject_exitprocess(&env->c->pinfo);
i = pool_destroy(env->m->pool);
1.9 +12 -5 jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.h
Index: procrun.h
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- procrun.h 21 Feb 2003 12:14:21 -0000 1.8
+++ procrun.h 21 Feb 2003 21:07:24 -0000 1.9
@@ -87,10 +87,15 @@
#define IDB_BMPHEADER 109
#define IDL_STDOUT 110
#define IDR_CMENU 111
-#define IDM_FILE_EXIT 112
-#define IDM_FILE_EDIT 113
-#define IDI_ICOCONTRY 114
-
+#define IDM_MENU_EXIT 112
+#define IDM_MENU_EDIT 113
+#define IDM_MENU_ABOUT 114
+#define IDI_ICOCONTRY 115
+#define IDR_RTFLIC 116
+#define IDB_BMPJAKARTA 117
+#define IDD_ABOUTBOX 118
+#define IDC_RICHEDIT21 119
+#define IDM_ABOUT 120
#define IDC_STATIC -1
#define PROC_ENV_COUNT 32
@@ -109,6 +114,7 @@
#define PROC_ARG_TEST_SERVICE "//TS//"
#define PROC_ARG_GUIT_SERVICE "//GT//"
#define PROC_ARG_GUID_SERVICE "//GD//"
+#define PROC_ARG_GUID_PROCESS "//GP//"
#define PROC_ARG_UPDATE_SERVICE "//US//"
#define PROC_ARG_EDIT_SERVICE "//ES//"
@@ -174,7 +180,8 @@
PROCRUN_CMD_STOP_SERVICE,
PROCRUN_CMD_DELETE_SERVICE,
PROCRUN_CMD_UPDATE_SERVICE,
- PROCRUN_CMD_EDIT_SERVICE
+ PROCRUN_CMD_EDIT_SERVICE,
+ PROCRUN_CMD_GUID_PROCESS
};
typedef struct mpool_t mpool_t;
1.4 +55 -6 jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.rc
Index: procrun.rc
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.rc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- procrun.rc 21 Feb 2003 12:14:21 -0000 1.3
+++ procrun.rc 21 Feb 2003 21:07:24 -0000 1.4
@@ -3,14 +3,43 @@
IDI_ICOCONWRAP ICON "tomcatp.ico"
IDI_ICOCONTRY ICON "tomcatr.ico"
+IDR_RTFLIC RTF "License.rtf"
+IDB_BMPJAKARTA BITMAP DISCARDABLE "jakarta-banner.bmp"
+
+#ifdef _MSC_VER
+IDR_CMENU MENUEX DISCARDABLE
+BEGIN
+ POPUP "&Process",65535,MFT_STRING,MFS_ENABLED
+ BEGIN
+ MENUITEM "E&xit", IDM_MENU_EXIT
+ END
+ POPUP "&Edit",65535,MFT_STRING,MFS_ENABLED
+ BEGIN
+ MENUITEM "&Copy", IDM_MENU_EDIT
+ END
+ POPUP "&Help",65535,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
+ BEGIN
+ MENUITEM "&About", IDM_MENU_ABOUT
+ END
+END
+#else
IDR_CMENU MENU DISCARDABLE
BEGIN
- POPUP "&File"
+ POPUP "&Process"
BEGIN
- MENUITEM "E&xit", IDM_FILE_EXIT
+ MENUITEM "E&xit", IDM_MENU_EXIT
+ END
+ POPUP "&Edit"
+ BEGIN
+ MENUITEM "&Copy", IDM_MENU_EDIT
+ END
+ POPUP "&Help"
+ BEGIN
+ MENUITEM "&About", IDM_MENU_ABOUT
END
END
+#endif
IDD_DLGCONSOLE DIALOGEX 0, 0, 480, 240
STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION |
@@ -21,12 +50,32 @@
FONT 10, "Courier New"
BEGIN
LISTBOX IDL_STDOUT,0,0,200,200,NOT LBS_NOTIFY | LBS_USETABSTOPS |
- LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL |
- NOT WS_BORDER | WS_VSCROLL |
- WS_HSCROLL | WS_TABSTOP,WS_EX_CLIENTEDGE
-
+ LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | NOT WS_BORDER |
+ WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,WS_EX_CLIENTEDGE
+END
+#ifdef _MSC_VER
+IDD_ABOUTBOX DIALOGEX 0, 0, 337, 167
+STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
+CAPTION "About"
+FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
+BEGIN
+ DEFPUSHBUTTON "&OK",IDOK,285,150,50,14
+ CONTROL "",IDC_RICHEDIT21,"RichEdit20A",ES_MULTILINE |
+ ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
+ CONTROL 117,IDC_STATIC,"Static",SS_BITMAP,0,0,337,30
+END
+#else
+IDD_ABOUTBOX DIALOGEX 0, 0, 337, 167
+STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
+CAPTION "About"
+FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
+BEGIN
+ DEFPUSHBUTTON "&OK",IDOK,285,150,50,14
+ CONTROL "",IDC_RICHEDIT21,"RichEdit20A",ES_MULTILINE |
+ ES_READONLY | WS_BORDER | WS_VSCROLL,0,0,335,145
END
+#endif
1 VERSIONINFO
FILEVERSION 2,1,0,0
1.4 +20 -2 jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.vcproj
Index: procrun.vcproj
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.vcproj,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- procrun.vcproj 13 Feb 2003 17:48:35 -0000 1.3
+++ procrun.vcproj 21 Feb 2003 21:07:24 -0000 1.4
@@ -19,6 +19,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
+ OptimizeForProcessor="0"
AdditionalIncludeDirectories="$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="_WIN32,WIN32,_DEBUG,_DEBUG_TRACE,_WINDOWS,STRICT,_WIN32_WINNT=0x0400,PROCRUN_WINAPP"
MinimalRebuild="TRUE"
@@ -48,7 +49,8 @@
<Tool
Name="VCPreLinkEventTool"/>
<Tool
- Name="VCResourceCompilerTool"/>
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_MSC_VER"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
@@ -95,7 +97,8 @@
<Tool
Name="VCPreLinkEventTool"/>
<Tool
- Name="VCResourceCompilerTool"/>
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_MSC_VER"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
@@ -301,17 +304,32 @@
<File
RelativePath="procrun.h">
</File>
+ <File
+ RelativePath="resource.h">
+ </File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
<File
+ RelativePath="jakarta-banner.bmp">
+ </File>
+ <File
RelativePath="procrun.rc">
</File>
<File
RelativePath="proctry.ico">
</File>
+ <File
+ RelativePath="tomcatp.ico">
+ </File>
+ <File
+ RelativePath="tomcatr.ico">
+ </File>
</Filter>
+ <File
+ RelativePath="License.rtf">
+ </File>
</Files>
<Globals>
</Globals>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org