--- mstools/samples/select/demo.c 2018/08/09 18:20:52 1.1.1.2 +++ mstools/samples/select/demo.c 2018/08/09 18:24:05 1.1.1.3 @@ -1,3 +1,14 @@ + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + /**************************************************************************** PROGRAM: Demo.c @@ -6,15 +17,15 @@ FUNCTIONS: - WinMain() - calls initialization function, processes message loop - DemoInit() - initializes window data and registers window - DemoWndProc() - processes messages - About() - processes messages for "About" dialog box + WinMain() - calls initialization function, processes message loop + DemoInit() - initializes window data and registers window + DemoWndProc() - processes messages + About() - processes messages for "About" dialog box COMMENTS: - This code is a modified version of the CURSOR.C program. Instead of - using inline code for drawing the shape, the routines from the Select - library are called. + This code is a modified version of the CURSOR.C program. Instead of + using inline code for drawing the shape, the routines from the Select + library are called. ****************************************************************************/ @@ -31,13 +42,13 @@ INT X = 0, Y = 0; RECT Rect; -INT Shape = SL_BLOCK; /* Shape to use for rectangle */ -BOOL RetainShape = FALSE; /* Retain or destroy shape */ +INT Shape = SL_BLOCK; /* Shape to use for rectangle */ +BOOL RetainShape = FALSE; /* Retain or destroy shape */ int APIENTRY WinMain(HANDLE hInstance, - HANDLE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) + HANDLE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) { HWND hWnd; @@ -46,32 +57,32 @@ int APIENTRY WinMain(HANDLE hInstance, UNREFERENCED_PARAMETER(lpCmdLine); if (!hPrevInstance) - if (!DemoInit(hInstance)) - return (NULL); + if (!DemoInit(hInstance)) + return (0); hInst = hInstance; hWnd = CreateWindow("Demo", - "Demo Sample Application", - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - NULL, - NULL, - hInstance, - NULL); + "Demo Sample Application", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + NULL, + hInstance, + NULL); if (!hWnd) - return (NULL); + return (0); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); - while (GetMessage(&msg, NULL, NULL, NULL)) { - TranslateMessage(&msg); - DispatchMessage(&msg); + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); } return (msg.wParam); } @@ -103,7 +114,7 @@ BOOL DemoInit(HANDLE hInstance) pWndClass->lpszClassName = (LPSTR) "Demo"; pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH); pWndClass->hInstance = hInstance; - pWndClass->style = NULL; + pWndClass->style = 0; pWndClass->lpfnWndProc = (WNDPROC)DemoWndProc; bSuccess = RegisterClass(pWndClass); @@ -121,29 +132,29 @@ BOOL DemoInit(HANDLE hInstance) MESSAGES: - WM_SYSCOMMAND - system menu (About dialog box) - WM_CREATE - create window - WM_DESTROY - destroy window - WM_LBUTTONDOWN - left mouse button - WM_MOUSEMOVE - mouse movement - WM_LBUTTONUP - left button released - - WM_COMMAND messages: - IDM_BOX - use inverted box for selecting a region - IDM_BLOCK - use empty box for selecting a region - IDM_RETAIN - retain/delete selection on button release + WM_SYSCOMMAND - system menu (About dialog box) + WM_CREATE - create window + WM_DESTROY - destroy window + WM_LBUTTONDOWN - left mouse button + WM_MOUSEMOVE - mouse movement + WM_LBUTTONUP - left button released + + WM_COMMAND messages: + IDM_BOX - use inverted box for selecting a region + IDM_BLOCK - use empty box for selecting a region + IDM_RETAIN - retain/delete selection on button release COMMENTS: - When the left mouse button is pressed, btrack is set to TRUE so that - the code for WM_MOUSEMOVE will keep track of the mouse and update the - box accordingly. Once the button is released, btrack is set to - FALSE, and the current position is saved. Holding the SHIFT key - while pressing the left button will extend the current box rather - then erasing it and starting a new one. The exception is when the - retain shape option is enabled. With this option, the rectangle is - zeroed whenever the mouse is released so that it can not be erased or - extended. + When the left mouse button is pressed, btrack is set to TRUE so that + the code for WM_MOUSEMOVE will keep track of the mouse and update the + box accordingly. Once the button is released, btrack is set to + FALSE, and the current position is saved. Holding the SHIFT key + while pressing the left button will extend the current box rather + then erasing it and starting a new one. The exception is when the + retain shape option is enabled. With this option, the rectangle is + zeroed whenever the mouse is released so that it can not be erased or + extended. ****************************************************************************/ @@ -158,72 +169,72 @@ LONG APIENTRY DemoWndProc( switch (message) { - case WM_COMMAND: + case WM_COMMAND: + + // LOWORD added for portability + + switch (LOWORD(wParam)) { + case IDM_BOX: + Shape = SL_BOX; + hMenu = GetMenu(hWnd); + CheckMenuItem(hMenu, IDM_BOX, MF_CHECKED); + CheckMenuItem(hMenu, IDM_BLOCK, MF_UNCHECKED); + break; + + case IDM_BLOCK: + Shape = SL_BLOCK; + hMenu = GetMenu(hWnd); + CheckMenuItem(hMenu, IDM_BOX, MF_UNCHECKED); + CheckMenuItem(hMenu, IDM_BLOCK, MF_CHECKED); + break; + + case IDM_RETAIN: + if (RetainShape) { + hMenu = GetMenu(hWnd); + CheckMenuItem(hMenu, IDM_RETAIN, MF_UNCHECKED); + RetainShape = FALSE; + } + else { + hMenu = GetMenu(hWnd); + CheckMenuItem(hMenu, IDM_RETAIN, MF_CHECKED); + RetainShape = TRUE; + } + break; + + case IDM_ABOUT: + lpProcAbout = MakeProcInstance((FARPROC)About, hInst); + DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)lpProcAbout); + FreeProcInstance(lpProcAbout); + break; + + } + break; + + case WM_LBUTTONDOWN: + + bTrack = TRUE; /* user has pressed the left button */ + + /* If you don't want the shape cleared, you must clear the Rect + * coordinates before calling StartSelection + */ - // LOWORD added for portability + if (RetainShape) + SetRectEmpty(&Rect); - switch (LOWORD(wParam)) { - case IDM_BOX: - Shape = SL_BOX; - hMenu = GetMenu(hWnd); - CheckMenuItem(hMenu, IDM_BOX, MF_CHECKED); - CheckMenuItem(hMenu, IDM_BLOCK, MF_UNCHECKED); - break; - - case IDM_BLOCK: - Shape = SL_BLOCK; - hMenu = GetMenu(hWnd); - CheckMenuItem(hMenu, IDM_BOX, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_BLOCK, MF_CHECKED); - break; - - case IDM_RETAIN: - if (RetainShape) { - hMenu = GetMenu(hWnd); - CheckMenuItem(hMenu, IDM_RETAIN, MF_UNCHECKED); - RetainShape = FALSE; - } - else { - hMenu = GetMenu(hWnd); - CheckMenuItem(hMenu, IDM_RETAIN, MF_CHECKED); - RetainShape = TRUE; - } - break; - - case IDM_ABOUT: - lpProcAbout = MakeProcInstance((FARPROC)About, hInst); - DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)lpProcAbout); - FreeProcInstance(lpProcAbout); - break; - - } - break; - - case WM_LBUTTONDOWN: - - bTrack = TRUE; /* user has pressed the left button */ - - /* If you don't want the shape cleared, you must clear the Rect - * coordinates before calling StartSelection - */ - - if (RetainShape) - SetRectEmpty(&Rect); - - StartSelection(hWnd, MAKEMPOINT(lParam), &Rect, - (wParam & MK_SHIFT) ? SL_EXTEND | Shape : Shape); - break; - - case WM_MOUSEMOVE: - if (bTrack) - UpdateSelection(hWnd, MAKEMPOINT(lParam), &Rect, Shape); - break; + StartSelection(hWnd, MAKEMPOINT(lParam), &Rect, + (wParam & MK_SHIFT) ? SL_EXTEND | Shape : Shape); + break; + + case WM_MOUSEMOVE: + if (bTrack) + UpdateSelection(hWnd, MAKEMPOINT(lParam), &Rect, Shape); + break; - case WM_LBUTTONUP: + case WM_LBUTTONUP: if (bTrack) - EndSelection(MAKEMPOINT(lParam), &Rect); - bTrack = FALSE; - break; + EndSelection(MAKEMPOINT(lParam), &Rect); + bTrack = FALSE; + break; case WM_SIZE: switch (wParam) { @@ -237,14 +248,14 @@ LONG APIENTRY DemoWndProc( } break; - case WM_DESTROY: - PostQuitMessage(NULL); - break; + case WM_DESTROY: + PostQuitMessage(0); + break; - default: - return (DefWindowProc(hWnd, message, wParam, lParam)); + default: + return (DefWindowProc(hWnd, message, wParam, lParam)); } - return (NULL); + return (0); } /**************************************************************************** @@ -255,8 +266,8 @@ LONG APIENTRY DemoWndProc( MESSAGES: - WM_INITDIALOG - initialize dialog box - WM_COMMAND - Input received + WM_INITDIALOG - initialize dialog box + WM_COMMAND - Input received ****************************************************************************/ @@ -267,18 +278,18 @@ BOOL APIENTRY About( LONG lParam) { switch (message) { - case WM_INITDIALOG: - return (TRUE); + case WM_INITDIALOG: + return (TRUE); - case WM_COMMAND: - // LOWORD added for portability - if (LOWORD(wParam) == IDOK - || LOWORD(wParam) == IDCANCEL) { - EndDialog(hDlg, TRUE); - return (TRUE); - } - return (TRUE); + case WM_COMMAND: + // LOWORD added for portability + if (LOWORD(wParam) == IDOK + || LOWORD(wParam) == IDCANCEL) { + EndDialog(hDlg, TRUE); + return (TRUE); + } + return (TRUE); } return (FALSE); - UNREFERENCED_PARAMETER(lParam); + UNREFERENCED_PARAMETER(lParam); }