Example #1
0
static long msgProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
    MprThread   *tp;
    char        buf[ME_MAX_FNAME];

    switch (msg) {
    case WM_DESTROY:
    case WM_QUIT:
        mprShutdown(0, -1, 0);
        break;
    
    case APPWEB_MONITOR_MESSAGE:
        return monitorEvent(hwnd, wp, lp);

    case WM_COMMAND:
        switch (LOWORD(wp)) {
        case MA_MENU_STATUS:
            break;

        case MA_MENU_DOC:
            runBrowser("http://embedthis.com/appweb/doc/index.html");
            break;

#if UNUSED
        case MA_MENU_MANAGE:
            runBrowser("/index.html");
            break;
#endif
        case MA_MENU_START:
            tp = mprCreateThread("startService", startService, 0, 0);
            mprStartThread(tp);
            break;

        case MA_MENU_STOP:
            tp = mprCreateThread("stopService", stopService, 0, 0);
            mprStartThread(tp);
            break;

        case MA_MENU_ABOUT:
            /*
                Single-threaded users beware. This blocks !!
             */
            fmt(buf, sizeof(buf), "%s %s", ME_TITLE, ME_VERSION);
            MessageBoxEx(hwnd, buf, mprGetAppTitle(), MB_OK, 0);
            break;

        case MA_MENU_EXIT:
            PostMessage(hwnd, WM_QUIT, 0, 0L);
            break;

        default:
            return (long) DefWindowProc(hwnd, msg, wp, lp);
        }
        break;

    default:
        return (long) DefWindowProc(hwnd, msg, wp, lp);
    }
    return 0;
}
Example #2
0
static long msgProc(HWND hwnd, UINT msg, UINT wp, LPARAM lp)
{
    MprThread   *tp;
    char        buf[MPR_MAX_FNAME];

    switch (msg) {
    case WM_DESTROY:
    case WM_QUIT:
        mprTerminate(MPR_EXIT_GRACEFUL, -1);
        break;
    
    case APPWEB_MONITOR_MESSAGE:
        return monitorEvent(hwnd, wp, lp);

    case WM_COMMAND:
        switch (LOWORD(wp)) {
        case MA_MENU_STATUS:
            break;

        case MA_MENU_DOC:
            runBrowser("/doc/index.html");
            break;

        case MA_MENU_MANAGE:
            runBrowser("/index.html");
            break;

        case MA_MENU_START:
            tp = mprCreateThread("startService", startService, 0, 0);
            mprStartThread(tp);
            break;

        case MA_MENU_STOP:
            tp = mprCreateThread("stopService", stopService, 0, 0);
            mprStartThread(tp);
            break;

        case MA_MENU_ABOUT:
            /*
                Single-threaded users beware. This blocks !!
             */
            mprSprintf(buf, sizeof(buf), "%s %s-%s", BIT_TITLE, BIT_VERSION, BIT_BUILD_NUMBER);
            MessageBoxEx(hwnd, buf, mprGetAppTitle(), MB_OK, 0);
            break;

        case MA_MENU_EXIT:
            PostMessage(hwnd, WM_QUIT, 0, 0L);
            break;

        default:
            return (long) DefWindowProc(hwnd, msg, wp, lp);
        }
        break;

    default:
        return (long) DefWindowProc(hwnd, msg, wp, lp);
    }
    return 0;
}
Example #3
0
static long msgProc(HWND hwnd, uint msg, uint wp, long lp)
{
	char	buf[MPR_MAX_FNAME];
	int		sock, winMask;

	switch (msg) {
	case WM_DESTROY:
	case WM_QUIT:
		mp->terminate(1);
		break;
	
	case APPWEB_SOCKET_MESSAGE:
		sock = wp;
		winMask = LOWORD(lp);
		// errCode = HIWORD(lp);
		mp->serviceIO(sock, winMask);
		break;

	case APPWEB_TRAY_MESSAGE:
		return trayEvent(hwnd, wp, lp);
		break;

	case WM_COMMAND:
		switch (LOWORD(wp)) {
		case MPR_HTTP_MENU_CONSOLE:
			runBrowser("/admin/index.html");
			break;

		case MPR_HTTP_MENU_HELP:
			runBrowser("/doc/product/index.html");
			break;

		case MPR_HTTP_MENU_ABOUT:
			//
			//	Single-threaded users beware. This blocks !!!
			//
			mprSprintf(buf, sizeof(buf), "Embedthis %s %s-%s", 
				BLD_NAME, BLD_VERSION, BLD_NUMBER);
			MessageBoxEx(NULL, buf, mp->getAppTitle(), MB_OK, 0);
			break;

		case MPR_HTTP_MENU_STOP:
			mp->terminate(1);
			break;

		default:
			return DefWindowProc(hwnd, msg, wp, lp);
		}
		break;

	default:
		return DefWindowProc(hwnd, msg, wp, lp);
	}
	return 0;
}
Example #4
0
/*
 *  Respond to monitor icon events
 */
static int monitorEvent(HWND hwnd, WPARAM wp, LPARAM lp)
{
    RECT            windowRect;
    POINT           p, pos;
    HWND            h;
    char            textBuf[48];
    uint            msg;
    int             state;

    msg = (uint) lp;

    /*
     *  Show the menu on single right click
     */
    if (msg == WM_RBUTTONUP) {
        state = queryService();

        if (state < 0 || state & SERVICE_STOPPED) {
            mprSprintf(textBuf, sizeof(textBuf), "%s Stopped", BLD_NAME);
            updateMenu(MA_MENU_STATUS, textBuf, 0, -1);
            updateMenu(MA_MENU_START, 0, 1, 0);
            updateMenu(MA_MENU_STOP, 0, -1, 0);
        } else {
            mprSprintf(textBuf, sizeof(textBuf), "%s Running", BLD_NAME);
            updateMenu(MA_MENU_STATUS, textBuf, 0, 1);
            updateMenu(MA_MENU_START, 0, -1, 0);
            updateMenu(MA_MENU_STOP, 0, 1, 0);
        }

        /*
         *  Popup the context menu. Position near the bottom of the screen
         */
        h = GetDesktopWindow();
        GetWindowRect(h, &windowRect);
        GetCursorPos(&pos);

        p.x = pos.x;
        p.y = windowRect.bottom - 20;

        SetForegroundWindow(appHwnd);
        TrackPopupMenu(subMenu, TPM_RIGHTALIGN | TPM_RIGHTBUTTON, p.x, p.y, 0, appHwnd, NULL);
        /* Required Windows work-around */
        PostMessage(appHwnd, WM_NULL, 0, 0);

        return 0;
    }

    /*
     *  Launch the Appweb Monitor Manager on a double click
     */
    if (msg == WM_LBUTTONDBLCLK) {
        runBrowser("/index.html");
        return 0;
    }
    return 1;
}
Example #5
0
static int trayEvent(HWND hwnd, WPARAM wp, LPARAM lp)
{
	RECT		windowRect;
	POINT		p, pos;
	uint		msg;

	msg = (uint) lp;

	//
	//	Show the menu on single right click
	//
	if (msg == WM_RBUTTONUP) {
		HWND	h = GetDesktopWindow();
		GetWindowRect(h, &windowRect);
		GetCursorPos(&pos);

		p.x = pos.x;
		p.y = windowRect.bottom;

		SetForegroundWindow(appHwnd);
		TrackPopupMenu(subMenu, TPM_RIGHTALIGN | TPM_RIGHTBUTTON, p.x, p.y, 
			0, appHwnd, NULL);
		// FUTURE -- PostMessage(appHwnd, WM_NULL, 0, 0);
		mp->selectService->awaken();
		return 0;
	}

	//
	//	Launch the browser on a double click
	//
	if (msg == WM_LBUTTONDBLCLK) {
		runBrowser("/");
		return 0;
	}

	return 1;
}
Example #6
0
int APIENTRY WinMain(HINSTANCE inst, HINSTANCE junk, char *args, int junk2)
{
    char    **argv, *argp;
    int     argc, err, nextArg, manage, stop;

    mpr = mprCreate(0, NULL, NULL);

    err = 0;
    manage = 0;
    appInst = inst;
    stop = 0;
    serviceName = BLD_COMPANY "-" BLD_PRODUCT;
    serviceTitle = BLD_NAME;
    serviceWindowName = BLD_PRODUCT "Angel";
    serviceWindowTitle = BLD_NAME "Angel";

    mprSetAppName(mpr, BLD_PRODUCT "Monitor", BLD_NAME " Monitor", BLD_VERSION);
    appName = mprGetAppName(mpr);
    appTitle = mprGetAppTitle(mpr);

    mprSetLogHandler(mpr, logHandler, NULL);

    chdir(mprGetAppDir(mpr));

    /*
     *  Parse command line arguments
     */
    if (mprMakeArgv(mpr, "", args, &argc, &argv) < 0) {
        return FALSE;
    }
    for (nextArg = 1; nextArg < argc; nextArg++) {
        argp = argv[nextArg];
        if (*argp != '-') {
            break;
        }
        if (strcmp(argp, "--manage") == 0) {
            manage++;

        } else if (strcmp(argp, "--stop") == 0) {
            stop++;

        } else {
            err++;
        }

        if (err) {
            mprUserError(mpr, "Bad command line: %s\n"
                "  Usage: %s [options]\n"
                "  Switches:\n"
                "    --manage             # Launch browser to manage",
                "    --stop               # Stop a running monitor",
                args, appName);
            return -1;
        }
    }

    if (stop) {
        stopMonitor();
        return 0;
    }

    if (findInstance(mpr)) {
        mprUserError(mpr, "Application %s is already active.", mprGetAppTitle(mpr));
        return MPR_ERR_BUSY;
    }

    /*
     *  Create the window
     */ 
    if (initWindow(mpr) < 0) {
        mprUserError(mpr, "Can't initialize application Window");
        return MPR_ERR_CANT_INITIALIZE;
    }

    if (manage) {
        /*
         *  Launch the browser 
         */
        runBrowser("/index.html");

    } else {

        if (openMonitorIcon() < 0) {
            mprUserError(mpr, "Can't open %s tray", appName);

        } else {
            eventLoop();
            closeMonitorIcon();
        }
    }

    // mprFree(mpr);

    return 0;
}
Example #7
0
static long msgProc(HWND hwnd, uint msg, uint wp, long lp)
{
    char    buf[MPR_MAX_FNAME];

    switch (msg) {
    case WM_DESTROY:
    case WM_QUIT:
        mprSignalExit(mpr);
        break;
    
    case APPWEB_MONITOR_MESSAGE:
        return monitorEvent(hwnd, wp, lp);

    case WM_COMMAND:
        switch (LOWORD(wp)) {
        case MA_MENU_STATUS:
            break;

        case MA_MENU_DOC:
            runBrowser("/doc/index.html");
            break;

        case MA_MENU_MANAGE:
            runBrowser("/index.html");
            break;

        case MA_MENU_START:
            startService();
            break;

        case MA_MENU_STOP:
            stopService();
            break;

        case MA_MENU_ABOUT:
            /*
             *  Single-threaded users beware. This blocks !!
             */
            mprSprintf(buf, sizeof(buf), "%s %s-%s", BLD_NAME, BLD_VERSION, BLD_NUMBER);
            MessageBoxEx(NULL, buf, mprGetAppTitle(mpr), MB_OK, 0);
            break;

        case MA_MENU_EXIT:
            /* 
             *  FUTURE
             *
             *  h = CreateDialog(appInst, MAKEINTRESOURCE(IDD_EXIT), appHwnd, dialogProc);
             *  ShowWindow(h, SW_SHOW);
             */
            PostMessage(hwnd, WM_QUIT, 0, 0L);
            break;

        default:
            return DefWindowProc(hwnd, msg, wp, lp);
        }
        break;

    default:
        return DefWindowProc(hwnd, msg, wp, lp);
    }
    return 0;
}
Example #8
0
APIENTRY WinMain(HINSTANCE inst, HINSTANCE junk, char *command, int junk2)
{
    char    *argv[MPR_MAX_ARGC], *argp;
    int     argc, err, nextArg, manage, stop;

    argc = mprParseArgs(command, &argv[1], MPR_MAX_ARGC - 1) + 1;
    if (mprCreate(argc, argv, MPR_USER_EVENTS_THREAD | MPR_NO_WINDOW) == NULL) {
        exit(1);
    }
    if ((app = mprAllocObj(App, manageApp)) == NULL) {
        exit(2);
    }
    mprAddRoot(app);

    err = 0;
    stop = 0;
    manage = 0;
    app->appInst = inst;
    app->serviceName = sclone(BIT_COMPANY "-" BIT_PRODUCT);
    app->serviceTitle = sclone(BIT_TITLE);
    app->serviceWindowName = sclone(BIT_PRODUCT "Angel");
    app->serviceWindowTitle = sclone(BIT_TITLE "Angel");

    mprSetAppName(BIT_PRODUCT "Monitor", BIT_TITLE " Monitor", BIT_VERSION);
    mprSetLogHandler(logHandler);
    chdir(mprGetAppDir());

    /*
        Parse command line arguments
     */
    for (nextArg = 1; nextArg < argc; nextArg++) {
        argp = argv[nextArg];
        if (*argp != '-') {
            break;
        }
        if (strcmp(argp, "--manage") == 0) {
            manage++;
        } else if (strcmp(argp, "--stop") == 0) {
            stop++;
        } else {
            err++;
        }
        if (err) {
            mprUserError("Bad command line: %s\n"
                "  Usage: %s [options]\n"
                "  Switches:\n"
                "    --manage             # Launch browser to manage",
                "    --stop               # Stop a running monitor",
                command, mprGetAppName());
            return -1;
        }
    }
    if (stop) {
        stopMonitor();
        return 0;
    }
    if (findInstance()) {
        mprUserError("Application %s is already active.", mprGetAppTitle());
        return MPR_ERR_BUSY;
    }
    if (mprInitWindow() < 0) {
        mprUserError("Can't initialize application Window");
        return MPR_ERR_CANT_INITIALIZE;
    }
    app->appHwnd = mprGetHwnd();
    mprSetWinMsgCallback(msgProc);
    if (app->taskBarIcon > 0) {
        ShowWindow(app->appHwnd, SW_MINIMIZE);
        UpdateWindow(app->appHwnd);
    }
    if (manage) {
        /*
            Launch the browser 
         */
        runBrowser("/index.html");

    } else {
        if (openMonitorIcon() < 0) {
            mprUserError("Can't open %s tray", mprGetAppName());
        } else {
            eventLoop();
            closeMonitorIcon();
        }
    }
    return 0;
}
Example #9
0
APIENTRY WinMain(HINSTANCE inst, HINSTANCE junk, char *command, int junk2)
{
    char    *argv[ME_MAX_ARGC], *argp;
    int     argc, err, nextArg, manage, stop;

	argv[0] = ME_NAME "Monitor";
    argc = mprParseArgs(command, &argv[1], ME_MAX_ARGC - 1) + 1;

    if (mprCreate(argc, argv, MPR_USER_EVENTS_THREAD | MPR_NO_WINDOW) == NULL) {
        exit(1);
    }
    if ((app = mprAllocObj(App, manageApp)) == NULL) {
        exit(2);
    }
    mprAddRoot(app);

    err = 0;
    stop = 0;
    manage = 0;
    app->appInst = inst;
    app->company = sclone(ME_COMPANY);
    app->serviceName = sclone(ME_NAME);
    mprSetLogHandler(logHandler);

    chdir(mprGetAppDir());

    /*
        Parse command line arguments
     */
    for (nextArg = 1; nextArg < argc; nextArg++) {
        argp = argv[nextArg];
        if (*argp != '-') {
            break;
        }
        if (strcmp(argp, "--manage") == 0) {
            manage++;
        } else if (strcmp(argp, "--stop") == 0) {
            stop++;
        } else {
            err++;
        }
        if (err) {
            mprError("appweb monitor", "Bad command line: %s\n"
                "  Usage: %s [options]\n"
                "  Switches:\n"
                "    --manage             # Launch browser to manage",
                "    --stop               # Stop a running monitor",
                command, mprGetAppName());
            return -1;
        }
    }
    if (stop) {
        stopMonitor();
        return 0;
    }
    if (findInstance()) {
        mprError("appweb monitor", "Application %s is already active.", mprGetAppTitle());
        return MPR_ERR_BUSY;
    }
    app->hwnd = mprSetWindowsThread(0);
    mprSetWinMsgCallback(msgProc);

    if (app->taskBarIcon > 0) {
        ShowWindow(app->hwnd, SW_MINIMIZE);
        UpdateWindow(app->hwnd);
    }
    if (manage) {
        /*
            Launch the browser 
         */
        runBrowser("/index.html");

    } else {
        if (openMonitorIcon() < 0) {
            mprError("appweb monitor", "Cannot open %s tray", mprGetAppName());
        } else {
            mprServiceEvents(-1, 0);
            closeMonitorIcon();
        }
    }
    mprDestroy();
    return 0;
}