Technology Corner

Home » CodeProject » Suspend or resume windows controls to be redraw

Suspend or resume windows controls to be redraw

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 80 other followers

Twitter updates

Archives

RSS InfoQ Feeds

  • Presentation: Testing in Production - Quality Software Faster
    Michael Bryzek explores what it’s like to build quality software with no development, QA or staging environments. He deep dives into “verifying in production” - what it takes to build software that can be tested continuously in production. By Michael Bryzek
  • Presentation: Performance Beyond Throughput: An OpenJ9 Case Study
    Marius Pirvu talks about the new advancements in the area of JVM performance using the latest open source JVM technology at Eclipse OpenJ9 running with OpenJDK. He shows us how the view from “the bottom of the stack” can help in finding and fixing stubborn performance problems often missed by high-level performance analysis tools. By Marius Pirvu
  • DigitalOcean Revamps Compute Plans and Pricing Structure
    After spending 2017 adding ancillary services to their virtual machine-centric cloud, DigitalOcean kicked off 2018 with some product and pricing changes. Last year, DigitalOcean added support for firewalls, monitoring, load balancers, and object storage. Today's announcement highlights three new classes of servers, some with upgraded CPU, memory and sto […]
  • The Brief Lifespan of a JavaScript Framework
    The lifecycle of a JavaScript framework is extraordinarily limited, according to a new analysis by Stack Overflow. But the data may also show how the lifespan of a major framework differs from those that satisfy a specific niche. By David Iffland
  • Microservices Resiliency and Fault Tolerance Using Istio and Kubernetes
    Animesh Singh and Tommy Li from IBM spoke at the recent KubeCon + CloudNativeCon North America 2017 Conference about the microservices resiliency and fault tolerance leveraging Istio framework. They also showed how to configure and use circuit breakers and other resiliency features using Istio. By Srini Penchikala
  • Podcast: Wendy Closson on Mindfulness and Effective Communication
    In this podcast Shane Hastie, Lead Editor for Culture & Methods, spoke to Wendy Closson about her journey of recovery from contracting a rare, deadly form of cancer to leading to the Optimize You track at QCon New York By Wendy Closson
  • Last Npm Incident Uncovers Security Vulnerability
    Last week, the npm registry had an operations incident that caused a number of highly depended on packages, such as require-from-string, to become unavailable. While the incident was relatively straightforward to solve, it uncovered a major security vulnerability that could have been exploited to inject malicious code in projects using npm. By Sergio De Simo […]
  • Presentation: How the Olympics Can Make You a Better Person
    Sandy Mamoli shares learnings from her professional sports career, covering topics such as meritocracy and diversity, rapid feedback, radical candor and high-performance teams. By Sandy Mamoli
  • Presentation: Hacking for Fun and Profit
    Heather Wilde discusses what motivates people to hack, what it takes to become a Certified Ethical Hacker, and who is hiring hackers today. By Heather Wilde
  • Presentation: Polyglot Persistence Powering Microservices
    Roopa Tangirala takes a look at Netflix’s common platform used to manage, maintain, and scale persistence infrastructures (including building reliable systems on unreliable infrastructure). She shares the benefits, pitfalls, and lessons learned from their polyglot persistence architecture to shape the success of various services. By Roopa Tangirala

Recently, I was facing issue with third party Image Viewer to apply multiple operations before redrawing of images.
Third-party control was not allowing to suspend and resume painting of images inherently. After searching for various solutions, I found a solution that can be achieved using windows message WM_SETREDRAW from an application to Windows to allow changes in that control to be redrawn or to prevent changes in that control from being redrawn.

public class UIDrawController
{
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);

private const int WM_SETREDRAW = 11;

public static void SuspendDrawing(Control ctrl)
{
SendMessage(ctrl.Handle, WM_SETREDRAW, false, 0);
}

public static void ResumeDrawing(Control ctrl)
{
SendMessage(ctrl.Handle, WM_SETREDRAW, true, 0);
ctrl.Refresh();
}
}

Example Usage:


public ImageViewer : UserControl
{

public void LoadDocument(string filename)
{

UIDrawController.SuspendDrawing(this);

OpenImage(filename);
FitToWidth();
Rotate90();
ApplyImageFilters();

UIDrawController.ResumeDrawing(this);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blogs I Follow

%d bloggers like this: