|
Retrieving Graphic-Object Attributes and Selecting New Graphic Objects
An application can retrieve the attributes for a pen, brush, palette, font, or
bitmap by calling the GetCurrentObject and GetObject functions. The GetCurrentObject function returns a handle identifying the object currently selected into the
device context; the GetObject function returns a structure that describes the object's attributes.
The following example shows how an application can retrieve the current brush
attributes and use the retrieved data to determine whether it is necessary to
select a new brush.
HDC hdc; /* display DC handle */
HBRUSH hbrushNew, hbrushOld; /* brush handles */
HBRUSH hbrush; /* brush handle */
LOGBRUSH lb; /* logical-brush structure */
/*
* Retrieve a handle identifying the current brush.
*/
hbrush = GetCurrentObject(hdc, OBJ_BRUSH);
/*
* Retrieve a LOGBRUSH structure that contains the
* current brush attributes.
*/
GetObject(hbrush, sizeof(LOGBRUSH), &lb);
/*
* If the current brush is not a solid-black brush,
* replace it with the solid-black stock brush.
*/
if ((lb.lbStyle != BS_SOLID)
|| (lb.lbColor != 0x000000)) {
hbrushNew = GetStockObject(BLACK_BRUSH);
hbrushOld = SelectObject(hdc, hbrushNew);
}
/* Perform painting operations with the white brush. */
/*
* After completing the last painting operation
* with the new brush, the application should
* select the original brush back into the
* device context and delete the new brush.
* In this example, hbrushNew contains a handle
* to a stock object. It is not necessary (but it
* is not harmful) to call DeleteObject on a stock
* object. If hbrushNew contained a handle to a brush
* created by a function such as CreateBrushIndirect,
* it would be necessary to call DeleteObject.
*/
SelectObject(hdc, hbrushOld);
DeleteObject(hbrushNew);
Note that the application saved the original brush handle when calling the SelectObject function the first time. This handle is saved so that the original brush can
be selected back into the device context after the last painting operation has
been completed with the new brush. After the original brush is selected back
into the device context, the new brush is deleted, freeing memory in the GDI
heap.
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|