Beispiel #1
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(curt_app);
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);

    /* 参数解析 <网页文件> */
    if (argc < 1)
        return (QST_ERROR);
    g_html = argv[0];

    /* 标准 VCL 过程开始 */
    try
    {
        Application->Initialize();
        Application->Title = WIN_TITLE;
        Application->CreateForm(__classid(TfrmMain), &frmMain);
        Application->Run();
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
            throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }
    return (QST_OKAY);
}
Beispiel #2
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(curt_app);
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    ximp_stop_running();
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);

    sINIu*  ini;
    ansi_t* str;
    bool_t  old = TRUE;

    /* 加载配置文件 */
    str = file_load_as_strA(QST_PATH_CONFIG WIN_ICONF);
    if (str != NULL) {
        ini = ini_parseU(str);
        mem_free(str);
        if (ini != NULL) {
            old = ini_key_intxU("sdir::old_style", TRUE, ini);
            ini_closeU(ini);
        }
    }

    /* 参数解析 [起始目录] */
    g_root = NULL;
    if (argc > 0)
    {
        /* 验证目录是否存在 */
        if (misc_dir_exist(argv[0]))
            g_root = argv[0];
    }

    /* 未指定目录则使用上次结果 */
    if (g_root == NULL)
        g_root = file_load_as_strA(QST_SELECT_DIR);
    if (!old)
    {
        BROWSEINFOA     bi;
        LPITEMIDLIST    pidl;
        ansi_t  path[MAX_PATH];

        /* 使用新风格的目录打开窗口 */
        CoInitialize(NULL);
        bi.hwndOwner = NULL;
        bi.pidlRoot  = NULL;
        bi.pszDisplayName = path;
        bi.lpszTitle = "";
        bi.ulFlags = BIF_RETURNONLYFSDIRS;
        if (g_root == NULL)
            bi.lpfn = NULL;
        else
            bi.lpfn = BrowseCallbackProc;
        bi.lParam = 0;
        bi.iImage = 0;
        pidl = SHBrowseForFolderA(&bi);
        if (pidl != NULL &&
            SHGetPathFromIDListA(pidl, path))
            ximp_dir_write(path);
        CoUninitialize();
        return (QST_OKAY);
    }

    /* 标准 VCL 过程开始 */
    try
    {
        Application->Initialize();
        Application->Title = WIN_TITLE;
        Application->CreateForm(__classid(TfrmMain), &frmMain);
        Application->Run();
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
            throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }
    return (QST_OKAY);
}
Beispiel #3
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);
    mem_zero(&s_wrk_ctx, sizeof(s_wrk_ctx));

    int qt_argc;

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);
    qt_argc = (int)argc;

    QApplication    qt_app(qt_argc, argv);

    qt_app.setApplicationName("QstComm");
    qt_app.setOrganizationName("QuestLAB");

    sint_t  x1, y1;
    uint_t  ww, hh;

    /* 生成一个可变大小的窗口 */
    mtlock_init(&s_wrk_ctx.lock);
    qst_load_cfg(&s_wrk_ctx.cfgs);
    misc_desk_init(WIN_ICONF, &x1, &y1, &ww, &hh,
                   QCOM_DEF_WIDTH, QCOM_DEF_HEIGHT);
    if (ww < QCOM_DEF_WIDTH)  ww = QCOM_DEF_WIDTH;
    if (hh < QCOM_DEF_HEIGHT) hh = QCOM_DEF_HEIGHT;

    RECT            w_rect;
    sint_t          fw, fh;
    QMainWindow     qt_win;

    /* Qt 里的宽高都不包括边框
       需要自己用 Win32 API 获取 */
    qt_win.setWindowFlags(qt_win.windowFlags()
        & (~Qt::WindowMaximizeButtonHint));
    qt_win.move(x1, y1);
    qt_win.resize(ww, hh);
    s_wrk_ctx.hwnd = (HWND)qt_win.winId();
    if (!GetWindowRect(s_wrk_ctx.hwnd, &w_rect))
        return (QST_ERROR);
    fw = w_rect.right - w_rect.left - ww;
    fh = w_rect.bottom - w_rect.top - hh;
    qt_win.setMinimumSize(QCOM_DEF_WIDTH  - fw,
                          QCOM_DEF_HEIGHT - fh);
    qt_win.resize(ww - fw, hh - fh);

    QWidget*        cent = new QWidget (&qt_win);
    CTextEdit*      edit = new CTextEdit (cent);
    QHBoxLayout*    hori = new QHBoxLayout (cent);

    /* 创建窗体里的控件 */
    hori->setSpacing(6);
    hori->setContentsMargins(8, 8, 8, 8);
    hori->addWidget(edit);
    qt_win.setCentralWidget(cent);

    CTextOper   oper(&qt_win, edit);

    s_wrk_ctx.oper = (void_t*)(&oper);
    SetClassLongPtr(s_wrk_ctx.hwnd, GCLP_HICON, (LONG_PTR)
                    LoadIconA(curt_app, (ansi_t*)101));

    /* 初始化 ANSI 上下文 */
    if (!qst_csi_init())
        return (QST_ERROR);
    qst_set_viewer(&s_wrk_ctx);

    /* 初始化网络 */
    if (!socket_init())
        return (QST_ERROR);
    s_wrk_ctx.netw = netw_cli_open(EXE_XNAME);
    if (s_wrk_ctx.netw == NULL)
        return (QST_ERROR);

    /* 读取需要超时, 不然线程无法退出 */
    socket_set_timeout(s_wrk_ctx.netw, -1, QST_TCP_TOUT);

    thrd_t  thrd;

    /* 生成工作线程 */
    s_wrk_ctx.quit = FALSE;
    s_wrk_ctx.comm.quit = FALSE;
    s_wrk_ctx.comm.text = TRUE;
    s_wrk_ctx.comm.rtype = "text";
    s_wrk_ctx.comm.stype = "text";
    s_wrk_ctx.comm.title = NULL;
    s_wrk_ctx.comm.render = qst_txt_show;
    s_wrk_ctx.page = get_sys_codepage();
    qst_update_title(&s_wrk_ctx);
    thrd = thread_new(0, qst_com_main, &s_wrk_ctx, FALSE);
    if (thrd == NULL)
        return (QST_ERROR);
    sio_init();

    /* 开始 Qt 流程 */
    qt_win.show();
    qt_app.exec();

    /* 关闭线程直接退出 */
    if (!s_wrk_ctx.quit)
        s_wrk_ctx.quit = TRUE;
    thread_wait(thrd);
    thread_del(thrd);
    netw_cli_close(s_wrk_ctx.netw);
    sio_free();
    qst_csi_free();
    return (QST_OKAY);
}
Beispiel #4
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(curt_app);
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);

    /* 参数解析 <脚本文件> */
    if (argc < 1)
        return (QST_ERROR);

    leng_t  size;
    ansi_t* root;
    ansi_t* temp;
    ansi_t* exec;
    ansi_t  path[MAX_PATHA];

    /* 合成 LUA_PATH & LUA_CPATH 目录 */
    exec = file_load_as_strA(QST_ROOT_START);
    if (exec == NULL) {
        size = GetCurrentDirectoryA(sizeof(path), path);
        if (size == 0 || size > sizeof(path))
            return (QST_ERROR);
        if (path[size - 1] == '\\')
            path[size - 1] = 0x00;
        exec = str_dupA(path);
        if (exec == NULL)
            return (QST_ERROR);
    }
    temp = str_dupA(exec);
    if (temp == NULL) {
        mem_free(exec);
        return (QST_ERROR);
    }
    root = str_fmtA("%s\\lualib", exec);
    mem_free(exec);
    if (root == NULL) {
        mem_free(temp);
        return (QST_ERROR);
    }

    DWORD   cf = 0;

    /* 根据扩展名选择用哪个启动 */
    if (filext_checkA(argv[0], ".lua")) {
        exec = str_fmtA("%s\\lua.exe \"%s\"", temp, argv[0]);
        cf = CREATE_NEW_CONSOLE;
    }
    else
    if (filext_checkA(argv[0], ".wlua")) {
        exec = str_fmtA("%s\\wlua.exe \"%s\"", temp, argv[0]);
        cf = CREATE_NO_WINDOW;
    }
    else {
        exec = NULL;
    }
    mem_free(temp);
    if (exec == NULL) {
        mem_free(root);
        return (QST_ERROR);
    }

    STARTUPINFOA        si;
    PROCESS_INFORMATION pi;

    /* 启动脚本 */
    mem_zero(&si, sizeof(si));
    si.cb = sizeof(STARTUPINFOA);
    SetEnvironmentVariableA("LUA_PATH", root);
    SetEnvironmentVariableA("LUA_CPATH", root);
    size  = str_lenA(root);
    size -= str_lenA("\\lualib");
    root[size] = 0x00;
    if (CreateProcessA(NULL, exec, NULL, NULL, FALSE,
                       cf, NULL, root, &si, &pi)) {
        WaitForSingleObject(pi.hProcess, INFINITE);
        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);
    }
    mem_free(exec);
    mem_free(root);
    return (QST_OKAY);
}