#define XVT_INCL_NATIVE #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include /////////////////////////////////////////////////////////// // Operating system dependent functions /////////////////////////////////////////////////////////// bool os_destroy_native_icon(unsigned icon) { return DestroyIcon((HICON)icon) != 0; } void os_draw_native_icon(WINDOW win, const RCT& rct, unsigned icon) { HDC hdc = (HDC)xvt_vobj_get_attr(win, ATTR_NATIVE_GRAPHIC_CONTEXT); int x = (rct.right + rct.left - 32) / 2; int y = (rct.bottom + rct.top - 32) / 2; DrawIcon(hdc, x, y, (HICON)icon); } int os_execute(const TFilename& path, bool sync, bool iconizetask, bool showchild) { int exitcode = -1; STARTUPINFO start; PROCESS_INFORMATION pi; memset(&start, 0, sizeof(start)); start.cb = sizeof(start); start.dwX = start.dwY = start.dwXSize = start.dwYSize = CW_USEDEFAULT; start.dwFlags = STARTF_USESHOWWINDOW; start.wShowWindow = showchild ? SW_SHOW : SW_HIDE; BOOL started = CreateProcess(NULL,(char*)(const char*)path, NULL, NULL, FALSE, 0, NULL, NULL, &start, &pi); if (started) { HANDLE hProcess = pi.hProcess; if (sync) { ATOM aBa0Atom = NULL; if (iconizetask && showchild && main_app().name() == "ba0100") { TString str; str << "ba0100->" << cmd2name(path); aBa0Atom = GlobalAddAtom(str); } WaitForInputIdle(hProcess, INFINITE); bool was_maximized = FALSE; if (iconizetask) { TTemp_window tw(TASK_WIN); RCT rct_scr, rct_tsk; xvt_vobj_get_client_rect(SCREEN_WIN, &rct_scr); xvt_vobj_get_client_rect(tw.win(), &rct_tsk); was_maximized = rct_scr.right == rct_tsk.right; tw.iconize(); tw.deactivate(); } if (WaitForSingleObject(hProcess, INFINITE) != 0xFFFFFFFF) { unsigned long exit_code; if (GetExitCodeProcess(hProcess, &exit_code)) exitcode = int(exit_code); else exitcode = -2; } if (aBa0Atom) GlobalDeleteAtom(aBa0Atom); if (iconizetask) { TTemp_window tw(TASK_WIN); if (was_maximized) tw.maximize(); else os_restore_window(tw.win()); tw.activate(); // do_events(); non si puo fare qui'" } } else exitcode = 0; CloseHandle(pi.hThread); CloseHandle(hProcess); } else { exitcode = GetLastError(); error_box("Impossibile eseguire '%s': %d", (const char*)path, exitcode); } return exitcode; } int os_get_printer_names(TToken_string& t) { char* buf = t.get_buffer(4096); // ammazzao' GetProfileString("devices", NULL, "", buf, t.size()); for (int i = 0; i < t.size(); i++) { if (buf[i] == '\0') { if (buf[i+1] != '\0') buf[i] = t.separator(); else break; } } return t.items(); } bool os_set_default_printer(const char* name) { CHECK(name && *name > ' ', "Null printer name"); TString pdev(name); if (pdev.find(',') < 0) { TString szDevice(256); GetProfileString ("devices", pdev, "", szDevice.get_buffer(), szDevice.size()); pdev << ',' << szDevice; } bool ok = WriteProfileString("windows", "device", pdev) != 0; return ok; } bool os_get_default_printer(TString& name) { char* buf = name.get_buffer(256); bool ok = GetProfileString ("windows", "device", ",,,", buf, name.size()) != 0; return ok; } bool os_spawn_by_menu() { bool ok = true; #ifndef DBG TString16 str = main_app().name(); ok = str == "ba0100"; if (!ok) { str.insert("ba0100->", 0); ok = GlobalFindAtom(str) != NULL; } #endif return ok; } void os_iconize_window(WINDOW win) { HWND hwnd = (HWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW); ShowWindow(hwnd, SW_MINIMIZE); } void os_maximize_window(WINDOW win) { HWND hwnd = (HWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW); HWND twin = (HWND)xvt_vobj_get_attr(TASK_WIN, ATTR_NATIVE_WINDOW); if (hwnd != twin) { HWND pare = GetParent(hwnd); RECT rct; GetClientRect(pare, &rct); if (pare == twin) rct.bottom -= 24; SetWindowPos(hwnd, pare, rct.left, rct.top, rct.right, rct.bottom, SWP_NOZORDER); } else ShowWindow(hwnd, SW_SHOWMAXIMIZED); } void os_restore_window(WINDOW win) { HWND hwnd = (HWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW); ShowWindow(hwnd, SW_NORMAL); } bool os_dongle_server_running() { ATOM a = GlobalFindAtom("DONGLE_SERVER_ATOM"); return a != 0; } HIDDEN const char* _file_to_find = NULL; struct TFindWindowInfo { HINSTANCE _instance; TFilename _file; HWND _hwnd; TFindWindowInfo() : _instance(NULL), _hwnd(NULL) { } }; BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { TFindWindowInfo* w = (TFindWindowInfo*)lParam; HINSTANCE inst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE); if (inst == w->_instance) { const LONG style = GetWindowLong(hwnd, GWL_STYLE); if ((style & WS_CAPTION) != 0) // Ha la caption? { w->_hwnd = hwnd; return FALSE; } return TRUE; } TString256 str; GetWindowText(hwnd, str.get_buffer(), str.size()); str.upper(); if (str.find(w->_file) >= 0) { w->_hwnd = hwnd; return FALSE; } return TRUE; } unsigned long os_execute_in_window(const TFilename& path, WINDOW win) { const unsigned long exitcode = WinExec(path, SW_SHOWNORMAL); if (exitcode < 32) return 0; TFindWindowInfo w; w._instance = (HINSTANCE) exitcode; const int space = path.find(' '); if (space > 0) w._file = path.mid(space+1); else w._file = path; w._file = w._file.name(); w._file.ext(""); w._file.upper(); const clock_t start = clock(); while (w._hwnd == NULL && (clock() - start) < 10*CLOCKS_PER_SEC) { xvt_app_process_pending_events(); EnumWindows(EnumWindowsProc, LPARAM(&w)); } if (w._hwnd != NULL) // L'ho trovata! { RCT rct; xvt_vobj_get_client_rect(win, &rct); HWND nat = (HWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW); SetParent(w._hwnd, nat); // LONG style = GetWindowLong(w._hwnd, GWL_STYLE); // style |= WS_CHILD; // SetWindowLong(w._hwnd, GWL_STYLE, style); const int fx = GetSystemMetrics(SM_CXFRAME); const int fy = GetSystemMetrics(SM_CYFRAME); int cy = GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYBORDER); if (GetMenu(w._hwnd) != NULL) cy += GetSystemMetrics(SM_CYMENU); SetWindowPos(w._hwnd, nat, -fx, -fy-cy, rct.right+2*fx, rct.bottom+cy+2*fy, SWP_NOZORDER); } return (unsigned long) w._hwnd; }