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->远程监视

  • 相关阅读:
    web框架和Django框架的初识
    外键的变种,单表的查询,多表的查询
    数据库的安装与初识
    响应式设计中几个class区别
    Velocity+Java较全教程
    Web开发基础
    AutoCompleteTextView不能使用的问题
    Http中Cookie与Set-Cookie头
    Java Web 乱码
    Karel运行环境配置
  • 原文地址:https://www.cnblogs.com/chenjm/p/2683289.html
Copyright © 2011-2022 走看看