The CaptureScreen. NET bitmap. Like all Windows Forms programs, compiling the program requires references to the System, System. Drawing, and System. Forms DLLs. To use the program, simply click the client area.
|Published (Last):||4 February 2011|
|PDF File Size:||12.59 Mb|
|ePub File Size:||20.32 Mb|
|Price:||Free* [*Free Regsitration Required]|
The CaptureScreen. NET bitmap. Like all Windows Forms programs, compiling the program requires references to the System, System. Drawing, and System. Forms DLLs. To use the program, simply click the client area. The program creates a bitmap the size of the screen, copies the screen contents into the bitmap, and then displays the bitmap stretched to the size of its client area. You can use techniques shown in Chapter 11, 16, and 24 of Programming Windows with C to save the bitmap to a file, or copy it to the clipboard.
The only external Win32 function required in CaptureScreen is the famous BitBlt bit-block transfer function. BitBlt requires two devices context handles — a source and a destination. Both device context handles can be obtained from methods provided by the. NET Graphics class. FromHwnd method with an argument of zero. I was prompted to try calling Graphics.
The OnClick method then creates a bitmap with the same size and resolution of the screen. Once the bitmap is created, the OnClick method creates a Graphics object for the bitmap by calling the static Graphics. FromImage method. The GetHdc method of the Graphics class provides device context handles based on both Graphics objects. At this point, BitBlt can be called. The rest is just cleanup. A different approach is required that obtains a device context handle from the Win32 function CreateDC, and later deletes it with DeleteDC.
The WhatColor. The program sets a timer to display the RGB value of the pixel underneath the mouse position. The C WhatColor program is somewhat enhanced to display both the hexadecimal and decimal renditions of the pixel color. At each timer tick, the program obtains the current mouse coordinates using the static method Control. It obtains a device context handle for the whole screen using CreateDC, gets the pixel color from GetPixel and then deletes the device context handle by calling DeleteDC.
The OnPaint method using String. Format to create a two-line string containing the hexadecimal and decimal text renditions of the color, and then uses DrawString with a StringFormat object to center the text in the window.
Books by Charles Petzold
Microsoft Press, ; pages An introduction to Windows Forms programming with an emphasis on. NET 2. Microsoft Press, ; pages A tutorial for people wishing to learn the C programming language. No prior programming knowledge is required.
Download EBOOK Programming Microsoft Windows Forms PDF for free
Source Code For source code to programs in the book, go to the companion content page. Source Code Translated to Visual Basic. NET and can be downloaded here. Step 1.
Programming Microsoft® Windows® Forms
Reading Pixels from the Screen