资源描述:
《c如何让winform嵌入桌面窗口最底层》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、此类将窗体永远置于窗口最底层。首先,调用一些User32.dll的WinAPI函数。internalclassUser32{publicconstintSE_SHUTDOWN_PRIVILEGE=0x13;[DllImport("user32.dll")]publicstaticexternIntPtrFindWindow(stringlpClassName,stringlpWindowName);[DllImport("user32.dll")]publicstaticexternIntPtrSetParent(IntPtrhWndChild,IntPtrhWndNewParent);[D
2、llImport("user32.dll")]publicstaticexternboolSetWindowPos(IntPtrhWnd,inthWndInsertAfter,intX,intY,intcx,intcy,uintuFlags);}然后,在WinForm里面:publicMainForm(){InitializeComponent();try{if(Environment.OSVersion.Version.Major<6){base.SendToBack();IntPtrhWndNewParent=User32.FindWindow("Progman",null);User3
3、2.SetParent(base.Handle,hWndNewParent);}else{User32.SetWindowPos(base.Handle,1,0,0,0,0,User32.SE_SHUTDOWN_PRIVILEGE);}}catch(ApplicationExceptionexx){MessageBox.Show(this,exx.Message,"PintoDesktop");}}privatevoidMainForm_Activated(objectsender,EventArgse){if(Environment.OSVersion.Version.Major>=6){
4、User32.SetWindowPos(base.Handle,1,0,0,0,0,User32.SE_SHUTDOWN_PRIVILEGE);}}privatevoidMainForm_Paint(objectsender,PaintEventArgse){if(Environment.OSVersion.Version.Major>=6){User32.SetWindowPos(base.Handle,1,0,0,0,0,User32.SE_SHUTDOWN_PRIVILEGE);}}