ImageToAccess/Program.cs
来源:互联网 发布:程序员修炼之道pdf网盘 编辑:程序博客网 时间:2024/05/22 14:06
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Win32;
using Access = Microsoft.Office.Interop.Access;
namespace ImageAccess
{
static class Program
{
#region DllImportAttribute
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
static extern bool ShowWindow(IntPtr handle, int flags);
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
static extern bool SetForegroundWindow(IntPtr handle);
#endregion
[STAThread]
static void Main()
{
#region Mutex
bool isCreated; // 互斥体名称须唯一。
using (Mutex newMutex = new Mutex(true, @"Local/ImageAccess", out isCreated))
{
if (isCreated)
{
string dbPath = Path.Combine(Application.StartupPath, "Images.mdb");
if (File.Exists(dbPath))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (RegistryKey subKey = Application.UserAppDataRegistry)
{
FormImageAccess frame = new FormImageAccess();
subKey.SetValue("Handle", frame.Handle);
Application.Run(frame);
}
newMutex.ReleaseMutex(); // 释放互斥体的所属权。
}
else
{
Access.Application newAccess = new Access.Application();
newAccess.NewCurrentDatabase(dbPath);
dao.Database db = newAccess.CurrentDb();
db.Execute("create table [Images] (Name Text primary key, Bytes Image)", Type.Missing);
db.NewPassword("", "jinzhexian");
db.Close();
newAccess.Quit(Access.AcQuitOption.acQuitSaveNone);
newAccess = null;
GC.Collect();
Application.ExitThread();
}
}
else
{
string text = string.Format("“{0}”应用程序已经运行。", AppDomain.CurrentDomain.FriendlyName);
MessageBox.Show(text, "系统提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
using (RegistryKey subKey = Application.UserAppDataRegistry)
{
IntPtr handle = new IntPtr(Convert.ToInt32(subKey.GetValue("Handle")));
ShowWindow(handle, 1);
SetForegroundWindow(handle);
}
Application.ExitThread();
}
}
#endregion
}
}
}
- ImageToAccess/Program.cs
- ImageToAccess/FormImageAccess.Designer.cs
- ImageToAccess/FormImageAccess.cs
- Program.cs
- Program.cs
- ImageSQL/Program.cs
- 我的一个Program.cs文件代码
- 新方法登录后窗体跳转【Program.cs】
- WinForm的Program.cs处理:全局异常&单例运行
- program
- Program
- program
- program
- PROGRAM
- Program
- program
- Program
- program
- 监测点2.2
- ImageToAccess/FormImageAccess.cs
- document.forms用法
- VMware三种网络模式与linux下使用实例
- 装系统时检测不到IDE光驱?
- ImageToAccess/Program.cs
- 顺序栈的操作
- 网站挂马播报(2010.1.28)
- 不知道怎么让自己前进
- Struts2 ognl中的#、%和$符号用法说明
- 第二章 寄存器
- 冲动的代价
- wxWidgets编程时碰到的问题及解答
- 急找广东二级市政,机电,二级房建建造师及造价师兼职