Click here to Skip to main content
15,882,055 members
Articles / Desktop Programming / Windows Forms

Clipz - A Friendly Introduction to the Windows 7 Taskbar Features

Rate me:
Please Sign up or sign in to vote.
4.91/5 (57 votes)
17 Dec 2009CPOL9 min read 71.7K   1.6K   123  
An overview of the Windows 7 taskbar features, and how to use then in your own applications.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Clipz.NativeMethods;

namespace Clipz
{
    public class RichTextHost : RichTextBox
    {
        private const double Inch = 14.4; // represents one inch

        public int Print(int charFrom, int charTo, Graphics gr, Rectangle bounds)
        {
            RECT rectToPrint;
            rectToPrint.Top = 0;
            rectToPrint.Bottom = (int)(bounds.Height * Inch);
            rectToPrint.Left = 0;
            rectToPrint.Right = (int)(bounds.Width * Inch);

            RECT rectPage;
            rectPage.Top = 0;
            rectPage.Bottom = (int)(gr.ClipBounds.Height * Inch);
            rectPage.Left = 0;
            rectPage.Right = (int)(gr.ClipBounds.Right * Inch);

            var hdc = gr.GetHdc();
            FORMATRANGE fmtRange;
            fmtRange.chrg.cpMax = charTo;
            fmtRange.chrg.cpMin = charFrom;
            fmtRange.hdc = hdc; 
            fmtRange.hdcTarget = hdc;
            fmtRange.rc = rectToPrint; 
            fmtRange.rcPage = rectPage;

            var res = IntPtr.Zero;
            var wparam = IntPtr.Zero;
            wparam = new IntPtr(1);

            var lparam = IntPtr.Zero;
            lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
            Marshal.StructureToPtr(fmtRange, lparam, false);

            // Send the rendered data for 'printing'
            res = User32.SendMessage(Handle, (int)WindowsMessages.EM_FORMATRANGE, wparam, lparam);
            Marshal.FreeCoTaskMem(lparam);
            gr.ReleaseHdc(hdc);
            
            return res.ToInt32();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer PageLabs
United States United States
I'm the founder of PageLabs, a web-based performance and SEO optimization site.

Give your site a boost in performance, even take a free speed test!

http://www.pagelabs.com

Comments and Discussions