日期:2014-05-17 浏览次数:20792 次
private void Form1_Load(object sender, EventArgs e)
{
printClass myPrint = new printClass();
if (!myPrint.init()) { MessageBox.Show("error"); }
else
{
myPrint.print("aaaaaaa");
myPrint.clo();
}
}
}
public class printClass {
const uint GENERIC_WRITE = 0x40000000;
const uint GENERIC_READ = 0x80000000;
const uint OPEN_EXISTING = 0x03;
[DllImport("kernel32.dll",CharSet=CharSet.Auto,SetLastError=true)]
static extern SafeFileHandle CreateFile(string name,uint access,uint shareMode,uint security,uint dispition,uint flag,uint tempfile);
SafeFileHandle handle;
FileStream fs;
public bool init() {
handle = CreateFile(@"LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (handle.IsInvalid) { return false; }
else {
fs = new FileStream(handle, FileAccess.Write);
fs.WriteByte(0x1B); fs.WriteByte(0x40);
return true;
}
}
public void print(string text)
{
byte[] bytes = Encoding.ASCII.GetBytes(text);
fs.Write(bytes, 0, bytes.Length);
}
public void scroll() {
fs.WriteByte(0x1B); fs.WriteByte(0x4A); fs.WriteByte(0x1E);
}
public void cate()&nb