📄 acrobatcontrol.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
namespace UtilControl
{
public class AcrobatControl
{
int iHandle;
Process acrobat;
string strFileName;
bool IsFullScreen;
bool IsMax;
int intZoom;
bool IsVersionPro;
public AcrobatControl()
{
iHandle = 0;
strFileName = "";
IsFullScreen = false;
intZoom = 0;
IsVersionPro = false;
IsMax = true;
}
public void OpenFile(string strPath)
{
if (acrobat != null)
{
this.CloseFile();
}
iHandle = 0;
strFileName = "";
IsFullScreen = false;
intZoom = 0;
string strAppName = UtilControl.clsRegistry.GetStringValue(Microsoft.Win32.Registry.LocalMachine, "SOFTWARE\\Adobe\\Adobe Acrobat\\7.0\\InstallPath", "");
if (strAppName == null)
{
strAppName = UtilControl.clsRegistry.GetStringValue(Microsoft.Win32.Registry.LocalMachine, "SOFTWARE\\Adobe\\Acrobat Reader\\7.0\\InstallPath", "");
strAppName += "\\AcroRd32.exe";
IsVersionPro = false;
}
else
{
strAppName += "\\Acrobat.exe";
IsVersionPro = true;
}
acrobat = new Process();
acrobat.StartInfo.FileName = strAppName;
acrobat.StartInfo.Arguments = strPath;
acrobat.Start();
strFileName = GetFileName(strPath);
this.Maximize();
SetActivate();
}
public void CloseFile()
{
iHandle = GetHandle();
if (iHandle != 0)
{
if (acrobat != null)
{
acrobat.Close();
acrobat.Dispose();
}
GC.Collect();
Win32.SendMessage(iHandle, (int)Win32.WM_SYSCOMMAND, (int)Win32.SC.CLOSE, 0);
}
}
public void ToggleMaxMin()
{
if (IsMax == true)
{
this.Minimize();
}
else
{
this.Maximize();
}
}
public void Zoom()
{
Maximize();
iHandle = GetHandle();
if (iHandle != 0)
{
if (intZoom > 3) {intZoom = 0;}
Win32.SendMessage(iHandle, (int)Win32.WM_COMMAND, (int)GetZoomCode(intZoom), 0);
intZoom++;
}
}
private int GetZoomCode(int ZoomCode)
{
if (IsVersionPro == false)
{
switch (ZoomCode)
{
case 0:
return (int)Win32.ACRO.ACTUALSIZE;
case 1:
return (int)Win32.ACRO.FITPAGE;
case 2:
return (int)Win32.ACRO.FITWIDTH;
case 3:
return (int)Win32.ACRO.FITVISIBLE;
default:
return 0;
}
}
else
{
switch (ZoomCode)
{
case 0:
return (int)Win32.ACROPRO.ACTUALSIZE;
case 1:
return (int)Win32.ACROPRO.FITPAGE;
case 2:
return (int)Win32.ACROPRO.FITWIDTH;
case 3:
return (int)Win32.ACROPRO.FITVISIBLE;
default:
return 0;
}
}
}
public void Up()
{
Maximize();
PressKeyDownUp((ushort)Win32.VK.UP);
}
public void Down()
{
Maximize();
PressKeyDownUp((ushort)Win32.VK.DOWN);
}
public void Left()
{
Maximize();
PressKeyDownUp((ushort)Win32.VK.SHIFT,(ushort)Win32.VK.LEFT);
}
public void Right()
{
Maximize();
PressKeyDownUp((ushort)Win32.VK.SHIFT, (ushort)Win32.VK.RIGHT);
}
public void PageUp()
{
Maximize();
PressKeyDownUp((ushort)Win32.VK.LEFT);
}
public void PageDown()
{
Maximize();
PressKeyDownUp((ushort)Win32.VK.RIGHT);
}
public void FullScreen()
{
iHandle = GetHandle();
if(IsFullScreen == false)
{
if (iHandle != 0)
{
this.Maximize();
if (IsVersionPro == false)
{
Win32.SendMessage(iHandle, (int)Win32.WM_COMMAND, (int)Win32.ACRO.FULLSCREEN, 0);
}
else
{
Win32.SendMessage(iHandle, (int)Win32.WM_COMMAND, (int)Win32.ACROPRO.FULLSCREEN, 0);
}
IsFullScreen = true;
}
}
else
{
PressKeyDownUp((ushort)Win32.VK.ESCAPE);
IsFullScreen = false;
}
}
private void Maximize()
{
if (IsFullScreen == true)
{
return;
}
iHandle = GetHandle();
if (iHandle != 0)
{
Win32.SendMessage(iHandle, (int)Win32.WM_SYSCOMMAND, (int)Win32.SC.MAXIMIZE, 0);
IsMax = true;
}
}
private void Minimize()
{
if (IsFullScreen == true)
{
return;
}
iHandle = GetHandle();
if (iHandle != 0)
{
Win32.SendMessage(iHandle, (int)Win32.WM_SYSCOMMAND, (int)Win32.SC.MINIMIZE, 0);
IsMax = false;
}
}
private string GetFileName(string strPath)
{
string[] strPathElement;
char[] sperator = new char[1];
sperator[0] = '\\';
strPathElement = strPath.Split(sperator);
return strPathElement[strPathElement.Length - 1];
}
private int GetHandle()
{
string strWindow = "Adobe Acrobat Professional";
string strWFileName = "";
if (strFileName.Length > 0)
{
strWFileName = " - [" + strFileName + "]";
}
strWindow += strWFileName;
int intHandle = Win32.FindWindow("AdobeAcrobat", strWindow);
if (intHandle == 0)
{
strWindow = "Adobe Reader";
strWindow += strWFileName;
intHandle = Win32.FindWindow("AdobeAcrobat", strWindow);
}
return intHandle;
}
private void PressKeyDownUp(ushort usKey)
{
PressKeyDown(usKey);
PressKeyUp(usKey);
}
private void PressKeyDownUp(ushort usKey1, ushort usKey2)
{
PressKeyDown(usKey1);
PressKeyDownUp(usKey2);
PressKeyUp(usKey1);
}
private void PressKeyDownUp(ushort usKey1, ushort usKey2, ushort usKey3)
{
PressKeyDown(usKey1);
PressKeyDownUp(usKey2, usKey3);
PressKeyUp(usKey1);
}
private void PressKeyDown(ushort usKey)
{
this.SetActivate();
Win32.keybd_event(Convert.ToByte(usKey), (byte)0, 0, UIntPtr.Zero);
}
private void PressKeyUp(ushort usKey)
{
this.SetActivate();
Win32.keybd_event(Convert.ToByte(usKey), (byte)0, Win32.KEYEVENTF_KEYUP, UIntPtr.Zero);
}
private void SetActivate()
{
iHandle = GetHandle();
if (iHandle != Win32.GetForegroundWindow())
{
Win32.SetForegroundWindow(iHandle);
System.Threading.Thread.Sleep(100);
}
}
public void Swap()
{
if (IsFullScreen == true)
{
this.FullScreen();
}
this.Minimize();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -