zoukankan      html  css  js  c++  java
  • WinCE 判断程序是否运行 如果运行则激活到前台窗口的线程

        [DllImport("coredll.Dll")]
            private static extern int ReleaseMutex(IntPtr hMutex);

            [DllImport("coredll.dll", EntryPoint = "CreateMutex", SetLastError = true)]
            public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes, bool InitialOwner, string MutexName);

            const int ERROR_ALREADY_EXISTS = 0183;

            [DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)]
            public static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);

            [DllImport("coredll.dll")]
            public static extern bool SetForegroundWindow(IntPtr hWnd);

        #region Main
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [MTAThread]
            static void Main()
            {
                string strAppName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
                IntPtr hMutex = CreateMutex(IntPtr.Zero, true, strAppName);

                if (Marshal.GetLastWin32Error() == ERROR_ALREADY_EXISTS)
                {
                    ReleaseMutex(hMutex);
                    MessageBox.Show("The application is running!");

                    //通过Class找到对应的窗口句柄  #NETCF_AGL_BASE_ 为窗口的ClassName
                    IntPtr mainWin = FindWindowCE("#NETCF_AGL_BASE_", null);
                    //SetForegroundWindow函数将创建指定的窗口,并激活到前台窗口的线程
                    bool result = SetForegroundWindow(mainWin);
                    return;
                }

        else
                {

           if (AppEntry.Login())
                            Application.Run(AppEntry.frmTmsOrderSearch);
                        else
                            Application.Exit();

        }

      }

    WinCE Form的Class可以通过VS自带工具查看

    Visual Studio Remote Tools->远程监视

  • 相关阅读:
    常用坐标系椭球参数整理
    ArcEngine编辑保存错误:Unable to create logfile system tables
    ArcEngine:The XY domain on the spatial reference is not set or invalid错误
    dockManager中DockPanel的刷新问题!
    ibatis实现Iterate的使用
    mongodb用子文档做为查询条件的两种方法
    Eclipse中的文件导航插件StartExplorer
    mongoVUE的增删改查操作使用说明
    什么是脏读,不可重复读,幻读
    转:Maven常用命令
  • 原文地址:https://www.cnblogs.com/chenjm/p/2683289.html
Copyright © 2011-2022 走看看