На главную

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 | Скачать Вниз

Defining the Clipping Region



When the user selects the Define Clip Region option, Windows issues a WM_COMMAND message. The wParam parameter of this message contains an application-defined constant, IDM_DEFINE, that indicates that the user selected this option from the menu. The application processes this input by setting a Boolean flag, fDefineRegion, as shown in the following code sample.

case WM_COMMAND:
switch (wParam) {

case IDM_DEFINE:
fDefineRegion = TRUE;
break;


After selecting the Define Clipping Region option, the user can begin drawing the rectangle by clicking and dragging the mouse while the cursor is in the application's client area.
When the user presses the left button, Windows issues a WM_LBUTTONDOWN message. The lParam parameter of this message contains the cursor coordinates, which correspond to the upper left corner of a rectangle used to define the clipping region. The application processes the WM_LBUTTONDOWN message, as follows.

/* These variables are required for clipping. */

static POINT ptUpperLeft;
static POINT ptLowerRight;
static POINT aptRect[5];
static POINT ptTmp;
static POINTS ptsTmp;
static BOOL fDefineRegion;
static BOOL fRegionExists;
static HRGN hrgn;
static RECT rctTmp;
int i;

switch (message) {

case WM_LBUTTONDOWN:
if (fDefineRegion) {

/* Retrieve the new upper left corner. */

ptsTmp = MAKEPOINTS(lParam);
ptUpperLeft.x = (LONG) ptsTmp.x;

ptUpperLeft.y = (LONG) ptsTmp.y;
}

if (fRegionExists) {

/* Erase the previous rectangle. */

hdc = GetDC(hwnd);
SetROP2(hdc, R2_NOTXORPEN);

if (!Polyline(hdc, (CONST POINT *) aptRect, 5))
errhandler("Polyline Failed", hwnd);
ReleaseDC(hwnd, hdc);

/* Clear the rectangle coordinates. */

for (i = 0; i < 4; i++) {
aptRect[i].x = 0;
aptRect[i].y = 0;

}

/* Clear the temporary point structure. */

ptTmp.x = 0;
ptTmp.y = 0;

/* Clear the lower right coordinates. */

ptLowerRight.x = 0;
ptLowerRight.y = 0;

/* Reset the flag. */

fRegionExists = FALSE;
fDefineRegion = TRUE;

/* Retrieve the new upper left corner. */

ptsTmp = MAKEPOINTS(lParam);
ptUpperLeft.x = (LONG) ptsTmp.x;

ptUpperLeft.y = (LONG) ptsTmp.y;
}
break;


As the user drags the mouse, Windows issues WM_MOUSEMOVE messages and stores the new cursor coordinates in the lParam parameter. Each time the application receives a new WM_MOUSEMOVE message, it erases the previous rectangle (if one exists) and draws the new rectangle by calling the Polyline function, passing it the coordinates of the four corners of the rectangle. The application performs the following tasks.

/* These variables are required for clipping. */

static POINT ptUpperLeft;
static POINT ptLowerRight;
static POINT aptRect[5];
static POINT ptTmp;
static POINTS ptsTmp;
static BOOL fDefineRegion;
static BOOL fRegionExists;
static HRGN hrgn;
static RECT rctTmp;
int i;

switch (message) {

case WM_MOUSEMOVE:

if (wParam & MK_LBUTTON && fDefineRegion) {

/* Get a window DC. */

hdc = GetDC(hwnd);

if (!SetROP2(hdc, R2_NOTXORPEN))

errhandler("SetROP2 Failed", hwnd);


/*
* If previous mouse movement occurred, store the original
* lower right corner coordinates in a temporary structure.
*/

if (ptLowerRight.x) {
ptTmp.x = ptLowerRight.x;
ptTmp.y = ptLowerRight.y;
}

/*
* Get the new coordinates of the clipping region's lower
* right corner.
*/


ptsTmp = MAKEPOINTS(lParam);
ptLowerRight.x = (LONG) ptsTmp.x;
ptLowerRight.y = (LONG) ptsTmp.y;


/*
* If previous mouse movement occurred, erase the original
* rectangle.
*/

if (ptTmp.x) {
aptRect[0].x = ptUpperLeft.x;
aptRect[0].y = ptUpperLeft.y;
aptRect[1].x = ptTmp.x;
aptRect[1].y = ptUpperLeft.y;
aptRect[2].x = ptTmp.x;

aptRect[2].y = ptTmp.y;
aptRect[3].x = ptUpperLeft.x;
aptRect[3].y = ptTmp.y;
aptRect[4].x = aptRect[0].x;
aptRect[4].y = aptRect[0].y;

if (!Polyline(hdc, (CONST POINT *) aptRect, 5))
errhandler("Polyline Failed", hwnd);
}

aptRect[0].x = ptUpperLeft.x;
aptRect[0].y = ptUpperLeft.y;
aptRect[1].x = ptLowerRight.x;
aptRect[1].y = ptUpperLeft.y;

aptRect[2].x = ptLowerRight.x;
aptRect[2].y = ptLowerRight.y;
aptRect[3].x = ptUpperLeft.x;
aptRect[3].y = ptLowerRight.y;
aptRect[4].x = aptRect[0].x;
aptRect[4].y = aptRect[0].y;

if (!Polyline(hdc, (CONST POINT *) aptRect, 5))
errhandler("Polyline Failed", hwnd);

ReleaseDC(hwnd, hdc);
}
break;



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

Определяющий Отсечение Региона



Когда потребитель выбирается выбор Региона Клипа Define, Окно выпускает сообщение WM_COMMAND. Параметр wParam этого сообщения содержит определенную прикладную константу, IDM_DEFINE, которая указывает, что пользователь выбирался эту опцию из меню. Приложение обрабатывает этот ввод устанавливая Логический флаг, fDefineRegion, как показано в кодовом образце следующего.

случай WM_COMMAND: ключ (wParam) {

случай IDM_DEFINE: fDefineRegion = ИСТИНА;
прерывание;


После выбора Define, вырезать опцию Области, пользователь может начать рисовать прямоугольник щелкая и таща мышь тогда как курсор - в прикладной области клиента.
Когда пользователь нажимает левую кнопку, Windows выпускает сообщение WM_LBUTTONDOWN. Параметр lParam этого сообщения содержит координаты курсора, которые переписываются в верхний левый угол прямоугольника использованного, чтобы определять вырезать область. Приложение обрабатывает сообщение WM_LBUTTONDOWN, следующим образом.

/* Эти переменные необходимы для clipping. */

статическая ТОЧКА ptUpperLeft;
статическая ТОЧКА ptLowerRight;
статическая ТОЧКА aptRect[5];
статическая ТОЧКА ptTmp;
статические ТОЧКИ ptsTmp;
статический BOOL fDefineRegion;
статический BOOL fRegionExists;
статический HRGN hrgn;
статический RECT rctTmp;
int i;

ключ (сообщение) {

случай WM_LBUTTONDOWN: если (fDefineRegion) {

/* Извлеките новый верхний левый corner. */

ptsTmp = MAKEPOINTS(lParam);
ptUpperLeft.x = (ДОЛГО (ДЛИНОЙ)) ptsTmp.x;

ptUpperLeft.y = (ДОЛГО (ДЛИНОЙ)) ptsTmp.y;
}

если (fRegionExists) {

/* Выстирайте предшествующий rectangle. */

hdc = GetDC(hwnd);
SetROP2(hdc, R2_NOTXORPEN);

если (!Ломаная линия(hdc, (ТОЧКА CONST *) aptRect, 5)) errhandler("Polyline Потерпевший неудачу", hwnd);
ReleaseDC(hwnd, hdc);

/* Очистите прямоугольник coordinates. */

для (i = 0; я < 4; я++) { aptRect[i].x = 0;
aptRect[i].y = 0;

}

/* Очистите временную точку structure. */

ptTmp.x = 0;
ptTmp.y = 0;

/* Очистите правый нижний coordinates. */

ptLowerRight.x = 0;
ptLowerRight.y = 0;

/* Восстановите flag. */

fRegionExists = ЛОЖЬ;
fDefineRegion = ИСТИНА;

/* Извлеките новый верхний левый corner. */

ptsTmp = MAKEPOINTS(lParam);
ptUpperLeft.x = (ДОЛГО (ДЛИНОЙ)) ptsTmp.x;

ptUpperLeft.y = (ДОЛГО (ДЛИНОЙ)) ptsTmp.y;
}
прерывание;


Так как пользователь тащит мышь, Windows выпускает сообщения WM_MOUSEMOVE и загружает новые координаты курсора в параметр lParam. Всякий раз, когда приложение получает новое сообщение WM_MOUSEMOVE, оно стирает предшествующий прямоугольник (если один существует) и делает новым прямоугольником вызывая функцию Ломаной линии, передающую это координаты четырех углов прямоугольника. Приложение выполняет следующие задачи.

/* Эти переменные необходимы для clipping. */

статическая ТОЧКА ptUpperLeft;
статическая ТОЧКА ptLowerRight;
статическая ТОЧКА aptRect[5];
статическая ТОЧКА ptTmp;
статические ТОЧКИ ptsTmp;
статический BOOL fDefineRegion;
статический BOOL fRegionExists;
статический HRGN hrgn;
статический RECT rctTmp;
int i;

ключ (сообщение) {

случай WM_MOUSEMOVE:

если (wParam & MK_LBUTTON && fDefineRegion) {

/* Получите окно DC. */

hdc = GetDC(hwnd);

если (!SetROP2(hdc, R2_NOTXORPEN))

errhandler("SetROP2 Потерпевший неудачу", hwnd);


/*
* Если предшествующее перемещение мыши происходило бы, загрузите подлинник
* правые нижние координаты угла во временной структуре.
*/

если (ptLowerRight.x) { ptTmp.x = ptLowerRight.x;
ptTmp.y = ptLowerRight.y;
}

/*
* Получите новые координаты отсечения регион более низкий
* угол права.
*/


ptsTmp = MAKEPOINTS(lParam);
ptLowerRight.x = (ДОЛГО (ДЛИНОЙ)) ptsTmp.x;
ptLowerRight.y = (ДОЛГО (ДЛИНОЙ)) ptsTmp.y;


/*
* Если предшествующее перемещение мыши происходило бы, выстирайте подлинник
* прямоугольник.
*/

если (ptTmp.x) { aptRect[0].x = ptUpperLeft.x;
aptRect[0].y = ptUpperLeft.y;
aptRect[1].x = ptTmp.x;
aptRect[1].y = ptUpperLeft.y;
aptRect[2].x = ptTmp.x;

aptRect[2].y = ptTmp.y;
aptRect[3].x = ptUpperLeft.x;
aptRect[3].y = ptTmp.y;
aptRect[4].x = aptRect[0].x;
aptRect[4].y = aptRect[0].y;

если (!Ломаная линия(hdc, (ТОЧКА CONST *) aptRect, 5)) errhandler("Polyline Потерпевший неудачу", hwnd);
}

aptRect[0].x = ptUpperLeft.x;
aptRect[0].y = ptUpperLeft.y;
aptRect[1].x = ptLowerRight.x;
aptRect[1].y = ptUpperLeft.y;

aptRect[2].x = ptLowerRight.x;
aptRect[2].y = ptLowerRight.y;
aptRect[3].x = ptUpperLeft.x;
aptRect[3].y = ptLowerRight.y;
aptRect[4].x = aptRect[0].x;
aptRect[4].y = aptRect[0].y;

если (!Ломаная линия(hdc, (ТОЧКА CONST *) aptRect, 5)) errhandler("Polyline Потерпевший неудачу", hwnd);

ReleaseDC(hwnd, hdc);
}
прерывание;



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