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

  • 相关阅读:
    【bzoj2733】永无乡(无旋treap启发式合并 + 并查集)
    【bzoj2002】弹飞绵羊(分块)
    【bzoj2724】蒲公英(分块)
    【最大M子段和】dp + 滚动数组
    【最大连续子段和】单调队列 + 前缀和优化
    【广告印刷】单调队列
    【烽火传递】dp + 单调队列优化
    【志愿者选拔】单调队列、输入优化
    【Sliding Window】单调队列
    【序列操作V】平衡树(无旋treap)
  • 原文地址:https://www.cnblogs.com/chenjm/p/2683289.html
Copyright © 2011-2022 走看看