Files correlati : tutti Ricompilazione Demo : [ ] Commento : Cancellato un sacco, una sporta ed un sacchettino di plastica di roba inutile: riferimenti a FOXPRO, simboli doppi, __tmp_string e compagnia bella. git-svn-id: svn://10.65.10.50/trunk@10949 c028cbd2-c16b-5b4b-a496-9718f37d4682
481 lines
12 KiB
C++
Executable File
481 lines
12 KiB
C++
Executable File
#define XVT_INCL_NATIVE
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <os_dep.h>
|
|
|
|
#include <commdlg.h>
|
|
#include <winver.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <applicat.h>
|
|
#include <config.h>
|
|
#include <utility.h>
|
|
#include <window.h>
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// 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);
|
|
}
|
|
|
|
unsigned long os_get_free_memory()
|
|
{
|
|
MEMORYSTATUS ms;
|
|
GlobalMemoryStatus(&ms);
|
|
return ms.dwAvailPhys;
|
|
}
|
|
|
|
bool os_is_removable_drive(const char* path)
|
|
{
|
|
return GetDriveType(path) == DRIVE_REMOVABLE;
|
|
}
|
|
|
|
bool os_is_network_drive(const char* path)
|
|
{
|
|
return GetDriveType(path) == DRIVE_REMOTE;
|
|
}
|
|
|
|
bool os_is_fixed_drive(const char* path)
|
|
{
|
|
UINT dt = GetDriveType(path);
|
|
return dt == DRIVE_FIXED;
|
|
}
|
|
|
|
static unsigned long get_disk_size(const char* path, bool tot, char unit)
|
|
{
|
|
char drive[_MAX_DRIVE+1];
|
|
_splitpath(path, drive, NULL, NULL, NULL);
|
|
strcat(drive, "/");
|
|
DWORD nSecPerClust, nBytePerSec, nFreeClust, nTotalClust;
|
|
::GetDiskFreeSpace(drive, &nSecPerClust, &nBytePerSec, &nFreeClust, &nTotalClust);
|
|
|
|
__int64 nBytes = tot ? nTotalClust : nFreeClust;
|
|
nBytes *= nSecPerClust;
|
|
nBytes *= nBytePerSec;
|
|
switch (unit)
|
|
{
|
|
case 'K': nBytes >>= 10; break; // Kilobytes
|
|
case 'M': nBytes >>= 20; break; // Megabytes
|
|
case 'G': nBytes >>= 30; break; // Gigabytes
|
|
case 'T': nBytes >>= 40; break; // Terabytes
|
|
default: break;
|
|
}
|
|
|
|
const unsigned long nMax = (unsigned long)(~0L);
|
|
unsigned long nVal = nBytes > nMax ? nMax : (unsigned long)nBytes;
|
|
return nVal;
|
|
}
|
|
|
|
unsigned long os_get_disk_size(const char* path, char unit)
|
|
{
|
|
return get_disk_size(path, true, unit);
|
|
}
|
|
|
|
unsigned long os_get_disk_free_space(const char* path, char unit)
|
|
{
|
|
return get_disk_size(path, false, unit);
|
|
}
|
|
|
|
bool os_test_disk_free_space(const char* path, unsigned long filesize)
|
|
{
|
|
// Arrotonda per eccesso al Kilobyte
|
|
unsigned long kb = (filesize+1023)/1024;
|
|
return kb <= os_get_disk_free_space(path, 'K');
|
|
}
|
|
|
|
/*
|
|
void os_exec_help_command(MENU_TAG tag, const char* key)
|
|
{
|
|
TFilename hlp("prassi.hlp");
|
|
TString mod(key);
|
|
if (mod.not_empty())
|
|
{
|
|
mod.cut(2); mod.lower();
|
|
if (mod != "ba")
|
|
hlp.insert(mod, 0);
|
|
}
|
|
else
|
|
{
|
|
if (tag == M_HELP_ONCONTEXT)
|
|
tag = M_HELP_CONTENTS;
|
|
}
|
|
HWND hwnd = (HWND)xvt_vobj_get_attr(TASK_WIN, ATTR_NATIVE_WINDOW);
|
|
switch(tag)
|
|
{
|
|
case M_HELP_CONTENTS:
|
|
WinHelp(hwnd, hlp, HELP_CONTENTS, 0);
|
|
break;
|
|
case M_HELP_SEARCH:
|
|
WinHelp(hwnd, hlp, HELP_PARTIALKEY, (DWORD)"");
|
|
break;
|
|
case M_HELP_HELPONHELP:
|
|
WinHelp(hwnd, hlp, HELP_HELPONHELP, 0);
|
|
break;
|
|
case M_HELP_ONCONTEXT:
|
|
if (hlp.exist())
|
|
{
|
|
struct MULTIGUY
|
|
{
|
|
DWORD mkSize;
|
|
TCHAR mkKeylist;
|
|
TCHAR mkKeyphrase[16];
|
|
} mk;
|
|
|
|
mk.mkSize = sizeof(MULTIGUY);
|
|
mk.mkKeylist = 'M';
|
|
strncpy(mk.mkKeyphrase, key, sizeof(mk.mkKeyphrase));
|
|
|
|
WinHelp(hwnd, hlp, HELP_MULTIKEY, (DWORD)&mk);
|
|
}
|
|
break;
|
|
default: break;
|
|
}
|
|
}
|
|
*/
|
|
|
|
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;
|
|
}
|
|
|
|
os_type os_get_type()
|
|
{
|
|
os_type t = os_Unknown;
|
|
OSVERSIONINFO ovi;
|
|
if (GetVersionEx(&ovi))
|
|
{
|
|
switch (ovi.dwPlatformId)
|
|
{
|
|
case VER_PLATFORM_WIN32s:
|
|
t = os_Win32s;
|
|
break;
|
|
case VER_PLATFORM_WIN32_NT:
|
|
t = os_WindowsNT;
|
|
break;
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
|
t = os_Windows95;
|
|
if (ovi.dwMajorVersion == 4 || (ovi.dwMajorVersion > 4 && ovi.dwMinorVersion > 0))
|
|
t = os_Windows98;
|
|
break;
|
|
default:
|
|
t = os_Unknown;
|
|
break;
|
|
}
|
|
}
|
|
return t;
|
|
}
|
|
|
|
void os_post_menu_event(WINDOW win, MENU_TAG tag)
|
|
{
|
|
HWND w = (HWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW);
|
|
PostMessage(w, WM_COMMAND, tag, 0L);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
bool os_test_network_version()
|
|
{
|
|
if (os_get_type() == os_Windows95)
|
|
{
|
|
char* VREDIRNAME = "vredir.vxd";
|
|
DWORD handle;
|
|
|
|
DWORD dwSize = GetFileVersionInfoSize(VREDIRNAME,&handle);
|
|
if (dwSize)
|
|
{
|
|
BYTE infoBuffer[512];
|
|
GetFileVersionInfo(VREDIRNAME,handle,dwSize,infoBuffer);
|
|
long *language;
|
|
void * lpBuffer;
|
|
UINT Size;
|
|
if (VerQueryValue(infoBuffer, "\\VarFileInfo\\Translation", (void **)&language, &Size) && Size!=0)
|
|
{
|
|
char szName[128];
|
|
sprintf(szName, "\\StringFileInfo\\%04x%04x\\FileVersion",LOWORD(*language), HIWORD(*language));
|
|
if (VerQueryValue(infoBuffer, szName, &lpBuffer, &Size) && Size!=0)
|
|
{
|
|
TToken_string v((const char *)lpBuffer,'.');
|
|
int subver=atoi(v.get(2));
|
|
if (subver >=1111 && subver <=1115)
|
|
return error_box("La versione %s del driver di rete '%s' contiene un bug riconosciuto da Microsoft.\nConsultare la documentazione sul sito AGA per eliminare questo inconveniente.",(const char *)lpBuffer, VREDIRNAME);
|
|
else
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
message_box("Impossibile determinare la versione del driver di rete '%s'",VREDIRNAME);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void os_sleep(long m)
|
|
{
|
|
::Sleep(m);
|
|
}
|
|
|
|
void os_beep(int severity)
|
|
{
|
|
switch (severity)
|
|
{
|
|
case 0: MessageBeep(MB_OK); break;
|
|
case 1: MessageBeep(MB_ICONEXCLAMATION); break;
|
|
default: MessageBeep(MB_ICONSTOP); break;
|
|
}
|
|
}
|
|
|