/// <summary> /// 将窗体嵌入桌面 /// </summary> /// <param name="window">winform窗体实例</param> public static void DesktopEmbedWindow(Form window) { IntPtr pWndP = WinAPIHelper.FindWindow("Progman", null); IntPtr pWnd = WinAPIHelper.FindWindowEx(pWndP, IntPtr.Zero, "SHELLDLL_DefVIew", null); if (pWnd != IntPtr.Zero) { WinAPIHelper.SendMessage(pWndP, 0x52c, IntPtr.Zero, IntPtr.Zero); } IntPtr pWndA = WinAPIHelper.FindWindow("WorkerW", null); pWnd = WinAPIHelper.FindWindowEx(pWndA, IntPtr.Zero, "SHELLDLL_DefVIew", null); while (pWnd == IntPtr.Zero) { pWndA = WinAPIHelper.FindWindowEx(IntPtr.Zero, pWndA, "WorkerW", null); pWnd = WinAPIHelper.FindWindowEx(pWndA, IntPtr.Zero, "SHELLDLL_DefVIew", null); } pWndA = WinAPIHelper.FindWindowEx(IntPtr.Zero, pWndA, "WorkerW", null); pWnd = WinAPIHelper.FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null); if (pWndA != IntPtr.Zero) { WinAPIHelper.SetParent(window.Handle, pWndA); } else { System.Windows.Forms.MessageBox.Show("嵌入桌面失败!"); } }
private void Btn_Close_MouseUp(object sender, MouseButtonEventArgs e) { Statistics_Box.Children.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { WinAPIHelper.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); } Close(); }
/// <summary> /// 加载二维码 /// </summary> private void LoadQrCode(Bitmap qrCodeImage) { qrcodeBox.Dispatcher.Invoke(delegate() { IntPtr myImagePtr = qrCodeImage.GetHbitmap(); //创建GDI对象,返回指针 BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); //创建imgSource WinAPIHelper.DeleteObject(myImagePtr); qrcodeBox.Source = imgsource; }); }
/// <summary> /// 获取登陆二维码并显示 /// </summary> private void GetQrcode() { re: //获取二维码要包含的url string str = Bas.GetHTTPBody("https://passport.bilibili.com/qrcode/getLoginUrl", "", "https://passport.bilibili.com/login"); if (!string.IsNullOrEmpty(str)) { JObject obj = JObject.Parse(str); if ((int)obj["code"] == 0) { // 生成二维码的内容 string strCode = obj["data"]["url"].ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); //生成二维码位图 Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 0, 6, false); qrcodeBox.Dispatcher.Invoke(delegate() { IntPtr myImagePtr = qrCodeImage.GetHbitmap(); //创建GDI对象,返回指针 BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); //创建imgSource WinAPIHelper.DeleteObject(myImagePtr); qrcodeBox.Source = imgsource; }); Monitor = new Timer(MonitorCallback, obj["data"]["oauthKey"].ToString(), 1000, 1000); Refresher = new Timer(RefresherCallback, null, 180000, Timeout.Infinite); } } else { goto re; } }