public void CreateAndShow(IntPtr sourceWindow) { // register the thumbnail to associate this form's hwnd (where we // want the thumbnail rendered to) with the parent hwnd // (which is the window we want the thumbnail of) and put the info // in the thumbnail handle m_hThumbnail = DwmApi.DwmRegisterThumbnail(this.Handle, sourceWindow); // create and set a thumbnail properties to tell the DWM // how we want the thumbnail to be rendered. DwmApi.DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); m_ThumbnailProperties.dwFlags = DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_VISIBLE + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_OPACITY + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_RECTDESTINATION + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_SOURCECLIENTAREAONLY; m_ThumbnailProperties.opacity = 255; m_ThumbnailProperties.fVisible = true; m_ThumbnailProperties.rcSource = m_ThumbnailProperties.rcDestination = new DwmApi.RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); m_ThumbnailProperties.fSourceClientAreaOnly = true; // now update the thumbnail properties - this actually starts the live rendering // in the thumbnail DwmApi.DwmUpdateThumbnailProperties(m_hThumbnail, m_ThumbnailProperties); this.Show(); object j = (object)this.ClientRectangle; //this.DrawToBitmap(Bitmap.FromFile()); }
protected override void Dispose(bool disposing) { //if (disposing && (components != null)) components.Dispose(); base.Dispose(disposing); // when you are done with the thumbnail, unregister it if (m_hThumbnail != IntPtr.Zero) { if (DwmApi.DwmIsCompositionEnabled()) { DwmApi.DwmUnregisterThumbnail(m_hThumbnail); } try { m_hThumbnail = IntPtr.Zero; } catch (Exception excnorg) { this.Dispose(); } } }