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

  • 相关阅读:
    ObjectARX 学习笔记007:创建模态对话框的一般步骤
    c#的DateTime.Now函数详解
    LinQ 使用案例1
    LinQ 泛型方法Array>ForEach在数组中进行迭代并调用自定义的委托
    LinQ Lambda表达式用作泛型活动
    win7x64bit VS2010 CAD2013断点 调试 捕捉成功,困扰一周的问题解决了
    法兰数据库设计方案
    关于CAD的开发思路
    法兰程序CAD开发的进展
    法兰动态块设计思路
  • 原文地址:https://www.cnblogs.com/chenjm/p/2683289.html
Copyright © 2011-2022 走看看