На главную

On-line справка по Win32 API

Написать письмо
БЕСПЛАТНАЯ ежедневная online лотерея! Выигрывай каждый день БЕСПЛАТНО!
Список всех статей A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z | Скачать Вниз

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.


Пригласи друзей и счет твоего мобильника всегда будет положительным!
Предыдущая статья
 
Сайт Народ.Ру Интернет
Следующая статья
Пригласи друзей и счет твоего мобильника всегда будет положительным!

Поиск Graphic-Object Приписывает и Выбираясь Новые Графические Объекты



Приложение может извлечь атрибутам для ручки, щетки, палитры, шрифта, или побитовое отображение вызывая GetCurrentObject и функции GetObject. Функция GetCurrentObject возвращает ручку, опознающую объект к настоящему времени выбирался в контекст устройства; функция GetObject возвращает структуру, которая описывает объектные атрибуты.

Следующий пример показывает как приложение может извлечь текущую щетку приписывает и использует извлеченные данные, чтобы определять независимо необходимо должно выбираться новую щетку.

hdc HDC; /* отобразите ручку DC */ HBRUSH hbrushNew, hbrushOld; /* щетка оперируется */ HBRUSH hbrush; /* ручка щетки */ lb LOGBRUSH; /* логическая щетка структуры */

/*
* Извлеките ручку опознавая текущую щетку.
*/

hbrush = GetCurrentObject(hdc, OBJ_BRUSH);

/*
* Извлеките структуру LOGBRUSH, которая содержит the
* текущая щетка приписывается.

*/

GetObject(hbrush, sizeof(LOGBRUSH), &lb);

/*
* Если текущая щетка не является твердой-черной щеткой,
* замените это твердой-черной фондовой щеткой.
*/

если ((lb.lbStyle != BS_SOLID) || (lb.lbColor != 0x000000)) { hbrushNew = GetStockObject(BLACK_BRUSH);
hbrushOld = SelectObject(hdc, hbrushNew);
}


/* Выполните операции живописи с белым brush. */


/*
* После завершать последний раз изображающей операции

* с новой щеткой, приложение должно
* выберитесь оригинальную щетку снова в the
* контекст устройства и удаляет новую щетку.
* В этом примере, hbrushNew содержит ручку
* на фондовый объект. Нет необходимости (но это
* не вредное), чтобы называть DeleteObject в акции
* объект. Если hbrushNew содержал бы ручку в щетку
* созданное функцией как например, CreateBrushIndirect,
* это будет необходимо называть DeleteObject.

*/

SelectObject(hdc, hbrushOld);
DeleteObject(hbrushNew);


Отметьте, что приложение сохраняло оригинальная ручка щетки при вызове SelectObject функционировать сначала. Эта ручка сохранена чтобы оригинальная щетка может быть выбрана снова в контекст устройства после того, как последний раз изображающая операция будет кончена новой щеткой. После того, как оригинальная щетка будет выбрана снова в контекст устройства, новая щетка удалена, освобождая память в куче GDI.


Вверх Version 1.3, Oct 26 2010 © 2007, 2010, mrhx Вверх
 mrhx software  Русский перевод OpenGL  Русский перевод Win32 API
 
Используются технологии uCoz