📄 scutils.c
字号:
{
char PGPtools[MAX_PATH];
char StrRes[500];
PGPscPGPpath(PGPtools);
// Since Windows can't handle tray launched from CD
SetCurrentDirectory(PGPtools);
strcat(PGPtools,"PGPmail.exe");
if(!PGPclExecute(PGPtools, SW_SHOW))
{
LoadString (g_hinst, IDS_CANTOPENPGPTOOLS, StrRes, sizeof(StrRes));
MessageBox(hwnd,PGPtools,
StrRes,
MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
return FALSE;
}
return TRUE;
}
BOOL PGPscDoLaunchDisk(HWND hwnd)
{
char PGPtools[MAX_PATH];
char StrRes[500];
PGPscPGPpath(PGPtools);
// Since Windows can't handle tray launched from CD
SetCurrentDirectory(PGPtools);
strcat(PGPtools,"PGPdisk.exe");
if(!PGPclExecute(PGPtools, SW_SHOW))
{
LoadString (g_hinst, IDS_CANTOPENPGPDISK, StrRes, sizeof(StrRes));
MessageBox(hwnd,PGPtools,
StrRes,
MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
return FALSE;
}
return TRUE;
}
BOOL ReadWipePref(PGPContextRef context,
PGPBoolean *pbWarnOnWipe)
{
PGPPrefRef prefRef;
PGPError err;
*pbWarnOnWipe=TRUE;
err=PGPclPeekClientLibPrefRefs(&prefRef,NULL);
if(IsntPGPError(err))
{
PGPGetPrefBoolean (prefRef,
kPGPPrefWarnOnWipe, pbWarnOnWipe);
}
return TRUE;
}
BOOL PGPscEraseClipboard(HWND hwnd,void *PGPsc)
{
int result;
PGPBoolean bWarnOnWipe;
PGPContextRef context;
int rst;
context=(PGPContextRef)PGPsc;
if(hwnd!=NULL)
{
ReadWipePref(context,&bWarnOnWipe);
if(bWarnOnWipe)
{
rst=PGPscMessageBox (hwnd,IDS_LASTCHANCE,IDS_REALLYWIPECLIPBOARD,
MB_YESNO|MB_DEFBUTTON2|MB_ICONEXCLAMATION);
if(rst==IDNO)
return FALSE;
}
}
OpenClipboard(NULL);
result=EmptyClipboard();
CloseClipboard();
return result;
}
BOOL CheckClipboard()
{
char *pInput;
DWORD dwInputSize;
UINT ClipboardFormat;
BOOL RetVal;
RetVal=FALSE;
pInput=RetrieveClipboardData
(NULL,&ClipboardFormat,&dwInputSize);
if((ClipboardFormat == CF_TEXT)&&(pInput!=0))
{
if(*pInput!=0)
{
RetVal=TRUE;
}
}
if(pInput!=0)
{
memset(pInput,0x00,dwInputSize);
free(pInput);
}
return RetVal;
}
void ControlA(SCSHARED *scShared)
{
scShared->g_KeyArray[0]=VK_CONTROL|SK_KEYDOWN;
scShared->g_KeyArray[1]='A'|SK_KEYDOWN;
scShared->g_KeyArray[2]='A';
scShared->g_KeyArray[3]=VK_CONTROL;
SendKeys( scShared->g_KeyArray, 4 );
}
void ControlC(SCSHARED *scShared)
{
scShared->g_KeyArray[0]=VK_CONTROL|SK_KEYDOWN;
scShared->g_KeyArray[1]='C'|SK_KEYDOWN;
scShared->g_KeyArray[2]='C';
scShared->g_KeyArray[3]=VK_CONTROL;
SendKeys( scShared->g_KeyArray, 4 );
}
void ControlV(SCSHARED *scShared)
{
scShared->g_KeyArray[0]=VK_CONTROL|SK_KEYDOWN;
scShared->g_KeyArray[1]='V'|SK_KEYDOWN;
scShared->g_KeyArray[2]='V';
scShared->g_KeyArray[3]=VK_CONTROL;
SendKeys( scShared->g_KeyArray, 4 );
}
void EMSetSel(HWND hwndEdit)
{
SendMessage(hwndEdit,EM_SETSEL,0,-1);
}
void WMCopy(HWND hwndEdit)
{
SendMessage(hwndEdit,WM_COPY,0,0);
}
HWND PGPscReadCurrentFocus()
{
return PGPhkReadCurrentFocus();
}
BOOL PGPscDoCopy(HWND hwnd,void *PGPsc,BOOL bUseCurrent,HWND *hwndFocus,BOOL *bStartingCR)
{
BOOL ClipOK;
HWND hwndEdit;
BOOL RetVal=TRUE;
char WinClass[256];
PGPContextRef context;
DWORD OtherAppThreadID;
DWORD OtherAppProcessID;
HWND hwndOldFocus;
DWORD TrayThreadID;
SCSHARED *scShared;
HANDLE hMapObject;
*bStartingCR=FALSE;
// Lots of overhead here but the only way to do it for
// terminal services and XP. .
scShared=SCGetSharedMem(&hMapObject);
context=(PGPContextRef)PGPsc;
*hwndFocus=NULL;
if(bUseCurrent)
{
TrayThreadID=GetCurrentThreadId();
hwndEdit=PGPhkReadCurrentFocus();
*hwndFocus=hwndEdit;
GetClassName(hwndEdit,WinClass,255);
PGPscEraseClipboard(NULL,context);
// We can key off WinClass if something else
// needs to be done
OtherAppThreadID = GetWindowThreadProcessId( hwndEdit,
&OtherAppProcessID);
AttachThreadInput( TrayThreadID, OtherAppThreadID, TRUE );
hwndOldFocus=SetFocus(hwndEdit);
*bStartingCR=TRUE; // Selected text
WMCopy(hwndEdit);
ClipOK=CheckClipboard();
if(!ClipOK)
{
*bStartingCR=FALSE; // Needed CTRL A
// We can key off WinClass if something else
// needs to be done
EMSetSel(hwndEdit);
WMCopy(hwndEdit);
ClipOK=CheckClipboard();
if(!ClipOK)
{
*bStartingCR=TRUE; // Selected Text
ControlC(scShared);
ClipOK=CheckClipboard();
if(!ClipOK)
{
*bStartingCR=FALSE; // Needed CTRL A
ControlA(scShared);
ControlC(scShared);
ClipOK=CheckClipboard();
if(!ClipOK)
{
RetVal=FALSE;
}
}
}
}
AttachThreadInput( TrayThreadID, OtherAppThreadID, FALSE );
SetFocus(hwndOldFocus);
}
if(!RetVal)
{
#if _DEBUG
char szInfo[256];
sprintf(szInfo,"Class %s HWND %x",WinClass,hwndEdit);
MessageBox(hwnd,szInfo,"Couldn't get text. _DEBUG VERSION ONLY_ info",
MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
#else
PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_CANTAUTOCOPY,
MB_OK|MB_ICONSTOP);
#endif
}
SCReleaseSharedMem(scShared,hMapObject);
return RetVal;
}
void PGPscDoPaste(BOOL bUseCurrent,HWND hwndFocus)
{
HWND hwndEdit;
char WinClass[256];
DWORD OtherAppThreadID;
DWORD OtherAppProcessID;
DWORD TrayThreadID;
SCSHARED *scShared;
HANDLE hMapObject;
// Lots of overhead here but the only way to do it for
// terminal services and XP. .
scShared=SCGetSharedMem(&hMapObject);
if(bUseCurrent)
{
TrayThreadID=GetCurrentThreadId();
hwndEdit=hwndFocus;
GetClassName(hwndEdit,WinClass,255);
OtherAppThreadID = GetWindowThreadProcessId( hwndEdit,
&OtherAppProcessID);
AttachThreadInput( TrayThreadID, OtherAppThreadID, TRUE );
// We can key off WinClass if something else
// needs to be done
SetFocus(hwndEdit);
ControlV(scShared);
AttachThreadInput( TrayThreadID, OtherAppThreadID, FALSE );
}
SCReleaseSharedMem(scShared,hMapObject);
}
void PGPscDoFocus(BOOL bUseCurrent,HWND hwndFocus)
{
HWND hwndEdit;
char WinClass[256];
DWORD OtherAppThreadID;
DWORD OtherAppProcessID;
DWORD TrayThreadID;
if(bUseCurrent)
{
TrayThreadID=GetCurrentThreadId();
hwndEdit=hwndFocus;
GetClassName(hwndEdit,WinClass,255);
OtherAppThreadID = GetWindowThreadProcessId( hwndEdit,
&OtherAppProcessID);
AttachThreadInput( TrayThreadID, OtherAppThreadID, TRUE );
// We can key off WinClass if something else
// needs to be done
SetFocus(hwndEdit);
AttachThreadInput( TrayThreadID, OtherAppThreadID, FALSE );
}
}
BOOL FileHasThisExtension(char *filename,char *extension)
{
char *p;
if(filename!=NULL)
{
if((p = strrchr(filename, '\\')))
filename=p; // we just want the filename not path
if((p = strrchr(filename, '.')))
{
p++;
if(!strcmpi(p,extension))
return TRUE;
}
}
return FALSE;
}
LRESULT CALLBACK PlaybackHook( int nCode, WPARAM wParam,
LPARAM lParam )
{
LPEVENTMSG lpEM;
SCSHARED *scShared;
HANDLE hMapObject;
// Lots of overhead here but the only way to do it for
// terminal services and XP. .
scShared=SCGetSharedMem(&hMapObject);
switch(nCode)
{
case HC_SKIP:
{
scShared->g_fDelay = TRUE; // CORRECT PLACE TO RESET fDelay
scShared->g_KeyIndex++;
if( scShared->g_KeyIndex == scShared->g_NumKeys )
{
// no more keys?
// remove hook
UnhookWindowsHookEx(scShared->g_hJournalHook);
scShared->g_hJournalHook = NULL;
}
SCReleaseSharedMem(scShared,hMapObject);
return 0;
}
case HC_GETNEXT:
{
lpEM = (LPEVENTMSG)lParam;
if( scShared->lpJournalKeys[scShared->g_KeyIndex] & SK_KEYDOWN )
lpEM->message = scShared->lpJournalKeys[scShared->g_KeyIndex] & SK_SYSKEY
? WM_SYSKEYDOWN : WM_KEYDOWN;
else
lpEM->message = scShared->lpJournalKeys[scShared->g_KeyIndex] & SK_SYSKEY
? WM_SYSKEYUP : WM_KEYUP;
lpEM->paramL = LOBYTE(scShared->lpJournalKeys[scShared->g_KeyIndex])
| (MapVirtualKey(LOBYTE(scShared->lpJournalKeys[scShared->g_KeyIndex]),0)<<8);
lpEM->paramH = 1;
lpEM->time = GetCurrentTime();
if( scShared->g_fDelay )
{
// Toggle pause variable so that the next call will not
// pause. Return the pause length specified by
// ticks_delay since this is the first time the event
// has been requested.
scShared->g_fDelay = FALSE; // <<<< CORRECT PLACE TO CLEAR fDelay
SCReleaseSharedMem(scShared,hMapObject);
return( 100 ); // 50 milliseconds changed to 100 for termserver
}
else
{
SCReleaseSharedMem(scShared,hMapObject);
// Duplicate event. Return 0 delay
return 0;
}
}
default:
{
HHOOK hJournalHook;
hJournalHook=scShared->g_hJournalHook;
SCReleaseSharedMem(scShared,hMapObject);
return CallNextHookEx(hJournalHook,nCode,wParam,lParam);
}
}
}
BOOL ClearMessageLoop(void)
{
MSG msg;
// Clear the message loop
while( PeekMessage(&msg,NULL,0,0,PM_REMOVE) )
{
if( msg.message == WM_QUIT )
{
PostMessage(msg.hwnd,msg.message,msg.wParam,msg.lParam);
return FALSE;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return TRUE;
}
#define KeyDown( uKey ) ( GetAsyncKeyState(uKey) & 0x8000 )
BOOL WINAPI SendKeys( UINT *lpKeys, UINT nKeys )
{
MSG msg;
SCSHARED *scShared;
HANDLE hMapObject;
// Lots of overhead here but the only way to do it for
// terminal services and XP. .
scShared=SCGetSharedMem(&hMapObject);
if( scShared->g_hJournalHook )
{
#ifdef _DEBUG
// Should never get here...
MessageBox(NULL,"Hook already exists? Exiting...",
"DEBUG INFO ONLY!",
MB_OK);
#endif
SCReleaseSharedMem(scShared,hMapObject);
return FALSE;
}
if(!ClearMessageLoop())
{
SCReleaseSharedMem(scShared,hMapObject);
return FALSE;
}
// Sit and spin until control keys are released
while( KeyDown(VK_MENU) || KeyDown(VK_SHIFT) || KeyDown(VK_CONTROL) )
{
if( PeekMessage(&msg,NULL,0,0,PM_REMOVE) )
{
if( msg.message == WM_QUIT )
{
PostMessage(msg.hwnd,msg.message,msg.wParam,msg.lParam);
SCReleaseSharedMem(scShared,hMapObject);
return FALSE;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if(!ClearMessageLoop())
{
SCReleaseSharedMem(scShared,hMapObject);
return FALSE;
}
scShared->lpJournalKeys = lpKeys;
scShared->g_KeyIndex = 0;
scShared->g_NumKeys = nKeys;
scShared->g_fDelay = TRUE;
scShared->g_hJournalHook = SetWindowsHookEx(WH_JOURNALPLAYBACK,
(HOOKPROC)PlaybackHook,g_hinst,0);
// While hooking, pump the messages
while(scShared->g_hJournalHook)
{
if( PeekMessage(&msg,NULL,0,0,PM_REMOVE) )
{
if( msg.message == WM_QUIT )
{
if( scShared->g_hJournalHook )
{
UnhookWindowsHookEx(scShared->g_hJournalHook);
}
PostMessage(msg.hwnd,msg.message,msg.wParam,msg.lParam);
SCReleaseSharedMem(scShared,hMapObject);
return FALSE;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if(!ClearMessageLoop())
{
SCReleaseSharedMem(scShared,hMapObject);
return FALSE;
}
SCReleaseSharedMem(scShared,hMapObject);
return TRUE;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -