成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C# Windows CE使用小技巧實(shí)例

開發(fā) 后端
C# Windows CE使用小技巧實(shí)例主要向你介紹了WinCE下使用C#來打開一個(gè)外部文件、單步執(zhí)行程序等等,希望對(duì)你學(xué)習(xí)了解C# Windows CE使用有所幫助。

C# Windows CE使用的一些感受:使用Windows的開發(fā)機(jī)上用C#啟動(dòng)一個(gè)外部程序的方法有很多,但這些方法用在使用WinCE的目標(biāo)工控機(jī)上都無能為力。

C# Windows CE使用1、

現(xiàn)在以打開一個(gè)IE為例,介紹如何在WinCE下使用C#來打開一個(gè)外部文件:

首先添加命名空間

  1. usingSystem.Runtime.InteropServices;, 

然后調(diào)用API函數(shù):

  1. [DllImport("coredll.Dll",  
  2. EntryPoint="CreateProcess",SetLastError=true)]  
  3.  
  4. externstaticintCreateProcess(  
  5. stringstrImageName,stringstrCmdLine,  
  6. IntPtrpProcessAttributes,IntPtrpThreadAttributes,  
  7. intbInheritsHandle,intdwCreationFlags,  
  8. IntPtrpEnvironment, IntPtrpCurrentDir,  
  9. IntPtrbArray,ProcessInfooProc);  
  10.  
  11. publicclassProcessInfo  
  12.  
  13. {  
  14.  
  15. publicInt32hProcess;  
  16.  
  17. publicInt32hThread;  
  18.  
  19. publicInt32ProcessID;  
  20.  
  21. publicInt32ThreadID;  
  22.  

最后就可以編寫需要打開IE的代碼了(點(diǎn)擊一個(gè)按鈕打開IE瀏覽器中相應(yīng)內(nèi)容,此例程要求打開目標(biāo)工控機(jī)硬盤上的Readme文件):

  1. privatevoidbutton_Click(  
  2. objectsender,System.EventArgse)  
  3.  
  4. {  
  5.  
  6. ProcessInfopi=newProcessInfo();  
  7.  
  8. CreateProcess(" \\windows\\iesample.exe",  
  9. "\\HardDisk\\Readme.htm",IntPtr.Zero,  
  10. IntPtr.Zero,0,0,IntPtr.Zero,  
  11. IntPtr.Zero,IntPtr.Zero,pi);  
  12.  

C# Windows CE使用2、

有時(shí)候我們會(huì)希望我們的程式只被執(zhí)行一次,VB的時(shí)代我們會(huì)用App.PrevInstance,而.net的時(shí)代我們可以用下列方式實(shí)現(xiàn)

  1. [STAThread]  
  2.  
  3. staticvoidMain()  
  4.  
  5. {  
  6.  
  7. //如果跟本程式命名的行程只有一個(gè)才執(zhí)行程式  
  8.  
  9. if(System.Diagnostics.Process.  
  10. GetProcessesByName(  
  11.  
  12. Application.ProductName).Length==1)  
  13.  
  14. {  
  15.  
  16. Application.Run(newForm1());  
  17.  
  18. }  
  19.  

但此方法在WinCE下無法實(shí)現(xiàn),所以我們還是要先調(diào)用動(dòng)態(tài)鏈接庫,

  1. [DllImport("coredll.Dll")]  
  2.  
  3. privatestaticexternintGetLastError();  
  4.  
  5. [DllImport("coredll.Dll")]  
  6.  
  7. privatestaticexternintReleaseMutex(IntPtrhMutex);  
  8.  
  9. [DllImport("coredll.Dll")]  
  10.  
  11. privatestaticexternIntPtrCreateMutex(  
  12. SECURITY_ATTRIBUTESlpMutexAttributes,  
  13. boolbInitialOwner,stringlpName);  
  14.  
  15. [StructLayout(youtKind.Sequential)]  
  16.  
  17. publicclassSECURITY_ATTRIBUTES  
  18.  
  19. {  
  20.  
  21. publicintnLength;  
  22.  
  23. publicintlpSecurityDescriptor;  
  24.  
  25. publicintbInheritHandle;  
  26.  
  27. }  
  28.  
  29. constintERROR_ALREADY_EXISTS=0183;  

然后編寫代碼

  1. staticvoidMain()  
  2.  
  3. {  
  4.  
  5. #regionApi_CallCreateMutex;  
  6.  
  7. IntPtrhMutex;  
  8.  
  9. hMutex=CreateMutex(null,false,"程序名");  
  10.  
  11. if(GetLastError()!=ERROR_ALREADY_EXISTS)  
  12.  
  13. {  
  14.  
  15. Application.Run(newFrmmenu());  
  16.  
  17. }  
  18.  
  19. else 
  20.  
  21. {  
  22.  
  23. MessageBox.Show("本程序只允許同時(shí)運(yùn)行一個(gè)");  
  24.  
  25. ReleaseMutex(hMutex);  
  26.  
  27. }  
  28.  
  29. #endregion  
  30.  

C# Windows CE使用3、

在.NETFramework中沒有函數(shù)可以激活屬于另外一個(gè)進(jìn)程或程序的窗體,所以我們要通過調(diào)用API函數(shù)來實(shí)現(xiàn):

  1. usingSystem.Runtime.InteropServices;  
  2.  
  3. [DllImport("coredll.Dll")]  
  4.  
  5. publicstaticexternIntPtrFindWindow(  
  6. Stringclassname,Stringtitle);  
  7.  
  8. [DllImport("coredll.Dll")]  
  9.  
  10. publicstaticexternvoidSetForegroundWindow(IntPtrhwnd); 

然后使用下列代碼即可

  1. IntPtrhDlg;  
  2.  
  3. hDlg=FindWindow(null,"窗口標(biāo)題");  
  4.  
  5. SetForegroundWindow(hDlg); 

最后,WinCE下的C#里不支持GroupBox控件,建議使用Panel控件代替;不支持Frame控件,如果非要達(dá)到那樣的效果,可以用Label和TextBox組和起來應(yīng)付一下。

其實(shí),任何時(shí)候,只要.NETFramework無法滿足編程者需要的時(shí)候,通常都可以使用托管(interop)機(jī)制直接與Windows交互。大家也許看出調(diào)用原有的[DllImport("user32.Dll")]動(dòng)態(tài)鏈接庫時(shí)無法滿足WinCE下程序要求,所以我們調(diào)用了[DllImport("coredll.Dll")]。希望這篇文章能給初學(xué)者提供一些捷徑。

C# Windows CE使用的一些感受和實(shí)例的介紹就向你介紹到這里,希望對(duì)你了解C# Windows CE使用有所幫助。

【編輯推薦】

  1. C#Windows應(yīng)用程序開發(fā)之窗體控件
  2. C#Windows應(yīng)用程序開發(fā)之添加菜單
  3. C#Windows應(yīng)用程序開發(fā)之添加狀態(tài)條
  4. C#Windows應(yīng)用程序開發(fā)之事件處理器
  5. c# Windows CE讀取電池電量的實(shí)現(xiàn)
責(zé)任編輯:仲衡 來源: wmisv.com.cn
相關(guān)推薦

2009-08-17 09:57:00

C# Windows

2009-08-17 10:29:58

C# Windows

2009-08-17 10:17:01

C# Windows

2009-08-17 10:26:34

C# Windows

2009-08-17 10:11:12

C# Windows

2009-08-17 10:02:58

C# Windows

2009-08-17 10:22:19

C# Windows

2009-08-17 09:27:12

c# Windows

2009-08-27 15:17:18

C# interfacinterface使用

2009-09-09 22:31:21

c# textbox失

2009-09-14 14:25:53

C# Lambda EC# Lambda

2009-08-14 16:32:50

C#啟動(dòng)Windows

2009-09-02 18:44:19

C#遞歸

2009-09-04 15:53:42

C#內(nèi)存流

2009-08-26 13:36:33

C#打印控件

2009-08-13 14:56:46

C#的結(jié)構(gòu)體使用

2009-12-31 10:49:36

VPN配置實(shí)例

2009-08-27 16:54:59

C#開發(fā)技巧

2009-08-11 15:44:05

C#基本技巧

2009-08-14 17:04:19

Windows后臺(tái)服務(wù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 久久久久国产精品一区二区 | 亚洲综合视频 | 亚洲一区二区三区桃乃木香奈 | a爱视频| 天天操操 | 欧美一区二区视频 | 麻豆精品国产91久久久久久 | 亚洲国产精品视频 | 国产精品久久精品 | 午夜欧美 | 欧美日韩国产一区二区三区不卡 | 亚洲国产精品久久久久秋霞不卡 | 99精品国产一区二区三区 | 久久99精品国产99久久6男男 | 日本aⅴ中文字幕 | 久久久久一区 | 亚洲精品久久久久久久久久久 | 日韩成人在线播放 | 一级黄色日本片 | 亚洲一区二区三区在线免费 | 99精品电影 | 男人天堂免费在线 | 日本超碰| 免费在线一区二区三区 | 国产视频线观看永久免费 | 在线免费观看毛片 | 免费久久视频 | 午夜视频免费在线观看 | aacc678成免费人电影网站 | 三级免费av | 久视频在线观看 | 久久久久国产一区二区 | 日韩视频 中文字幕 | 国产伦精品一区二区三区高清 | 国产精品免费一区二区三区四区 | 国产一区二区三区视频免费观看 | 久久精品一级 | 欧美精品影院 | 日韩免费高清视频 | 日韩在线视频免费观看 | 啪啪综合网|