--- q_a/samples/regions/regions.c 2018/08/09 18:29:19 1.1.1.1 +++ q_a/samples/regions/regions.c 2018/08/09 18:29:33 1.1.1.2 @@ -1,4 +1,4 @@ -/************************************************************************\ +/******************************************************************************\ * * PROGRAM: Regions.c * @@ -45,76 +45,74 @@ * affect this region. When two regions are combined the * second region will be destroyed. * -\************************************************************************/ +* +* Microsoft Developer Support +* Copyright (c) 1992 Microsoft Corporation +* +\******************************************************************************/ #include #include "regions.h" -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: WinMain (standard WinMain INPUTS/RETURNS) * * GLOBAL VARS: hInst - Handle of program instance * -\************************************************************************/ +\******************************************************************************/ -int APIENTRY WinMain (HANDLE hInstance, HANDLE hPrevInstance, - LPSTR lpCmdLine, int nCmdShow) -{ HWND hWnd; +int WINAPI WinMain (HANDLE hInstance, HANDLE hPrevInstance, + LPSTR lpCmdLine, int nCmdShow) +{ HWND hwnd; MSG msg; if (!hPrevInstance) - { PWNDCLASS pWndClass; + { + WNDCLASS wc; - pWndClass = (PWNDCLASS) LocalAlloc (LPTR, sizeof(WNDCLASS)); - if(!pWndClass) - { MessageBox (NULL, "REGIONS: LocalAlloc() failed", NULL, MB_OK | - MB_ICONHAND); - return(FALSE); - } + wc.style = NULL; + wc.lpfnWndProc = (WNDPROC)MainWndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.hCursor = LoadCursor (NULL, IDC_ARROW); + wc.hbrBackground = GetStockObject (DKGRAY_BRUSH); + wc.lpszMenuName = (LPCTSTR) "Menu"; + wc.lpszClassName = (LPCTSTR) "Main"; - pWndClass->hCursor = LoadCursor (NULL, IDC_ARROW); - pWndClass->hIcon = LoadIcon(NULL, IDI_APPLICATION); - pWndClass->lpszMenuName = (LPSTR) "Menu"; - pWndClass->lpszClassName = (LPSTR) "Main"; - pWndClass->hbrBackground = GetStockObject (DKGRAY_BRUSH); - pWndClass->hInstance = hInstance; - pWndClass->style = NULL; - pWndClass->lpfnWndProc = (WNDPROC)MainWndProc; - - if (!RegisterClass (pWndClass)) - { MessageBox (NULL, "REGIONS: RegisterClass() failed", NULL, MB_OK | - MB_ICONHAND); + if (!RegisterClass (&wc)) + { + MessageBox (NULL, (LPCTSTR) "RegisterClass() failed", + (LPCTSTR) "Err! - REGIONS", MB_OK | MB_ICONEXCLAMATION); return(FALSE); } - - LocalFree (LocalHandle ((LPSTR)pWndClass)); } hInst = hInstance; - hWnd = CreateWindow ("Main", "Regions API Sample", - WS_OVERLAPPED | WS_CAPTION | - WS_SYSMENU | WS_MINIMIZEBOX, - CW_USEDEFAULT, CW_USEDEFAULT, - 220, 280, NULL, NULL, hInstance, NULL); - if (!hWnd) + if (!(hwnd = CreateWindow ("Main", "Regions API Sample", + WS_OVERLAPPED | WS_CAPTION | + WS_SYSMENU | WS_MINIMIZEBOX, + CW_USEDEFAULT, CW_USEDEFAULT, + 220, 280, NULL, NULL, hInstance, NULL))) return (NULL); - ShowWindow(hWnd, nCmdShow); - UpdateWindow(hWnd); + ShowWindow (hwnd, nCmdShow); - while (GetMessage(&msg, NULL, NULL, NULL)) - { TranslateMessage(&msg); - DispatchMessage(&msg); + while (GetMessage (&msg, NULL, NULL, NULL)) + { + TranslateMessage (&msg); + DispatchMessage (&msg); } + return (msg.wParam); - UNREFERENCED_PARAMETER(lpCmdLine); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: MainWndProc (standard window procedure INPUTS/RETURNS) * @@ -137,11 +135,12 @@ int APIENTRY WinMain (HANDLE hInstance, * bOffsetRgnFlag - A BOOL which tells whether to offset up * and left or down and right. * -\************************************************************************/ +\******************************************************************************/ -LONG APIENTRY MainWndProc (HWND hWnd, UINT message, UINT wParam, - LONG lParam) -{ static RECT rect; +LRESULT CALLBACK MainWndProc (HWND hWnd, UINT message, WPARAM wParam, + LPARAM lParam) +{ + static RECT rect; static PTRACKRECTSTRUCT ptr; static BOOL bOffsetRgnFlag = FALSE; static WORD lButtonFlag = 0; @@ -149,68 +148,76 @@ LONG APIENTRY MainWndProc (HWND hWnd, UI HDC hdc; switch (message) - { case WM_CREATE: + { + case WM_CREATE: + hMenu = GetMenu (hWnd); currRgn = -1; Reset (RESET_ALL); break; case WM_COMMAND: + switch (LOWORD(wParam)) - { case IDM_ERASE: + { + case IDM_ERASE: Reset (RESET_ALL); InvalidateRect (hWnd, NULL, TRUE); break; case IDM_OFFSETRGN: - /**************************************************************\ - * Offset rgnArray[currRgn].hrgn either down & right, or up & - * left (depending on bOffsetRgnFlag). Toggle bOffsetRgnFlag. - \**************************************************************/ + // + // Offset rgnArray[currRgn].hrgn either down & right, or up & + // left (depending on bOffsetRgnFlag). Toggle bOffsetRgnFlag. + // if (bOffsetRgnFlag) + OffsetRgn (rgnArray[currRgn].hrgn, 15, 10); + else + OffsetRgn (rgnArray[currRgn].hrgn, -15, -10); + bOffsetRgnFlag = ~bOffsetRgnFlag; InvalidateRect (hWnd, NULL, TRUE); - break; case IDM_INVERTRGN: + hdc = GetDC (hWnd); InvertRgn (hdc, rgnArray[currRgn].hrgn); ReleaseDC (hWnd, hdc); break; -#ifdef NOTIMPLEMENTED - case IDM_FRAMERGN: + hdc = GetDC (hWnd); FrameRgn (hdc, rgnArray[currRgn].hrgn, - GetStockObject (WHITE_BRUSH), 2, 2); + GetStockObject (LTGRAY_BRUSH), 2, 2); ReleaseDC (hWnd, hdc); break; -#endif case IDM_PTINRGN: - /**************************************************************\ - * Uncheck "RectInRgn" menu item, toggle "PtInRgn" menu item, - * toggle lButtonFlag - \**************************************************************/ + // + // Uncheck "RectInRgn" menu item, toggle "PtInRgn" menu item, + // toggle lButtonFlag + // if (lButtonFlag == IDM_RECTINRGN) CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN, MF_UNCHECKED | MF_BYCOMMAND); - if (lButtonFlag == IDM_PTINRGN) { + if (lButtonFlag == IDM_PTINRGN) + { CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN, MF_UNCHECKED | MF_BYCOMMAND); lButtonFlag = 0; } - else { + else + { CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN, MF_CHECKED | MF_BYCOMMAND); lButtonFlag = IDM_PTINRGN; @@ -219,20 +226,24 @@ LONG APIENTRY MainWndProc (HWND hWnd, UI case IDM_RECTINRGN: - /**************************************************************\ - * Uncheck "PtInRgn" menu item, toggle "RectInRgn" menu item, - * toggle lButtonFlag - \**************************************************************/ + // + // Uncheck "PtInRgn" menu item, toggle "RectInRgn" menu item, + // toggle lButtonFlag + // if (lButtonFlag == IDM_PTINRGN) + CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN, MF_UNCHECKED | MF_BYCOMMAND); - if (lButtonFlag == IDM_RECTINRGN) { + + if (lButtonFlag == IDM_RECTINRGN) + { CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN, MF_UNCHECKED | MF_BYCOMMAND); lButtonFlag = 0; } - else { + else + { CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN, MF_CHECKED | MF_BYCOMMAND); lButtonFlag = IDM_RECTINRGN; @@ -241,10 +252,10 @@ LONG APIENTRY MainWndProc (HWND hWnd, UI case IDM_SETRECTRGN: - /**************************************************************\ - * Reset rgnArray[currRgn].hrgn to be the rectangle which - * currently bounds it. - \**************************************************************/ + // + // Reset rgnArray[currRgn].hrgn to be the rectangle which + // currently bounds it. + // GetRgnBox (rgnArray[currRgn].hrgn, &rect); SetRectRgn (rgnArray[currRgn].hrgn, (int) rect.left, @@ -253,79 +264,92 @@ LONG APIENTRY MainWndProc (HWND hWnd, UI InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_GETRGNBOX: /* put up dlg which call GetRgnBox */ - DialogBox (hInst, "RgnBox", hWnd, (DLGPROC)RgnBoxDlgProc); + case IDM_GETRGNBOX: // put up dlg which call GetRgnBox + + DialogBox (hInst, (LPCTSTR) "RgnBox", hWnd, (DLGPROC)RgnBoxDlgProc); break; - case IDM_ELLIPSE: /* create an elliptic rgn */ + case IDM_ELLIPSE: // create an elliptic region + MyCreateRgn (ELLIPTIC_RGN); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_POLYPOLYGON: /* create a polyPolygon rgn */ + case IDM_POLYPOLYGON: // create a polyPolygon region + MyCreateRgn (POLYPOLYGON_RGN); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_RECT: /* create a rectangular rgn */ + case IDM_RECT: // create a rectangular rgn + MyCreateRgn (RECT_RGN); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_AND: /* combine previous 2 rgns */ + case IDM_AND: // combine previous 2 rgns + MyCombineRgn (RGN_AND); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_COPY: /* combine previous 2 rgns */ + case IDM_COPY: // combine previous 2 rgns + MyCombineRgn (RGN_COPY); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_DIFF: /* combine previous 2 rgns */ + case IDM_DIFF: // combine previous 2 rgns + MyCombineRgn (RGN_DIFF); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_OR: /* combine previous 2 rgns */ + case IDM_OR: // combine previous 2 rgns + MyCombineRgn (RGN_OR); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_XOR: /* combine previous 2 rgns */ + case IDM_XOR: // combine previous 2 rgns + MyCombineRgn (RGN_XOR); InvalidateRect (hWnd, NULL, TRUE); break; - case IDM_ABOUT: /* put up About dialog box */ - DialogBox (hInst, "AboutBox", hWnd, (DLGPROC)AboutDlgProc); + case IDM_ABOUT: // put up About dialog box + + DialogBox (hInst, (LPCTSTR) "About", hWnd, (DLGPROC)AboutDlgProc); break; } return (NULL); case WM_LBUTTONDOWN: { - /******************************************************************\ - * if the "PtInRgn" menu item is checked, then see if the point at - * which this event happened is within currRgn, MessageBeep if so. - * - * else if the "RectInRgn" menu items are checked, then start - * tracking rectangle mode - \******************************************************************/ + // + // if the "PtInRgn" menu item is checked, then see if the point at + // which this event happened is within currRgn, MessageBeep if so. + // + // else if the "RectInRgn" menu items are checked, then start + // tracking rectangle mode + // if (lButtonFlag == IDM_PTINRGN) - { if (currRgn > -1) + { + if (currRgn > -1) + if (PtInRegion (rgnArray[currRgn].hrgn, (int) LOWORD(lParam), (int) HIWORD(lParam))) MessageBeep (0); } else if (lButtonFlag == IDM_RECTINRGN) + if ((ptr = TrackRect (NULL, TRECT_NEW, hWnd, lParam)) == NULL) - /****************************************************************\ - * If TrackRect failed to LocalAlloc, then disable the - * IDM_RECTINRGN opion. - \****************************************************************/ + // + // If TrackRect failed to LocalAlloc, then disable the + // IDM_RECTINRGN opion. + // EnableMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN, MF_DISABLED | MF_GRAYED | MF_BYCOMMAND); @@ -334,64 +358,76 @@ LONG APIENTRY MainWndProc (HWND hWnd, UI } case WM_MOUSEMOVE: - /******************************************************************\ - * if in tracking rectangle mode call TrackRect - \******************************************************************/ + // + // if in tracking rectangle mode call TrackRect + // if (lButtonFlag == IDM_RECTINRGN && GetCapture () == hWnd) + TrackRect (ptr, TRECT_PAINT, hWnd, lParam); + return (NULL); case WM_LBUTTONUP: - /******************************************************************\ - * if in tracking rectangle mode call TrackRect, check out the final - * rectangle, and see if it intersects currRgn - \******************************************************************/ + // + // if in tracking rectangle mode call TrackRect, check out the final + // rectangle, and see if it intersects currRgn + // if (lButtonFlag == IDM_RECTINRGN && GetCapture () == hWnd) { - /****************************************************************\ - * call TrackRect with TRECT_PAINT so it updates the rectangle - * for the last time, then again with TRECT_DELETE so it frees - * up the TRACKRECTSTRUCT it allocated - \****************************************************************/ + // + // call TrackRect with TRECT_PAINT so it updates the rectangle + // for the last time, then again with TRECT_DELETE so it frees + // up the TRACKRECTSTRUCT it allocated + // TrackRect (ptr, TRECT_PAINT, hWnd, lParam); rect = ptr->trackRect; TrackRect (ptr, TRECT_DELETE, hWnd, lParam); if (RectInRegion (rgnArray[currRgn].hrgn, &rect)) + MessageBeep (0); } return (NULL); - case WM_PAINT: { + case WM_PAINT: + { PAINTSTRUCT ps; COLORREF crColor; HBRUSH hBrush; hdc = BeginPaint (hWnd, &ps); - /******************************************************************\ - * For each rgn we created determine appropriate color & draw it - \******************************************************************/ + // + // For each rgn we created determine appropriate color & draw it + // for (i = 0; i <= currRgn; i++) - { if (rgnArray[i].hrgn != NULL) - { crColor = 0x000000; - if (rgnArray[i].type & ELLIPTIC_RGN) /* add some red */ + { + if (rgnArray[i].hrgn != NULL) + { + crColor = 0x000000; + if (rgnArray[i].type & ELLIPTIC_RGN) // add some red + crColor |= 0x0000ff; - if (rgnArray[i].type & POLYPOLYGON_RGN) /* add some green */ + + if (rgnArray[i].type & POLYPOLYGON_RGN) // add some green + crColor |= 0x00ff00; - if (rgnArray[i].type & RECT_RGN) /* add some blue */ + + if (rgnArray[i].type & RECT_RGN) // add some blue + crColor |= 0xff0000; + hBrush = CreateSolidBrush (crColor); - /**************************************************************\ - * Alternately, the following would work: - * SelectObject (hdc, hBrush); - * FillRgn (hdc, rgnArray[i].hrgn); - \**************************************************************/ + // + // Alternately, the following would work: + // SelectObject (hdc, hBrush); + // FillRgn (hdc, rgnArray[i].hrgn); + // FillRgn (hdc, rgnArray[i].hrgn, hBrush); DeleteObject (hBrush); @@ -410,36 +446,33 @@ LONG APIENTRY MainWndProc (HWND hWnd, UI -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: AboutDlgProc (standard dialog procedure INPUTS/RETURNS) * * COMMENTS: Displays "about" message * -\************************************************************************/ +\******************************************************************************/ -BOOL APIENTRY AboutDlgProc (HWND hDlg, UINT message, UINT wParam, - LONG lParam) +LRESULT CALLBACK AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam, + LPARAM lParam) { switch (message) - { case WM_INITDIALOG: - - return (TRUE); - + { case WM_COMMAND: - if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { EndDialog(hDlg, TRUE); + if (LOWORD(wParam) == IDOK) + { + EndDialog(hwnd, TRUE); return (TRUE); } return (TRUE); } return (FALSE); - UNREFERENCED_PARAMETER(lParam); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: RgnBoxDlgProc (standard dialog procedure INPUTS/RETURNS) * @@ -452,52 +485,58 @@ BOOL APIENTRY AboutDlgProc (HWND hDlg, U * COMMENTS: Displays bounding rectangle of most recently created * region. * -\************************************************************************/ +\******************************************************************************/ -BOOL APIENTRY RgnBoxDlgProc (HWND hDlg, UINT message, UINT wParam, - LONG lParam) +LRESULT CALLBACK RgnBoxDlgProc (HWND hwnd, UINT message, WPARAM wParam, + LPARAM lParam) { switch (message) - { case WM_INITDIALOG: - { RECT rect; + { + case WM_INITDIALOG: + { + RECT rect; char buf[15]; - /******************************************************************\ - * get the bounding rect of currRgn, fill in the dlg controls - * with text string describing the bounding rect. - \******************************************************************/ + // + // get the bounding rect of currRgn, fill in the dlg controls + // with text string describing the bounding rect. + // if (GetRgnBox (rgnArray[currRgn].hrgn, &rect) == SIMPLEREGION) - SetDlgItemText (hDlg, 102, "SIMPLEREGION"); + + SetDlgItemText (hwnd, 102, "SIMPLEREGION"); + else - SetDlgItemText (hDlg, 102, "COMPLEXREGION"); + + SetDlgItemText (hwnd, 102, "COMPLEXREGION"); wsprintf (buf, "%ld", rect.left); - SetDlgItemText (hDlg, 107, buf); + SetDlgItemText (hwnd, 107, buf); wsprintf (buf, "%ld", rect.top); - SetDlgItemText (hDlg, 108, buf); + SetDlgItemText (hwnd, 108, buf); wsprintf (buf, "%ld", rect.right); - SetDlgItemText (hDlg, 109, buf); + SetDlgItemText (hwnd, 109, buf); wsprintf (buf, "%ld", rect.bottom); - SetDlgItemText (hDlg, 110, buf); + SetDlgItemText (hwnd, 110, buf); return (TRUE); } + case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { EndDialog(hDlg, TRUE); + { + EndDialog(hwnd, TRUE); return (TRUE); } return (TRUE); } return (FALSE); - UNREFERENCED_PARAMETER(lParam); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: MyCreateRgn * @@ -520,25 +559,31 @@ BOOL APIENTRY RgnBoxDlgProc (HWND hDlg, * COMMENTS: Creates a region (based on rgnStyle), increments currRgn, * and fills in rgnArray[currRgn]. * -\************************************************************************/ +\******************************************************************************/ void MyCreateRgn (WORD rgnStyle) -{ if (++currRgn == 0) /* if this is 1st rgn enable options menu */ +{ + if (++currRgn == 0) // if this is 1st region enable options menu + Reset (ENABLE_OPTIONS); - else if (currRgn == 1) /* if this is 2nd rgn enable combine menu */ + + else if (currRgn == 1) // if this is 2nd region enable combine menu + Reset (ENABLE_COMBINERGN); + rgnArray[currRgn].type = rgnStyle; switch (rgnStyle) - { case ELLIPTIC_RGN: + { + case ELLIPTIC_RGN: - /******************************************************************\ - * The following will also work here: - * CreateEllipticRgn ((int) ellipseRect.left, - * (int) ellipseRect.top, - * (int) ellipseRect.right, - * (int) ellipseRect.bottom); - \******************************************************************/ + // + // The following will also work here: + // CreateEllipticRgn ((int) ellipseRect.left, + // (int) ellipseRect.top, + // (int) ellipseRect.right, + // (int) ellipseRect.bottom); + // rgnArray[currRgn].hrgn = CreateEllipticRgnIndirect (&ellipseRect); @@ -548,9 +593,9 @@ void MyCreateRgn (WORD rgnStyle) case POLYPOLYGON_RGN: - /******************************************************************\ - * Alternately, several calls to CreatePolygonRgn could be made. - \******************************************************************/ + // + // Alternately, several calls to CreatePolygonRgn could be made. + // rgnArray[currRgn].hrgn = CreatePolyPolygonRgn (polyPolygonPoints, polyPolygonCounts, @@ -562,9 +607,9 @@ void MyCreateRgn (WORD rgnStyle) case RECT_RGN: - /******************************************************************\ - * Alternately, a call to CreatePolygonRgn could be made. - \******************************************************************/ + // + // Alternately, a call to CreatePolygonRgn could be made. + // rgnArray[currRgn].hrgn = CreateRectRgn (rectRect.left, rectRect.top, @@ -579,7 +624,7 @@ void MyCreateRgn (WORD rgnStyle) -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: MyCombineRgn * @@ -598,28 +643,32 @@ void MyCreateRgn (WORD rgnStyle) * results in rgnArray[currRgn-1]. Destroys rgnArray[currRgn] * and decrements currRgn. * -\************************************************************************/ +\******************************************************************************/ void MyCombineRgn (int fnCombineMode) { - if (currRgn >= 1) /* only if two or more regions have been created */ - { CombineRgn (rgnArray[currRgn-1].hrgn, rgnArray[currRgn-1].hrgn, + if (currRgn >= 1) // only if two or more regions have been created + { + CombineRgn (rgnArray[currRgn-1].hrgn, rgnArray[currRgn-1].hrgn, rgnArray[currRgn].hrgn, fnCombineMode); rgnArray[currRgn-1].type |= rgnArray[currRgn].type; - /* Delete the second of the two regions after combining */ + // + // Delete the second of the two regions after combining + // DeleteObject (rgnArray[currRgn--].hrgn); if (currRgn == 0) + Reset (DISABLE_COMBINERGN); } } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: Reset * @@ -636,42 +685,56 @@ void MyCombineRgn (int fnCombineMode) * COMMENTS: Sets appropriate menu states and deletes old regions * according to "action" parameter. * -\************************************************************************/ +\******************************************************************************/ void Reset (WORD action) -{ UINT i; +{ + UINT i; switch (action) - { case RESET_ALL: + { + case RESET_ALL: if (currRgn > 0) + for (i = 0; i <= (UINT) currRgn; i++) + DeleteObject (rgnArray[i].hrgn); + currRgn = -1; for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++) + EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_DISABLED | MF_GRAYED | MF_BYCOMMAND); for (i = IDM_ELLIPSE; i <= IDM_RECT; i++) + EnableMenuItem (GetSubMenu (hMenu, 1), i, MF_ENABLED | MF_BYCOMMAND); for (i = IDM_AND; i <= IDM_XOR; i++) + EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED | MF_BYCOMMAND); break; case ENABLE_OPTIONS: + for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++) + EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_ENABLED | MF_BYCOMMAND); break; case ENABLE_COMBINERGN: + for (i = IDM_AND; i <= IDM_XOR; i++) + EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_ENABLED | MF_BYCOMMAND); break; case DISABLE_COMBINERGN: + for (i = IDM_AND; i <= IDM_XOR; i++) + EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED | MF_BYCOMMAND); break; @@ -679,7 +742,7 @@ void Reset (WORD action) } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: TrackRect() * @@ -696,39 +759,48 @@ void Reset (WORD action) * * COMMENTS: This function provides tracking rectangle functionality. * -\************************************************************************/ +\******************************************************************************/ PTRACKRECTSTRUCT TrackRect (PTRACKRECTSTRUCT ptr, int action, HWND hWnd, - LONG lParam) -{ if ((ptr == NULL) && (action != TRECT_NEW)) return NULL; + LPARAM lParam) +{ + if ((ptr == NULL) && (action != TRECT_NEW)) return NULL; switch (action) { - /********************************************************************\ - * TRECT_NEW: Allocate new PTRACKRECTSTRUCT. Fill in initial values - * for the fields of the structure. Set up the HDC - * correctly. - * - * return - pointer to the new object. - \********************************************************************/ + // + // TRECT_NEW: Allocate new PTRACKRECTSTRUCT. Fill in initial values + // for the fields of the structure. Set up the HDC + // correctly. + // + // return - pointer to the new object. + // case TRECT_NEW: - { PTRACKRECTSTRUCT ptr; + { + PTRACKRECTSTRUCT ptr; if ((ptr = LocalAlloc (LPTR, sizeof (TRACKRECTSTRUCT))) == NULL) - { MessageBox (hWnd, "REGIONS: LocalAlloc() failed", "Err!", + { + MessageBox (hWnd, (LPCTSTR) "REGIONS: LocalAlloc() failed", "Err!", MB_OK | MB_ICONEXCLAMATION); return NULL; } - /* initialize the HDC and other fields. */ + // + // initialize the HDC and other fields. + // + ptr->hdc = GetDC(hWnd); SetROP2(ptr->hdc, R2_NOT); SelectObject (ptr->hdc, GetStockObject (NULL_BRUSH)); SelectObject (ptr->hdc, CreatePen (PS_SOLID, 2, (COLORREF) 0x01000009)); - /* initialize the size. */ + // + // initialize the size + // + ptr->trackRect.left = ptr->trackRect.right = (LONG) (ptr->xOrigin = LOWORD (lParam)); ptr->trackRect.top = ptr->trackRect.bottom = @@ -739,12 +811,13 @@ PTRACKRECTSTRUCT TrackRect (PTRACKRECTST return (ptr); } - /********************************************************************\ - * TRECT_DELETE: Free up the memory allocated for the tracking rect. - * Also, erase the last rectangle we drew. - \********************************************************************/ + // + // TRECT_DELETE: Free up the memory allocated for the tracking rect. + // Also, erase the last rectangle we drew. + // case TRECT_DELETE: + Rectangle (ptr->hdc, (int) ptr->trackRect.left, (int) ptr->trackRect.top, (int) ptr->trackRect.right, @@ -754,39 +827,45 @@ PTRACKRECTSTRUCT TrackRect (PTRACKRECTST ReleaseCapture (); return NULL; - /********************************************************************\ - * TRECT_PAINT: Draw the tracking rectangle (involves erasing last - * rectangle at old coordinates, and drawing new rect - * at new coordinates). - \********************************************************************/ + // + // TRECT_PAINT: Draw the tracking rectangle (involves erasing last + // rectangle at old coordinates, and drawing new rect + // at new coordinates). + // case TRECT_PAINT: - /******************************************************************\ - * Remove the last rectangle we painted by painting over it again - \******************************************************************/ + // + // Remove the last rectangle we painted by painting over it again + // Rectangle (ptr->hdc, (int) ptr->trackRect.left, (int) ptr->trackRect.top, (int) ptr->trackRect.right, (int) ptr->trackRect.bottom); - /******************************************************************\ - * We want to restrict our Rectangle() calls to paint within the - * client area, so do a bounds check on lParam and reset any - * values which fall outside the client area (eg. <1, - * >clientRect.left, >clientRect.top). - \******************************************************************/ + // + // We want to restrict our Rectangle() calls to paint within the + // client area, so do a bounds check on lParam and reset any + // values which fall outside the client area (eg. <1, + // >clientRect.left, >clientRect.top). + // if ((SHORT)LOWORD(lParam) < 1) + lParam &= 0xffff0000; + else if (LOWORD(lParam) > (WORD) (ptr->clientRect.right- 1)) + lParam = MAKELONG ((WORD) ptr->clientRect.right - 1, HIWORD(lParam)); if ((SHORT)HIWORD(lParam) < 1) + lParam &= 0x0000ffff; + else if (HIWORD(lParam) > (WORD) (ptr->clientRect.bottom - 1)) + lParam = MAKELONG (LOWORD(lParam), (WORD) ptr->clientRect.bottom - 1); @@ -799,9 +878,9 @@ PTRACKRECTSTRUCT TrackRect (PTRACKRECTST ptr->trackRect.bottom = (LONG) (ptr->yOrigin > HIWORD(lParam) ? ptr->yOrigin : HIWORD(lParam)); - /******************************************************************\ - * Redraw the tracking rectangle - \******************************************************************/ + // + // Redraw the tracking rectangle + // Rectangle (ptr->hdc, (int) ptr->trackRect.left, (int) ptr->trackRect.top,