`
jinvasshole
  • 浏览: 769027 次
文章分类
社区版块
存档分类
最新评论

windows mobile 5.0 进程管理、窗体管理、重启和关闭操作系统

 
阅读更多

1、进程管理 :在NET Compact Framework里进程管理的函数相对要比net Framework里要简化,不过仍然可以比较好的控制程序进程。

A.启动进程:在启动进程后返回进程的id

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->/// <summary>
/// 启动进程
/// </summary>
/// <param name="fileName"> 启动文件的目录路径 </param>
/// <returns> 返回启动进程的进程ID </returns>
public static int StartProcess( string fileName)
{
int progressID = 0 ;

try
{
// 这个目录是动态的
progressID = System.Diagnostics.Process.Start(fileName).Id;
return progressID;
}
catch // (Exception ex)
{
// throw ex;
return 0 ;
}
}

B.获取当前进程的ID

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->/// <summary>
/// 获取当前进程ID
/// </summary>
public static int GetCurrentProcessID()
{
Process currentProcess
= Process.GetCurrentProcess();
int CurrentProcessID = currentProcess.Id;
return CurrentProcessID;
}

C.终止当前进程

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->/// <summary>
/// 终止当前进程
/// </summary>
public static void KillCurrentProcess()
{
System.Diagnostics.Process.GetCurrentProcess().Kill();
}

D.通过进程ID来终止进程

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->/// <summary>
/// 终止进程
/// </summary>
/// <param name="progressID"> 进程ID </param>
/// <returns> true 表示终止成功,反之表示失败 </returns>
public static bool KillProcess( int progressID)
{
try
{
System.Diagnostics.Process.GetProcessById(progressID).Kill();
return true ;
}
catch // (Exception ex)
{
// throw ex;
return false ;
}
}

2、窗体管理。在NET Compact Framework(2.0)的窗体类(System.Windows.Forms.Form))虽然提供WindowsState属性,这个属性是 FormWindowState 枚举类型,在枚举中只有Normal 和 Maximized,不过不能通过Maximized来控制窗体最小,同时也无法控制窗体的关闭。要是实现关闭和最小化只能通过调用api来实现。下面是 有关代码:

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->[DllImport( " coredll.dll " )]
private extern static bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport(
" coredll.dll " )]
private static extern IntPtr FindWindow( string lpClassName, string lpWindowName);
/// 最小化窗体
public static void WindowsMin( string frmTextName)
{

IntPtr hwnd
= FindWindow( null , frmTextName);
ShowWindow(hwnd,
6 );
}
/// 隐藏窗体
public static void WindowHide( string frmTextName)
{
IntPtr hwnd
= FindWindow( null , frmTextName);
ShowWindow(hwnd,
0 );
}

3、重启和关闭操作系统。同样是调用api来完成。

<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
[DllImport(
" Aygshell.dll " )]
static extern bool ExitWindowsEx( uint uFlags, int dwReserved);
private const uint EWX_REBOOT = 2 ;
private const uint EWX_POWEROFF = 8 ;

/// 重启操作系统
public static void RootWindows()
{
ExitWindowsEx(EWX_REBOOT,
0 );
}

/// 关闭操作系统
public static void ShutDownWindows()
{
ExitWindowsEx(EWX_POWEROFF,
0 );
}

以上代码的运行环境和开发环境:windows mobile5.0 +ppc sdk +vs2005

本文地址:http://www.watch-life.net/windows-mobile/process-window-form-system-manager.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics