📄 process.xs
字号:
HWNDWindowFromPoint(long x, long y, HWND hwnd, BOOL fChildren){ POINTL ppl; ppl.x = x; ppl.y = y; if (!pWinWindowFromPoint) AssignFuncPByORD(pWinWindowFromPoint, ORD_WinWindowFromPoint); return SaveWinError(pWinWindowFromPoint(hwnd, &ppl, fChildren));}static HSWITCHswitch_of(HWND hwnd, PID pid){ HSWITCH hSwitch; if (!(_emx_env & 0x200)) croak("switch_entry not implemented on DOS"); /* not OS/2. */ if (CheckWinError(hSwitch = myWinQuerySwitchHandle(hwnd, pid))) croak_with_os2error("WinQuerySwitchHandle"); return hSwitch;}static voidfill_swentry(SWENTRY *swentryp, HWND hwnd, PID pid){ int rc; HSWITCH hSwitch = switch_of(hwnd, pid); swentryp->hswitch = hSwitch; if (CheckOSError(myWinQuerySwitchEntry(hSwitch, &swentryp->swctl))) croak_with_os2error("WinQuerySwitchEntry");}static voidfill_swentry_default(SWENTRY *swentryp){ fill_swentry(swentryp, NULLHANDLE, getpid());}static SV*myWinQueryActiveDesktopPathname(){ SV *buf = newSVpv("",0); STRLEN n_a; SvGROW(buf, MAXPATHLEN); QueryActiveDesktopPathname(SvPV(buf,n_a), MAXPATHLEN); SvCUR_set(buf, strlen(SvPV(buf, n_a))); return buf;}SV *myWinQueryAtomName(ATOM atom, HATOMTBL hAtomTbl){ ULONG len = QueryAtomLength(hAtomTbl, atom); if (len) { /* Probably always so... */ SV *sv = newSVpvn("",0); STRLEN n_a; SvGROW(sv, len + 1); len = QueryAtomName(hAtomTbl, atom, SvPV(sv, n_a), len + 1); if (len) { /* Probably always so... */ SvCUR_set(sv, len); *SvEND(sv) = 0; return sv; } SvREFCNT_dec(sv); } return &PL_sv_undef;}#define myWinQueryClipbrdFmtInfo QueryClipbrdFmtInfo/* Put data into shared memory, then call SetClipbrdData */voidClipbrdData_set(SV *sv, int convert_nl, unsigned long fmt, unsigned long rgfFmtInfo, HAB hab){ STRLEN len; char *buf; char *pByte = 0, *s, c; ULONG nls = 0, rc, handle; if (rgfFmtInfo & CFI_POINTER) { s = buf = SvPV_force(sv, len); if (convert_nl) { while ((c = *s++)) { if (c == '\r' && *s == '\n') s++; else if (c == '\n') nls++; } } if (CheckOSError(DosAllocSharedMem((PPVOID)&pByte, 0, len + nls + 1, PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE | OBJ_GETTABLE))) croak_with_os2error("ClipbrdData_set: DosAllocSharedMem error"); if (!nls) memcpy(pByte, buf, len + 1); else { char *t = pByte, *e = buf + len; while (buf < e) { c = *t++ = *buf++; if (c == '\n' && (t == pByte + 1 || t[-2] != '\r')) t[-1] = '\r', *t++ = '\n'; } } handle = (ULONG)pByte; } else { handle = (ULONG)SvUV(sv); } if (!SetClipbrdData(hab, handle, fmt, rgfFmtInfo)) { if (fmt & CFI_POINTER) DosFreeMem((PPVOID)&pByte); croak_with_os2error("ClipbrdData_set: WinSetClipbrdData error"); }}ULONGQueryMemoryRegionSize(ULONG addr, ULONG *flagp, ULONG len, I32 interrupt){ ULONG l, f; /* Modifiable copy */ ULONG rc; do { l = len; rc = DosQueryMem((void *)addr, &l, &f); } while ( interrupt ? 0 : rc == ERROR_INTERRUPT ); /* We assume this is not about addr *//* if (rc == ERROR_INVALID_ADDRESS) return 0xFFFFFFFF;*/ os2cp_croak(rc,"QueryMemoryRegionSize"); if (flagp) *flagp = f; return l;}static ULONGdefault_fmtInfo(ULONG fmt){ switch (fmt) { case CF_PALETTE: /* Actually, fmtInfo not documented for palette... */ case CF_BITMAP: case CF_METAFILE: case CF_DSPBITMAP: case CF_DSPMETAFILE: return CFI_HANDLE; default: return CFI_POINTER; }}#if 0ULONGmyWinMessageBox(HWND hwndParent, HWND hwndOwner, PCSZ pszText, PCSZ pszCaption, ULONG idWindow, ULONG flStyle){ ULONG rc = MessageBox(hwndParent, hwndOwner, pszText, pszCaption, idWindow, flStyle); if (rc == MBID_ERROR) rc = 0; if (CheckWinError(rc)) croak_with_os2error("MessageBox"); return rc;}ULONGmyWinMessageBox2(HWND hwndParent, HWND hwndOwner, PCSZ pszText, PCSZ pszCaption, ULONG idWindow, PMB2INFO pmb2info){ ULONG rc = MessageBox2(hwndParent, hwndOwner, pszText, pszCaption, idWindow, pmb2info); if (rc == MBID_ERROR) rc = 0; if (CheckWinError(rc)) croak_with_os2error("MessageBox2"); return rc;}#endif/* static ULONG (* APIENTRY16 pDosSmSetTitle)(ULONG, PSZ); */ULONG _THUNK_FUNCTION(DosSmSetTitle)(ULONG, PSZ);#if 0 /* Does not work. */static ULONG (*pDosSmSetTitle)(ULONG, PSZ);static voidsesmgr_title_set(char *s){ SWENTRY swentry; static HMODULE hdosc = 0; BYTE buf[20]; long rc; fill_swentry_default(&swentry); if (!pDosSmSetTitle || !hdosc) { if (CheckOSError(DosLoadModule(buf, sizeof buf, "sesmgr", &hdosc))) croak("Cannot load SESMGR: no `%s'", buf); if (CheckOSError(DosQueryProcAddr(hdosc, 0, "DOSSMSETTITLE", (PFN*)&pDosSmSetTitle))) croak("Cannot load SESMGR.DOSSMSETTITLE, err=%ld", rc); }/* (pDosSmSetTitle)(swcntrl.idSession,s); */ rc = ((USHORT) (_THUNK_PROLOG (2+4); _THUNK_SHORT (swcntrl.idSession); _THUNK_FLAT (s); _THUNK_CALLI (*pDosSmSetTitle))); if (CheckOSError(rc)) warn("*DOSSMSETTITLE: err=%ld, ses=%ld, addr=%x, *paddr=%x", rc, swcntrl.idSession, &_THUNK_FUNCTION(DosSmSetTitle), pDosSmSetTitle);}#else /* !0 */static boolsesmgr_title_set(char *s){ SWENTRY swentry; long rc; fill_swentry_default(&swentry); rc = ((USHORT) (_THUNK_PROLOG (2+4); _THUNK_SHORT (swentry.swctl.idSession); _THUNK_FLAT (s); _THUNK_CALL (DosSmSetTitle)));#if 0 if (CheckOSError(rc)) warn("DOSSMSETTITLE: err=%ld, ses=%ld, addr=%x", rc, swcntrl.idSession, _THUNK_FUNCTION(DosSmSetTitle));#endif return !CheckOSError(rc);}#endif /* !0 */#if 0 /* Does not work. */USHORT _THUNK_FUNCTION(Win16SetTitle) ();static voidset_title2(char *s){ long rc; rc = ((USHORT) (_THUNK_PROLOG (4); _THUNK_FLAT (s); _THUNK_CALL (Win16SetTitle))); if (CheckWinError(rc)) warn("Win16SetTitle: err=%ld", rc);}#endifSV *process_swentry(unsigned long pid, HWND hwnd){ SWENTRY swentry; if (!(_emx_env & 0x200)) croak("process_swentry not implemented on DOS"); /* not OS/2. */ fill_swentry(&swentry, hwnd, pid); return newSVpvn((char*)&swentry, sizeof(swentry));}SV *swentries_list(){ int num, n = 0; STRLEN n_a; PSWBLOCK pswblk; SV *sv = newSVpvn("",0); if (!(_emx_env & 0x200)) croak("swentries_list not implemented on DOS"); /* not OS/2. */ if (!pWinQuerySwitchList) AssignFuncPByORD(pWinQuerySwitchList, ORD_WinQuerySwitchList); num = pWinQuerySwitchList(0, NULL, 0); /* HAB is not required */ if (!num) croak("(Unknown) error during WinQuerySwitchList()"); /* Allow one extra entry to allow overflow detection (may happen if the list has been changed). */ while (num > n) { if (n == 0) n = num + 1; else n = 2*num + 10; /* Enlarge quickly */ SvGROW(sv, sizeof(ULONG) + sizeof(SWENTRY) * n + 1); pswblk = (PSWBLOCK) SvPV_force(sv, n_a); num = pWinQuerySwitchList(0, pswblk, SvLEN(sv)); } SvCUR_set(sv, sizeof(ULONG) + sizeof(SWENTRY) * num); *SvEND(sv) = 0; return sv;}SWENTRYswentry( char *title, HWND sw_hwnd, HWND icon_hwnd, HPROGRAM owner_phandle, PID owner_pid, ULONG owner_sid, ULONG visible, ULONG nonswitchable, ULONG jumpable, ULONG ptype, HSWITCH sw_entry){ SWENTRY e; strncpy(e.swctl.szSwtitle, title, MAXNAMEL); e.swctl.szSwtitle[60] = 0; e.swctl.hwnd = sw_hwnd; e.swctl.hwndIcon = icon_hwnd; e.swctl.hprog = owner_phandle; e.swctl.idProcess = owner_pid; e.swctl.idSession = owner_sid; e.swctl.uchVisibility = ((visible ? SWL_VISIBLE : SWL_INVISIBLE) | (nonswitchable ? SWL_GRAYED : 0)); e.swctl.fbJump = (jumpable ? SWL_JUMPABLE : 0); e.swctl.bProgType = ptype; e.hswitch = sw_entry; return e;}SV *create_swentry( char *title, HWND owner_hwnd, HWND icon_hwnd, HPROGRAM owner_phandle, PID owner_pid, ULONG owner_sid, ULONG visible, ULONG nonswitchable, ULONG jumpable, ULONG ptype, HSWITCH sw_entry){ SWENTRY e = swentry(title, owner_hwnd, icon_hwnd, owner_phandle, owner_pid, owner_sid, visible, nonswitchable, jumpable, ptype, sw_entry); return newSVpvn((char*)&e, sizeof(e));}intchange_swentrysw(SWENTRY *sw){ ULONG rc; /* For CheckOSError */ if (!(_emx_env & 0x200)) croak("change_entry() not implemented on DOS"); /* not OS/2. */ if (!pWinChangeSwitchEntry) AssignFuncPByORD(pWinChangeSwitchEntry, ORD_WinChangeSwitchEntry); return !CheckOSError(pWinChangeSwitchEntry(sw->hswitch, &sw->swctl));}intchange_swentry(SV *sv){ STRLEN l; PSWENTRY pswentry = (PSWENTRY)SvPV(sv, l); if (l != sizeof(SWENTRY)) croak("Wrong structure size %ld!=%ld in change_swentry()", (long)l, (long)sizeof(SWENTRY)); return change_swentrysw(pswentry);}#define swentry_size() (sizeof(SWENTRY))voidgetscrsize(int *wp, int *hp){ int i[2]; _scrsize(i); *wp = i[0]; *hp = i[1];}/* Force vio to not cross 64K-boundary: */#define VIO_FROM_VIOB \ vio = viob; \ if (!_THUNK_PTR_STRUCT_OK(vio)) \ vio++boolscrsize_set(int w, int h){ VIOMODEINFO viob[2], *vio; ULONG rc; VIO_FROM_VIOB; if (h == -9999) h = w, w = 0; vio->cb = sizeof(*vio); if (CheckOSError(VioGetMode( vio, 0 ))) return 0; if( w > 0 ) vio->col = (USHORT)w; if( h > 0 ) vio->row = (USHORT)h; vio->cb = 8; if (CheckOSError(VioSetMode( vio, 0 ))) return 0; return 1;}voidcursor(int *sp, int *ep, int *wp, int *ap){ VIOCURSORINFO viob[2], *vio; ULONG rc; VIO_FROM_VIOB; if (CheckOSError(VioGetCurType( vio, 0 ))) croak_with_os2error("VioGetCurType() error"); *sp = vio->yStart; *ep = vio->cEnd; *wp = vio->cx; *ep = vio->attr;}boolcursor__(int is_a){ int s,e,w,a; cursor(&s, &e, &w, &a); if (is_a) return a; else return w;}boolcursor_set(int s, int e, int w, int a){ VIOCURSORINFO viob[2], *vio; ULONG rc; VIO_FROM_VIOB; vio->yStart = s; vio->cEnd = e; vio->cx = w; vio->attr = a; return !CheckOSError(VioSetCurType( vio, 0 ));}static intbufsize(void){#if 1 VIOMODEINFO viob[2], *vio; ULONG rc; VIO_FROM_VIOB; vio->cb = sizeof(*vio); if (CheckOSError(VioGetMode( vio, 0 ))) croak_with_os2error("Can't get size of buffer for screen");#if 0 /* buf=323552247, full=1118455, partial=0 */ croak("Lengths: buf=%d, full=%d, partial=%d",vio->buf_length,vio->full_length,vio->partial_length); return newSVpvn((char*)vio->buf_addr, vio->full_length);#endif return vio->col * vio->row * 2; /* How to get bytes/cell? 2 or 4? */#else /* 0 */ int i[2]; _scrsize(i); return i[0]*i[1]*2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -