home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-01 | 3.5 MB | 90,571 lines |
Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
- %@1@%%@AH@%OS/2 v1.2 Sample Code%@EH@%%@AE@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ACCEL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\ACCEL\ACCEL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ACCEL.C -- Sample demonstrating calls included with INCL_WINACCELERATORS%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Overview:%@NL@%
- %@AB@% * Accelerators are used to reduce the number of keystrokes needed to%@NL@%
- %@AB@% * execute a command (hence "accelerating" a user's processing time)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Strategy:%@NL@%
- %@AB@% * This application allows the user to experiment with various settings,%@NL@%
- %@AB@% * by popping up a dialog box in which the user can specify an accelerator.%@NL@%
- %@AB@% * One possible modification to this program is to have the user hit the%@NL@%
- %@AB@% * desired key sequence, and to use KbdCharIn() to figure out what the key%@NL@%
- %@AB@% * sequence is, and then set the accelerator. Another is to implement the%@NL@%
- %@AB@% * "Delete" operation, by perhaps listing the accelerators in a list box.%@NL@%
- %@AB@% * This wasn't done primarily because that would require reorganization%@NL@%
- %@AB@% * (compression) of the accelerator table: it could not be easily done with%@NL@%
- %@AB@% * a WinDeleteAccel call (because such a call does not exist).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_WINACCELERATORS %@NL@%
- %@AI@%#define %@AE@% INCL_WINBUTTONS // Needed for checkboxes in dialogs %@NL@%
- %@AI@%#define %@AE@% INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@% INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINFRAMEMGR // for SC_MINIMIZE constant %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<malloc.h> // Needed for dynamic memory allocation %@NL@%
- %@AI@%#include %@AE@%<stdio.h> // Needed for sscanf() call %@NL@%
- %@AI@%#include %@AE@%"accel.h" // Needed for resource IDs %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Globals%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char ach[8]; // Temporary: used to store Key: field%@NL@%
- char szAppName[] = "ACCEL.EXE";%@NL@%
- char szClassName[] = "Accelerator";%@NL@%
- char szMessage[] = " - Accelerator Table Example";%@NL@%
- int cbSize; // Size of Accel. Table in bytes%@NL@%
- int iTemp; // Used to store Key: value, if number%@NL@%
- void *pTemp; // Used so free() won't give warnings%@NL@%
- HAB hab;%@NL@%
- HACCEL haccSystem; // Handle to system accelerator table%@NL@%
- HACCEL haccTable; // Handle to app-local acceltable%@NL@%
- HMQ hmqAccel;%@NL@%
- HWND hwndAccel; // Client window%@NL@%
- HWND hwndAccelFrame; // Frame window%@NL@%
- PACCELTABLE pacctTable; // Points to table with ACCEL entries%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%Message(s) WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, s, \ %@NL@%
- szAppName, 0, MB_OK | MB_ICONEXCLAMATION)%@NL@%
- %@AI@%#define %@AE@% Check(b) WinSendDlgItemMsg(hwndDlg, b, \ %@NL@%
- BM_SETCHECK, MPFROMSHORT(1), 0L)%@NL@%
- %@AI@%#define %@AE@%Checked(b) WinSendDlgItemMsg(hwndDlg, b, BM_QUERYCHECK, 0L, 0L) %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Internals%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL InitializeAccelTable(void);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Main routine...initializes window and message queue%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void cdecl main(void) {%@NL@%
- QMSG qmsg;%@NL@%
- ULONG ctldata;%@NL@%
- %@NL@%
- %@AB@%/* Initialize a PM application */%@AE@%%@NL@%
- hab = WinInitialize(0);%@NL@%
- hmqAccel = WinCreateMsgQueue(hab, 0);%@NL@%
- %@NL@%
- %@AB@%/* Register the main window's class */%@AE@%%@NL@%
- if (!WinRegisterClass(hab, szClassName, AccelWndProc, CS_SIZEREDRAW, 0))%@NL@%
- return;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Create the window%@NL@%
- %@AB@% We create it without an accelerator table, but we'll load one later%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ctldata = FCF_STANDARD & ~FCF_ACCELTABLE;%@NL@%
- hwndAccelFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &ctldata,%@NL@%
- szClassName, szMessage, WS_VISIBLE, (HMODULE) NULL, IDR_ACCEL, &hwndAccel);%@NL@%
- WinShowWindow(hwndAccelFrame, TRUE);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Load the accelerator tables%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!InitializeAccelTable()) {%@NL@%
- Message("Accelerator table not initialized!");%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Poll messages from event queue */%@AE@%%@NL@%
- while(WinGetMsg(hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0))%@NL@%
- WinDispatchMsg(hab, (PQMSG)&qmsg);%@NL@%
- %@NL@%
- %@AB@%/* Clean up */%@AE@%%@NL@%
- if (!WinDestroyAccelTable(haccTable))%@NL@%
- Message("Could not destroy ACCELTABLE");%@NL@%
- WinDestroyWindow(hwndAccelFrame);%@NL@%
- WinDestroyMsgQueue(hmqAccel);%@NL@%
- WinTerminate(hab);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AccelWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This routine processes WM_PAINT. It passes%@NL@%
- %@AB@% * everything else to the Default Window Procedure.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- HPS hPS;%@NL@%
- RECTL rcl;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- %@NL@%
- case WM_HELP:%@NL@%
- %@AB@%/* If WM_HELP, pop up Help dialog box */%@AE@%%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, (HMODULE) NULL, IDD_HELP, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (COMMANDMSG(&msg)->cmd) {%@NL@%
- %@NL@%
- %@AB@%/* On most WM_COMMAND messages, give the About... box */%@AE@%%@NL@%
- case IDM_ABOUT:%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc,%@NL@%
- (HMODULE) NULL, IDD_ABOUT, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* Create your own accelerator dialog */%@AE@%%@NL@%
- case IDM_CREATE:%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, CreateDlgProc,%@NL@%
- (HMODULE) NULL, IDD_CREATE, NULL);%@NL@%
- %@NL@%
- default: break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- %@AB@%/* Open the presentation space */%@AE@%%@NL@%
- hPS = WinBeginPaint(hwnd, NULL, &rcl);%@NL@%
- %@NL@%
- %@AB@%/* Fill the background with Dark Blue */%@AE@%%@NL@%
- WinFillRect(hPS, &rcl, CLR_DARKBLUE);%@NL@%
- %@NL@%
- %@AB@%/* Finish painting */%@AE@%%@NL@%
- WinEndPaint(hPS);%@NL@%
- break;%@NL@%
- %@NL@%
- default: return WinDefWindowProc(hwnd, msg, mp1, mp2); break;%@NL@%
- }%@NL@%
- return 0L;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AboutDlgProc(hwndDlg, msg, mp1, mp2)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HWND hwndDlg;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hwndDlg, TRUE);%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hwndDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK CreateDlgProc(hwndDlg, msg, mp1, mp2)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Create Accelerator dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HWND hwndDlg;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch(msg) {%@NL@%
- case WM_INITDLG:%@NL@%
- %@AB@%/* Set the defaults */%@AE@%%@NL@%
- Check(IDD_CHAR); Check(IDD_CMD);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK:%@NL@%
- %@AB@%/* Get the accelerator table (allocate an extra space) */%@AE@%%@NL@%
- cbSize = WinCopyAccelTable(haccTable, NULL, 0);%@NL@%
- pTemp = (void *) malloc(cbSize + sizeof(ACCEL));%@NL@%
- pacctTable = (PACCELTABLE) pTemp;%@NL@%
- cbSize = WinCopyAccelTable(haccTable, pacctTable, cbSize);%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%accNew pacctTable->aaccel[pacctTable->cAccel] %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Command:%@NL@%
- %@AB@% if SYSCOMMAND, make the window minimize.%@NL@%
- %@AB@% if HELP, we'll pop up a dialog box.%@NL@%
- %@AB@% otherwise, pop up the About... dialog box.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (Checked(IDD_SYSCMD)) accNew.cmd = SC_MINIMIZE;%@NL@%
- else accNew.cmd = IDM_ABOUT;%@NL@%
- %@NL@%
- %@AB@%/* Get the states from the dialog box */%@AE@%%@NL@%
- accNew.fs = 0;%@NL@%
- if (Checked(IDD_ALT)) accNew.fs |= AF_ALT;%@NL@%
- if (Checked(IDD_CHAR)) accNew.fs |= AF_CHAR;%@NL@%
- if (Checked(IDD_CONTROL)) accNew.fs |= AF_CONTROL;%@NL@%
- if (Checked(IDD_FHELP)) accNew.fs |= AF_HELP;%@NL@%
- if (Checked(IDD_LONEKEY)) accNew.fs |= AF_LONEKEY;%@NL@%
- if (Checked(IDD_SCANCODE)) accNew.fs |= AF_SCANCODE;%@NL@%
- if (Checked(IDD_SHIFT)) accNew.fs |= AF_SHIFT;%@NL@%
- if (Checked(IDD_SYSCMD)) accNew.fs |= AF_SYSCOMMAND;%@NL@%
- if (Checked(IDD_VKEY)) accNew.fs |= AF_VIRTUALKEY;%@NL@%
- %@NL@%
- %@AB@%/* Get the key to be defined */%@AE@%%@NL@%
- WinQueryDlgItemText(hwndDlg, IDD_ENTRY, 8, ach);%@NL@%
- if (('0' <= ach[0]) && (ach[0] <= '9')) {%@NL@%
- sscanf(ach, "%i", &iTemp);%@NL@%
- accNew.key = (USHORT) iTemp;%@NL@%
- }%@NL@%
- else accNew.key = (USHORT) ach[0];%@NL@%
- %@NL@%
- %@AB@%/* Increment the count of accelerator records */%@AE@%%@NL@%
- pacctTable->cAccel++;%@NL@%
- %@NL@%
- %@AB@%/* Cleanup, then create a new accelerator table */%@AE@%%@NL@%
- WinDestroyAccelTable(haccTable);%@NL@%
- haccTable = WinCreateAccelTable(hab, pacctTable);%@NL@%
- %@NL@%
- %@AB@%/* Set the new accelerator table, and clean up */%@AE@%%@NL@%
- WinSetAccelTable(hab, haccTable, hwndAccelFrame);%@NL@%
- free(pTemp);%@NL@%
- %@NL@%
- case DID_CANCEL:%@NL@%
- WinDismissDlg(hwndDlg, TRUE);%@NL@%
- %@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hwndDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- BOOL InitializeAccelTable(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the accelerator table by loading it from the%@NL@%
- %@AB@% resource file. Note that you can load an accelerator%@NL@%
- %@AB@% table from a DLL, if you change the NULL parameter.%@NL@%
- %@AB@% The system accelerator table is accessible after this%@NL@%
- %@AB@% call: one possible use for this would be a List...%@NL@%
- %@AB@% dialog box, which would list all system & app. accelerators.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- haccSystem = WinQueryAccelTable(hab, NULL);%@NL@%
- haccTable = WinLoadAccelTable(hab, 0, IDR_ACCEL);%@NL@%
- return WinSetAccelTable(hab, haccTable, hwndAccelFrame);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%APP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\MDI\APP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* app.c - MDI Sample application%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINCOMMON %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINRECTANGLES %@NL@%
- %@AI@%#define %@AE@%INCL_WINHEAP %@NL@%
- %@AI@%#define %@AE@%INCL_WINSCROLLBARS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIPRIMITIVES %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%"app.h" %@NL@%
- %@AI@%#include %@AE@%"appdata.h" %@NL@%
- %@AI@%#include %@AE@%"mdi.h" %@NL@%
- %@AI@%#include %@AE@%"mdidata.h" %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Function prototypes%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL AppInit(VOID);%@NL@%
- BOOL MDIInit(VOID);%@NL@%
- VOID AppTerminate(VOID);%@NL@%
- VOID MDITerminate(VOID);%@NL@%
- BOOL AppNewDocument(USHORT, PSZ);%@NL@%
- VOID TrackSplitbars(HWND, USHORT, SHORT, SHORT);%@NL@%
- VOID MDIDesktopSize(HWND, MPARAM, MPARAM);%@NL@%
- VOID MDIDesktopSetFocus(HWND, MPARAM); %@NL@%
- VOID MDIDesktopActivateDoc(SHORT idMenuitem);%@NL@%
- BOOL AppNewDocument(USHORT, PSZ);%@NL@%
- NPDOC MDINewDocument(USHORT fsStyle, PSZ pszClassName);%@NL@%
- VOID MDISetInitialDocPos(HWND hwndNewFrame);%@NL@%
- %@NL@%
- VOID AddToWindowMenu(NPDOC);%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- int cdecl main(void)%@NL@%
- {%@NL@%
- QMSG qmsg;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Initialize the application globals%@NL@%
- %@AB@% * and create the main window.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (AppInit() == FALSE) {%@NL@%
- WinAlarm(HWND_DESKTOP, WA_ERROR);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Initialize the MDI globals etc..%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (MDIInit() == FALSE) {%@NL@%
- WinAlarm(HWND_DESKTOP, WA_ERROR);%@NL@%
- WinAlarm(HWND_DESKTOP, WA_ERROR);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Create an initial, untitled document.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- AppNewDocument(DS_HORZSPLITBAR | DS_VERTSPLITBAR, szDocClass);%@NL@%
- %@NL@%
- while (WinGetMsg(NULL, (PQMSG)&qmsg, NULL, 0, 0)) {%@NL@%
- WinDispatchMsg(NULL, (PQMSG)&qmsg);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Do the clean-up of the MDI code.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MDITerminate();%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Do the clean-up of the Application.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- AppTerminate();%@NL@%
- %@NL@%
- DosExit(EXIT_PROCESS, 0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY MDIWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- RECTL rclPaint, rclWindow;%@NL@%
- POINTL ptlPatternRef;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- hps = WinBeginPaint(hwnd, (HPS)NULL, &rclPaint);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Set the pattern to be at the top-left%@NL@%
- %@AB@% * since we're top-left aligning the bits.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowRect(hwnd, (PRECTL)&rclWindow);%@NL@%
- ptlPatternRef.x = rclWindow.xLeft;%@NL@%
- ptlPatternRef.y = rclWindow.yTop;%@NL@%
- GpiSetPatternRefPoint(hps, &ptlPatternRef);%@NL@%
- %@NL@%
- WinFillRect(hps, &rclPaint, SYSCLR_APPWORKSPACE);%@NL@%
- %@NL@%
- WinEndPaint(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- %@AI@%#if %@AE@%0 %@NL@%
- case WM_SIZE:%@NL@%
- %@NL@%
- %@AB@%/* HACK -- only reposition the windows if it is not going to or coming%@NL@%
- %@AB@% from a minimized position, it would be better to what%@NL@%
- %@AB@% WM_WINDOWPOSCHANGED and pay attention to the fs fields of the SWP%@NL@%
- %@AB@% structure */%@AE@%%@NL@%
- %@NL@%
- if ( SHORT1FROMMP(mp1) && SHORT2FROMMP(mp1) &&%@NL@%
- SHORT1FROMMP(mp2) && SHORT2FROMMP(mp2) ) {%@NL@%
- MDIDesktopSize ( hwnd, mp1, mp2 );%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- %@AI@%#else %@AE@%%@NL@%
- case WM_SIZE:%@NL@%
- MDIDesktopSize ( hwnd, mp1, mp2 );%@NL@%
- break;%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- case WM_SETFOCUS:%@NL@%
- MDIDesktopSetFocus(hwnd, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (SHORT1FROMMP(mp1)) {%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Pass these accelerators onto the active document's%@NL@%
- %@AB@% * frame so it can process it.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * These are the CMD_ values from the document system%@NL@%
- %@AB@% * menu.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- case CMD_DOCRESTORE:%@NL@%
- WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_RESTORE, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_DOCNEXT:%@NL@%
- WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_NEXT, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_DOCMINIMIZE:%@NL@%
- WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_MINIMIZE, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_DOCCLOSE:%@NL@%
- WinSendMsg(hwndActiveDoc, WM_SYSCOMMAND, (MPARAM)SC_CLOSE, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_DOCSPLIT:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Call TrackSplitbars() with -1 for xMouse to tell%@NL@%
- %@AB@% * it to reposition the pointer to where the%@NL@%
- %@AB@% * splitbars currently are.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSetPointer(HWND_DESKTOP, hptrHVSplit);%@NL@%
- TrackSplitbars(WinWindowFromID(hwndActiveDoc, FID_CLIENT),%@NL@%
- SPS_VERT | SPS_HORZ, -1, -1);%@NL@%
- WinSetPointer(HWND_DESKTOP, hptrArrow);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_NEW:%@NL@%
- if (AppNewDocument(DS_HORZSPLITBAR | DS_VERTSPLITBAR, szDocClass) == FALSE)%@NL@%
- WinAlarm(HWND_DESKTOP, WA_ERROR);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_CLOSE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Close the active document.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hwndActiveDoc)%@NL@%
- WinSendMsg(hwndActiveDoc, WM_CLOSE, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_ABOUT:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Put up the About... dialog box%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, NULL, IDD_ABOUT, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_EXIT:%@NL@%
- WinPostMsg(hwnd, WM_QUIT, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_ARRANGETILED:%@NL@%
- ArrangeWindows(AWP_TILED);%@NL@%
- break;%@NL@%
- %@NL@%
- case CMD_ARRANGECASCADED:%@NL@%
- ArrangeWindows(AWP_CASCADED);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * The means a window title was selected from%@NL@%
- %@AB@% * the window menu. Have the MDI code activate%@NL@%
- %@AB@% * the correct window based on the menuitem ID.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * WARNING: Be sure to keep you applications%@NL@%
- %@AB@% * menuitem IDs < CMD_WINDOWITEMS.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MULTIPLEMENU */%@AE@%%@NL@%
- %@AB@%/* Also in here we need to pass document unique WM_COMMAND%@NL@%
- %@AB@% messages on down to the document's client procs */%@AE@%%@NL@%
- %@NL@%
- if (SHORT1FROMMP(mp1) >= CMD_WINDOWITEMS)%@NL@%
- MDIDesktopActivateDoc(SHORT1FROMMP(mp1));%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return (0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- BOOL AppNewDocument(USHORT fsStyle, PSZ pszClassName)%@NL@%
- {%@NL@%
- register NPDOC npdocNew;%@NL@%
- HWND hwndFrame, hwndClient;%@NL@%
- HWND hwndHScroll, hwndVScroll;%@NL@%
- %@NL@%
- npdocNew = MDINewDocument(fsStyle, pszClassName);%@NL@%
- %@NL@%
- npdocNew->clrBackground = clrNext++;%@NL@%
- if (clrNext > CLR_PALEGRAY)%@NL@%
- clrNext = CLR_BACKGROUND;%@NL@%
- %@NL@%
- hwndFrame = npdocNew->hwndFrame;%@NL@%
- hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Setup the scrollbars.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndHScroll = WinWindowFromID(hwndFrame, FID_HORZSCROLL);%@NL@%
- WinSendMsg(hwndHScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),%@NL@%
- MPFROM2SHORT(0, 600));%@NL@%
- hwndHScroll = WinWindowFromID(hwndFrame, ID_HORZSCROLL2);%@NL@%
- WinSendMsg(hwndHScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),%@NL@%
- MPFROM2SHORT(0, 600));%@NL@%
- %@NL@%
- hwndVScroll = WinWindowFromID(hwndFrame, FID_VERTSCROLL);%@NL@%
- WinSendMsg(hwndVScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),%@NL@%
- MPFROM2SHORT(0, 600));%@NL@%
- hwndVScroll = WinWindowFromID(hwndFrame, ID_VERTSCROLL2);%@NL@%
- WinSendMsg(hwndVScroll, SBM_SETSCROLLBAR, MPFROMSHORT(0),%@NL@%
- MPFROM2SHORT(0, 600));%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Set the focus the client so the new window will be%@NL@%
- %@AB@% * active when we show it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSetFocus(HWND_DESKTOP, hwndClient);%@NL@%
- %@NL@%
- AddToWindowMenu(npdocNew); %@AB@%/* Moved here from end of%@NL@%
- %@AB@% MdiNewDocument routine so that the doc has%@NL@%
- %@AB@% been activated, and therefore the main%@NL@%
- %@AB@% window has a menu before attempting to add%@NL@%
- %@AB@% the doc to the main window's menu */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Set the initial position of the frame window and make it visible.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MDISetInitialDocPos(hwndFrame);%@NL@%
- %@NL@%
- return (TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT EXPENTRY AboutDlgProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- {%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hDlg, TRUE); break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%APPDATA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\MDI\APPDATA.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINCOMMON %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINACCELERATORS %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINHEAP %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%"app.h" %@NL@%
- %@AI@%#include %@AE@%"mdi.h" %@NL@%
- %@NL@%
- char szMDIClass[] = "PM MDI Sample App";%@NL@%
- char szDocClass[] = "PM MDI Document";%@NL@%
- USHORT cxBorder, cyBorder, cyHScroll, cxVScroll, cyVScrollArrow;%@NL@%
- USHORT cxScreen, cyScreen, cyIcon, cxByteAlign, cyByteAlign;%@NL@%
- USHORT cxSizeBorder, cySizeBorder;%@NL@%
- ULONG clrNext = CLR_BACKGROUND;%@NL@%
- LONG rglDevCaps[(CAPS_VERTICAL_FONT_RES - CAPS_FAMILY)];%@NL@%
- %@NL@%
- %@AB@%/* Main globals */%@AE@%%@NL@%
- HAB hab;%@NL@%
- HHEAP hHeap;%@NL@%
- HMQ hmqMDI;%@NL@%
- HWND hwndMDI, hwndMDIFrame;%@NL@%
- HWND hwndActiveDoc;%@NL@%
- FONTMETRICS fmSystemFont;%@NL@%
- NPDOC npdocFirst = NULL;%@NL@%
- %@NL@%
- %@AB@%/* Menu globals */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- HWND hwndSysMenu;%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%APPDOC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\MDI\APPDOC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% appdoc.c - MDI application%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINCOMMON %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINACCELERATORS %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@%INCL_WINHEAP %@NL@%
- %@AI@%#define %@AE@%INCL_WINSCROLLBARS %@NL@%
- %@AI@%#define %@AE@%INCL_WINRECTANGLES %@NL@%
- %@AI@%#define %@AE@%INCL_WINCOUNTRY %@NL@%
- %@AI@%#define %@AE@%INCL_GPIPRIMITIVES %@NL@%
- %@AI@%#define %@AE@%INCL_GPILOGCOLORTABLE %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%"app.h" %@NL@%
- %@AI@%#include %@AE@%"appdata.h" %@NL@%
- %@AI@%#include %@AE@%"mdi.h" %@NL@%
- %@AI@%#include %@AE@%"mdidata.h" %@NL@%
- %@NL@%
- %@AB@%/* Function prototypes */%@AE@%%@NL@%
- VOID AppHScroll(HWND hwnd, MPARAM mp1, MPARAM mp2);%@NL@%
- VOID AppVScroll(HWND hwnd, MPARAM mp1, MPARAM mp2);%@NL@%
- VOID AppEraseBackground(HWND hwnd, HPS hps);%@NL@%
- VOID AppPaint(HWND hwnd);%@NL@%
- VOID MDIClose(HWND hwndClient);%@NL@%
- BOOL MDICreate(HWND);%@NL@%
- BOOL MDIDestroy(HWND);%@NL@%
- BOOL MDIActivate(HWND, BOOL);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * The array of RGB values for the rounded%@NL@%
- %@AB@% * rectangles.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- LONG aclrRGB[16] = {%@NL@%
- RGB_RED, RGB_WHITE, RGB_GREEN, RGB_BLACK,%@NL@%
- RGB_BLUE, RGB_WHITE, RGB_YELLOW, RGB_BLACK,%@NL@%
- RGB_CYAN, RGB_BLACK, RGB_PINK, RGB_BLACK,%@NL@%
- RGB_WHITE, RGB_PINK, RGB_BLACK, RGB_RED%@NL@%
- };%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY DocWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CREATE:%@NL@%
- if (MDICreate(hwnd) == FALSE)%@NL@%
- return ( (MRESULT) TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- MDIDestroy(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CLOSE:%@NL@%
- MDIClose(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_HSCROLL:%@NL@%
- AppHScroll(hwnd, mp1, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_VSCROLL:%@NL@%
- AppVScroll(hwnd, mp1, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ERASEBACKGROUND:%@NL@%
- AppEraseBackground(hwnd, (HPS)mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- AppPaint(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ACTIVATE:%@NL@%
- MDIActivate(hwnd, (BOOL)SHORT1FROMMP(mp1));%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return (0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- VOID AppEraseBackground(HWND hwnd, HPS hps)%@NL@%
- {%@NL@%
- RECTL rclPaint;%@NL@%
- HWND hwndFrame, hwndClient;%@NL@%
- register NPDOC npdoc;%@NL@%
- %@NL@%
- npdoc = NPDOCFROMCLIENT(hwnd);%@NL@%
- hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We know the main client is around so%@NL@%
- %@AB@% * go ahead and erase it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowRect(hwnd, &rclPaint);%@NL@%
- WinMapWindowPoints(hwnd, hwndFrame, (PPOINTL)&rclPaint, 2);%@NL@%
- WinFillRect(hps, &rclPaint, npdoc->clrBackground);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Now check to see which of the other client windows%@NL@%
- %@AB@% * are around and erase them.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * We do all this to avoid erasing the splitbars.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (npdoc->fs & DF_SPLITVERT) {%@NL@%
- %@NL@%
- hwndClient = WinWindowFromID(hwndFrame, ID_CLIENT2);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If it became invisible due to the frame%@NL@%
- %@AB@% * window getting too small, then don't%@NL@%
- %@AB@% * bother drawing.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (WinIsWindowVisible(hwndClient) != FALSE) {%@NL@%
- WinQueryWindowRect(hwndClient, &rclPaint);%@NL@%
- WinMapWindowPoints(hwndClient, hwndFrame,%@NL@%
- (PPOINTL)&rclPaint, 2);%@NL@%
- WinFillRect(hps, &rclPaint, npdoc->clrBackground);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if (npdoc->fs & DF_SPLITHORZ) {%@NL@%
- %@NL@%
- hwndClient = WinWindowFromID(hwndFrame, ID_CLIENT3);%@NL@%
- if (WinIsWindowVisible(hwndClient) != FALSE) {%@NL@%
- WinQueryWindowRect(hwndClient, &rclPaint);%@NL@%
- WinMapWindowPoints(hwndClient, hwndFrame,%@NL@%
- (PPOINTL)&rclPaint, 2);%@NL@%
- WinFillRect(hps, &rclPaint, npdoc->clrBackground);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If we're split in both directions, then there's%@NL@%
- %@AB@% * a ID_CLIENT4 window.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((npdoc->fs & (DF_SPLITHORZ | DF_SPLITVERT)) ==%@NL@%
- (DF_SPLITHORZ | DF_SPLITVERT)) {%@NL@%
- %@NL@%
- hwndClient = WinWindowFromID(hwndFrame, ID_CLIENT4);%@NL@%
- if (WinIsWindowVisible(hwndClient) != FALSE) {%@NL@%
- WinQueryWindowRect(hwndClient, &rclPaint);%@NL@%
- WinMapWindowPoints(hwndClient, hwndFrame,%@NL@%
- (PPOINTL)&rclPaint, 2);%@NL@%
- WinFillRect(hps, &rclPaint, npdoc->clrBackground);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- VOID AppHScroll(HWND hwnd, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HWND hwndFrame;%@NL@%
- NPDOC npdoc;%@NL@%
- RECTL rclPaintBottom, rclPaintTop;%@NL@%
- RECTL rclWindowBottom, rclWindowTop;%@NL@%
- HWND hwndClientBottom, hwndClientTop;%@NL@%
- HWND hwndScrollbar;%@NL@%
- register NPVIEW npviewBottom, npviewTop;%@NL@%
- SHORT posSlider, xOriginOld;%@NL@%
- USHORT cmd, idScrollbar;%@NL@%
- %@NL@%
- hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);%@NL@%
- npdoc = NPDOCFROMCLIENT(hwnd);%@NL@%
- %@NL@%
- idScrollbar = SHORT1FROMMP(mp1);%@NL@%
- %@NL@%
- switch (idScrollbar) {%@NL@%
- %@NL@%
- case FID_HORZSCROLL:%@NL@%
- hwndClientTop = hwnd;%@NL@%
- if (npdoc->fs & DF_SPLITHORZ) {%@NL@%
- hwndClientBottom = WinWindowFromID(hwndFrame, ID_CLIENT3);%@NL@%
- } else {%@NL@%
- hwndClientBottom = NULL;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case ID_HORZSCROLL2:%@NL@%
- hwndClientTop = WinWindowFromID(hwndFrame, ID_CLIENT2);%@NL@%
- if (npdoc->fs & DF_SPLITHORZ) {%@NL@%
- hwndClientBottom = WinWindowFromID(hwndFrame, ID_CLIENT4);%@NL@%
- } else {%@NL@%
- hwndClientBottom = NULL;%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- hwndScrollbar = WinWindowFromID(hwndFrame, idScrollbar);%@NL@%
- %@NL@%
- npviewTop = NPVIEWFROMCLIENT(hwndClientTop);%@NL@%
- WinQueryWindowRect(hwndClientTop, &rclWindowTop);%@NL@%
- %@NL@%
- if (hwndClientBottom != NULL) {%@NL@%
- npviewBottom = NPVIEWFROMCLIENT(hwndClientBottom);%@NL@%
- WinQueryWindowRect(hwndClientBottom, &rclWindowBottom);%@NL@%
- }%@NL@%
- %@NL@%
- posSlider = (SHORT) (ULONG) WinSendMsg(hwndScrollbar, SBM_QUERYPOS, NULL, NULL);%@NL@%
- %@NL@%
- cmd = SHORT2FROMMP(mp2);%@NL@%
- switch (cmd) {%@NL@%
- %@NL@%
- case SB_LINELEFT:%@NL@%
- posSlider -= 16;%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_LINERIGHT:%@NL@%
- posSlider += 16;%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_PAGELEFT:%@NL@%
- posSlider -= ((SHORT)rclWindowTop.xRight - 16);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_PAGERIGHT:%@NL@%
- posSlider += ((SHORT)rclWindowTop.xRight - 16);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_SLIDERPOSITION:%@NL@%
- posSlider = SHORT1FROMMP(mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- WinSendMsg(hwndScrollbar, SBM_SETPOS, MPFROMSHORT(posSlider), NULL);%@NL@%
- %@NL@%
- xOriginOld = npviewTop->xOrigin;%@NL@%
- npviewTop->xOrigin = (SHORT) (ULONG) WinSendMsg(hwndScrollbar, SBM_QUERYPOS, NULL, NULL);%@NL@%
- WinScrollWindow(hwndClientTop, xOriginOld - npviewTop->xOrigin, 0,%@NL@%
- NULL, NULL, NULL, &rclPaintTop, NULL);%@NL@%
- %@NL@%
- if (hwndClientBottom != NULL) {%@NL@%
- xOriginOld = npviewBottom->xOrigin;%@NL@%
- npviewBottom->xOrigin = npviewTop->xOrigin;%@NL@%
- WinScrollWindow(hwndClientBottom, xOriginOld - npviewBottom->xOrigin,%@NL@%
- 0, NULL, NULL, NULL, &rclPaintBottom, NULL);%@NL@%
- }%@NL@%
- %@NL@%
- WinMapWindowPoints(hwndClientTop, hwndFrame, (PPOINTL)&rclPaintTop, 2);%@NL@%
- WinInvalidateRect(hwndFrame, &rclPaintTop, TRUE);%@NL@%
- %@NL@%
- if (hwndClientBottom != NULL) {%@NL@%
- WinMapWindowPoints(hwndClientBottom, hwndFrame, (PPOINTL)&rclPaintBottom, 2);%@NL@%
- WinInvalidateRect(hwndFrame, &rclPaintBottom, TRUE);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- VOID AppVScroll(HWND hwnd, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HWND hwndFrame;%@NL@%
- NPDOC npdoc;%@NL@%
- RECTL rclPaintRight, rclPaintLeft;%@NL@%
- RECTL rclWindowRight, rclWindowLeft;%@NL@%
- HWND hwndClientRight, hwndClientLeft;%@NL@%
- HWND hwndScrollbar;%@NL@%
- register NPVIEW npviewRight, npviewLeft;%@NL@%
- SHORT posSlider, yOriginOld;%@NL@%
- USHORT cmd, idScrollbar;%@NL@%
- %@NL@%
- hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);%@NL@%
- npdoc = NPDOCFROMCLIENT(hwnd);%@NL@%
- %@NL@%
- idScrollbar = SHORT1FROMMP(mp1);%@NL@%
- %@NL@%
- switch (idScrollbar) {%@NL@%
- %@NL@%
- case FID_VERTSCROLL:%@NL@%
- hwndClientLeft = hwnd;%@NL@%
- if (npdoc->fs & DF_SPLITVERT) {%@NL@%
- hwndClientRight = WinWindowFromID(hwndFrame, ID_CLIENT2);%@NL@%
- } else {%@NL@%
- hwndClientRight = NULL;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case ID_VERTSCROLL2:%@NL@%
- hwndClientLeft = WinWindowFromID(hwndFrame, ID_CLIENT3);%@NL@%
- if (npdoc->fs & DF_SPLITVERT) {%@NL@%
- hwndClientRight = WinWindowFromID(hwndFrame, ID_CLIENT4);%@NL@%
- } else {%@NL@%
- hwndClientRight = NULL;%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- hwndScrollbar = WinWindowFromID(hwndFrame, idScrollbar);%@NL@%
- %@NL@%
- npviewLeft = NPVIEWFROMCLIENT(hwndClientLeft);%@NL@%
- WinQueryWindowRect(hwndClientLeft, &rclWindowLeft);%@NL@%
- %@NL@%
- if (hwndClientRight != NULL) {%@NL@%
- npviewRight = NPVIEWFROMCLIENT(hwndClientRight);%@NL@%
- WinQueryWindowRect(hwndClientRight, &rclWindowRight);%@NL@%
- }%@NL@%
- %@NL@%
- posSlider = (SHORT) (ULONG) WinSendMsg(hwndScrollbar, SBM_QUERYPOS, NULL, NULL);%@NL@%
- %@NL@%
- cmd = SHORT2FROMMP(mp2);%@NL@%
- switch (cmd) {%@NL@%
- %@NL@%
- case SB_LINEUP:%@NL@%
- posSlider -= 16;%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_LINEDOWN:%@NL@%
- posSlider += 16;%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_PAGEUP:%@NL@%
- posSlider -= ((SHORT)rclWindowLeft.yTop - 16);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_PAGEDOWN:%@NL@%
- posSlider += ((SHORT)rclWindowLeft.yTop - 16);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_SLIDERPOSITION:%@NL@%
- posSlider = SHORT1FROMMP(mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- WinSendMsg(hwndScrollbar, SBM_SETPOS, MPFROMSHORT(posSlider), NULL);%@NL@%
- %@NL@%
- yOriginOld = npviewLeft->yOrigin;%@NL@%
- npviewLeft->yOrigin = (SHORT) (ULONG) WinSendMsg(hwndScrollbar, SBM_QUERYPOS, NULL, NULL);%@NL@%
- WinScrollWindow(hwndClientLeft, 0, npviewLeft->yOrigin - yOriginOld,%@NL@%
- NULL, NULL, NULL, &rclPaintLeft, NULL);%@NL@%
- %@NL@%
- if (hwndClientRight != NULL) {%@NL@%
- yOriginOld = npviewRight->yOrigin;%@NL@%
- npviewRight->yOrigin = npviewLeft->yOrigin;%@NL@%
- WinScrollWindow(hwndClientRight, 0, npviewRight->yOrigin - yOriginOld,%@NL@%
- NULL, NULL, NULL, &rclPaintRight, NULL);%@NL@%
- }%@NL@%
- %@NL@%
- WinMapWindowPoints(hwndClientLeft, hwndFrame, (PPOINTL)&rclPaintLeft, 2);%@NL@%
- WinInvalidateRect(hwndFrame, &rclPaintLeft, TRUE);%@NL@%
- %@NL@%
- if (hwndClientRight != NULL) {%@NL@%
- WinMapWindowPoints(hwndClientRight, hwndFrame, (PPOINTL)&rclPaintRight, 2);%@NL@%
- WinInvalidateRect(hwndFrame, &rclPaintRight, TRUE);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- VOID AppPaint(HWND hwnd)%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- RECTL rclPaint, rclWindow, rclTest, rclDst;%@NL@%
- POINTL ptl, ptlPatternRef;%@NL@%
- register NPVIEW npview;%@NL@%
- AREABUNDLE abnd;%@NL@%
- LONG clrStart, clrEnd, clrInc, clr;%@NL@%
- SHORT i, j;%@NL@%
- %@NL@%
- hps = WinBeginPaint(hwnd, (HPS)NULL, &rclPaint);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Go into RGB mode.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GpiCreateLogColorTable(hps, 0L, LCOLF_RGB, 0L, 0L, NULL);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Make rclPaint an inclusive-inclusive rectangle%@NL@%
- %@AB@% * since that's how GpiBox() will be output.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- rclPaint.xLeft--;%@NL@%
- rclPaint.yBottom--;%@NL@%
- %@NL@%
- npview = NPVIEWFROMCLIENT(hwnd);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Set the pattern to be at the top-left%@NL@%
- %@AB@% * since we're top-left aligning the bits.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowRect(hwnd, (PRECTL)&rclWindow);%@NL@%
- ptlPatternRef.x = rclWindow.xLeft - npview->xOrigin;%@NL@%
- ptlPatternRef.y = rclWindow.yTop + npview->yOrigin;%@NL@%
- GpiSetPatternRefPoint(hps, &ptlPatternRef);%@NL@%
- %@NL@%
- for (i = 0; i < 8; i++) {%@NL@%
- %@NL@%
- clr = clrStart = aclrRGB[i * 2];%@NL@%
- clrEnd = aclrRGB[(i * 2) + 1];%@NL@%
- clrInc = (clrEnd - clrStart) / 8;%@NL@%
- %@NL@%
- for (j = 0; j < 8; j++) {%@NL@%
- abnd.lColor = clr + (j * clrInc);%@NL@%
- GpiSetAttrs(hps, PRIM_AREA, ABB_COLOR, 0L, (PBUNDLE)&abnd);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Only draw the box if it's going to%@NL@%
- %@AB@% * be visible in the update region.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSetRect(NULL, &rclTest, 10 + (i * 75),%@NL@%
- (SHORT)rclWindow.yTop - 75 - (j * 75), 75 + (i * 75),%@NL@%
- (SHORT)rclWindow.yTop - 10 - (j * 75));%@NL@%
- %@NL@%
- WinOffsetRect(NULL, &rclTest, -npview->xOrigin, npview->yOrigin);%@NL@%
- %@NL@%
- if (WinIntersectRect(NULL, &rclDst, &rclTest, &rclPaint)) {%@NL@%
- %@NL@%
- ptl.x = rclTest.xLeft;%@NL@%
- ptl.y = rclTest.yTop;%@NL@%
- GpiSetCurrentPosition(hps, (PPOINTL)&ptl);%@NL@%
- %@NL@%
- ptl.x = rclTest.xRight;%@NL@%
- ptl.y = rclTest.yBottom;%@NL@%
- GpiBox(hps, DRO_OUTLINEFILL, (PPOINTL)&ptl, 40L, 40L);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- WinEndPaint(hps);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%APPINIT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\MDI\APPINIT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% mdiinit.c - MDI initialization funtions.%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINCOMMON %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINRECTANGLES %@NL@%
- %@AI@%#define %@AE@%INCL_WINHEAP %@NL@%
- %@AI@%#define %@AE@%INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@%INCL_GPILCIDS %@NL@%
- %@AI@%#define %@AE@%INCL_DEV %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%"app.h" %@NL@%
- %@AI@%#include %@AE@%"appdata.h" %@NL@%
- %@AI@%#include %@AE@%"mdi.h" %@NL@%
- %@AI@%#include %@AE@%"mdidata.h" %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Function prototypes */%@AE@%%@NL@%
- BOOL RegisterWindowClasses(VOID);%@NL@%
- VOID InitSysValues(VOID);%@NL@%
- %@NL@%
- %@NL@%
- BOOL AppInit(VOID)%@NL@%
- {%@NL@%
- ULONG ctlData;%@NL@%
- HPS hps;%@NL@%
- HDC hdc;%@NL@%
- %@NL@%
- hab = WinInitialize(0);%@NL@%
- %@NL@%
- hmqMDI = WinCreateMsgQueue(hab, 0);%@NL@%
- %@NL@%
- if (!RegisterWindowClasses())%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- ctlData = FCF_TITLEBAR | FCF_MINMAX | FCF_SIZEBORDER | FCF_SYSMENU |%@NL@%
- FCF_MENU | FCF_TASKLIST | FCF_SHELLPOSITION | FCF_ICON;%@NL@%
- %@NL@%
- hwndMDIFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,%@NL@%
- (VOID FAR *)&ctlData, szMDIClass, (PSZ)NULL,%@NL@%
- WS_VISIBLE | WS_CLIPCHILDREN, NULL, IDR_MDI,%@NL@%
- (HWND FAR *)&hwndMDI);%@NL@%
- %@NL@%
- %@NL@%
- if (hwndMDIFrame == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- %@AB@%/* MULTIPLEMENU */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Remember the first menu so we can put it back when all the documents are%@NL@%
- %@AB@% closed */%@AE@%%@NL@%
- hwndFirstMenu=WinWindowFromID(hwndMDIFrame, FID_MENU);%@NL@%
- %@NL@%
- hHeap = WinCreateHeap(0, 0, 0, 0, 0, 0);%@NL@%
- %@NL@%
- if (hHeap == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- hps = WinGetPS(hwndMDI);%@NL@%
- %@NL@%
- hdc = GpiQueryDevice(hps);%@NL@%
- DevQueryCaps(hdc, CAPS_FAMILY, CAPS_VERTICAL_FONT_RES, (PLONG)rglDevCaps);%@NL@%
- %@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- InitSysValues();%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- VOID InitSysValues(VOID)%@NL@%
- {%@NL@%
- cyTitlebar = (SHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);%@NL@%
- cyIcon = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYICON);%@NL@%
- %@NL@%
- cxBorder = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);%@NL@%
- cyBorder = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);%@NL@%
- %@NL@%
- cxSizeBorder = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);%@NL@%
- cySizeBorder = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);%@NL@%
- %@NL@%
- cxByteAlign = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXBYTEALIGN);%@NL@%
- cyByteAlign = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYBYTEALIGN);%@NL@%
- %@NL@%
- cxVScroll = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL);%@NL@%
- cyVScrollArrow = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYVSCROLLARROW);%@NL@%
- cyHScroll = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);%@NL@%
- %@NL@%
- cxScreen = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);%@NL@%
- cyScreen = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);%@NL@%
- %@NL@%
- cxMinmaxButton = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- BOOL RegisterWindowClasses(VOID)%@NL@%
- {%@NL@%
- if (!WinRegisterClass(NULL, szMDIClass, (PFNWP)MDIWndProc,%@NL@%
- CS_SYNCPAINT, 0))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- if (!WinRegisterClass(NULL, szDocClass, (PFNWP)DocWndProc,%@NL@%
- 0L, sizeof(NPVIEW)))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- VOID AppTerminate(VOID)%@NL@%
- {%@NL@%
- WinDestroyWindow(hwndMDIFrame);%@NL@%
- %@NL@%
- WinDestroyHeap(hHeap);%@NL@%
- %@NL@%
- WinDestroyMsgQueue(hmqMDI);%@NL@%
- %@NL@%
- WinTerminate(hab);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARRANGE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\MDI\ARRANGE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* ARRANGE.c - This file contains code to do window arrangment.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINCOMMON %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINRECTANGLES %@NL@%
- %@AI@%#define %@AE@%INCL_WINHEAP %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%"app.h" %@NL@%
- %@AI@%#include %@AE@%"appdata.h" %@NL@%
- %@AI@%#include %@AE@%"mdi.h" %@NL@%
- %@AI@%#include %@AE@%"mdidata.h" %@NL@%
- %@NL@%
- %@NL@%
- MINMAXFIX %@AB@%/* add hack to keep the min/max icons in sync with reality */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* internal function prototypes */%@AE@%%@NL@%
- BOOL SetTilePositions(PRECTL prc, SHORT cWnd, PSWP aswp);%@NL@%
- SHORT CeilSquareRoot(USHORT us);%@NL@%
- BOOL SetCascadePositions(PRECTL prc, SHORT cWnd, PSWP aswp);%@NL@%
- BOOL SetCascadeParams(PRECTL prc, SHORT *pxEdge, SHORT *pyEdge,%@NL@%
- SHORT *pxDelta, SHORT *pyDelta, SHORT *cMaxWnd);%@NL@%
- BOOL GetArrangeSwp(USHORT *, SWP *, USHORT *, SWP *);%@NL@%
- BOOL GetArrangeRectangle(PRECTL, BOOL);%@NL@%
- BOOL ArrangeIconPositions(USHORT, PSWP);%@NL@%
- %@NL@%
- %@AB@%/* internal constants */%@AE@%%@NL@%
- %@AI@%#define %@AE@%CASC_EDGE_NUM 2 %@NL@%
- %@AI@%#define %@AE@%CASC_EDGE_DENOM 3 %@NL@%
- %@NL@%
- %@AB@%/* local constants */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ICON_PARK_NUM 5 %@NL@%
- %@AI@%#define %@AE@%ICON_PARK_DENOM 3 %@NL@%
- %@AI@%#define %@AE@%CLASS_NAME_LENGTH 8 %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* ArrangeWindowPositions%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function sets positions for arranging windows nicely in a rectangle.%@NL@%
- %@AB@%* The hwnd field of each SWP structure should be set by the user, either%@NL@%
- %@AB@%* before or after calling this function. The function sets all other%@NL@%
- %@AB@%* fields. The SWP array can then be passed to WinSetMultWindowPos() to do%@NL@%
- %@AB@%* the physical arrangement. There are two arrangement styles available,%@NL@%
- %@AB@%* AWP_TILED and AWP_CASCADED.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* AWP_TILED:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The tiles are generated by rows, top left (first) to bottom right (last).%@NL@%
- %@AB@%* Each row has the same number of tiles. The number of tiles in each%@NL@%
- %@AB@%* column will differ by at most one, with each column containing one fewer%@NL@%
- %@AB@%* tile to the left of the other columns.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* AWP_CASCADED:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The windows are generated bottom right (first) to top left (last).%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameters:%@NL@%
- %@AB@%* prc: rectangle to contain the tiled windows%@NL@%
- %@AB@%* cWnd: number of windows to tile%@NL@%
- %@AB@%* aswp: array of SWP structures, one for each tile window%@NL@%
- %@AB@%* fStyle: the style to arrange the windows%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL ArrangeWindowPositions(PRECTL prc, SHORT cWnd, PSWP aswp, USHORT fStyle)%@NL@%
- {%@NL@%
- %@AB@%/* check validity of input rectangle */%@AE@%%@NL@%
- if ((prc->xRight - prc->xLeft < 1) || (prc->yTop - prc->yBottom < 1)) {%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* set window positions */%@AE@%%@NL@%
- switch (fStyle) {%@NL@%
- case AWP_TILED:%@NL@%
- return SetTilePositions(prc, cWnd, aswp);%@NL@%
- case AWP_CASCADED:%@NL@%
- return SetCascadePositions(prc, cWnd, aswp);%@NL@%
- default:%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* SetTilePositions%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function sets positions for tiling windows in a rectangle.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* NOTE:%@NL@%
- %@AB@%* There are a few subtleties to this code:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The algorithm lays tiles in a modified NxN grid. It can be shown%@NL@%
- %@AB@%* that any positive number of tiles can be laid out in such a grid of%@NL@%
- %@AB@%* N columns so that each column has at least N-2 tiles and no column%@NL@%
- %@AB@%* has more than one tile more than any other. Proof left to the%@NL@%
- %@AB@%* interested reader.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The tiles coordinates are not generated by stepping over a fixed%@NL@%
- %@AB@%* interval since this will not usually fill the rectangle completely.%@NL@%
- %@AB@%* Thus the offset at each step is calculated from the previous tile%@NL@%
- %@AB@%* to the correct fractional position within the whole rectangle.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Since the last "row" of tiles may not have any members in the beginning%@NL@%
- %@AB@%* columns, these tiles are addressed differently in the SWP array to%@NL@%
- %@AB@%* account for the "missing" tiles.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameters:%@NL@%
- %@AB@%* prc: rectangle to contain the tiled windows%@NL@%
- %@AB@%* cWnd: number of windows to tile the rectangle with%@NL@%
- %@AB@%* aswp: array of SWP structures, one for each tile window%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL SetTilePositions(PRECTL prc, SHORT cWnd, PSWP aswp)%@NL@%
- {%@NL@%
- register SHORT usRoot;%@NL@%
- register SHORT cExtras;%@NL@%
- SHORT iChange;%@NL@%
- SHORT cDiff;%@NL@%
- SHORT x, y, cx, cy;%@NL@%
- SHORT iRow, iCol;%@NL@%
- %@NL@%
- %@AB@%/* get grid dimensions */%@AE@%%@NL@%
- usRoot = CeilSquareRoot(cWnd);%@NL@%
- cExtras = usRoot * usRoot - cWnd;%@NL@%
- %@NL@%
- %@AB@%/* find column where number of rows increases and find initial%@NL@%
- %@AB@% difference of rows versus columns */%@AE@%%@NL@%
- if (cExtras >= usRoot) {%@NL@%
- iChange = cExtras - usRoot;%@NL@%
- cDiff = 2;%@NL@%
- } else {%@NL@%
- iChange = cExtras;%@NL@%
- cDiff = 1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* assign x coordinates */%@AE@%%@NL@%
- x = (SHORT)prc->xLeft;%@NL@%
- cx = 0;%@NL@%
- for (iCol = 0; iCol < usRoot; iCol++) {%@NL@%
- x += cx - cxBorder;%@NL@%
- cx = ((SHORT)prc->xLeft) +%@NL@%
- (((SHORT)(prc->xRight - prc->xLeft)) * (iCol + 1)) / usRoot -%@NL@%
- x + cxBorder;%@NL@%
- for (iRow = 0; iRow < usRoot - cDiff; iRow++) {%@NL@%
- aswp[iRow * usRoot + iCol].x = x;%@NL@%
- aswp[iRow * usRoot + iCol].cx = cx;%@NL@%
- aswp[iRow * usRoot + iCol].fs = SWP_SIZE | SWP_MOVE;%@NL@%
- }%@NL@%
- %@AB@%/* assign "extra" row */%@AE@%%@NL@%
- if (iCol >= iChange) {%@NL@%
- aswp[iRow * usRoot + iCol - iChange].x = x;%@NL@%
- aswp[iRow * usRoot + iCol - iChange].cx = cx;%@NL@%
- aswp[iRow * usRoot + iCol - iChange].fs = SWP_SIZE | SWP_MOVE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* assign y coordinates, columns without extra row */%@AE@%%@NL@%
- y = (SHORT)prc->yBottom;%@NL@%
- cy = 0;%@NL@%
- for (iRow = usRoot - cDiff - 1; iRow >= 0; iRow--) {%@NL@%
- y += cy - cyBorder;%@NL@%
- cy = ((SHORT)prc->yBottom) +%@NL@%
- (((SHORT)(prc->yTop - prc->yBottom)) * (usRoot - cDiff - iRow)) /%@NL@%
- (usRoot - cDiff) - y + cyBorder;%@NL@%
- for (iCol = 0; iCol < iChange; iCol++) {%@NL@%
- aswp[iRow * usRoot + iCol].y = y;%@NL@%
- aswp[iRow * usRoot + iCol].cy = cy;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* assign y coordinates, columns with extra row */%@AE@%%@NL@%
- %@AB@%/* do last row first (different offsets) */%@AE@%%@NL@%
- y = (SHORT)prc->yBottom - cyBorder;%@NL@%
- cy = ((SHORT)(prc->yTop - prc->yBottom)) / (usRoot - cDiff + 1) +%@NL@%
- 2 * cyBorder;%@NL@%
- for (iCol = iChange; iCol < usRoot; iCol++) {%@NL@%
- aswp[usRoot * (usRoot - cDiff) + iCol - iChange].y = y;%@NL@%
- aswp[usRoot * (usRoot - cDiff) + iCol - iChange].cy = cy;%@NL@%
- }%@NL@%
- for (iRow = usRoot - cDiff - 1; iRow >= 0; iRow--) {%@NL@%
- y += cy - cyBorder;%@NL@%
- cy = ((SHORT)(prc->yBottom)) +%@NL@%
- (((SHORT)(prc->yTop - prc->yBottom)) * (usRoot - cDiff - iRow + 1))%@NL@%
- / (usRoot - cDiff + 1) - y + cyBorder;%@NL@%
- for (iCol = iChange; iCol < usRoot; iCol++) {%@NL@%
- aswp[iRow * usRoot + iCol].y = y;%@NL@%
- aswp[iRow * usRoot + iCol].cy = cy;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* CeilSquareRoot%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function returns the smallest integer greater or equal to the square%@NL@%
- %@AB@%* root of an unsigned 16 bit integer.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameter:%@NL@%
- %@AB@%* us: value to take the root of%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- SHORT CeilSquareRoot(register USHORT us)%@NL@%
- {%@NL@%
- register SHORT i;%@NL@%
- %@NL@%
- %@AB@%/* prevent overflow of large numbers */%@AE@%%@NL@%
- if (us > 0xFE * 0xFE)%@NL@%
- return 0xFF;%@NL@%
- %@NL@%
- %@AB@%/* iterate up past root */%@AE@%%@NL@%
- for (i = 0; i*i < (SHORT) us; i++)%@NL@%
- ;%@NL@%
- return i;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* SetCascadePositions%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function sets positions for cascading windows in a rectangle.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameters:%@NL@%
- %@AB@%* prc: rectangle to contain the cascaded windows%@NL@%
- %@AB@%* cWnd: number of windows to cascade%@NL@%
- %@AB@%* aswp: array of SWP structures, one for each cascaded window%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL SetCascadePositions(PRECTL prc, SHORT cWnd, PSWP aswp)%@NL@%
- {%@NL@%
- SHORT xEdge, yEdge;%@NL@%
- SHORT xDelta, yDelta;%@NL@%
- SHORT cMaxWnd;%@NL@%
- register SHORT x, y;%@NL@%
- SHORT i, j;%@NL@%
- RECTL rc;%@NL@%
- %@NL@%
- %@AB@%/* set cascade parameters */%@AE@%%@NL@%
- rc.xLeft = prc->xLeft - cxBorder;%@NL@%
- rc.xRight = prc->xRight + cyBorder;%@NL@%
- rc.yBottom = prc->yBottom - cyBorder;%@NL@%
- rc.yTop = prc->yTop + cyBorder;%@NL@%
- if (!SetCascadeParams((PRECTL)&rc, &xEdge, &yEdge, &xDelta, &yDelta,%@NL@%
- &cMaxWnd)) {%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- if (cWnd <= cMaxWnd) {%@NL@%
- %@AB@%/* only one run needed; move to top left corner */%@AE@%%@NL@%
- x = (SHORT)rc. xLeft;%@NL@%
- y = (SHORT)rc. yTop - yEdge;%@NL@%
- for (i = cWnd - 1; i >= 0; i--) {%@NL@%
- aswp[i].x = x;%@NL@%
- aswp[i].y = y;%@NL@%
- aswp[i].cx = xEdge;%@NL@%
- aswp[i].cy = yEdge;%@NL@%
- aswp[i].fs = SWP_SIZE | SWP_MOVE;%@NL@%
- x += xDelta;%@NL@%
- y -= yDelta;%@NL@%
- }%@NL@%
- %@NL@%
- } else {%@NL@%
- %@NL@%
- %@AB@%/* multiple runs necessary; start at bottom right, iterate up to%@NL@%
- %@AB@% top left */%@AE@%%@NL@%
- %@NL@%
- i = 0;%@NL@%
- %@NL@%
- while (i < cWnd) {%@NL@%
- %@NL@%
- %@AB@%/* even run */%@AE@%%@NL@%
- x = ((SHORT)rc. xLeft) + (cMaxWnd-1) * xDelta;%@NL@%
- y = ((SHORT)rc. yTop) - yEdge - (cMaxWnd-1) * yDelta;%@NL@%
- for (j = 0; j < cMaxWnd; j++) {%@NL@%
- aswp[i].x = x;%@NL@%
- aswp[i].y = y;%@NL@%
- aswp[i].cx = xEdge;%@NL@%
- aswp[i].cy = yEdge;%@NL@%
- aswp[i].fs = SWP_SIZE | SWP_MOVE;%@NL@%
- x -= xDelta;%@NL@%
- y += yDelta;%@NL@%
- if (++i >= cWnd)%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if (i >= cWnd)%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* odd run, offset by half delta y, one and one half delta x */%@AE@%%@NL@%
- x = ((SHORT)rc. xLeft) + (cMaxWnd-1) * xDelta + xDelta/2;%@NL@%
- y = ((SHORT)rc. yTop) - yEdge - (cMaxWnd-1) * yDelta + yDelta/2;%@NL@%
- for (j = 0; j < cMaxWnd - 1; j++) {%@NL@%
- aswp[i].x = x;%@NL@%
- aswp[i].y = y;%@NL@%
- aswp[i].cx = xEdge;%@NL@%
- aswp[i].cy = yEdge;%@NL@%
- aswp[i].fs = SWP_SIZE | SWP_MOVE;%@NL@%
- x -= xDelta;%@NL@%
- y += yDelta;%@NL@%
- if (++i >= cWnd)%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* SetCascadeParams%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function sets parameters for cascading windows. The window edges%@NL@%
- %@AB@%* are based on a fraction CASC_EDGE_NUM/CASC_EDGE_DENOM of the rectangle.%@NL@%
- %@AB@%* The x delta is four system font characters across, the y delta is two%@NL@%
- %@AB@%* system lines high.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameters:%@NL@%
- %@AB@%* prc: rectangle to contain the windows%@NL@%
- %@AB@%* pxEdge: width of the cascaded windows%@NL@%
- %@AB@%* pyEdge: height of the cascaded windows%@NL@%
- %@AB@%* pxDelta: x cascade offset%@NL@%
- %@AB@%* pyDelta: y cascade offset%@NL@%
- %@AB@%* pcMaxWnd: maximum number of windows in a cascade%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL SetCascadeParams(PRECTL prc, SHORT *pxEdge, SHORT *pyEdge, SHORT *pxDelta,%@NL@%
- SHORT *pyDelta, SHORT *pcMaxWnd)%@NL@%
- {%@NL@%
- register SHORT xEdge, yEdge;%@NL@%
- SHORT xDelta, yDelta;%@NL@%
- SHORT cMaxWnd;%@NL@%
- %@NL@%
- %@AB@%/* get x and y deltas from system values */%@AE@%%@NL@%
- xDelta = LOUSHORT(WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER)) +%@NL@%
- LOUSHORT(WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON)) / 2 + 2;%@NL@%
- yDelta = LOUSHORT(WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER)) +%@NL@%
- LOUSHORT(WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR))%@NL@%
- - cyBorder;%@NL@%
- %@NL@%
- %@AB@%/* get initial cut at yEdge using fraction */%@AE@%%@NL@%
- yEdge = (((SHORT)(prc->yTop - prc->yBottom)) * CASC_EDGE_NUM) /%@NL@%
- CASC_EDGE_DENOM;%@NL@%
- %@NL@%
- %@AB@%/* determine maximum number of deltas used per run */%@AE@%%@NL@%
- cMaxWnd = (((SHORT)(prc->yTop - prc->yBottom)) - yEdge) / yDelta;%@NL@%
- %@NL@%
- %@AB@%/* set x and y edges so full cascade will fill rectangle completely */%@AE@%%@NL@%
- xEdge = ((SHORT)(prc->xRight - prc->xLeft)) - xDelta/2 - cMaxWnd * xDelta;%@NL@%
- yEdge = ((SHORT)(prc->yTop - prc->yBottom)) - cMaxWnd * yDelta;%@NL@%
- %@NL@%
- %@AB@%/* check that values are reasonable */%@AE@%%@NL@%
- if (cMaxWnd < 1 || xEdge < 1 || yEdge < 1) {%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- *pxEdge = xEdge;%@NL@%
- *pyEdge = yEdge;%@NL@%
- *pxDelta = xDelta;%@NL@%
- *pyDelta = yDelta;%@NL@%
- %@AB@%/* return cMaxWnd as the maximum number of windows in a cascade */%@AE@%%@NL@%
- *pcMaxWnd = cMaxWnd + 1;%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* ArrangeWindows%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function arranges application document windows.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns:%@NL@%
- %@AB@%* TRUE if successful%@NL@%
- %@AB@%* FALSE otherwise%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL ArrangeWindows(USHORT fStyle)%@NL@%
- {%@NL@%
- USHORT cswpWnd, cswpIcon;%@NL@%
- RECTL rcl;%@NL@%
- register BOOL fReturn = FALSE;%@NL@%
- SWP NEAR *npswpWnd;%@NL@%
- SWP NEAR *npswpIcon;%@NL@%
- %@NL@%
- npswpWnd = (SWP NEAR *) WinAllocMem(hHeap, sizeof(SWP) * cDocs);%@NL@%
- npswpIcon = (SWP NEAR *) WinAllocMem(hHeap, sizeof(SWP) * cDocs);%@NL@%
- %@NL@%
- GetArrangeSwp(&cswpWnd, npswpWnd, &cswpIcon, npswpIcon);%@NL@%
- %@NL@%
- GetArrangeRectangle((PRECTL)&rcl, (BOOL)cswpIcon);%@NL@%
- %@NL@%
- %@AB@%/* set window positions */%@AE@%%@NL@%
- if (!ArrangeWindowPositions((PRECTL)&rcl, cswpWnd, (PSWP)npswpWnd, fStyle) ||%@NL@%
- !ArrangeIconPositions(cswpIcon, (PSWP)npswpIcon)) {%@NL@%
- goto ARRANGE_CLEANUP;%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#if %@AE@%1 %@NL@%
- %@AB@%/* rearrange the windows */%@AE@%%@NL@%
- WinSetMultWindowPos(NULL, (PSWP)npswpWnd, cswpWnd);%@NL@%
- WinSetMultWindowPos(NULL, (PSWP)npswpIcon, cswpIcon);%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- fReturn = TRUE;%@NL@%
- %@NL@%
- ARRANGE_CLEANUP:%@NL@%
- WinFreeMem(hHeap, (NPBYTE)npswpWnd, sizeof(SWP) * cDocs);%@NL@%
- WinFreeMem(hHeap, (NPBYTE)npswpIcon, sizeof(SWP) * cDocs);%@NL@%
- %@NL@%
- return fReturn;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* GetArrangeHandles%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function generates the handles of all windows to be arranged and%@NL@%
- %@AB@%* creates an array of SWP structures containing those handles. Minimized%@NL@%
- %@AB@%* and non-minimized windows are separated. Non-frame, invisible and%@NL@%
- %@AB@%* non-sizeable windows are ignored.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameter:%@NL@%
- %@AB@%* npcswpWnd: number of nonminimized windows found%@NL@%
- %@AB@%* npswpWnd: array of SWP structures for nonminimized windows%@NL@%
- %@AB@%* npcswpIcon: number of minimized windows found%@NL@%
- %@AB@%* npswpIcon: array of SWP structures for minimized windows%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns:%@NL@%
- %@AB@%* TRUE if successful%@NL@%
- %@AB@%* FALSE otherwise%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL GetArrangeSwp(USHORT *npcswpWnd, SWP *npswpWnd, USHORT *npcswpIcon,%@NL@%
- SWP *npswpIcon)%@NL@%
- {%@NL@%
- register USHORT cWnd, cIcon;%@NL@%
- ULONG ulStyle;%@NL@%
- HWND hwnd;%@NL@%
- register NPDOC npdoc;%@NL@%
- %@NL@%
- cWnd = 0;%@NL@%
- cIcon = 0;%@NL@%
- %@NL@%
- %@AB@%/* enumerate windows and selectively add them to the arrange lists */%@AE@%%@NL@%
- for (hwnd = WinQueryWindow(hwndMDI, QW_TOP, FALSE);%@NL@%
- hwnd;%@NL@%
- hwnd = WinQueryWindow(hwnd, QW_NEXT, FALSE)) {%@NL@%
- %@NL@%
- %@AB@%/* make sure the window is visible and owned by the app client window */%@AE@%%@NL@%
- ulStyle = WinQueryWindowULong(hwnd, QWL_STYLE);%@NL@%
- if (WinQueryWindow(hwnd, QW_OWNER, FALSE) ||%@NL@%
- !(ulStyle & WS_VISIBLE)) {%@NL@%
- continue;%@NL@%
- }%@NL@%
- %@NL@%
- if (ulStyle & WS_MINIMIZED) {%@NL@%
- npswpIcon->hwnd = hwnd;%@NL@%
- npswpIcon++;%@NL@%
- cIcon++;%@NL@%
- } else {%@NL@%
- %@AB@%/* restore maximized windows */%@AE@%%@NL@%
- if (ulStyle & WS_MAXIMIZED) {%@NL@%
- %@NL@%
- %@AI@%#ifdef %@AE@%MINMAXFIX %@NL@%
- %@AB@%/* Bring the min/max buttons back to life for a moment so%@NL@%
- %@AB@% they stay in sync when the window is restored. Then put%@NL@%
- %@AB@% them back to the object window 07-Sep-1989 johnba%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- npdoc = NPDOCFROMCLIENT(WinWindowFromID(hwnd,FID_CLIENT));%@NL@%
- WinSetParent(npdoc->hwndMinmax, hwnd, FALSE);%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- WinSetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_RESTORE );%@NL@%
- %@AI@%#ifdef %@AE@%MINMAXFIX %@NL@%
- %@NL@%
- %@NL@%
- if (hwndActiveDoc != hwnd) {%@NL@%
- WinSetParent(npdoc->hwndMinmax, HWND_OBJECT, FALSE);%@NL@%
- WinSendMsg(hwnd, WM_UPDATEFRAME, 0L, 0L);%@NL@%
- }%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- }%@NL@%
- npswpWnd->hwnd = hwnd;%@NL@%
- npswpWnd++;%@NL@%
- cWnd++;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- *npcswpWnd = cWnd;%@NL@%
- *npcswpIcon = cIcon;%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* GetArrangeRectangle%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function determines the area in which task windows are arranged.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameter:%@NL@%
- %@AB@%* prc: the generated area rectangle%@NL@%
- %@AB@%* fIconPark: specifies if room should be made for icon parking lot%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns:%@NL@%
- %@AB@%* TRUE if successful%@NL@%
- %@AB@%* FALSE otherwise%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL GetArrangeRectangle(PRECTL prc, BOOL fIconPark)%@NL@%
- {%@NL@%
- register USHORT yIcon;%@NL@%
- register SHORT cxBorderInset;%@NL@%
- %@NL@%
- %@AB@%/* get dimensions of desktop window */%@AE@%%@NL@%
- WinQueryWindowRect(hwndMDI, prc);%@NL@%
- %@NL@%
- cxBorderInset = (SHORT)(WinQuerySysValue(HWND_DESKTOP, SV_CXBYTEALIGN) -%@NL@%
- WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER));%@NL@%
- WinInflateRect(NULL, prc, -cxBorderInset, -cxBorderInset * %@NL@%
- (cyBorder / cxBorder));%@NL@%
- %@NL@%
- if (fIconPark) {%@NL@%
- %@AB@%/* make room for single row of icon carpark */%@AE@%%@NL@%
- yIcon = LOUSHORT(WinQuerySysValue(HWND_DESKTOP, SV_CYICON));%@NL@%
- prc->yBottom += (yIcon * ICON_PARK_NUM) / ICON_PARK_DENOM;%@NL@%
- }%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* ArrangeIconPositions%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function sets positions for minimized windows.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Parameters:%@NL@%
- %@AB@%* cIcon: number of icons to position%@NL@%
- %@AB@%* aswp: array of SetWindowPos structures for those icons%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns:%@NL@%
- %@AB@%* TRUE if successful%@NL@%
- %@AB@%* FALSE otherwise%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL ArrangeIconPositions(USHORT cIcon, PSWP aswpIcon)%@NL@%
- {%@NL@%
- register USHORT i;%@NL@%
- %@NL@%
- for (i = 0; i < cIcon; i++) {%@NL@%
- aswpIcon[i].x = 0;%@NL@%
- aswpIcon[i].y = 0;%@NL@%
- aswpIcon[i].fs = SWP_MOVE;%@NL@%
- }%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%AVIO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\BROWSE\AVBROWSE\AVIO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% avio.c -- AVIO action routines%@NL@%
- %@AB@%%@NL@%
- %@AB@% Implements scrollbars, sets up an AVIO Presentation Space%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@% INCL_AVIO %@NL@%
- %@AI@%#define %@AE@% INCL_DEV %@NL@%
- %@AI@%#define %@AE@% INCL_VIO %@NL@%
- %@AI@%#define %@AE@% INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@% INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINTRACKRECT %@NL@%
- %@AI@%#define %@AE@% INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINSCROLLBARS %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- <string.h> %@AB@%/* One strlen() call in the Blast() macro */%@AE@%%@NL@%
- "avio.h" %@AB@%/* Get Avio-prefixed routine prototypes */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Constants%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- char Blank[2] = { 0x20, 0x07 }; %@AB@%/* <Space> + EGA white attribute */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros to make the code more readable%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/* Upper and Lower Bound Calculations */%@AE@%%@NL@%
- %@AI@%#define %@AE@% Abs(a) (((a) > 0) ? (a) : (-(a))) %@NL@%
- %@AI@%#define %@AE@% Min(a,b) (((a) < (b)) ? (a) : (b)) %@NL@%
- %@AI@%#define %@AE@% Max(a,b) (((a) > (b)) ? (a) : (b)) %@NL@%
- %@AI@%#define %@AE@%LowerBound(pos, disp, lbound) Max(pos - disp, lbound) %@NL@%
- %@AI@%#define %@AE@%UpperBound(pos, disp, ubound) Min(pos + disp, ubound) %@NL@%
- %@NL@%
- %@AB@%/* Scroll Bar Abbreviations */%@AE@%%@NL@%
- %@AI@%#define %@AE@%DisableSB(hSB) WinSetParent(hSB, HWND_OBJECT, TRUE) %@NL@%
- %@AI@%#define %@AE@%EnableSB(hSB) WinSetParent(hSB, hWndFrame, TRUE) %@NL@%
- %@AI@%#define %@AE@%SetScroll(h, pos, max) \ %@NL@%
- WinSendMsg(h, SBM_SETSCROLLBAR, MPFROM2SHORT(pos, 0), MPFROM2SHORT(0, max))%@NL@%
- %@NL@%
- %@AB@%/* Scrollbar redraw macros */%@AE@%%@NL@%
- %@AI@%#define %@AE@%UpdateOn(c, hsb) if (!(++c)) WinEnableWindowUpdate(hsb, TRUE) %@NL@%
- %@AI@%#define %@AE@%UpdateOff(c, hsb) if (!(c--)) WinEnableWindowUpdate(hsb, FALSE) %@NL@%
- %@AI@%#define %@AE@% UpdateFrame(sb) \ %@NL@%
- WinSendMsg(hWndFrame, WM_UPDATEFRAME, MPFROMLONG(sb), 0L)%@NL@%
- %@NL@%
- %@AB@%/* Scrolling Macros */%@AE@%%@NL@%
- ClearScreen() ScrollUp(-1) %@AB@%/* Scroll up an "infinite" # lines */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ScrollDown(n) VioScrollDn(0, 0, -1, -1, n, Blank, hVPS) %@NL@%
- %@AI@%#define %@AE@%ScrollUp(n) VioScrollUp(0, 0, -1, -1, n, Blank, hVPS) %@NL@%
- %@NL@%
- %@AB@%/* RectL -> SWP conversion macros */%@AE@%%@NL@%
- %@AI@%#define %@AE@% lcx(r) ((r.xRight - r.xLeft) + 1) %@NL@%
- %@AI@%#define %@AE@% lcy(r) ((r.yTop - r.yBottom) + 1) %@NL@%
- %@NL@%
- %@AB@%/* Miscellaneous macros */%@AE@%%@NL@%
- %@AI@%#define %@AE@%Blast(l, x, y) VioWrtCharStr(l, Min((SHORT) strlen(l), cxChScreen), x, y, hVPS) %@NL@%
- %@AI@%#define %@AE@%CalcChars(sPg, sCh) \ %@NL@%
- ((sCh) ? (Max(((sPg) / (sCh)), 0)) : 0)%@NL@%
- %@AI@%#define %@AE@% SetCellSize(h,w) VioSetDeviceCellSize(h, w, hVPS) %@NL@%
- %@AI@%#define %@AE@% Value(value) WinQuerySysValue(HWND_DESKTOP, value) %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% File-Local Variables%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HDC hDC; %@AB@%/* Device Context */%@AE@%%@NL@%
- HVPS hVPS; %@AB@%/* Virtual PS */%@AE@%%@NL@%
- int iTopLine; %@AB@%/* PS Line of window corner */%@AE@%%@NL@%
- int iCurCol; %@AB@%/* Current column of window corner */%@AE@%%@NL@%
- int cxChPage; %@AB@%/* Width and height of our window, in characters */%@AE@%%@NL@%
- int cyChPage;%@NL@%
- int iMaxHorz; %@AB@%/* Scroll bar upper bounds */%@AE@%%@NL@%
- int iMaxVert; %@NL@%
- BOOL fNeedHorz; %@AB@%/* Do we need the scroll bars or not? */%@AE@%%@NL@%
- BOOL fNeedVert;%@NL@%
- HWND hWndHorzSB; %@AB@%/* Window handles of ScrollBar windows */%@AE@%%@NL@%
- HWND hWndVertSB;%@NL@%
- extern HWND hWndFrame; %@AB@%/* Client, frame windows */%@AE@%%@NL@%
- extern HWND hWndClient;%@NL@%
- PFNWP pfnOldClient; %@AB@%/* Old Client Window Procedure pointer */%@AE@%%@NL@%
- PFNWP pfnOldFrame; %@AB@%/* Old Frame Window Procedure pointer */%@AE@%%@NL@%
- SHORT cyChPS; %@AB@%/* Number of rows in AVIO PS */%@AE@%%@NL@%
- SHORT cxChPS; %@AB@%/* Number of cols in AVIO PS */%@AE@%%@NL@%
- SHORT cyChScreen; %@AB@%/* Number of rows in display space */%@AE@%%@NL@%
- SHORT cxChScreen; %@AB@%/* Number of cols in display space */%@AE@%%@NL@%
- PFNQL pfnQueryLine;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Measurements used to help make the window look nice%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- LONG cxConstant, cyConstant; %@AB@%/* Miscellaneous frame lens */%@AE@%%@NL@%
- int cxMaxFrame, cyMaxFrame; %@AB@%/* Maximum frame widths */%@AE@%%@NL@%
- LONG lChWidth, lChHeight;%@NL@%
- SHORT cxMaxClient, cyMaxClient; %@AB@%/* Client area bounds */%@AE@%%@NL@%
- BOOL fCreatedPS; %@AB@%/* AVIO PS created */%@AE@%%@NL@%
- int cHUpdate = -1; %@AB@%/* Keep track of updates */%@AE@%%@NL@%
- int cVUpdate = -1;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Local prototypes%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- void FixScroll(BOOL, BOOL, HWND, ULONG, int *, int, int *);%@NL@%
- void UpdateScrollBars(RECTL);%@NL@%
- void Refresh(void);%@NL@%
- void Update(USHORT, USHORT, USHORT);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% The actual routines%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- void AvioInit(PLBINFO plbi) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize Presentation Space, Device Context, Scroll Bars%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- VIOCURSORINFO vci;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the line buffer info %@NL@%
- %@AB@% */%@AE@%%@NL@%
- cyChScreen = plbi->sRows;%@NL@%
- cxChScreen = plbi->sCols;%@NL@%
- cyChPS = plbi->sPSrows;%@NL@%
- cxChPS = plbi->sPScols;%@NL@%
- pfnQueryLine = plbi->pfnQL;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% One Time Initializations...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!fCreatedPS) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Create the AVIO Presentation Space, with one attribute byte%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hDC = WinOpenWindowDC(hWndClient); %@AB@%/* Open the device context */%@AE@%%@NL@%
- VioCreatePS(&hVPS, cyChPS, cxChPS + 1, 0, 1, 0);%@NL@%
- VioAssociate(hDC, hVPS); %@AB@%/* Link the PS with the DC */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Turn off the cursor (set invisible attribute)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- VioGetCurType(&vci, hVPS);%@NL@%
- vci.attr = -1;%@NL@%
- VioSetCurType(&vci, hVPS);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Measure the frame components%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cxConstant = 0;%@NL@%
- cyConstant = Value(SV_CYTITLEBAR) + Value(SV_CYMENU);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Snag scroll bar info%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hWndHorzSB = WinWindowFromID(hWndFrame, FID_HORZSCROLL);%@NL@%
- hWndVertSB = WinWindowFromID(hWndFrame, FID_VERTSCROLL);%@NL@%
- fNeedHorz = fNeedVert = TRUE;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Setup the Client and Frame routines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pfnOldFrame = WinSubclassWindow(hWndFrame, AvioFrameWndProc);%@NL@%
- pfnOldClient = WinSubclassWindow(hWndClient, AvioClientWndProc);%@NL@%
- fCreatedPS = TRUE;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Repaint the screen%@NL@%
- %@AB@% */%@AE@%%@NL@%
- iTopLine = iCurCol = 0;%@NL@%
- AvioStartup(plbi->fLargeFont);%@NL@%
- }%@NL@%
- %@NL@%
- void AvioStartup(BOOL fLargeFont) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clear the screen, set the font, redraw the area%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- RECTL rclFrame;%@NL@%
- %@NL@%
- ClearScreen();%@NL@%
- AvioLargeFont(fLargeFont);%@NL@%
- WinQueryWindowRect(hWndFrame, &rclFrame);%@NL@%
- UpdateScrollBars(rclFrame);%@NL@%
- Update(0, cyChPS, 0);%@NL@%
- }%@NL@%
- %@NL@%
- void AvioScroll(USHORT SB_Command, USHORT Position, BOOL Horizontal) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Process the scroll bar messages%@NL@%
- %@AB@%%@NL@%
- %@AB@% These routines are symmetric; in fact, SB_LINELEFT = SB_LINEUP, etc...%@NL@%
- %@AB@% so one might note that this could be condensed. It's left expanded for%@NL@%
- %@AB@% speed and clarity. The scrollbar values are bounded to stay inside%@NL@%
- %@AB@% the Presentation Space.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (Horizontal) { %@AB@%/* Horizontal Scroll Bar */%@AE@%%@NL@%
- switch (SB_Command) {%@NL@%
- case SB_LINELEFT:%@NL@%
- iCurCol = LowerBound(iCurCol, 1, 0); break;%@NL@%
- case SB_LINERIGHT:%@NL@%
- iCurCol = UpperBound(iCurCol, 1, iMaxHorz); break;%@NL@%
- case SB_PAGELEFT:%@NL@%
- iCurCol = LowerBound(iCurCol, cxChPage, 0); break;%@NL@%
- case SB_PAGERIGHT:%@NL@%
- iCurCol = UpperBound(iCurCol, cxChPage, iMaxHorz); break;%@NL@%
- case SB_SLIDERTRACK:%@NL@%
- iCurCol = (SHORT) Position;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- if (SB_Command != SB_SLIDERTRACK)%@NL@%
- SetScroll(hWndHorzSB, iCurCol, iMaxHorz);%@NL@%
- %@NL@%
- } else { %@AB@%/* Vertical Scroll Bar */%@AE@%%@NL@%
- switch (SB_Command) {%@NL@%
- case SB_LINEUP:%@NL@%
- iTopLine = LowerBound(iTopLine, 1, 0); break;%@NL@%
- case SB_LINEDOWN:%@NL@%
- iTopLine = UpperBound(iTopLine, 1, iMaxVert); break;%@NL@%
- case SB_PAGEUP:%@NL@%
- iTopLine = LowerBound(iTopLine, cyChPage, 0); break;%@NL@%
- case SB_PAGEDOWN:%@NL@%
- iTopLine = UpperBound(iTopLine, cyChPage, iMaxVert);break;%@NL@%
- case SB_SLIDERTRACK:%@NL@%
- iTopLine = (SHORT) Position;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- if (SB_Command != SB_SLIDERTRACK)%@NL@%
- SetScroll(hWndVertSB, iTopLine, iMaxVert);%@NL@%
- }%@NL@%
- Refresh();%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT AvioSize(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do the default AVIO sizing, and kyfe a few values%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- RECTL rclFrame;%@NL@%
- %@NL@%
- if (!fCreatedPS) return 0L;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Update the scroll bars, and the screen%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowRect(hWndFrame, &rclFrame);%@NL@%
- UpdateScrollBars(rclFrame);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Now, do the normal AVIO processing%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return WinDefAVioWindowProc(hWnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- %@NL@%
- void Update(USHORT usLineNum, USHORT usHowMany, USHORT usStartLine) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Updates N lines starting from START line on screen.%@NL@%
- %@AB@% Starts at saved line LINENUM.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT i; %@AB@%/* Loop index variable */%@AE@%%@NL@%
- USHORT usWhichLine = usLineNum; %@AB@%/* Line number to be queried */%@AE@%%@NL@%
- char *szLine;%@NL@%
- %@NL@%
- for (i = usStartLine; i < (usStartLine + usHowMany); i++) {%@NL@%
- szLine = (*pfnQueryLine)(usWhichLine++); %@AB@%/* Get the line */%@AE@%%@NL@%
- if (szLine) Blast(szLine, i, 0); %@AB@%/* Print it out */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void Refresh(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do the origin shifting and screen updating%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- SHORT Delta;%@NL@%
- int static iOldTopLine = 0;%@NL@%
- %@NL@%
- VioSetOrg(0, iCurCol, hVPS); %@AB@%/* Get the free AVIO horizontal shift */%@AE@%%@NL@%
- Delta = iTopLine - iOldTopLine; %@AB@%/* Compute vertical shift */%@AE@%%@NL@%
- if (Abs(Delta) < cyChPS) {%@NL@%
- if (Delta < 0) { %@AB@%/* Scroll Up -- make Delta positive*/%@AE@%%@NL@%
- ScrollDown(-Delta);%@NL@%
- Update(iTopLine, -Delta, 0);%@NL@%
- } else { %@AB@%/* Scroll Down by Delta */%@AE@%%@NL@%
- ScrollUp(Delta);%@NL@%
- Update(iTopLine + cyChPS - Delta, Delta, cyChPS - Delta);%@NL@%
- }%@NL@%
- } else AvioRedraw(); %@AB@%/* Redo the entire screen */%@AE@%%@NL@%
- iOldTopLine = iTopLine;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioClose(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Termination routines%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Destroy the Presentation Space%@NL@%
- %@AB@% */%@AE@%%@NL@%
- VioAssociate(NULL, hVPS);%@NL@%
- VioDestroyPS(hVPS);%@NL@%
- fCreatedPS = FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioPaint(HWND hWnd) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Paint the AVIO presentation space by telling it to show itself.%@NL@%
- %@AB@% A possible optimization here is to repaint only the update region.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- static HPS hPS;%@NL@%
- static RECTL RectL;%@NL@%
- %@NL@%
- hPS = WinBeginPaint(hWnd, (HPS) NULL, &RectL);%@NL@%
- VioShowPS(cyChPS, cxChPS, 0, hVPS);%@NL@%
- WinEndPaint(hPS);%@NL@%
- } %@NL@%
- %@NL@%
- MRESULT AvioMinMax(PSWP pSWP) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Handle WM_MINMAX messages, to make sure frame doesn't get too big%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (pSWP->fs & (SWP_MAXIMIZE | SWP_RESTORE)) {%@NL@%
- if (pSWP->fs & SWP_MAXIMIZE) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save cx, cy values for later origin displacement%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int Oldcx = pSWP->cx;%@NL@%
- int Oldcy = pSWP->cy;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Displace, and change to maximum size%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pSWP->x += (Oldcx -%@NL@%
- (pSWP->cx = cxMaxFrame + (int) (Value(SV_CXSIZEBORDER) << 1)));%@NL@%
- pSWP->y += (Oldcy -%@NL@%
- (pSWP->cy = cyMaxFrame + (int) (Value(SV_CYSIZEBORDER) << 1)));%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Now, fix the scroll bars%@NL@%
- %@AB@% */%@AE@%%@NL@%
- AvioAdjustFramePos(pSWP);%@NL@%
- return (MRESULT) TRUE;%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioClear(void) { ClearScreen(); }%@NL@%
- %@NL@%
- void AvioAdjustFramePos(PSWP pSWP) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Trap WM_ADJUSTWINDOWPOS messages to the frame with this routine.%@NL@%
- %@AB@% Keep the window sized right, and control scrollbar visibility.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- RECTL rclFrame;%@NL@%
- %@NL@%
- if (!(pSWP->cx && pSWP->cy)) return; %@AB@%/* Null area... */%@AE@%%@NL@%
- if (pSWP->fs & SWP_MINIMIZE) return; %@AB@%/* Iconic... */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Make sure the dimensions are in range%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pSWP->cx = Min(pSWP->cx, (cxMaxFrame + (SHORT)(Value(SV_CXSIZEBORDER)<<1)));%@NL@%
- pSWP->cy = Min(pSWP->cy, (cyMaxFrame + (SHORT)(Value(SV_CYSIZEBORDER)<<1)));%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Update the scroll bars%@NL@%
- %@AB@% */%@AE@%%@NL@%
- rclFrame.xLeft = (LONG) pSWP->x;%@NL@%
- rclFrame.xRight = (LONG) (pSWP->x + pSWP->cx - 1);%@NL@%
- rclFrame.yBottom = (LONG) pSWP->y;%@NL@%
- rclFrame.yTop = (LONG) (pSWP->y + pSWP->cy - 1);%@NL@%
- UpdateScrollBars(rclFrame);%@NL@%
- %@NL@%
- return; %@NL@%
- }%@NL@%
- %@NL@%
- void AvioTrackFrame(HWND hWnd, MPARAM mpTrackFlags) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Takes action on WM_TRACKFRAME message%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- static TRACKINFO tiTrackInfo;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the tracking information in the TrackInfo structure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSendMsg(hWnd, WM_QUERYTRACKINFO, mpTrackFlags, &tiTrackInfo);%@NL@%
- WinTrackRect(hWnd, NULL, &tiTrackInfo);%@NL@%
- }%@NL@%
- %@NL@%
- void AvioQueryTrackInfo(PTRACKINFO pTI) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Routine which processes WM_QUERYTRACKINFO messages to the frame.%@NL@%
- %@AB@% Call this routine after the default one to change various parameters.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Note: In reality, since we have a menu bar, we should make the%@NL@%
- %@AB@% minimum width of the window something such that it does not "fold."%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL fMove;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the grid set up for byte alignment (unless moving)%@NL@%
- %@AB@%%@NL@%
- %@AB@% cxGrid is set to half character width so that arrow keys%@NL@%
- %@AB@% will function when sizing (they try to size by half a%@NL@%
- %@AB@% character)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fMove = ((pTI->fs & TF_MOVE) == TF_MOVE);%@NL@%
- pTI->fs |= TF_GRID;%@NL@%
- pTI->cxGrid = (fMove) ? 1 : ((SHORT) lChWidth);%@NL@%
- pTI->cyGrid = (fMove) ? 1 : ((SHORT) lChHeight);%@NL@%
- pTI->cxKeyboard = (SHORT) lChWidth;%@NL@%
- pTI->cyKeyboard = (SHORT) lChHeight;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Bound the frame.%@NL@%
- %@AB@% Maximum: Sizing Border, Scrollbars, Title, Menus, client region%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pTI->ptlMaxTrackSize.x = (LONG) (pTI->cxBorder << 1) + (LONG) cxMaxFrame;%@NL@%
- pTI->ptlMaxTrackSize.y = (LONG) (pTI->cyBorder << 1) + (LONG) cyMaxFrame;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioRedraw(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clear, then redraw the entire Presentation Space%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- ClearScreen();%@NL@%
- Update(iTopLine, cyChPS, 0);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AvioClientWndProc%@NL@%
- (HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Window Procedure which traps messages to the Client area%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- switch (msg) {%@NL@%
- case WM_PAINT: %@AB@%/* Paint the AVIO way! */%@AE@%%@NL@%
- AvioPaint(hWnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_SIZE: %@AB@%/* Size the AVIO way! */%@AE@%%@NL@%
- return AvioSize(hWnd, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_HSCROLL:%@NL@%
- AvioScroll(HIUSHORT(mp2), LOUSHORT(mp2), TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_VSCROLL:%@NL@%
- AvioScroll(HIUSHORT(mp2), LOUSHORT(mp2), FALSE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ERASEBACKGROUND:%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_TRACKFRAME:%@NL@%
- AvioTrackFrame(hWnd, mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MINMAXFRAME: %@AB@%/* Limit Maximized window size */%@AE@%%@NL@%
- AvioMinMax((PSWP) mp1);%@NL@%
- %@NL@%
- %@AB@%/* fall through */%@AE@%%@NL@%
- %@NL@%
- default: return (*pfnOldClient)(hWnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AvioFrameWndProc(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Force the frame to stay small enough (no larger than the PS)%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- {%@NL@%
- BOOL rc; %@AB@%/* Return code from WM_QUERYTRACKINFO */%@AE@%%@NL@%
- %@NL@%
- switch(msg) {%@NL@%
- case WM_ADJUSTWINDOWPOS: %@AB@%/* Calculate scroll bar adjustments */%@AE@%%@NL@%
- AvioAdjustFramePos(mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_QUERYTRACKINFO: %@AB@%/* Get default, then process message */%@AE@%%@NL@%
- rc = (BOOL) SHORT1FROMMR((*pfnOldFrame)(hWnd, msg, mp1, mp2));%@NL@%
- AvioQueryTrackInfo((PTRACKINFO) mp2);%@NL@%
- return (MRESULT) rc;%@NL@%
- %@NL@%
- default: break;%@NL@%
- }%@NL@%
- return (*pfnOldFrame)(hWnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- %@NL@%
- void UpdateScrollBars(RECTL rclClient) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% This routine fixes up the scroll bars when the window is resized, or%@NL@%
- %@AB@% when the font size is changed.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Parameters: The dimensions of the frame window%@NL@%
- %@AB@% Result: Updates the scrollbars, enabling/disabling as needed%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL fNeededHorz = fNeedHorz; %@AB@%/* Did we need the scrollbars then? */%@AE@%%@NL@%
- BOOL fNeededVert = fNeedVert;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute the client rectangle, without the scrollbars%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinCalcFrameRect(hWndFrame, &rclClient, TRUE);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute page width -- do we need the horizontal scroll bar?%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cxChPage = (int) CalcChars(lcx(rclClient), lChWidth);%@NL@%
- fNeedHorz = ((iMaxHorz = Max(cxChScreen - cxChPage, 0)) > 0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute page height -- do we need the vertical scroll bar?%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cyChPage = (int) CalcChars(lcy(rclClient), lChHeight);%@NL@%
- fNeedVert = ((iMaxVert = Max(cyChScreen - cyChPage, 0)) > 0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Maintain scrollbar integrity%@NL@%
- %@AB@% */%@AE@%%@NL@%
- iCurCol = Min(iCurCol, iMaxHorz);%@NL@%
- iTopLine = Min(iTopLine, iMaxVert);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Now, update the scrollbars as necessary%@NL@%
- %@AB@% */%@AE@%%@NL@%
- FixScroll(fNeededHorz, fNeedHorz, hWndHorzSB,%@NL@%
- FCF_HORZSCROLL, &iCurCol, iMaxHorz, &cHUpdate);%@NL@%
- %@NL@%
- FixScroll(fNeededVert, fNeedVert, hWndVertSB,%@NL@%
- FCF_VERTSCROLL, &iTopLine, iMaxVert, &cVUpdate);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Now, update the screen to be visually consistent%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Refresh();%@NL@%
- }%@NL@%
- %@NL@%
- void FixScroll(fNeeded, fNeed, hWnd, flScroll, piPos, iMax, pc)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% This routine makes the necessary scrollbar adjustments, and%@NL@%
- %@AB@% also enables/disables them.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL fNeeded; %@AB@%/* Whether we used to need the scrollbar */%@AE@%%@NL@%
- BOOL fNeed; %@AB@%/* Whether we need the scrollbar now */%@AE@%%@NL@%
- HWND hWnd; %@AB@%/* Handle to the scrollbar window */%@AE@%%@NL@%
- ULONG flScroll; %@AB@%/* FCF_xxxxSCROLL flag (for the scrollbar) */%@AE@%%@NL@%
- int *piPos; %@AB@%/* Current location of scrollbar thumb */%@AE@%%@NL@%
- int iMax; %@AB@%/* New maximum for the scrollbar */%@AE@%%@NL@%
- int *pc; %@AB@%/* Counter for WinEnableWindowUpdate recursion */%@AE@%%@NL@%
- {%@NL@%
- if (fNeed) { %@AB@%/* Enable the scroll bar -- we didn't need it before */%@AE@%%@NL@%
- if (!fNeeded) {%@NL@%
- EnableSB(hWnd);%@NL@%
- UpdateOff((*pc), hWnd);%@NL@%
- UpdateFrame(flScroll);%@NL@%
- UpdateOn((*pc), hWnd);%@NL@%
- }%@NL@%
- SetScroll(hWnd, (*piPos) = Min((*piPos), iMax), iMax);%@NL@%
- } else { %@AB@%/* Disable the scroll bar, we no longer need it */%@AE@%%@NL@%
- if (fNeeded) {%@NL@%
- DisableSB(hWnd);%@NL@%
- UpdateOff((*pc), hWnd);%@NL@%
- UpdateFrame(flScroll);%@NL@%
- UpdateOn((*pc), hWnd);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void AvioLargeFont(BOOL fLargeFont) {%@NL@%
- static BOOL fFirst = TRUE; // Need to init?%@NL@%
- static LONG lSmallHt, lSmallWd, lLargeHt, lLargeWd; // Font sizes%@NL@%
- SWP swp;%@NL@%
- %@NL@%
- if (fFirst) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% The first time through, get the small and large font sizes%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DevQueryCaps(hDC, CAPS_CHAR_HEIGHT, 1L, &lLargeHt);%@NL@%
- DevQueryCaps(hDC, CAPS_CHAR_WIDTH, 1L, &lLargeWd);%@NL@%
- DevQueryCaps(hDC, CAPS_SMALL_CHAR_HEIGHT, 1L, &lSmallHt);%@NL@%
- DevQueryCaps(hDC, CAPS_SMALL_CHAR_WIDTH, 1L, &lSmallWd);%@NL@%
- fFirst = FALSE;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set the character size with VioSetDeviceCellSize%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SetCellSize( (SHORT) (lChHeight = ((fLargeFont) ? lLargeHt : lSmallHt)),%@NL@%
- (SHORT) (lChWidth = ((fLargeFont) ? lLargeWd : lSmallWd)) );%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute maximum size of client area%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cxMaxClient = (cxChPS * (SHORT) lChWidth);%@NL@%
- cxMaxFrame = cxMaxClient + (SHORT) cxConstant;%@NL@%
- cyMaxClient = (cyChPS * (SHORT) lChHeight);%@NL@%
- cyMaxFrame = cyMaxClient + (SHORT) cyConstant;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Send a WM_ADJUSTFRAMEPOS message%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowPos(hWndFrame, &swp);%@NL@%
- if (swp.fs & SWP_MAXIMIZE) {%@NL@%
- AvioMinMax(&swp);%@NL@%
- WinSetMultWindowPos(hWndFrame, &swp, 1);%@NL@%
- } else {%@NL@%
- swp.fs = SWP_ACTIVATE | SWP_MOVE | SWP_SHOW | SWP_SIZE;%@NL@%
- WinSetWindowPos(hWndFrame, NULL, swp.x, swp.y,%@NL@%
- Min(cxMaxFrame, swp.cx), Min(cyMaxFrame, swp.cy), swp.fs);%@NL@%
- }%@NL@%
- AvioAdjustFramePos(&swp); %@AB@%/* Fix up the frame, scroll bars */%@AE@%%@NL@%
- AvioPaint(hWndClient); %@AB@%/* Repaint with new characters */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%AVIO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\COMTALK\AVIO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% avio.c -- AVIO handling routines%@NL@%
- %@AB@% For a cleaner implementation, look at the BROWSE application.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Implements scrollbars, sets up an AVIO Presentation Space%@NL@%
- %@AB@% Intrinsically linked with a circular queue routine%@NL@%
- %@AB@%%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@% INCL_AVIO %@NL@%
- %@AI@%#define %@AE@% INCL_DEV %@NL@%
- %@AI@%#define %@AE@% INCL_VIO %@NL@%
- %@AI@%#define %@AE@% INCL_WIN %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%"global.h" %@NL@%
- "circleq.h" %@AB@%/* Get Circular Buffer routines */%@AE@%%@NL@%
- "avio.h" %@AB@%/* Prototype our routines */%@AE@%%@NL@%
- <stdio.h> %@AB@%/* Needed to open LOG file */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Constants%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- AVIO_PS_ROWS 25 %@AB@%/* Dimensions of the AVIO PS */%@AE@%%@NL@%
- %@AI@%#define %@AE@%AVIO_PS_COLUMNS MAXLINELEN %@NL@%
- CATTRBYTES 1 %@AB@%/* 1 or 3 attribute bytes/cell */%@AE@%%@NL@%
- DEFPAGEWIDTH 5 %@AB@%/* Default pagesizes */%@AE@%%@NL@%
- %@AI@%#define %@AE@% DEFPAGEHEIGHT 5 %@NL@%
- %@NL@%
- char Blank[2] = { 0x20, 0x07 };%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros to make the code more readable%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/* Upper and Lower Bound Calculations */%@AE@%%@NL@%
- %@AI@%#define %@AE@% Abs(a) (((a) > 0) ? (a) : (-(a))) %@NL@%
- %@AI@%#define %@AE@%LowerBound(pos, disp, lbound) Max(pos - disp, lbound) %@NL@%
- %@AI@%#define %@AE@%UpperBound(pos, disp, ubound) Min(pos + disp, ubound) %@NL@%
- %@NL@%
- %@AB@%/* Scroll Bar Abbreviations */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@% DisableSB(hSB) WinSetParent(hSB, HWND_OBJECT, FALSE) %@NL@%
- %@AI@%#define %@AE@% EnableSB(hSB) WinSetParent(hSB, hWndSBParent, FALSE) %@NL@%
- %@AI@%#define %@AE@% HBarHeight() (fNeedHorz ? lHSBHeight : 0L) %@NL@%
- %@AI@%#define %@AE@% VBarWidth() (fNeedVert ? lVSBWidth : 0L) %@NL@%
- %@AI@%#define %@AE@%SetScroll(h, pos, max) \ %@NL@%
- WinSendMsg(h, SBM_SETSCROLLBAR, MPFROM2SHORT(pos, 0), MPFROM2SHORT(0, max))%@NL@%
- %@AI@%#define %@AE@% UpdateFrame(sb) \ %@NL@%
- WinSendMsg(hWndSBParent, WM_UPDATEFRAME, MPFROMLONG(sb), 0L)%@NL@%
- %@AI@%#define %@AE@% UpdateOff(w) WinEnableWindowUpdate(w, FALSE) %@NL@%
- %@AI@%#define %@AE@% UpdateOn(w) WinEnableWindowUpdate(w, TRUE) %@NL@%
- %@NL@%
- %@AB@%/* Scrolling Macros */%@AE@%%@NL@%
- %@AI@%#define %@AE@% ClearScreen() ScrollUp(-1) %@NL@%
- %@AI@%#define %@AE@%ScrollDown(n) VioScrollDn(0, 0, -1, -1, n, Blank, hVPS) %@NL@%
- %@AI@%#define %@AE@% ScrollUp(n) VioScrollUp(0, 0, -1, -1, n, Blank, hVPS) %@NL@%
- %@AI@%#define %@AE@% SetCursor(x, y) VioSetCurPos((USHORT) x, (USHORT) y, hVPS) %@NL@%
- %@NL@%
- %@AB@%/* Miscellaneous */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If partial ANSI emulation is desired, use:%@NL@%
- %@AB@% VioSetCurPos((USHORT) x, (USHORT) y, hVPS); \%@NL@%
- %@AB@% VioWrtTTY(l->szText, l->cch, hVPS)%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%Blast(l, x, y) VioWrtCharStr(l->szText, l->cch, x, y, hVPS) %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Calculate the number of characters in a page%@NL@%
- %@AB@% For nicer behavior, you can do rounding here%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%CalcChars(pPg, pCh, default) \ %@NL@%
- ((pCh) ? (Max((int) ((pPg) / ((SHORT) pCh)), 0)) : (default))%@NL@%
- %@AI@%#define %@AE@% Value(value) WinQuerySysValue(HWND_DESKTOP, value) %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% File-Local Variables%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HDC hDC; %@AB@%/* Device Context */%@AE@%%@NL@%
- HVPS hVPS; %@AB@%/* Virtual PS */%@AE@%%@NL@%
- int iTopLine; %@AB@%/* PS Line of window corner */%@AE@%%@NL@%
- int iCurCol; %@AB@%/* Current column of window corner */%@AE@%%@NL@%
- int cchPgWidth; %@AB@%/* Width and height of our window */%@AE@%%@NL@%
- int cchPgHeight;%@NL@%
- int cchMaxHorz; %@AB@%/* Scroll bar upper bounds */%@AE@%%@NL@%
- int cchMaxVert; %@NL@%
- BOOL fNeedHorz; %@AB@%/* Do we need the scroll bars or not? */%@AE@%%@NL@%
- BOOL fNeedVert;%@NL@%
- HWND hWndHScroll; %@AB@%/* Window handles of ScrollBar windows */%@AE@%%@NL@%
- HWND hWndVScroll;%@NL@%
- HWND hWndSBParent; %@AB@%/* Could mooch off the value in main(), but won't */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Measurements used to help make the window look nice%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- LONG lChWidth, lChHeight; %@AB@%/* Character size */%@AE@%%@NL@%
- LONG lHSBHeight, lVSBWidth; %@AB@%/* Scrollbar measurements */%@AE@%%@NL@%
- LONG lMiscWidth, lMiscHeight; %@AB@%/* Border, titlebar, ... */%@AE@%%@NL@%
- int iMaxWidth, iMaxHeight; %@AB@%/* Client area bounds */%@AE@%%@NL@%
- int iMaxFrameWidth, iMaxFrameHeight; %@AB@%/* Frame window bounds */%@AE@%%@NL@%
- BOOL fCreated; %@AB@%/* AVIO PS created */%@AE@%%@NL@%
- int rc; %@AB@%/* Return code */%@AE@%%@NL@%
- VIOCURSORINFO vci;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Local prototypes%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- void GetMeasurements(void);%@NL@%
- void Update(USHORT, USHORT, USHORT, BOOL);%@NL@%
- void Refresh(BOOL);%@NL@%
- void WantCursor(BOOL);%@NL@%
- void SetScrollPos(void);%@NL@%
- void SetScrollPosHorz(void);%@NL@%
- void SetScrollPosVert(void);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% The actual routines%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- void GetMeasurements(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get display parameters%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Scroll bar widths and heights%@NL@%
- %@AB@% */%@AE@%%@NL@%
- lHSBHeight = Value(SV_CYHSCROLL);%@NL@%
- lVSBWidth = Value(SV_CXVSCROLL);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Non-PS widths and heights%@NL@%
- %@AB@% */%@AE@%%@NL@%
- lMiscHeight = (Value(SV_CYSIZEBORDER) << 1) %@AB@%/* A border on each side */%@AE@%%@NL@%
- + Value(SV_CYTITLEBAR) %@AB@%/* The title bar... */%@AE@%%@NL@%
- + Value(SV_CYMENU) %@AB@%/* ...and the menu bar */%@AE@%%@NL@%
- + Value(SV_CYBYTEALIGN); %@AB@%/* ...and alignment */%@AE@%%@NL@%
- %@NL@%
- lMiscWidth = (Value(SV_CXSIZEBORDER) << 1);%@AB@%/* A border on each side */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Height and width of characters%@NL@%
- %@AB@% */%@AE@%%@NL@%
- rc = DevQueryCaps(hDC, CAPS_CHAR_HEIGHT, 1L, &lChHeight);%@NL@%
- rc = DevQueryCaps(hDC, CAPS_CHAR_WIDTH, 1L, &lChWidth);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute size of client and frame windows%@NL@%
- %@AB@% */%@AE@%%@NL@%
- iMaxWidth = (AVIO_PS_COLUMNS * (int) lChWidth);%@NL@%
- iMaxHeight = (AVIO_PS_ROWS * (int) lChHeight);%@NL@%
- iMaxFrameWidth = (iMaxWidth + (int) lMiscWidth);%@NL@%
- iMaxFrameHeight = (iMaxHeight + (int) lMiscHeight);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute cursor attributes%@NL@%
- %@AB@% */%@AE@%%@NL@%
- vci.yStart = (USHORT) 0;%@NL@%
- vci.cEnd = (USHORT) lChHeight - 1;%@NL@%
- vci.cx = 0;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioInit(HWND hWndFrame, HWND hWndClient) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize Presentation Space, Device Context, Scroll Bars%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Create the AVIO Presentation Space%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hDC = WinOpenWindowDC(hWndClient);%@NL@%
- VioCreatePS(&hVPS, AVIO_PS_ROWS, AVIO_PS_COLUMNS, 0, CATTRBYTES, 0);%@NL@%
- VioAssociate(hDC, hVPS);%@NL@%
- fCreated = TRUE;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Turn on the cursor and home it%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WantCursor(TRUE);%@NL@%
- SetCursor(0, 0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Snag scroll bar info%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hWndHScroll = WinWindowFromID(hWndFrame, FID_HORZSCROLL);%@NL@%
- hWndVScroll = WinWindowFromID(hWndFrame, FID_VERTSCROLL);%@NL@%
- hWndSBParent = WinQueryWindow(hWndHScroll, QW_PARENT, FALSE);%@NL@%
- fNeedHorz = fNeedVert = TRUE;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get character height in pixels, etc...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GetMeasurements();%@NL@%
- }%@NL@%
- %@NL@%
- void AvioStartup(HWND hWndClient) {%@NL@%
- SWP swp;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the queue%@NL@%
- %@AB@% */%@AE@%%@NL@%
- QueInit();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the screen%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ClearScreen();%@NL@%
- WinQueryWindowPos(hWndClient, &swp);%@NL@%
- AvioSize(hWndClient, WM_NULL, NULL, MPFROM2SHORT(swp.cx, swp.cy));%@NL@%
- }%@NL@%
- %@NL@%
- void AvioScroll(USHORT SB_Command, USHORT usPosition, BOOL fHorizontal) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Process the scroll bar messages%@NL@%
- %@AB@%%@NL@%
- %@AB@% These routines are symmetric; in fact, SB_LINELEFT = SB_LINEUP, etc...%@NL@%
- %@AB@% so one might note that this could be condensed. It's left expanded for%@NL@%
- %@AB@% speed and clarity. I bound the values each way so that we stay inside%@NL@%
- %@AB@% the AVIO presentation space.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (fHorizontal) { %@AB@%/* Horizontal Scroll Bar */%@AE@%%@NL@%
- switch (SB_Command) {%@NL@%
- case SB_LINELEFT:%@NL@%
- iCurCol = LowerBound(iCurCol, 1, 0); break;%@NL@%
- case SB_LINERIGHT:%@NL@%
- iCurCol = UpperBound(iCurCol, 1, cchMaxHorz); break;%@NL@%
- case SB_PAGELEFT:%@NL@%
- iCurCol = LowerBound(iCurCol, cchPgWidth, 0); break;%@NL@%
- case SB_PAGERIGHT:%@NL@%
- iCurCol = UpperBound(iCurCol, cchPgWidth, cchMaxHorz); break;%@NL@%
- case SB_SLIDERTRACK:%@NL@%
- iCurCol = (SHORT) usPosition;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- if (SB_Command != SB_SLIDERTRACK)%@NL@%
- SetScroll(hWndHScroll, iCurCol, cchMaxHorz);%@NL@%
- %@NL@%
- } else { %@AB@%/* Vertical Scroll Bar */%@AE@%%@NL@%
- switch (SB_Command) {%@NL@%
- case SB_LINEUP:%@NL@%
- iTopLine = LowerBound(iTopLine, 1, 0); break;%@NL@%
- case SB_LINEDOWN:%@NL@%
- iTopLine = UpperBound(iTopLine, 1, cchMaxVert); break;%@NL@%
- case SB_PAGEUP:%@NL@%
- iTopLine = LowerBound(iTopLine, cchPgHeight, 0); break;%@NL@%
- case SB_PAGEDOWN:%@NL@%
- iTopLine = UpperBound(iTopLine, cchPgHeight, cchMaxVert); break;%@NL@%
- case SB_SLIDERTRACK:%@NL@%
- iTopLine = (SHORT) usPosition;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- if (SB_Command != SB_SLIDERTRACK)%@NL@%
- SetScroll(hWndVScroll, iTopLine, cchMaxVert);%@NL@%
- }%@NL@%
- Refresh(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT AvioSize(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do the default AVIO sizing, and kyfe a few values%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (!fCreated) return 0L;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute height and width of page in characters%@NL@%
- %@AB@%%@NL@%
- %@AB@% The scrollbars have already been subtracted out,%@NL@%
- %@AB@% since we are called by the client area.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cchPgHeight = CalcChars(SHORT2FROMMP(mp2), lChHeight, DEFPAGEHEIGHT); %@NL@%
- cchPgWidth = CalcChars(SHORT1FROMMP(mp2), lChWidth, DEFPAGEWIDTH);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Adjust scrollbar maximums%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cchMaxVert = Max(AVIO_PS_ROWS - cchPgHeight, 0);%@NL@%
- cchMaxHorz = Max(AVIO_PS_COLUMNS - cchPgWidth, 0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Maintain scrollbar integrity%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fNeedHorz = (cchMaxHorz > 0);%@NL@%
- fNeedVert = (cchMaxVert > 0);%@NL@%
- SetScroll(hWndHScroll, iCurCol = Min(iCurCol, cchMaxHorz), cchMaxHorz);%@NL@%
- SetScroll(hWndVScroll, iTopLine = Min(iTopLine,cchMaxVert), cchMaxVert);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do the Scroll Bar shifting%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Refresh(FALSE);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Now, do the normal AVIO processing%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return WinDefAVioWindowProc(hWnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- %@NL@%
- void Update%@NL@%
- (USHORT usLineNum, USHORT usHowMany, USHORT usStartLine, BOOL fForced) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Updates usHowMany lines starting from usStartLine on screen.%@NL@%
- %@AB@% Starts at saved line usLineNum. If fForced is set, all lines%@NL@%
- %@AB@% in range are displayed; otherwise it's lazy.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT i; %@AB@%/* Loop index */%@AE@%%@NL@%
- USHORT usWhichLine = usLineNum; %@AB@%/* Line to be queried */%@AE@%%@NL@%
- Line l; %@AB@%/* Line to be output */%@AE@%%@NL@%
- %@NL@%
- for (i = usStartLine; i < (usStartLine + usHowMany); i++) {%@NL@%
- l = QueQuery(usWhichLine++); %@AB@%/* Get the line */%@AE@%%@NL@%
- if (!l->fDrawn || fForced) {%@NL@%
- if (l->cch) Blast(l, i, 0); %@AB@%/* Print it out */%@AE@%%@NL@%
- if (!l->fComplete) SetCursor(i, l->cch);%@NL@%
- l->fDrawn = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void Refresh(BOOL fRedraw) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% fRedraw forces full redraw if set %@NL@%
- %@AB@%*/%@AE@%%@NL@%
- SHORT sDelta;%@NL@%
- int static iOldTopLine = -AVIO_PS_ROWS;%@NL@%
- %@NL@%
- VioSetOrg(0, iCurCol, hVPS); %@AB@%/* Get the free AVIO horizontal shift */%@AE@%%@NL@%
- sDelta = iTopLine - iOldTopLine; %@AB@%/* Compute vertical shift */%@AE@%%@NL@%
- if ((Abs(sDelta) < AVIO_PS_ROWS) && !fRedraw) {%@NL@%
- if (sDelta < 0) { %@AB@%/* Scroll Up -- make sDelta positive*/%@AE@%%@NL@%
- ScrollDown(-sDelta);%@NL@%
- Update(iTopLine, -sDelta, 0, TRUE);%@NL@%
- } else { %@AB@%/* Scroll Down by sDelta */%@AE@%%@NL@%
- ScrollUp(sDelta);%@NL@%
- Update(iTopLine + cchPgHeight - sDelta, sDelta,%@NL@%
- cchPgHeight - sDelta, TRUE);%@NL@%
- }%@NL@%
- } else AvioRedraw(); %@AB@%/* Redo the entire screen */%@AE@%%@NL@%
- iOldTopLine = iTopLine;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioClose (void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Termination routines%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Destroy the Presentation Space%@NL@%
- %@AB@% */%@AE@%%@NL@%
- VioAssociate(NULL, hVPS);%@NL@%
- VioDestroyPS(hVPS);%@NL@%
- fCreated = FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioPaint(HWND hWnd) {%@NL@%
- static HPS hPS;%@NL@%
- static RECTL rcl;%@NL@%
- %@NL@%
- hPS = WinBeginPaint(hWnd, NULL, &rcl);%@NL@%
- VioShowPS(AVIO_PS_ROWS, AVIO_PS_COLUMNS, 0, hVPS);%@NL@%
- WinEndPaint(hPS);%@NL@%
- } %@NL@%
- %@NL@%
- MRESULT AvioMinMax(PSWP pSWP) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Control Maximizing%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (pSWP->fs & (SWP_MAXIMIZE | SWP_RESTORE)) {%@NL@%
- if (pSWP->fs & SWP_MAXIMIZE) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save cx, cy values for later origin displacement%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int iOldcx = pSWP->cx;%@NL@%
- int iOldcy = pSWP->cy;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Displace, and change to maximum size%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pSWP->x += (iOldcx - (pSWP->cx = iMaxFrameWidth));%@NL@%
- pSWP->y += (iOldcy - (pSWP->cy = iMaxFrameHeight));%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Now, fix the scroll bars%@NL@%
- %@AB@% */%@AE@%%@NL@%
- AvioAdjustFrame(pSWP);%@NL@%
- return (MRESULT) TRUE;%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioClear(void) { ClearScreen(); }%@NL@%
- %@NL@%
- void AvioAdjustFrame(PSWP pSWP) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Trap WM_ADJUSTWINDOWPOS messages to the frame with this routine.%@NL@%
- %@AB@% Keep the window sized right, and control scrollbar visibility.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL fNeededHorz = fNeedHorz;%@NL@%
- BOOL fNeededVert = fNeedVert;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do scrollbar enable/disable calculations (but don't update the screen)%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (pSWP->fs & SWP_MINIMIZE) fNeedHorz = fNeedVert = FALSE;%@NL@%
- if ((pSWP->cx * pSWP->cy) == 0) return;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do we need them?%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fNeedVert = (pSWP->cy < (SHORT) (iMaxFrameHeight));%@NL@%
- fNeedHorz = (pSWP->cx < (SHORT) (iMaxFrameWidth + VBarWidth()));%@NL@%
- fNeedVert = (pSWP->cy < (SHORT) (iMaxFrameHeight + HBarHeight()));%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do width calculations to make sure we're staying small enough.%@NL@%
- %@AB@% The Tracking Rectangle shouldn't allow us to get too big.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Check if we're stretching too far%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pSWP->cx = Min(pSWP->cx, iMaxFrameWidth + (int) VBarWidth());%@NL@%
- pSWP->cy = Min(pSWP->cy, iMaxFrameHeight + (int) HBarHeight());%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ...if so, fix, then add them!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- AvioSize(NULL, WM_NULL, NULL, MPFROM2SHORT(%@NL@%
- pSWP->cx - (int) (lMiscWidth + VBarWidth()),%@NL@%
- pSWP->cy - (int) (lMiscHeight + HBarHeight()) ));%@NL@%
- %@NL@%
- if (fNeedHorz) {%@NL@%
- if (!fNeededHorz) {%@NL@%
- EnableSB(hWndHScroll);%@NL@%
- UpdateOff(hWndHScroll);%@NL@%
- UpdateFrame(FCF_HORZSCROLL);%@NL@%
- UpdateOn(hWndHScroll);%@NL@%
- }%@NL@%
- } else {%@NL@%
- if (fNeededHorz) {%@NL@%
- DisableSB(hWndHScroll);%@NL@%
- UpdateOff(hWndHScroll);%@NL@%
- UpdateFrame(FCF_HORZSCROLL);%@NL@%
- UpdateOn(hWndHScroll);%@NL@%
- }%@NL@%
- }%@NL@%
- if (fNeedVert) {%@NL@%
- if (!fNeededVert) {%@NL@%
- EnableSB(hWndVScroll);%@NL@%
- UpdateOff(hWndVScroll);%@NL@%
- UpdateFrame(FCF_VERTSCROLL);%@NL@%
- UpdateOn(hWndVScroll);%@NL@%
- }%@NL@%
- } else {%@NL@%
- if (fNeededVert) {%@NL@%
- DisableSB(hWndVScroll);%@NL@%
- UpdateOff(hWndVScroll);%@NL@%
- UpdateFrame(FCF_VERTSCROLL);%@NL@%
- UpdateOn(hWndVScroll);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void AvioTrackFrame(HWND hWnd, MPARAM mpTrackFlags) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Takes action on WM_TRACKFRAME message%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- static TRACKINFO tiTrackInfo;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the tracking information in the TrackInfo structure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSendMsg(hWnd, WM_QUERYTRACKINFO, mpTrackFlags, &tiTrackInfo);%@NL@%
- WinTrackRect(hWnd, NULL, &tiTrackInfo);%@NL@%
- }%@NL@%
- %@NL@%
- void AvioQueryTrackInfo(PTRACKINFO pTI) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Forces the frame to be byte aligned and bounded%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL fMove;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the grid set up for byte alignment%@NL@%
- %@AB@%%@NL@%
- %@AB@% Set cxGrid to half a character width, because sizing%@NL@%
- %@AB@% from the keyboard tries to move by half characters.%@NL@%
- %@AB@% Also, make sure we can move the window freely.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fMove = ((pTI->fs & TF_MOVE) == TF_MOVE);%@NL@%
- pTI->fs |= TF_GRID;%@NL@%
- pTI->cxGrid = (fMove) ? 1 : ((SHORT) lChWidth);%@NL@%
- pTI->cyGrid = (fMove) ? 1 : ((SHORT) lChHeight);%@NL@%
- pTI->cxKeyboard = (SHORT) lChWidth;%@NL@%
- pTI->cyKeyboard = (SHORT) lChHeight;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Bound the frame now%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pTI->ptlMinTrackSize.x = (pTI->cxBorder << 1) + lMiscWidth;%@NL@%
- pTI->ptlMinTrackSize.y = (pTI->cyBorder << 1) + lMiscHeight;%@NL@%
- pTI->ptlMaxTrackSize.x = iMaxFrameWidth + lVSBWidth + (pTI->cxBorder <<1);%@NL@%
- pTI->ptlMaxTrackSize.y = iMaxFrameHeight + lHSBHeight + (pTI->cyBorder <<1);%@NL@%
- }%@NL@%
- %@NL@%
- BOOL AvioUpdateLines(BOOL fPage, BOOL *fPaging) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Update the display%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- int cLines;%@NL@%
- %@NL@%
- cLines = QueUpdateHead(AVIO_PS_ROWS, fPage, *fPaging);%@NL@%
- if (cLines == AVIO_PS_ROWS) *fPaging = TRUE;%@NL@%
- if (cLines > 0) {%@NL@%
- ScrollUp(cLines);%@NL@%
- Update(iTopLine + AVIO_PS_ROWS - cLines, cLines,%@NL@%
- AVIO_PS_ROWS - cLines, TRUE);%@NL@%
- }%@NL@%
- Update(iTopLine, cchPgHeight, 0, FALSE);%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- void AvioRedraw(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clear, then redraw the entire Presentation Space%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- ClearScreen();%@NL@%
- Update(iTopLine, cchPgHeight, 0, TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- void WantCursor(BOOL fYes) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do the underscore cursor%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- vci.attr = (USHORT) (fYes ? 0 : -1);%@NL@%
- vci.yStart = 0;%@NL@%
- vci.cEnd = (USHORT) lChHeight - 1;%@NL@%
- vci.cx = 0;%@NL@%
- VioSetCurType(&vci, hVPS);%@NL@%
- }%@NL@%
- %@NL@%
- void AvioPageUp(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Execute the Page Up instruction%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- int cLines;%@NL@%
- %@NL@%
- cLines = QuePageUp(AVIO_PS_ROWS);%@NL@%
- ScrollDown(cLines);%@NL@%
- Update(iTopLine, cLines, 0, TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BIGBEN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\BIGBEN\BIGBEN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This example uses a few of the many VIO calls.%@NL@%
- %@AB@% * %@NL@%
- %@AB@% * This example puts the time on the screen in large numbers.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Created by Microsoft Corp. 1986%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<os2def.h> %@NL@%
- %@AI@%#define %@AE@%INCL_DOSPROCESS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSDATETIME %@NL@%
- %@AI@%#include %@AE@%<bsedos.h> %@NL@%
- %@AI@%#define %@AE@%INCL_SUB %@NL@%
- %@AI@%#include %@AE@%<bsesub.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% CHAR_WIDTH 8 %@NL@%
- %@AI@%#define %@AE@% CHAR_HEIGHT 7 %@NL@%
- %@NL@%
- CLOCK_ROW 10 %@AB@%/* row to start the clock */%@AE@%%@NL@%
- TOTAL_COLMS 80 %@AB@%/* screen size in colms */%@AE@%%@NL@%
- TOTAL_ROWS 24 %@AB@%/* screen size in rows */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- char BigChars[10][CHAR_HEIGHT][CHAR_WIDTH] = {%@NL@%
- %@NL@%
- {%@NL@%
- " 00 ",%@NL@%
- " 0 0 ",%@NL@%
- " 0 0",%@NL@%
- " 0 0",%@NL@%
- " 0 0",%@NL@%
- " 0 0 ",%@NL@%
- " 00 "%@NL@%
- },%@NL@%
- {%@NL@%
- " 1 ",%@NL@%
- " 1 ",%@NL@%
- " 1 ",%@NL@%
- " 1 ",%@NL@%
- " 1 ",%@NL@%
- " 1 ",%@NL@%
- " 1 "%@NL@%
- }, %@NL@%
- {%@NL@%
- " 2222 ",%@NL@%
- " 2 2",%@NL@%
- " 2",%@NL@%
- " 2 ",%@NL@%
- " 2 ",%@NL@%
- " 2 ",%@NL@%
- " 222222" %@NL@%
- },%@NL@%
- {%@NL@%
- " 33333 ",%@NL@%
- " 3",%@NL@%
- " 3",%@NL@%
- " 333 ",%@NL@%
- " 3",%@NL@%
- " 3",%@NL@%
- " 33333 " %@NL@%
- },%@NL@%
- {%@NL@%
- " 44 ",%@NL@%
- " 4 4 ",%@NL@%
- " 4 4 ",%@NL@%
- " 4 4 ",%@NL@%
- " 444444",%@NL@%
- " 4 ",%@NL@%
- " 4 " %@NL@%
- },%@NL@%
- {%@NL@%
- " 555555",%@NL@%
- " 5 ",%@NL@%
- " 55555 ",%@NL@%
- " 5",%@NL@%
- " 5",%@NL@%
- " 5 5",%@NL@%
- " 5555 " %@NL@%
- },%@NL@%
- {%@NL@%
- " 6 ",%@NL@%
- " 6 ",%@NL@%
- " 6 ",%@NL@%
- " 6666 ",%@NL@%
- " 6 6",%@NL@%
- " 6 6",%@NL@%
- " 6666 " %@NL@%
- },%@NL@%
- {%@NL@%
- " 777777",%@NL@%
- " 7",%@NL@%
- " 7 ",%@NL@%
- " 7 ",%@NL@%
- " 7 ",%@NL@%
- " 7 ",%@NL@%
- " 7 "%@NL@%
- },%@NL@%
- {%@NL@%
- " 8888 ",%@NL@%
- " 8 8",%@NL@%
- " 8 8",%@NL@%
- " 8888 ",%@NL@%
- " 8 8",%@NL@%
- " 8 8",%@NL@%
- " 8888 "%@NL@%
- },%@NL@%
- {%@NL@%
- " 9999 ",%@NL@%
- " 9 9",%@NL@%
- " 9 9",%@NL@%
- " 9999 ",%@NL@%
- " 9 ",%@NL@%
- " 9 ",%@NL@%
- " 9 "%@NL@%
- }%@NL@%
- };%@NL@%
- %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- unsigned rc; %@AB@%/* return code */%@AE@%%@NL@%
- DATETIME Now; %@AB@%/* time struct for DosGetDateTime */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* clear the screen */%@AE@%%@NL@%
- %@NL@%
- VioWrtNCell( " \07", TOTAL_ROWS * TOTAL_COLMS, 0, 0, 0 );%@NL@%
- %@NL@%
- %@AB@%/* paint separators between hours and minutes, and minutes and seconds*/%@AE@%%@NL@%
- %@NL@%
- VioWrtNCell( "|\07", 1, (CLOCK_ROW + 2), 27, 0 );%@NL@%
- VioWrtNCell( "|\07", 1, (CLOCK_ROW + 5), 27, 0 );%@NL@%
- VioWrtNCell( "|\07", 1, (CLOCK_ROW + 2), 52, 0 );%@NL@%
- VioWrtNCell( "|\07", 1, (CLOCK_ROW + 5), 52, 0 );%@NL@%
- %@NL@%
- for (;;) {%@NL@%
- %@NL@%
- %@AB@%/* get the system time */%@AE@%%@NL@%
- %@NL@%
- if (rc = DosGetDateTime( &Now)) {%@NL@%
- %@NL@%
- printf("DosGetDateTime failed, error: %d\n", rc);%@NL@%
- DosExit(EXIT_PROCESS, 0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* write the digits out to the screen */%@AE@%%@NL@%
- %@NL@%
- LoadNumber(Now.hours / 10, 5, CLOCK_ROW);%@NL@%
- LoadNumber(Now.hours % 10, 15, CLOCK_ROW);%@NL@%
- LoadNumber(Now.minutes / 10, 30, CLOCK_ROW);%@NL@%
- LoadNumber(Now.minutes % 10, 40, CLOCK_ROW);%@NL@%
- LoadNumber(Now.seconds / 10, 55, CLOCK_ROW);%@NL@%
- LoadNumber(Now.seconds % 10, 65, CLOCK_ROW);%@NL@%
- %@NL@%
- DosSleep(900L);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* display the digit at the given coordinates */%@AE@%%@NL@%
- %@NL@%
- LoadNumber( dig, x, y )%@NL@%
- unsigned dig;%@NL@%
- unsigned x;%@NL@%
- unsigned y;%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@AB@%/* write a list of char strings to make up a display number */%@AE@%%@NL@%
- %@NL@%
- for (i=0; (i < CHAR_HEIGHT); i++) %@NL@%
- %@NL@%
- %@AB@%/* write a character string starting from the coordinates */%@AE@%%@NL@%
- %@NL@%
- VioWrtCharStr( BigChars[dig][i], CHAR_WIDTH, y++, x, 0);%@NL@%
- } %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BIO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\BIO\BIO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Biorhythm - Utility to compute personal biorhythm charts.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created by Microsoft Corp., 1989%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Purpose:%@NL@%
- %@AB@%* Program entry point, initialization and GetMessage loop.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Arguments:%@NL@%
- %@AB@%* None%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (modified):%@NL@%
- %@AB@%* hAB - Handle to the Anchor Block%@NL@%
- %@AB@%* hMsgQ - Handle to the application's message queue%@NL@%
- %@AB@%* hwndAppFrame - Window handle of parent window's frame%@NL@%
- %@AB@%* hwndKidFrame - Window handle of parent window's frame%@NL@%
- %@AB@%* hwndApp - Window handle of parent window's client area%@NL@%
- %@AB@%* hwndKid - Window handle of child window's client area%@NL@%
- %@AB@%* szAppName[10] - RC file program name (Biorhythm).%@NL@%
- %@AB@%* szKidName[10] - RC file child window name (Legend).%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (referenced):%@NL@%
- %@AB@%* tmFontInfo - Text Metric structure defined during WM_CREATE %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Description:%@NL@%
- %@AB@%* The theory of biorhythms states that life consists of three cycles,%@NL@%
- %@AB@%* physical, emotional and intellectual of 23, 28 and 33 days,%@NL@%
- %@AB@%* respectively. The cycles each begin on the date of birth.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Limits:%@NL@%
- %@AB@%* The intended use of this program is for the 20th and 21st centuries.%@NL@%
- %@AB@%* The calculations of biorhythms will not be accurate outside of this%@NL@%
- %@AB@%* range due to formulae used to compute days between dates.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WIN %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stddef.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"bio.h" %@NL@%
- %@NL@%
- %@AB@%/* Write-once global variables */%@AE@%%@NL@%
- HAB hAB;%@NL@%
- HMQ hMsgQ;%@NL@%
- HWND hwndApp, hwndKid;%@NL@%
- HWND hwndAppFrame, hwndKidFrame;%@NL@%
- char szAppName[10];%@NL@%
- char szKidName[10];%@NL@%
- ULONG AppCtlData = FCF_STANDARD | FCF_VERTSCROLL | FCF_NOBYTEALIGN & ~FCF_SHELLPOSITION;%@NL@%
- ULONG KidCtlData = FCF_TITLEBAR;%@NL@%
- PFNWP OldFrameWndProc;%@NL@%
- %@NL@%
- %@AB@%/* Read-only global variables */%@AE@%%@NL@%
- extern FONTMETRICS tmFontInfo;%@NL@%
- extern SHORT cxLegendField;%@NL@%
- extern SHORT cxDateField;%@NL@%
- %@NL@%
- SHORT cdecl main( )%@NL@%
- {%@NL@%
- QMSG qMsg;%@NL@%
- SHORT dx, dy, x, y;%@NL@%
- SHORT cxSizeBorder;%@NL@%
- SHORT cySizeBorder;%@NL@%
- SHORT cxBorder;%@NL@%
- SHORT cyBorder;%@NL@%
- %@NL@%
- %@AB@%/* Standard initialization. Get anchor block and message queue. */%@AE@%%@NL@%
- hAB = WinInitialize(0);%@NL@%
- hMsgQ = WinCreateMsgQueue( hAB, 0 );%@NL@%
- %@NL@%
- %@AB@%/* Get string constants for parent and child window registration%@NL@%
- %@AB@% and creation from resource string table. */%@AE@%%@NL@%
- WinLoadString( hAB, (HMODULE) NULL, IDS_APPNAME, sizeof(szAppName), szAppName );%@NL@%
- WinLoadString( hAB, (HMODULE) NULL, IDS_KIDNAME, sizeof(szKidName), szKidName );%@NL@%
- %@NL@%
- %@AB@%/* Register parent window. Terminate if error. */%@AE@%%@NL@%
- if ( !WinRegisterClass( hAB, szAppName, BioWndProc,%@NL@%
- CS_CLIPCHILDREN | CS_SIZEREDRAW, 0 ) )%@NL@%
- return( FALSE );%@NL@%
- %@NL@%
- %@AB@%/* Register child window. Terminate if error. */%@AE@%%@NL@%
- if ( !WinRegisterClass( hAB, szKidName, KidWndProc, 0, 0 ) )%@NL@%
- return( FALSE );%@NL@%
- %@NL@%
- %@AB@%/* Create a parent window of class szAppName */%@AE@%%@NL@%
- hwndAppFrame = WinCreateStdWindow(%@NL@%
- HWND_DESKTOP,%@NL@%
- 0L,%@NL@%
- &AppCtlData,%@NL@%
- szAppName,%@NL@%
- NULL,%@NL@%
- 0L,%@NL@%
- (HMODULE) NULL,%@NL@%
- ID_BIO,%@NL@%
- (HWND FAR *)&hwndApp%@NL@%
- );%@NL@%
- %@NL@%
- %@AB@%/* Create a child window of class KidClass */%@AE@%%@NL@%
- hwndKidFrame = WinCreateStdWindow(%@NL@%
- hwndApp,%@NL@%
- FS_BORDER,%@NL@%
- &KidCtlData,%@NL@%
- szKidName,%@NL@%
- szKidName,%@NL@%
- 0L,%@NL@%
- (HMODULE) NULL,%@NL@%
- 0,%@NL@%
- (HWND FAR *)&hwndKid%@NL@%
- );%@NL@%
- %@NL@%
- %@AB@%/* Subclass frame so that minimum window size can be controled */%@AE@%%@NL@%
- OldFrameWndProc = WinSubclassWindow( hwndAppFrame, FrameWndProc );%@NL@%
- %@NL@%
- %@AB@%/* Get the size of the screen and border. Used to place and size window */%@AE@%%@NL@%
- cxSizeBorder = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CXSIZEBORDER );%@NL@%
- cySizeBorder = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER );%@NL@%
- cxBorder = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CXBORDER );%@NL@%
- cyBorder = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYBORDER );%@NL@%
- x = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );%@NL@%
- y = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );%@NL@%
- %@NL@%
- %@AB@%/* Calculate width and height of child window. Must be able to%@NL@%
- %@AB@% display three lines and wide enough for text and corresponding colored%@NL@%
- %@AB@% line. Must take into account titlebar and border vertical sizes. */%@AE@%%@NL@%
- dx = cxLegendField * 2;%@NL@%
- dy = (SHORT)(tmFontInfo.lMaxBaselineExt*3 +%@NL@%
- WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR ) +%@NL@%
- WinQuerySysValue( HWND_DESKTOP, SV_CYBORDER ) * 2);%@NL@%
- %@NL@%
- %@AB@%/* Place and size parent and child windows, then make them visible.%@NL@%
- %@AB@% WinCreateStdWindow does not include position and size arguments.%@NL@%
- %@AB@% Parent window is thin, but full screen high. Child window is placed%@NL@%
- %@AB@% 10 pixels over and up from the parent window's lower left corner. */%@AE@%%@NL@%
- WinSetWindowPos( hwndAppFrame, NULL,%@NL@%
- x-(3*cxDateField)+cxSizeBorder,%@NL@%
- -cySizeBorder,%@NL@%
- (3*cxDateField),%@NL@%
- y+2*cySizeBorder,%@NL@%
- SWP_MOVE | SWP_SIZE | SWP_ACTIVATE | SWP_SHOW );%@NL@%
- WinSetWindowPos( hwndKidFrame, NULL, 10, 10, dx, dy,%@NL@%
- SWP_MOVE | SWP_SIZE | SWP_ACTIVATE | SWP_SHOW );%@NL@%
- %@NL@%
- %@AB@%/* Get messages from application queue and dispatch them for processing */%@AE@%%@NL@%
- while( WinGetMsg( hAB, &qMsg, (HWND)NULL, 0, 0 ) )%@NL@%
- {%@NL@%
- WinDispatchMsg( hAB, &qMsg );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Clean up. All child windows will be destoyed automatically */%@AE@%%@NL@%
- WinDestroyWindow( hwndAppFrame );%@NL@%
- WinDestroyMsgQueue( hMsgQ );%@NL@%
- WinTerminate( hAB );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BIOCMD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\BIO\BIOCMD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BioDlg() - Dialog Box routine.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Purpose:%@NL@%
- %@AB@%* Allow setting of birthdate and viewing date for biorhythm display.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Arguments:%@NL@%
- %@AB@%* hDlg - Handle of Dialog Box owning message%@NL@%
- %@AB@%* message - Message itself%@NL@%
- %@AB@%* mp1 - Extra message-dependent info%@NL@%
- %@AB@%* mp2 - Extra message-dependent info%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (modified):%@NL@%
- %@AB@%* Born - Birthdate in julian days. Read from OS2.INI.%@NL@%
- %@AB@%* SelectDay - Current day being tracked, day is highlighted.%@NL@%
- %@AB@%* This is stored as # days from birthdate.%@NL@%
- %@AB@%* This is initialized to the current date in WM_CREATE.%@NL@%
- %@AB@%* Day - Day number from date born which is top line being%@NL@%
- %@AB@%* displayed. Initially three days before SelectDay.%@NL@%
- %@AB@%* bBorn - Boolean indicating whether valid birtdate entered or%@NL@%
- %@AB@%* defined in OS2.INI. Nothing graphed until valid.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (referenced):%@NL@%
- %@AB@%* hAB - Handle to the Anchor Block%@NL@%
- %@AB@%* szAppName[] - RC file program name (Biorhythm).%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Description:%@NL@%
- %@AB@%* Biorythm cycles start on the date of birth and the state of%@NL@%
- %@AB@%* of these cycles may be viewed on the selected date. A check%@NL@%
- %@AB@%* box is provided to update (record) the birthdate in the WIN.INI%@NL@%
- %@AB@%* file so that it will be automatically available in subsequent%@NL@%
- %@AB@%* sessions.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Limits:%@NL@%
- %@AB@%* Minor error checking is provided when OK is selected to make%@NL@%
- %@AB@%* sure that the dates specified fall in the 20th and 21st%@NL@%
- %@AB@%* centuries. No error checking is attempted to verify correct%@NL@%
- %@AB@%* month or day of month entries. %@NL@%
- %@AB@%*%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WIN %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"bio.h" %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AB@%/* Read-only global variables */%@AE@%%@NL@%
- extern HAB hAB;%@NL@%
- extern char szAppName[];%@NL@%
- %@NL@%
- %@AB@%/* Global variables (modified) */%@AE@%%@NL@%
- extern long SelectDay, Day;%@NL@%
- extern double Born;%@NL@%
- extern BOOL bBorn;%@NL@%
- %@NL@%
- %@AB@%/* Function prototypes */%@AE@%%@NL@%
- void InitBioDlg(HWND);%@NL@%
- void BioDlgCmd(HWND, MPARAM);%@NL@%
- %@NL@%
- MRESULT CALLBACK BioDlg( hDlg, message, mp1, mp2 )%@NL@%
- HWND hDlg;%@NL@%
- USHORT message;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch( message ) {%@NL@%
- case WM_INITDLG:%@NL@%
- InitBioDlg(hDlg);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- BioDlgCmd(hDlg, mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return( WinDefDlgProc( hDlg, message, mp1, mp2 ) );%@NL@%
- %@NL@%
- }%@NL@%
- return 0L;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* About() - General purpose About dialog box.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Purpose:%@NL@%
- %@AB@%* Provide program propoganda.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Arguments:%@NL@%
- %@AB@%* hDlg - Handle of Dialog Box owning message%@NL@%
- %@AB@%* message - Message itself%@NL@%
- %@AB@%* mp1 - Extra message-dependent info%@NL@%
- %@AB@%* mp2 - Extra message-dependent info%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- MRESULT CALLBACK About( hWndDlg, message, mp1, mp2 )%@NL@%
- HWND hWndDlg;%@NL@%
- USHORT message;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch( message )%@NL@%
- {%@NL@%
- case WM_COMMAND:%@NL@%
- switch( LOUSHORT( mp1 ) )%@NL@%
- {%@NL@%
- case DID_OK:%@NL@%
- WinDismissDlg( hWndDlg, TRUE );%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );%@NL@%
- }%@NL@%
- return( FALSE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void InitBioDlg(HWND hDlg) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If valid OS2.INI info, fill in birthdate edit fields%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT year, month;%@NL@%
- double day;%@NL@%
- %@NL@%
- if (bBorn) {%@NL@%
- calendar( Born, (int *)&year, (int *)&month, &day );%@NL@%
- WinSetDlgItemShort( hDlg, ID_BDYEAR, year, FALSE );%@NL@%
- WinSetDlgItemShort( hDlg, ID_BDMONTH, month, FALSE );%@NL@%
- WinSetDlgItemShort( hDlg, ID_BDDAY, (int)day, FALSE );%@NL@%
- }%@NL@%
- %@AB@%/* Display current date or date highlighted */%@AE@%%@NL@%
- calendar( Born+SelectDay, (int *)&year, (int *)&month, &day );%@NL@%
- WinSetDlgItemShort( hDlg, ID_YEAR, year, FALSE );%@NL@%
- WinSetDlgItemShort( hDlg, ID_MONTH, month, FALSE );%@NL@%
- WinSetDlgItemShort( hDlg, ID_DAY, (int)day, FALSE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void BioDlgCmd(HWND hDlg, MPARAM mp1) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Bio Dialog Box routine WM_COMMAND processor%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT year, month, iDay;%@NL@%
- double day;%@NL@%
- char szBuf[10];%@NL@%
- %@NL@%
- switch( LOUSHORT( mp1 ) ) {%@NL@%
- case DID_OK:%@NL@%
- %@AB@%/* Get the birthday edit field values */%@AE@%%@NL@%
- WinQueryDlgItemShort( hDlg, ID_BDYEAR, &year, FALSE );%@NL@%
- WinQueryDlgItemShort( hDlg, ID_BDMONTH, &month, FALSE );%@NL@%
- WinQueryDlgItemShort( hDlg, ID_BDDAY, &iDay, FALSE );%@NL@%
- day = (double)iDay;%@NL@%
- %@AB@%/* Check that date is within acceptable range */%@AE@%%@NL@%
- if (year<1900 || year>2100) {%@NL@%
- WinMessageBox( HWND_DESKTOP, hDlg,%@NL@%
- "Dates valid from 1900-2100",%@NL@%
- "Birthday!", 0,%@NL@%
- MB_OK | MB_ICONEXCLAMATION );%@NL@%
- break;%@NL@%
- }%@NL@%
- %@AB@%/* Get julian date of birth date */%@AE@%%@NL@%
- Born = julian( year, month, day );%@NL@%
- %@NL@%
- %@AB@%/* Write birth date to OS2.INI if check box checked */%@AE@%%@NL@%
- if (WinSendDlgItemMsg(hDlg, ID_OS2INI, BM_QUERYCHECK, 0L, 0L)) {%@NL@%
- sprintf(szBuf, "%d", year);%@NL@%
- WinWriteProfileString( hAB, szAppName, "Year", szBuf );%@NL@%
- sprintf(szBuf, "%d", month);%@NL@%
- WinWriteProfileString( hAB, szAppName, "Month", szBuf );%@NL@%
- sprintf(szBuf, "%d", (int)day);%@NL@%
- WinWriteProfileString( hAB, szAppName, "Day", szBuf );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Get selected day of interest edit field values */%@AE@%%@NL@%
- WinQueryDlgItemShort( hDlg, ID_YEAR, &year, FALSE );%@NL@%
- WinQueryDlgItemShort( hDlg, ID_MONTH, &month, FALSE );%@NL@%
- WinQueryDlgItemShort( hDlg, ID_DAY, &iDay, FALSE );%@NL@%
- day = (double)iDay;%@NL@%
- %@AB@%/* Check that date is within acceptable range */%@AE@%%@NL@%
- if (year<1900 || year>2100) {%@NL@%
- WinMessageBox( HWND_DESKTOP, hDlg,%@NL@%
- "Dates valid from 1900-2100",%@NL@%
- "Display Date!", 0,%@NL@%
- MB_OK | MB_ICONEXCLAMATION );%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Compute number of days since birth */%@AE@%%@NL@%
- SelectDay = (long)(julian( year, month, day ) - Born);%@NL@%
- %@AB@%/* Top date of display is 3 days before selected day */%@AE@%%@NL@%
- Day = SelectDay - 3;%@NL@%
- %@AB@%/* Got a valid birthdate, enable all routines */%@AE@%%@NL@%
- bBorn = TRUE;%@NL@%
- WinDismissDlg( hDlg, TRUE );%@NL@%
- break;%@NL@%
- %@NL@%
- case DID_CANCEL:%@NL@%
- %@AB@%/* Exit and ignore entries */%@AE@%%@NL@%
- WinDismissDlg( hDlg, FALSE );%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BIOPAINT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\BIO\BIOPAINT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% biopaint.c - WM_PAINT processing and calendar conversion routines%@NL@%
- %@AB@%%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_WIN %@NL@%
- %@AI@%#define %@AE@%INCL_GPI %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"bio.h" %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AB@%/* Read-only global variables */%@AE@%%@NL@%
- extern double Born;%@NL@%
- extern long Day, SelectDay;%@NL@%
- extern BOOL bBorn;%@NL@%
- extern FONTMETRICS tmFontInfo;%@NL@%
- extern int LinesPerPage;%@NL@%
- extern RECTL rclClient;%@NL@%
- extern SHORT cxDateField;%@NL@%
- %@NL@%
- %@AB@%/* Read-only static variables */%@AE@%%@NL@%
- static double Cycle[] = { 23.0, 28.0, 33.0 };%@NL@%
- static char cDayOfWeek[] = "MTWTFSS";%@NL@%
- extern LONG Color[];%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* APPPaint() - Parent window WM_PAINT processing routine.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Purpose:%@NL@%
- %@AB@%* Routine to graph biorhythm cycles and tabulate dates.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Arguments:%@NL@%
- %@AB@%* hWnd - Handle of Window owning message%@NL@%
- %@AB@%* message - Message itself%@NL@%
- %@AB@%* mp1 - Extra message-dependent info%@NL@%
- %@AB@%* mp2 - Extra message-dependent info%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (static):%@NL@%
- %@AB@%* Cycle[] - Array holding period for phy/emot/int: 23,28,33%@NL@%
- %@AB@%* cDayOfWeek[] - Array of chars holding first letter of days of week.%@NL@%
- %@AB@%* Color[] - Set of colored pens used to identify cycles.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (referenced):%@NL@%
- %@AB@%* Born - Birthdate in julian days. Read from WIN.INI.%@NL@%
- %@AB@%* SelectDay - Current day being tracked, day is highlighted.%@NL@%
- %@AB@%* This is stored as the number of days from birthdate.%@NL@%
- %@AB@%* Initialized to present day in WM_CREATE processing.%@NL@%
- %@AB@%* Day - Day number from date born which is top line being%@NL@%
- %@AB@%* displayed. Initially three days before SelectDay.%@NL@%
- %@AB@%* bBorn - Boolean indicating whether valid birtdate entered or%@NL@%
- %@AB@%* rclClient - Size of client area defined by WM_SIZE message%@NL@%
- %@AB@%* LinesPerPage - Number of system font lines on client area, defined%@NL@%
- %@AB@%* by WM_SIZE message handling%@NL@%
- %@AB@%* tmFontInfo - Text Metric structure defined during WM_CREATE %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Description:%@NL@%
- %@AB@%* Tabulates dates and graphs cycles. On color displays, weekends%@NL@%
- %@AB@%* are written in red. The update rectangle is used to minimize%@NL@%
- %@AB@%* repaint time of affected client area.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- VOID APIENTRY APPPaint( hWnd )%@NL@%
- HWND hWnd;%@NL@%
- {%@NL@%
- HPS hPS;%@NL@%
- POINTL ptl;%@NL@%
- int y, i;%@NL@%
- int start, last;%@NL@%
- char szDay[16];%@NL@%
- int Amplitude, offset;%@NL@%
- int year, month;%@NL@%
- double day;%@NL@%
- RECTL rc, rcClip;%@NL@%
- int DayOfWeek;%@NL@%
- HRGN hrgnClip;%@NL@%
- POINTL ptlTextBox[5];%@NL@%
- %@NL@%
- hPS = WinBeginPaint( hWnd, NULL, &rcClip );%@NL@%
- %@NL@%
- %@AB@%/* Erase client area */%@AE@%%@NL@%
- WinQueryWindowRect( hWnd, &rc );%@NL@%
- WinFillRect( hPS, &rc, CLR_WHITE );%@NL@%
- %@NL@%
- %@AB@%/* Label parts of table and graph. */%@AE@%%@NL@%
- ptl.y = rclClient.yTop - tmFontInfo.lMaxBaselineExt + %@AB@%/* Top line */%@AE@%%@NL@%
- tmFontInfo.lMaxDescender;%@NL@%
- ptl.x = 0;%@NL@%
- GpiCharStringAt( hPS, &ptl, 7L, (PCH)" DATE" );%@NL@%
- ptl.x = cxDateField + tmFontInfo.lAveCharWidth;%@NL@%
- GpiCharStringAt( hPS, &ptl, 3L, (PCH)"LOW" );%@NL@%
- GpiQueryTextBox( hPS, 4L, "HIGH", TXTBOX_COUNT, ptlTextBox );%@NL@%
- ptl.x = rclClient.xRight - ptlTextBox[TXTBOX_CONCAT].x - tmFontInfo.lAveCharWidth;%@NL@%
- GpiCharStringAt( hPS, &ptl, 4L, (PCH)"HIGH" );%@NL@%
- %@NL@%
- %@AB@%/* Underline labels from left to right across client area */%@AE@%%@NL@%
- ptl.y = rclClient.yTop - tmFontInfo.lMaxBaselineExt;%@NL@%
- ptl.x = 0;%@NL@%
- GpiMove( hPS, &ptl );%@NL@%
- ptl.x = rclClient.xRight;%@NL@%
- GpiLine( hPS, &ptl );%@NL@%
- %@NL@%
- %@AB@%/* Draw a vertical line separator between dates and cycles */%@AE@%%@NL@%
- ptl.y = rclClient.yTop;%@NL@%
- ptl.x = cxDateField;%@NL@%
- GpiMove( hPS, &ptl );%@NL@%
- ptl.y = rclClient.yBottom;%@NL@%
- GpiLine( hPS, &ptl );%@NL@%
- %@NL@%
- %@AB@%/* Draw a dotted vertical center line to reference cycles */%@AE@%%@NL@%
- GpiSetLineType( hPS, LINETYPE_DOT );%@NL@%
- ptl.x = (cxDateField + rclClient.xRight) / 2;%@NL@%
- GpiMove( hPS, &ptl );%@NL@%
- ptl.y = rclClient.yTop;%@NL@%
- GpiLine( hPS, &ptl );%@NL@%
- %@AB@%/* (Should not have to restore line type after EndPaint) */%@AE@%%@NL@%
- GpiSetLineType( hPS, LINETYPE_DEFAULT );%@NL@%
- %@NL@%
- %@AB@%/* Update only the range of lines which fall into update rectangle */%@AE@%%@NL@%
- start = (int)((rclClient.yTop - rcClip.yTop) / tmFontInfo.lMaxBaselineExt);%@NL@%
- if (start<1)%@NL@%
- start = 1;%@NL@%
- last = (int)((rclClient.yTop - rcClip.yBottom) / tmFontInfo.lMaxBaselineExt);%@NL@%
- if (last>(LinesPerPage-1))%@NL@%
- last = LinesPerPage-1;%@NL@%
- %@NL@%
- %@AB@%/* Set clip rectangle to completely draw entire rectangle representing%@NL@%
- %@AB@% each date affected. Start drawing one day before and after%@NL@%
- %@AB@% (outside clip rectangle) so that cycle lines will connect correctly%@NL@%
- %@AB@% with unaffected lines. */%@AE@%%@NL@%
- rcClip.yTop = rclClient.yTop - start*tmFontInfo.lMaxBaselineExt;%@NL@%
- start--;%@NL@%
- last++;%@NL@%
- rcClip.yBottom = rclClient.yTop - last*tmFontInfo.lMaxBaselineExt + 1;%@NL@%
- hrgnClip = GpiCreateRegion( hPS, 1L, &rcClip );%@NL@%
- GpiSetClipRegion( hPS, hrgnClip, &hrgnClip );%@NL@%
- %@NL@%
- %@AB@%/* List days and date */%@AE@%%@NL@%
- for (y=start; y<=last; y++) {%@NL@%
- %@AB@%/* Get the calendar date from julian day */%@AE@%%@NL@%
- calendar( Born+Day+y-1, &year, &month, &day );%@NL@%
- %@AB@%/* Get offset into days of the week initials array */%@AE@%%@NL@%
- DayOfWeek = (int)((LONG)(Born+Day+y) % 7);%@NL@%
- %@AB@%/* Assemble each of the parts in a buffer */%@AE@%%@NL@%
- sprintf(szDay, " %02d-%02d-%02d",%@NL@%
- month, (int)day, year - (trunc4((double)year / 100)*100) );%@NL@%
- %@AB@%/* If color available, draw weekends in red */%@AE@%%@NL@%
- if (DayOfWeek > 4)%@NL@%
- GpiSetColor( hPS, CLR_RED );%@NL@%
- ptl.x = 0;%@NL@%
- ptl.y = rclClient.yTop - ((y+1)*tmFontInfo.lMaxBaselineExt -%@NL@%
- tmFontInfo.lMaxDescender);%@NL@%
- GpiCharStringAt( hPS, &ptl, 1L, (PCH)&cDayOfWeek[DayOfWeek] );%@NL@%
- GpiQueryWidthTable( hPS, (LONG)'W', 1L, &ptl.x );%@NL@%
- GpiCharStringAt( hPS, &ptl, 9L, (PCH)szDay );%@NL@%
- GpiSetColor( hPS, CLR_BLACK );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Amplitude of sin wave is half client area minus space for dates */%@AE@%%@NL@%
- Amplitude = (int)((rclClient.xRight - cxDateField - tmFontInfo.lAveCharWidth) >> 1);%@NL@%
- %@AB@%/* Move to right, make room for column of dates */%@AE@%%@NL@%
- offset = (int)(Amplitude + cxDateField + tmFontInfo.lAveCharWidth - (tmFontInfo.lAveCharWidth>>1));%@NL@%
- for (i=0; i<3 && bBorn; i++ ) {%@NL@%
- GpiSetColor( hPS, Color[i] );%@NL@%
- for (y=start; y<=last; y++) {%@NL@%
- ptl.x = (int)(sin( (y+Day-1)/Cycle[i]*2*3.14159 ) * Amplitude + offset);%@NL@%
- ptl.y = rclClient.yTop - (y*tmFontInfo.lMaxBaselineExt +%@NL@%
- tmFontInfo.lMaxBaselineExt/2);%@NL@%
- if ((y+Day-1 > 0) && (y>start))%@NL@%
- GpiLine( hPS, &ptl );%@NL@%
- else%@NL@%
- GpiMove( hPS, &ptl );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Draw highlight on selected day if visible. */%@AE@%%@NL@%
- if ((SelectDay >= Day) && (SelectDay - Day < LinesPerPage - 1)) {%@NL@%
- rc.xRight = rclClient.xRight;%@NL@%
- rc.xLeft = rclClient.xLeft;%@NL@%
- rc.yTop = rclClient.yTop - (int)(SelectDay - Day + 1) * tmFontInfo.lMaxBaselineExt;%@NL@%
- rc.yBottom = rc.yTop - tmFontInfo.lMaxBaselineExt + 1;%@NL@%
- WinInvertRect( hPS, &rc );%@NL@%
- }%@NL@%
- %@NL@%
- WinEndPaint( hPS );%@NL@%
- %@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* julian() - Compute julian date from Gregorian calendar date.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Purpose:%@NL@%
- %@AB@%* Provide a standard time base.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Arguments:%@NL@%
- %@AB@%* year - Calendar year%@NL@%
- %@AB@%* month - Calendar month%@NL@%
- %@AB@%* day - Calendar day and fraction%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Return Value:%@NL@%
- %@AB@%* double - Julian date converted%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Description:%@NL@%
- %@AB@%* Convert Gregorian dates to Julian Days. Refer to Alamanac for%@NL@%
- %@AB@%* Computers (1978), p. B2, Naval Observatory Pub.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Limits:%@NL@%
- %@AB@%* Valid between ~1900 and 2099.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- double PASCAL julian (year, month, day)%@NL@%
- int year, month;%@NL@%
- double day;%@NL@%
- {%@NL@%
- double dj;%@NL@%
- double fracDay, intDay;%@NL@%
- %@NL@%
- fracDay = modf(day, &intDay);%@NL@%
- dj = (long)367*year - 7*(year + (month+9) / 12) / 4 + 275*month / 9 +%@NL@%
- intDay + 1721013.5 + fracDay;%@NL@%
- return dj;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* calendar() - Compute Gregorian calendar date from julian date.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Purpose:%@NL@%
- %@AB@%* Provide a standard time base.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Arguments:%@NL@%
- %@AB@%* juldate - Julian date to convert%@NL@%
- %@AB@%* year - Calendar year result%@NL@%
- %@AB@%* month - Calendar month result%@NL@%
- %@AB@%* day - Calendar day and fraction result%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Return Value:%@NL@%
- %@AB@%* void%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (modified):%@NL@%
- %@AB@%* none%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Globals (referenced):%@NL@%
- %@AB@%* none%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Description:%@NL@%
- %@AB@%* Convert Julian Days to Gregorian date. Refer to Astronomical%@NL@%
- %@AB@%* Formulae for Calculators (1979), p. 23, by Jean Meeus.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Limits:%@NL@%
- %@AB@%* Valid for positive Julian Day values.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- void PASCAL calendar (juldate, year, month, day)%@NL@%
- double juldate;%@NL@%
- int *year;%@NL@%
- int *month;%@NL@%
- double *day;%@NL@%
- {%@NL@%
- long b, c, d, e, z, alf;%@NL@%
- %@NL@%
- juldate = juldate + 0.5;%@NL@%
- z = trunc4(juldate);%@NL@%
- alf = trunc4((z - 1867216.25)/36524.25);%@NL@%
- b = z + 1 + alf - alf / 4 + 1524;%@NL@%
- c = trunc4((b - 122.1)/365.25);%@NL@%
- d = 365*c + c / 4;%@NL@%
- e = trunc4((b - d)/30.6001);%@NL@%
- *day = b - d - trunc4(30.6001*e) + juldate - z;%@NL@%
- if (e > 13)%@NL@%
- *month = (int)e - 13;%@NL@%
- else%@NL@%
- *month = (int)e - 1;%@NL@%
- if (*month > 2)%@NL@%
- *year = (int)c - 4716;%@NL@%
- else%@NL@%
- *year = (int)c - 4715;%@NL@%
- }%@NL@%
- %@NL@%
- long PASCAL trunc4( dflValue )%@NL@%
- double dflValue;%@NL@%
- {%@NL@%
- double intValue;%@NL@%
- modf(dflValue, &intValue);%@NL@%
- return (long)intValue;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BMAP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\MSNGR\BMAP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** MODULE Header ******************************\%@NL@%
- %@AB@%* Module Name: bmap.c - Messenger application - bitmap module%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 8/1/89 sanfords%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"msngr.h" %@NL@%
- %@AI@%#include %@AE@%"string.h" %@NL@%
- %@AI@%#ifdef %@AE@%SLOOP %@NL@%
- %@AI@%#define %@AE@%BITMAPINFOHEADER2 BITMAPINFOHEADER %@NL@%
- %@AI@%#define %@AE@%PBITMAPINFOHEADER2 PBITMAPINFOHEADER %@NL@%
- %@AI@%#define %@AE@%BITMAPINFO2 BITMAPINFO %@NL@%
- %@AI@%#define %@AE@%PBITMAPINFO2 PBITMAPINFO %@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- typedef struct _CDATA {%@NL@%
- RECTL rcl;%@NL@%
- HBITMAP hbm;%@NL@%
- BOOL fSelect;%@NL@%
- BOOL fSelecting;%@NL@%
- NPUSERLIST npUL;%@NL@%
- } CDATA;%@NL@%
- typedef CDATA *NPCDATA;%@NL@%
- %@NL@%
- %@NL@%
- typedef struct _PKT {%@NL@%
- HBITMAP hbm;%@NL@%
- SHORT cx;%@NL@%
- SHORT cy;%@NL@%
- char szName[MAX_NAMESTR + 1];%@NL@%
- } PKT;%@NL@%
- typedef PKT *NPPKT;%@NL@%
- %@NL@%
- extern HWND hwndMsngr;%@NL@%
- extern SHORT cyText;%@NL@%
- extern HAB hab;%@NL@%
- extern HSZ hszAppName;%@NL@%
- extern HSZ hszEmailName;%@NL@%
- extern char szEmailName[];%@NL@%
- extern HWND hwndLB;%@NL@%
- extern ITEMLIST msgTopicItemList[];%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * local procs%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MRESULT bmpInit(HWND hwnd, NPPKT ppktInit);%@NL@%
- MRESULT sndBmapInit(HWND hwnd, NPUSERLIST pUserItem);%@NL@%
- BOOL sndBmap(NPCDATA pcd);%@NL@%
- HBITMAP SnapRegion(HPS hps, PRECTL prcl);%@NL@%
- void DrawRgn(HPS hps, PRECTL prcl);%@NL@%
- void SortRect(PRECTL prcl, PRECTL prclSorted);%@NL@%
- HDC CreateDC(PSZ lpszDriver, HDC hdcCompat);%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%max(a,b) (((a) > (b)) ? (a) : (b)) %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * file globals%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ATOM fmtBmapPkt;%@NL@%
- HPOINTER hptrSelBmap = 0;%@NL@%
- HPOINTER hptrBmap = 0;%@NL@%
- %@NL@%
- void InitBmapModule()%@NL@%
- {%@NL@%
- fmtBmapPkt = WinAddAtom(WinQuerySystemAtomTable(), SZBMAPDATA);%@NL@%
- hptrSelBmap = WinLoadPointer(HWND_DESKTOP, (HMODULE)NULL, IDR_SELBMAP);%@NL@%
- hptrBmap = WinLoadPointer(HWND_DESKTOP, NULL, IDD_GETBITMAP);%@NL@%
- } %@NL@%
- %@NL@%
- void CloseBmapModule()%@NL@%
- {%@NL@%
- WinDeleteAtom(WinQuerySystemAtomTable(), fmtBmapPkt);%@NL@%
- WinDestroyPointer(hptrSelBmap);%@NL@%
- WinDestroyPointer(hptrBmap);%@NL@%
- }%@NL@%
- %@NL@%
- HDMGDATA bmpXfer(pXferInfo)%@NL@%
- PXFERINFO pXferInfo;%@NL@%
- {%@NL@%
- PBYTE pbuf;%@NL@%
- PKT pkt;%@NL@%
- PBITMAPINFO pbmi;%@NL@%
- HDC hdc;%@NL@%
- HPS hpsMem;%@NL@%
- SIZEL size;%@NL@%
- %@NL@%
- if (pXferInfo->usFmt != fmtBmapPkt)%@NL@%
- return(DDE_NOTPROCESSED);%@NL@%
- %@NL@%
- if (pXferInfo->usType == XTYP_POKE) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * we have bitmap bits...stick them into pkt.hbm.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pbuf = DdeAccessData(pXferInfo->hDmgData);%@NL@%
- %@NL@%
- DdeCopyBlock(pbuf, (PBYTE)&pkt.szName[0], MAX_NAMESTR + 1L);%@NL@%
- pbmi = (PBITMAPINFO)(pbuf + MAX_NAMESTR + 1);%@NL@%
- %@NL@%
- pkt.cx = pbmi->cx;%@NL@%
- pkt.cy = pbmi->cy;%@NL@%
- size.cx = (LONG)pkt.cx;%@NL@%
- size.cy = (LONG)pkt.cy;%@NL@%
- hdc = CreateDC((PSZ)"MEMORY", (HDC)NULL);%@NL@%
- hpsMem = GpiCreatePS(hab, hdc, &size,%@NL@%
- PU_ARBITRARY | GPIT_NORMAL | GPIA_ASSOC );%@NL@%
- pkt.hbm = GpiCreateBitmap(hpsMem, (PBITMAPINFOHEADER2)pbmi, CBM_INIT,%@NL@%
- (PBYTE)&pbmi->argbColor[1 << pbmi->cBitCount],%@NL@%
- (PBITMAPINFO2)pbmi);%@NL@%
- GpiAssociate(hpsMem, NULL);%@NL@%
- GpiDestroyPS(hpsMem);%@NL@%
- DevCloseDC(hdc);%@NL@%
- DdeFreeData(pXferInfo->hDmgData);%@NL@%
- %@NL@%
- WinLoadDlg(HWND_DESKTOP, hwndMsngr, BmpDlgProc, 0L, IDD_GETBITMAP,%@NL@%
- (PVOID)&pkt);%@NL@%
- return(1);%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This is the proc used for receiving a bitmap%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MRESULT EXPENTRY BmpDlgProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- HBITMAP hbm;%@NL@%
- HPS hps;%@NL@%
- WRECT wrc;%@NL@%
- %@NL@%
- switch(msg) {%@NL@%
- case WM_INITDLG:%@NL@%
- return(bmpInit(hwnd, (NPPKT)(SHORT)mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- if (hbm = ((NPPKT)WinQueryWindowUShort(hwnd, QWS_USER))->hbm)%@NL@%
- GpiDeleteBitmap(hbm);%@NL@%
- WinFreeMem(hheap, (NPBYTE)WinQueryWindowUShort(hwnd, QWS_USER),%@NL@%
- sizeof(PKT));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_WINDOWPOSCHANGED:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * hide the OK button when minimized since it messes up the icon.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((LONG)mp2 & AWP_MINIMIZED)%@NL@%
- WinShowWindow(WinWindowFromID(hwnd, MBID_OK), FALSE);%@NL@%
- else if ((LONG)mp2 & AWP_RESTORED)%@NL@%
- WinShowWindow(WinWindowFromID(hwnd, MBID_OK), TRUE);%@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- WinDestroyWindow(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- WinDefDlgProc(hwnd, msg, mp1, mp2);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * draw the bitmap just above the OK button.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- WinQueryWindowRect(WinWindowFromID(hwnd, MBID_OK), (PRECTL)&wrc);%@NL@%
- WinMapWindowPoints(WinWindowFromID(hwnd, MBID_OK), hwnd, (PPOINTL)&wrc, 2);%@NL@%
- wrc.yBottom = wrc.yTop + cyText / 2;%@NL@%
- hbm = ((NPPKT)WinQueryWindowUShort(hwnd, QWS_USER))->hbm;%@NL@%
- WinDrawBitmap(hps, hbm, (PRECTL)NULL, (PPOINTL)&wrc, 0L, 0L, DBM_NORMAL);%@NL@%
- WinReleasePS(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- MRESULT bmpInit(hwnd, ppktInit)%@NL@%
- HWND hwnd;%@NL@%
- NPPKT ppktInit;%@NL@%
- {%@NL@%
- char szTitle[MAX_TITLESTR];%@NL@%
- WRECT wrc;%@NL@%
- NPPKT ppkt;%@NL@%
- SHORT cxMin;%@NL@%
- %@NL@%
- if (!(ppkt = (NPPKT)WinAllocMem(hheap, sizeof(PKT))))%@NL@%
- return(1); %@NL@%
- *ppkt = *ppktInit;%@NL@%
- WinSetWindowUShort(hwnd, QWL_USER, (USHORT)ppkt);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This is required because currently, automatic ICON resource loading%@NL@%
- %@AB@% * is not supported for dialogs.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSendMsg(hwnd, WM_SETICON, (MPARAM)hptrBmap, 0L);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Set up title.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowText(hwnd, MAX_TITLESTR, (PSZ)szTitle);%@NL@%
- lstrcat(szTitle, szTitle, ppkt->szName);%@NL@%
- WinSetWindowText(hwnd, (PSZ)szTitle);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * resize the dialog so the bitmap just fits.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowRect(hwnd, (PRECTL)&wrc);%@NL@%
- cxMin = wrc.xRight;%@NL@%
- WinQueryWindowRect(WinWindowFromID(hwnd, MBID_OK), (PRECTL)&wrc);%@NL@%
- WinMapWindowPoints(WinWindowFromID(hwnd, MBID_OK), hwnd, (PPOINTL)&wrc, 2);%@NL@%
- WinSetWindowPos(hwnd, NULL, 0, 0, max(wrc.xLeft * 2 + ppkt->cx, cxMin),%@NL@%
- wrc.yTop + ppkt->cy + cyText +%@NL@%
- (SHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR), SWP_SIZE);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY SendBitmapDlgProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- NPCDATA pcd;%@NL@%
- POINTL pt;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- pcd = (NPCDATA)WinQueryWindowUShort(hwnd, QWS_USER);%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_INITDLG:%@NL@%
- return(sndBmapInit(hwnd, (NPUSERLIST)(SHORT)mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- WinFreeMem(hheap, (NPBYTE)pcd, sizeof(CDATA));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (LOUSHORT(mp1)) {%@NL@%
- case IDC_SENDBITMAP:%@NL@%
- if (sndBmap(pcd))%@NL@%
- WinDismissDlg(hwnd, 0);%@NL@%
- break;%@NL@%
- %@NL@%
- case MBID_CANCEL: %@NL@%
- WinDismissDlg(hwnd, 0);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDC_SELECT:%@NL@%
- pcd->fSelect = TRUE;%@NL@%
- WinSetCapture(HWND_DESKTOP, hwnd);%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1DOWN:%@NL@%
- if (pcd->fSelect) {%@NL@%
- if (pcd->hbm) {%@NL@%
- GpiDeleteBitmap(pcd->hbm);%@NL@%
- pcd->hbm = NULL;%@NL@%
- }%@NL@%
- WinSetRect(hab, &pcd->rcl, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1),%@NL@%
- SHORT1FROMMP(mp1), SHORT2FROMMP(mp1));%@NL@%
- WinMapWindowPoints(hwnd, (HWND)HWND_DESKTOP, (PPOINTL)&pcd->rcl, 2);%@NL@%
- hps = WinGetScreenPS(HWND_DESKTOP);%@NL@%
- DrawRgn(hps, &pcd->rcl);%@NL@%
- WinReleasePS(hps);%@NL@%
- pcd->fSelecting = TRUE;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MOUSEMOVE:%@NL@%
- if (pcd->fSelect) {%@NL@%
- WinSetPointer(HWND_DESKTOP, hptrSelBmap);%@NL@%
- } else {%@NL@%
- WinSetPointer(HWND_DESKTOP,%@NL@%
- WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE));%@NL@%
- }%@NL@%
- if (pcd->fSelecting) {%@NL@%
- hps = WinGetScreenPS(HWND_DESKTOP);%@NL@%
- DrawRgn(hps, &pcd->rcl); %@AB@%/* erase old rect */%@AE@%%@NL@%
- pt.x = SHORT1FROMMP(mp1);%@NL@%
- pt.y = SHORT2FROMMP(mp1);%@NL@%
- WinMapWindowPoints(hwnd, HWND_DESKTOP, &pt, 1);%@NL@%
- pcd->rcl.xRight = pt.x;%@NL@%
- pcd->rcl.yTop = pt.y;%@NL@%
- DrawRgn(hps, &pcd->rcl); %@AB@%/* draw new one */%@AE@%%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1UP:%@NL@%
- if (pcd->fSelecting) {%@NL@%
- WinSetCapture(HWND_DESKTOP, (HWND)NULL);%@NL@%
- hps = WinGetScreenPS(HWND_DESKTOP);%@NL@%
- DrawRgn(hps, &pcd->rcl);%@NL@%
- pcd->hbm = SnapRegion(hps, &pcd->rcl);%@NL@%
- WinReleasePS(hps);%@NL@%
- pcd->fSelecting = FALSE;%@NL@%
- pcd->fSelect = FALSE;%@NL@%
- WinEnableWindow(WinWindowFromID(hwnd, IDC_SENDBITMAP),%@NL@%
- !WinIsRectEmpty(hab, &pcd->rcl));%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * returns fFailed%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MPARAM sndBmapInit(hwnd, pUserItem)%@NL@%
- HWND hwnd;%@NL@%
- NPUSERLIST pUserItem;%@NL@%
- {%@NL@%
- NPCDATA pcd;%@NL@%
- char szTitle[MAX_TITLESTR];%@NL@%
- char szName[MAX_NAMESTR];%@NL@%
- %@NL@%
- if (!(pcd = (NPCDATA)WinAllocMem(hheap, sizeof(CDATA))))%@NL@%
- return(1);%@NL@%
- WinSetRectEmpty(hab, &pcd->rcl);%@NL@%
- pcd->hbm = NULL;%@NL@%
- pcd->fSelect = FALSE;%@NL@%
- pcd->fSelecting = FALSE;%@NL@%
- pcd->npUL = pUserItem;%@NL@%
- if (pcd->npUL->hConvMsg == NULL) {%@NL@%
- NotifyUser(SZCANTCONNECT);%@NL@%
- return(1);%@NL@%
- }%@NL@%
- WinQueryWindowText(hwnd, MAX_TITLESTR, szTitle);%@NL@%
- DdeGetHszString(pcd->npUL->hsz, szName, (LONG)MAX_NAMESTR);%@NL@%
- lstrcat(szTitle, szTitle, szName);%@NL@%
- WinSetWindowText(hwnd, (PSZ)szTitle);%@NL@%
- WinSetWindowUShort(hwnd, QWS_USER, (USHORT)pcd);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- BOOL sndBmap(pcd)%@NL@%
- NPCDATA pcd;%@NL@%
- {%@NL@%
- BITMAPINFOHEADER bih;%@NL@%
- SHORT cbBuffer, cbBitmapInfo;%@NL@%
- PBYTE pbBuffer;%@NL@%
- PBITMAPINFO pbmi;%@NL@%
- PSZ pszName;%@NL@%
- SEL sel;%@NL@%
- HPS hps;%@NL@%
- HDC hdc;%@NL@%
- SIZEL size;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Compute the size of the image-data buffer and the bitmap information%@NL@%
- %@AB@% * structure.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GpiQueryBitmapParameters(pcd->hbm, &bih);%@NL@%
- cbBuffer = (((bih.cBitCount * bih.cx) + 31) / 32) * 4;%@NL@%
- if (cbBuffer > 0xFFFF / bih.cy / bih.cPlanes) {%@NL@%
- NotifyUser(SZTOOBIG);%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- cbBuffer *= bih.cy * bih.cPlanes;%@NL@%
- cbBitmapInfo = sizeof(BITMAPINFO) +%@NL@%
- (sizeof(RGB) * (1 << bih.cBitCount));%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Allocate memory for the image data-buffer and the bitmap information%@NL@%
- %@AB@% * structure.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosAllocSeg(cbBuffer + cbBitmapInfo + MAX_NAMESTR + 1, &sel, 0);%@NL@%
- pszName = (PSZ)MAKEP(sel, 0);%@NL@%
- lstrcpy(pszName, szEmailName);%@NL@%
- pbmi = (PBITMAPINFO)(pszName + MAX_NAMESTR + 1);%@NL@%
- pbBuffer = (PBYTE)&pbmi->argbColor[1 << bih.cBitCount];%@NL@%
- *(PBITMAPINFOHEADER)pbmi = bih;%@NL@%
- %@NL@%
- size.cx = (LONG)bih.cx;%@NL@%
- size.cy = (LONG)bih.cy;%@NL@%
- hdc = CreateDC((PSZ)"MEMORY", (HDC)NULL);%@NL@%
- hps = GpiCreatePS(hab, hdc, &size,%@NL@%
- PU_ARBITRARY | GPIT_NORMAL | GPIA_ASSOC );%@NL@%
- GpiSetBitmap(hps, pcd->hbm);%@NL@%
- GpiQueryBitmapBits(hps, 0L, (LONG)bih.cy, (PBYTE)pbBuffer,%@NL@%
- (PBITMAPINFO2)pbmi);%@NL@%
- GpiAssociate(hps, NULL);%@NL@%
- GpiDestroyPS(hps);%@NL@%
- DevCloseDC(hdc);%@NL@%
- %@NL@%
- if (!DdeClientXfer(pszName,%@NL@%
- (LONG)(cbBuffer + cbBitmapInfo + MAX_NAMESTR + 1),%@NL@%
- pcd->npUL->hConvMsg,%@NL@%
- msgTopicItemList[IIL_BMPXFER].hszItem,%@NL@%
- fmtBmapPkt, XTYP_POKE, ulTimeout, 0L)) {%@NL@%
- MyPostError(DdeGetLastError());%@NL@%
- }%@NL@%
- %@NL@%
- DosFreeSeg(sel);%@NL@%
- GpiDeleteBitmap(pcd->hbm);%@NL@%
- pcd->hbm = NULL;%@NL@%
- WinSetRectEmpty(hab, &pcd->rcl);%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- HBITMAP SnapRegion(hps, prcl)%@NL@%
- HPS hps;%@NL@%
- PRECTL prcl;%@NL@%
- {%@NL@%
- HDC hdc;%@NL@%
- HBITMAP hbm, hbmOld;%@NL@%
- BITMAPINFOHEADER bih;%@NL@%
- POINTL rgpt[3];%@NL@%
- HPS hpsMem;%@NL@%
- SIZEL size;%@NL@%
- %@NL@%
- SortRect(prcl, prcl);%@NL@%
- WinInflateRect(hab, prcl, -1, -1);%@NL@%
- %@NL@%
- size.cx = (USHORT)(prcl->xRight - prcl->xLeft);%@NL@%
- size.cy = (USHORT)(prcl->yTop - prcl->yBottom);%@NL@%
- %@NL@%
- %@AB@%/* Create a memory DC */%@AE@%%@NL@%
- hdc = CreateDC((PSZ)"MEMORY", (HDC)NULL);%@NL@%
- %@NL@%
- %@AB@%/* create a memory PS */%@AE@%%@NL@%
- hpsMem = GpiCreatePS(hab, hdc, &size,%@NL@%
- PU_ARBITRARY | GPIT_NORMAL | GPIA_ASSOC );%@NL@%
- %@NL@%
- %@AB@%/* Create a bitmap */%@AE@%%@NL@%
- bih.cbFix = sizeof(BITMAPINFOHEADER);%@NL@%
- bih.cx = (SHORT)size.cx;%@NL@%
- bih.cy = (SHORT)size.cy;%@NL@%
- bih.cPlanes = 1;%@NL@%
- bih.cBitCount = 8;%@NL@%
- hbm = GpiCreateBitmap(hpsMem, (PBITMAPINFOHEADER2)&bih, 0L, 0, 0);%@NL@%
- if (hbm == GPI_ERROR) %@NL@%
- return(0);%@NL@%
- %@NL@%
- %@AB@%/* put the bitmap into the memory PS */%@AE@%%@NL@%
- hbmOld = GpiSetBitmap(hpsMem, hbm);%@NL@%
- %@NL@%
- %@AB@%/* copy the window to the memory PS */%@AE@%%@NL@%
- rgpt[0].x = 0;%@NL@%
- rgpt[0].y = 0;%@NL@%
- rgpt[1].x = size.cx;%@NL@%
- rgpt[1].y = size.cy;%@NL@%
- rgpt[2].x = prcl->xLeft;%@NL@%
- rgpt[2].y = prcl->yBottom;%@NL@%
- GpiBitBlt(hpsMem, hps, 3L, (PPOINTL)&rgpt[0], ROP_SRCCOPY, 0L);%@NL@%
- %@NL@%
- %@AB@%/* free the bitmap */%@AE@%%@NL@%
- GpiSetBitmap(hpsMem, hbmOld);%@NL@%
- %@NL@%
- %@AB@%/* destroy the memory DC */%@AE@%%@NL@%
- GpiAssociate(hpsMem, NULL);%@NL@%
- GpiDestroyPS(hpsMem);%@NL@%
- DevCloseDC(hdc);%@NL@%
- return(hbm);%@NL@%
- } %@AB@%/* end snapregion */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- HDC CreateDC(lpszDriver, hdcCompat)%@NL@%
- PSZ lpszDriver;%@NL@%
- HDC hdcCompat;%@NL@%
- {%@NL@%
- struct {%@NL@%
- ULONG FAR *lpLogAddr;%@NL@%
- PSZ lpszDriver;%@NL@%
- } opendc;%@NL@%
- %@NL@%
- opendc.lpLogAddr = NULL;%@NL@%
- opendc.lpszDriver = lpszDriver;%@NL@%
- %@NL@%
- return((HDC)DevOpenDC(hab, OD_MEMORY, (PSZ)"*", 2L,%@NL@%
- (PDEVOPENDATA)&opendc, hdcCompat));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void DrawRgn(hps, prcl)%@NL@%
- HPS hps;%@NL@%
- PRECTL prcl;%@NL@%
- {%@NL@%
- RECTL rclSorted;%@NL@%
- %@NL@%
- SortRect(prcl, &rclSorted);%@NL@%
- WinDrawBorder(hps, &rclSorted, 1, 1, SYSCLR_WINDOW, SYSCLR_WINDOW,%@NL@%
- DB_DESTINVERT | DB_STANDARD);%@NL@%
- }%@NL@%
- %@NL@%
- void SortRect(prcl, prclSorted)%@NL@%
- PRECTL prcl;%@NL@%
- PRECTL prclSorted;%@NL@%
- {%@NL@%
- LONG l;%@NL@%
- %@NL@%
- WinCopyRect(hab, prclSorted, prcl);%@NL@%
- if (prclSorted->yTop < prclSorted->yBottom) {%@NL@%
- l = prclSorted->yBottom;%@NL@%
- prclSorted->yBottom = prclSorted->yTop;%@NL@%
- prclSorted->yTop = l;%@NL@%
- }%@NL@%
- %@NL@%
- if (prclSorted->xRight < prclSorted-> xLeft) {%@NL@%
- l = prclSorted->xRight;%@NL@%
- prclSorted->xRight = prclSorted->xLeft;%@NL@%
- prclSorted->xLeft = l;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BROWSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\BROWSE\AVBROWSE\BROWSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% browse.c -- AVIO File Browsing Utility%@NL@%
- %@AB@%%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@% INCL_WINTRACKRECT %@NL@%
- %@AI@%#define %@AE@% INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"avio.h" %@NL@%
- %@AI@%#include %@AE@%"browse.h" %@NL@%
- %@AI@%#include %@AE@%<opendlg.h> %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Constants%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%MAXLINELEN 120 %@NL@%
- %@AI@%#define %@AE@%AVIO_PS_ROWS 25 %@NL@%
- %@AI@%#define %@AE@% AVIO_PS_COLS 80 %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Global Variables%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- FILE *pfInput;%@NL@%
- PFNWP pfnOldClient;%@NL@%
- char *aszLines[NUM_DATA_LINES];%@NL@%
- SHORT sTopLine = 0;%@NL@%
- DLF dlfInput;%@NL@%
- HFILE hfInput;%@NL@%
- USHORT usAction;%@NL@%
- LBINFO lbiData;%@NL@%
- HPOINTER hptrWait;%@NL@%
- HPOINTER hptrArrow;%@NL@%
- HWND hWndClient;%@NL@%
- HWND hWndFrame;%@NL@%
- BOOL fLargeFont = FALSE;%@NL@%
- SHORT sMaxLine;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open the input file%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- int cdecl main(int argc, char *argv[]) {%@NL@%
- static CHAR szClientClass[] = "Browse";%@NL@%
- static CHAR szCaption[] = "";%@NL@%
- HAB hAB;%@NL@%
- HMQ hmq;%@NL@%
- QMSG qmsg;%@NL@%
- ULONG flFrameFlags = FCF_STANDARD | FCF_HORZSCROLL | FCF_VERTSCROLL;%@NL@%
- ULONG flFrameStyle = WS_VISIBLE | FS_SCREENALIGN;%@NL@%
- char *szInFile;%@NL@%
- %@NL@%
- hAB = WinInitialize(0);%@NL@%
- hmq = WinCreateMsgQueue(hAB, 0);%@NL@%
- %@NL@%
- WinRegisterClass(hAB, szClientClass, BrowseWndProc, CS_SYNCPAINT, 0);%@NL@%
- %@NL@%
- hWndFrame = WinCreateStdWindow(HWND_DESKTOP, flFrameStyle,%@NL@%
- &flFrameFlags, szClientClass, szCaption,%@NL@%
- 0L, (HMODULE) NULL, ID_RESOURCE, &hWndClient);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the hourglass and arrow pointers%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE);%@NL@%
- hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);%@NL@%
- %@NL@%
- if (argc == 1) pfInput = stdin;%@NL@%
- else {%@NL@%
- if (!(pfInput = fopen(argv[1], "r"))) {%@NL@%
- fprintf(stderr, "***Error: Could not open %s", szInFile);%@NL@%
- return(-1);%@NL@%
- }%@NL@%
- }%@NL@%
- ReadFile();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Setup AVIO PS and force a paint%@NL@%
- %@AB@% Note: This subclasses the client and frame windows%@NL@%
- %@AB@% */%@AE@%%@NL@%
- lbiData.sPSrows = AVIO_PS_ROWS;%@NL@%
- lbiData.sPScols = AVIO_PS_COLS;%@NL@%
- lbiData.sRows = sTopLine;%@NL@%
- lbiData.sCols = sMaxLine;%@NL@%
- lbiData.pfnQL = (PFNQL) RetrieveLine;%@NL@%
- lbiData.fLargeFont = FALSE;%@NL@%
- AvioInit(&lbiData);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Process messages%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while (WinGetMsg(hAB, &qmsg, NULL, 0, 0)) WinDispatchMsg(hAB, &qmsg);%@NL@%
- %@NL@%
- %@AB@%/* Blast the AVIO PS */%@AE@%%@NL@%
- AvioClose();%@NL@%
- %@NL@%
- WinDestroyWindow(hWndFrame);%@NL@%
- WinDestroyMsgQueue(hmq);%@NL@%
- WinTerminate(hAB);%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- void ReadFile(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Reads in a file using <stdio.h> fgets() calls.%@NL@%
- %@AB@% It might be wise to put better word wrap facilities here%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- char szLine[MAXLINELEN];%@NL@%
- %@NL@%
- %@AB@%/* Put up the hourglass */%@AE@%%@NL@%
- WinSetPointer(HWND_DESKTOP, hptrWait);%@NL@%
- %@NL@%
- %@AB@%/* Reinitialize buffer, MaxLineLength */%@AE@%%@NL@%
- for (; sTopLine > 0; ) free(aszLines[--sTopLine]);%@NL@%
- sMaxLine = 0;%@NL@%
- %@NL@%
- %@AB@%/* Read in the file */%@AE@%%@NL@%
- while (fgets(szLine, MAXLINELEN, pfInput)) {%@NL@%
- %@NL@%
- %@AB@%/* Convert LF (\n) into NULL (\0) */%@AE@%%@NL@%
- if (szLine[strlen(szLine) - 1] == '\n') {%@NL@%
- szLine[strlen(szLine) - 1] = 0;%@NL@%
- } else szLine[MAXLINELEN - 1] = 0;%@NL@%
- %@NL@%
- if (StoreLine(szLine)) {%@NL@%
- fprintf(stderr,"***Error: Line buffer full\n");%@NL@%
- return;%@NL@%
- }%@NL@%
- }%@NL@%
- fclose(pfInput);%@NL@%
- %@NL@%
- %@AB@%/* Reset the mouse pointer */%@AE@%%@NL@%
- WinSetPointer(HWND_DESKTOP, hptrArrow);%@NL@%
- %@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- SHORT StoreLine(char *szLine) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Put a line into the line buffer; line numbers are free%@NL@%
- %@AB@% For > 64K data, add code here and in RetrieveLine%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- int i, cLinePos;%@NL@%
- BOOL fDone;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Check if top line exceeded, or malloc() fails%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (sTopLine == NUM_DATA_LINES) return -1;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute line length with tabs expanded%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cLinePos = 0;%@NL@%
- for (i = 0; i < MAXLINELEN; i++) {%@NL@%
- switch(szLine[i]) {%@NL@%
- case '\0':%@NL@%
- cLinePos++; i = MAXLINELEN;%@NL@%
- break;%@NL@%
- case '\t':%@NL@%
- do {%@NL@%
- cLinePos++;%@NL@%
- } while (cLinePos % 8);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- cLinePos++;%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- if (cLinePos > sMaxLine) sMaxLine = cLinePos;%@NL@%
- if (!(aszLines[sTopLine] = malloc(cLinePos))) return -1;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Copy szLine into the line buffer. Expand tabs here.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- i = cLinePos = 0; fDone = FALSE;%@NL@%
- while ((i <= MAXLINELEN) && (!fDone)) {%@NL@%
- switch(szLine[i]) {%@NL@%
- case '\t':%@NL@%
- do {%@NL@%
- aszLines[sTopLine][cLinePos++] = ' ';%@NL@%
- } while (cLinePos % 8);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- aszLines[sTopLine][cLinePos++] = szLine[i];%@NL@%
- fDone = !szLine[i];%@NL@%
- break;%@NL@%
- }%@NL@%
- i++;%@NL@%
- }%@NL@%
- sTopLine++;%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- char * _loadds RetrieveLine(USHORT usLineNum) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Return line numbered usLineNum%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if ((SHORT) usLineNum >= sTopLine) { %@AB@%/* Out of range */%@AE@%%@NL@%
- return NULL;%@NL@%
- }%@NL@%
- return aszLines[usLineNum];%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK BrowseWndProc(hWnd, msg, mp1, mp2)%@NL@%
- HWND hWnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Handle the About... and Open... messages%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch (COMMANDMSG(&msg)->cmd) {%@NL@%
- case IDM_ABOUT:%@NL@%
- WinDlgBox(HWND_DESKTOP, hWnd, AboutDlgProc,%@NL@%
- (HMODULE) NULL, IDD_ABOUT, NULL);%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_OPEN:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open the file, using the file dialog%@NL@%
- %@AB@% then reopen it with stdio calls%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SetupDLF(&dlfInput, DLG_OPENDLG, &hfInput,%@NL@%
- "\\*.*", NULL, "Browse Open File",%@NL@%
- "Select a file to be browsed.");%@NL@%
- DlgFile(hWnd, &dlfInput);%@NL@%
- pfInput = fopen(dlfInput.szOpenFile, "r");%@NL@%
- ReadFile();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Close the opened handle%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosClose(hfInput);%@NL@%
- %@NL@%
- %@AB@%/* Fix up the screen display */%@AE@%%@NL@%
- lbiData.sRows = sTopLine;%@NL@%
- lbiData.sCols = sMaxLine;%@NL@%
- lbiData.fLargeFont = fLargeFont;%@NL@%
- AvioInit(&lbiData);%@NL@%
- %@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_FONT:%@NL@%
- AvioLargeFont(fLargeFont = !fLargeFont);%@NL@%
- return 0;%@NL@%
- %@NL@%
- default: return 0;%@NL@%
- }%@NL@%
- break;%@NL@%
- default: return WinDefWindowProc(hWnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return 0L;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AboutDlgProc(hDlg, msg, mp1, mp2)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HWND hDlg;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hDlg, TRUE); break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BROWSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\BROWSE\VBROWSE\BROWSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% VIO File Browsing Application%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@% INCL_KBD %@NL@%
- %@AI@%#define %@AE@% INCL_VIO %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"browse.h" %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Global Variables%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- FILE *pfInput;%@NL@%
- char *aszLines[NUM_DATA_LINES];%@NL@%
- SHORT sTopLine= -1;%@NL@%
- SHORT sRows;%@NL@%
- SHORT HorScrollPos=0;%@NL@%
- BYTE abBlank[2] = { 0x20, 0x07 }; %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros for Vio calls%@NL@%
- %@AB@% The last parameter is zero because we're using a VIO PS%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%ClearScreen() VioScrollDn(0, 0, -1, -1, -1, abBlank, 0) %@NL@%
- %@AI@%#define %@AE@% Move(r,c) VioSetCurPos(r, c, 0) %@NL@%
- %@AI@%#define %@AE@%ScrollDown(n) VioScrollDn(0, 0, -1, -1, n, abBlank, 0) %@NL@%
- %@AI@%#define %@AE@%ScrollUp(n) VioScrollUp(0, 0, -1, -1, n, abBlank, 0) %@NL@%
- %@AI@%#define %@AE@%Write(s) VioWrtTTY(s, strlen(s), 0) %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros for bounds checking%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%Abs(x) (((x) > 0) ? (x) : (-(x))) %@NL@%
- %@AI@%#define %@AE@%Max(x, y) (((x) > (y)) ? (x) : (y)) %@NL@%
- %@AI@%#define %@AE@%Min(x, y) (((x) < (y)) ? (x) : (y)) %@NL@%
- %@AI@%#define %@AE@%LowerBound(pos, disp, lbound) Max(pos - disp, lbound) %@NL@%
- %@AI@%#define %@AE@%UpperBound(pos, disp, ubound) Min(pos + disp, ubound) %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Functions%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- int cdecl main(int argc, char *argv[]) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open the input file and initialize globals%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- char *szFilename;%@NL@%
- VIOMODEINFO viomiMode;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open the Input File%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (argc == 1)%@NL@%
- pfInput = stdin;%@NL@%
- else {%@NL@%
- szFilename = argv[1];%@NL@%
- if (!(pfInput = fopen(szFilename,"r"))) {%@NL@%
- fprintf(stderr, "***Error: Could not open %s", szFilename);%@NL@%
- return(-1);%@NL@%
- }%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Read it into the line buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (ReadFile()) return(-1);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the video parameters%@NL@%
- %@AB@% */%@AE@%%@NL@%
- viomiMode.cb = sizeof(viomiMode);%@NL@%
- VioGetMode(&viomiMode, 0);%@NL@%
- sRows = (SHORT) viomiMode.row;%@NL@%
- %@NL@%
- DisplayScreen(0, TRUE);%@NL@%
- ManipulateFile();%@NL@%
- %@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- SHORT ReadFile(VOID) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Read lines from the file into the line buffer%@NL@%
- %@AB@% If there's an error, abort the program (return -1)%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- char szLine[MAXLINELENGTH];%@NL@%
- %@NL@%
- while (fgets(szLine, MAXLINELENGTH, pfInput)) {%@NL@%
- %@NL@%
- %@AB@%/* Convert LF (\n) character to NULL (\0) */%@AE@%%@NL@%
- if (szLine[strlen(szLine)-1] == '\n')%@NL@%
- szLine[strlen(szLine)-1] = 0;%@NL@%
- else {%@NL@%
- fprintf(stderr,"***Error: Incomplete line read\n");%@NL@%
- return(-1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Put the line into the line buffer */%@AE@%%@NL@%
- if (StoreLine(szLine)) {%@NL@%
- fprintf(stderr,"***Error: Line buffer full\n");%@NL@%
- return(-1);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Close the Input file */%@AE@%%@NL@%
- fclose(pfInput);%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- VOID ManipulateFile(VOID) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Main loop for display processing%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- CHAR ch;%@NL@%
- SHORT sLine = 0;%@NL@%
- %@NL@%
- %@AB@%/* The main command loop */%@AE@%%@NL@%
- while ((ch = GetKbdInput()) != ESC) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Take user input and compute new top line of screen%@NL@%
- %@AB@% by taking appropriate jump in jumptable.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Note: no horizontal scrolling.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch (ch) {%@NL@%
- case LINE_UP: sLine = LowerBound(sLine, 1, 0); break;%@NL@%
- case LINE_DOWN: sLine = UpperBound(sLine, 1, BOTTOM); break;%@NL@%
- case PAGE_UP: sLine = LowerBound(sLine, sRows, 0); break;%@NL@%
- case PAGE_DOWN: sLine = UpperBound(sLine, sRows, BOTTOM); break;%@NL@%
- case HOME_KEY: sLine = 0; break;%@NL@%
- case END_KEY: sLine = BOTTOM; break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- DisplayScreen((USHORT) sLine, !ch);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Set Cursor to the bottom of the screen */%@AE@%%@NL@%
- Move((USHORT) sRows - 1, 0);%@NL@%
- }%@NL@%
- %@NL@%
- SHORT StoreLine(char *szLine) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Put a line into the line buffer; line numbers are free%@NL@%
- %@AB@% For > 64K data, add code here and in RetrieveLine%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Check if top line exceeded, or if malloc() fails%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((sTopLine == NUM_DATA_LINES) ||%@NL@%
- ((aszLines[++sTopLine] = malloc(strlen(szLine) + 1)) == NULL))%@NL@%
- %@NL@%
- return -1;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Copy szLine into the line buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- strcpy(aszLines[sTopLine], szLine);%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- SHORT RetrieveLine(char **pszLine , USHORT usLineNum) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Return line numbered usLineNum%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if ((SHORT) usLineNum > sTopLine) return -1; %@AB@%/* Out of range */%@AE@%%@NL@%
- *pszLine = aszLines[usLineNum];%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- VOID DisplayScreen(USHORT usDisplayTop, BOOL fForceDraw) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Display lines on the screen, starting at usDisplayTop%@NL@%
- %@AB@% by scrolling, then painting new information%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- SHORT sDelta;%@NL@%
- static USHORT usOldDispTop;%@NL@%
- %@NL@%
- sDelta = usDisplayTop - usOldDispTop;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If only a few lines need repainting...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((Abs(sDelta) < sRows) && !fForceDraw ) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Moving to a "higher line", so:%@NL@%
- %@AB@% Scroll down by the amount (make the difference positive)%@NL@%
- %@AB@% Paint in the lines at the top%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (sDelta < 0) {%@NL@%
- ScrollDown(-sDelta);%@NL@%
- Refresh(usDisplayTop, -sDelta, 0);%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Moving to a "lower line", so:%@NL@%
- %@AB@% Scroll the information up, and paint at the bottom%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ScrollUp(sDelta);%@NL@%
- Refresh(usDisplayTop + sRows - sDelta, sDelta, sRows - sDelta);%@NL@%
- }%@NL@%
- } else { %@AB@%/* Paint the entire screen */%@AE@%%@NL@%
- ClearScreen();%@NL@%
- Refresh(usDisplayTop, sRows, 0);%@NL@%
- }%@NL@%
- usOldDispTop = usDisplayTop;%@NL@%
- }%@NL@%
- %@NL@%
- VOID Refresh (USHORT iLine, USHORT usLines, USHORT usStart) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Updates usLines lines, starting at line iLine in the line%@NL@%
- %@AB@% buffer, and line usStart on the screen%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT usLine;%@NL@%
- char *szLine;%@NL@%
- %@NL@%
- for (usLine = 0; usLine < usLines; usLine++) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Read the line, set the cursor, print the line%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (RetrieveLine(&szLine, (iLine + usLine))) break;%@NL@%
- Move((usStart + usLine), 0);%@NL@%
- Write(szLine);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- CHAR GetKbdInput(VOID) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get chars, then check scan codes and return our own values%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- KBDKEYINFO kbciKeyInfo;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Wait for characters%@NL@%
- %@AB@% */%@AE@%%@NL@%
- KbdCharIn(&kbciKeyInfo, IO_WAIT, 0);%@NL@%
- %@NL@%
- switch (kbciKeyInfo.chScan) {%@NL@%
- case ESC: %@AB@%/* escape */%@AE@%%@NL@%
- case LINE_UP:%@NL@%
- case LINE_DOWN:%@NL@%
- case PAGE_UP:%@NL@%
- case PAGE_DOWN:%@NL@%
- case HOME_KEY:%@NL@%
- case END_KEY:%@NL@%
- return kbciKeyInfo.chScan; break;%@NL@%
- default:%@NL@%
- return((CHAR) NULL); break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CALC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CALC\CALC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header *********************************/%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* Module Name: calc.c - Calc application */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* OS/2 Presentation Manager version of Calc, ported from Windows version */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* Created by Microsoft Corporation, 1987 */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINCLIPBOARD %@NL@%
- %@AI@%#define %@AE@%INCL_GPIPRIMITIVES %@NL@%
- %@AI@%#define %@AE@%INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@%INCL_GPILCIDS %@NL@%
- %@AI@%#define %@AE@%INCL_DEV %@NL@%
- %@AI@%#define %@AE@%INCL_ERRORS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSPROCESS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSSEMAPHORES %@NL@%
- %@AI@%#define %@AE@%INCL_DOSNLS %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%"calc.h" %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* GLOBAL VARIABLES */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@NL@%
- CHAR chLastKey, chCurrKey;%@NL@%
- CHAR szreg1[20], szreg2[20], szmem[20], szregx[20];%@NL@%
- CHAR szTitle[30], szErrorString[20], szPlusMinus[2];%@NL@%
- SHORT sCharWidth, sCharHeight;%@NL@%
- extern BOOL fError;%@NL@%
- BOOL fValueInMemory = FALSE;%@NL@%
- BOOL fMDown = FALSE; %@AB@%/* TRUE iff 'm' key depressed */%@AE@%%@NL@%
- UCHAR uchMScan = 0; %@AB@%/* scan code for 'm' key */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TOLOWER(x) ( (((x) >= 'A') && ((x) <= 'Z')) ? (x)|0x20 : (x)) %@NL@%
- %@AI@%#define %@AE@%WIDTHCONST 28 %@NL@%
- %@AI@%#define %@AE@%CXCHARS 37 %@NL@%
- %@AI@%#define %@AE@%CYCHARS 13 %@NL@%
- %@NL@%
- HAB hab;%@NL@%
- HDC hdcLocal; %@AB@%/* Local used for button bitmap */%@AE@%%@NL@%
- HPS hpsLocal;%@NL@%
- HDC hdcSqr; %@AB@%/* Sqr used for square-root bitmap */%@AE@%%@NL@%
- HPS hpsSqr;%@NL@%
- HBITMAP hbmLocal, hbmSqr;%@NL@%
- HMQ hmqCalc;%@NL@%
- HWND hwndCalc, hwndMenu;%@NL@%
- HWND hwndCalcFrame;%@NL@%
- HPS hpsCalc;%@NL@%
- HDC hdcCalc;%@NL@%
- HPOINTER hptrFinger;%@NL@%
- %@NL@%
- DEVOPENSTRUC dop = %@AB@%/* used by DevOpenDC */%@AE@%%@NL@%
- {%@NL@%
- NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL%@NL@%
- };%@NL@%
- %@NL@%
- static char achKeys[25] = %@AB@%/* keyboard keys */%@AE@%%@NL@%
- {%@NL@%
- '\271', '0', '.', '\261', '+', '=',%@NL@%
- '\272', '1', '2', '3', '-', 'c',%@NL@%
- '\273', '4', '5', '6', '*', '%',%@NL@%
- '\274', '7', '8', '9', '/', 'q',%@NL@%
- NULL%@NL@%
- };%@NL@%
- %@NL@%
- static CHAR achDKeys[25] = %@AB@%/* 4th key is plusminus */%@AE@%%@NL@%
- {%@NL@%
- ' ', '0', '.', '+', '+', '=',%@NL@%
- ' ', '1', '2', '3', '-', 'C',%@NL@%
- ' ', '4', '5', '6', '*', '%',%@NL@%
- ' ', '7', '8', '9', '/', ' ',%@NL@%
- NULL%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* PROCEDURE DECLARATIONS */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID FarStrcpy( PSZ, PSZ);%@NL@%
- MPARAM EXPENTRY AboutDlgProc( HWND, USHORT, MPARAM, MPARAM);%@NL@%
- BOOL CalcInit(VOID);%@NL@%
- VOID CalcPaint( HWND, HPS);%@NL@%
- VOID CalcTextOut( HPS, INT, INT, PCH, INT);%@NL@%
- MRESULT EXPENTRY CalcWndProc( HWND, USHORT, MPARAM, MPARAM);%@NL@%
- VOID cdecl main(VOID);%@NL@%
- VOID DataXCopy( VOID);%@NL@%
- VOID DataXPaste( VOID);%@NL@%
- VOID DrawNumbers( HPS);%@NL@%
- VOID Evaluate(BYTE);%@NL@%
- BOOL FlashSqr( HPS, PWPOINT);%@NL@%
- VOID FlipKey( HPS, INT, INT);%@NL@%
- VOID FrameKey( HPS, INT, INT);%@NL@%
- VOID InitCalc( VOID);%@NL@%
- BOOL InterpretChar( CHAR);%@NL@%
- VOID ProcessKey( PWPOINT);%@NL@%
- BOOL PSInit( VOID);%@NL@%
- CHAR Translate( PWPOINT);%@NL@%
- VOID UpdateDisplay( VOID);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID CalcTextOut( hps, iX, iY, pch, iCount)%@NL@%
- %@NL@%
- HPS hps;%@NL@%
- INT iX, iY;%@NL@%
- PCH pch;%@NL@%
- INT iCount;%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- %@NL@%
- ptl.x = iX;%@NL@%
- ptl.y = iY;%@NL@%
- %@NL@%
- GpiSetColor( hps, CLR_BLACK);%@NL@%
- GpiCharStringAt( hps, (PPOINTL)&ptl, (LONG)iCount, (PSZ)pch);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* Write the appropriate number or error string to the display area */%@AE@%%@NL@%
- %@AB@%/* and mark memory-in-use if appropriate. */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- UpdateDisplay()%@NL@%
- {%@NL@%
- RECTL rcl;%@NL@%
- %@NL@%
- rcl.xLeft = (6 * sCharWidth);%@NL@%
- rcl.yBottom = 1050 * sCharHeight / 100;%@NL@%
- rcl.xRight = rcl.xLeft + (12 * sCharWidth);%@NL@%
- rcl.yTop = rcl.yBottom + (3 * sCharHeight) / 2;%@NL@%
- %@NL@%
- WinFillRect( hpsCalc, &rcl, CLR_WHITE); %@AB@%/* paint display area white */%@AE@%%@NL@%
- if( fError)%@NL@%
- WinDrawText( hpsCalc%@NL@%
- , -1%@NL@%
- , szErrorString%@NL@%
- , &rcl%@NL@%
- , CLR_BLACK%@NL@%
- , CLR_WHITE%@NL@%
- , DT_RIGHT | DT_VCENTER );%@NL@%
- else%@NL@%
- WinDrawText( hpsCalc%@NL@%
- , -1%@NL@%
- , szreg1%@NL@%
- , &rcl%@NL@%
- , CLR_BLACK%@NL@%
- , CLR_WHITE%@NL@%
- , DT_RIGHT | DT_VCENTER );%@NL@%
- %@NL@%
- if (fValueInMemory) %@AB@%/* little black square shows mem use */%@AE@%%@NL@%
- {%@NL@%
- rcl.xLeft = (6 * sCharWidth);%@NL@%
- rcl.yBottom = 1050 * sCharHeight / 100;%@NL@%
- rcl.xRight = rcl.xLeft + (sCharWidth / 2);%@NL@%
- rcl.yTop = rcl.yBottom + (sCharHeight / 2);%@NL@%
- WinFillRect( hpsCalc, &rcl, CLR_BLACK);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* Display helpful info */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- MPARAM EXPENTRY%@NL@%
- AboutDlgProc( hwnd, msg, mp1, mp2)%@NL@%
- %@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- if (msg == WM_COMMAND)%@NL@%
- {%@NL@%
- WinDismissDlg(hwnd, TRUE);%@NL@%
- return(MPFROMSHORT(TRUE));%@NL@%
- }%@NL@%
- else return(WinDefDlgProc( hwnd, msg, mp1, mp2));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* General initialization */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- BOOL%@NL@%
- CalcInit()%@NL@%
- {%@NL@%
- hab = WinInitialize( NULL);%@NL@%
- %@NL@%
- hmqCalc = WinCreateMsgQueue( hab, 0);%@NL@%
- if( !hmqCalc)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- WinLoadString( NULL, NULL, 1, 30, (PSZ)szTitle);%@NL@%
- WinLoadString( NULL, NULL, 2, 20, (PSZ)szErrorString);%@NL@%
- WinLoadString( NULL, NULL, 3, 2, (PSZ)szPlusMinus);%@NL@%
- %@NL@%
- if (!WinRegisterClass( hab, szTitle, CalcWndProc, CS_SIZEREDRAW, 0))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- hptrFinger = WinLoadPointer( HWND_DESKTOP, (HMODULE)NULL, IDP_FINGER);%@NL@%
- %@NL@%
- InitCalc(); %@AB@%/* arithmetic initialization */%@AE@%%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* main procedure */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID cdecl%@NL@%
- main()%@NL@%
- {%@NL@%
- QMSG qmsg;%@NL@%
- ULONG ulFCF;%@NL@%
- %@NL@%
- if (!CalcInit()) { %@AB@%/* general initialization */%@AE@%%@NL@%
- WinAlarm(HWND_DESKTOP, WA_ERROR);%@NL@%
- goto exit;%@NL@%
- }%@NL@%
- %@NL@%
- if (!PSInit()) { %@AB@%/* presentation spaces & bitmaps */%@AE@%%@NL@%
- WinAlarm(HWND_DESKTOP, WA_ERROR);%@NL@%
- goto exit;%@NL@%
- }%@NL@%
- %@NL@%
- ulFCF = FCF_STANDARD & ~(LONG)(FCF_SIZEBORDER | FCF_MAXBUTTON);%@NL@%
- hwndCalcFrame = WinCreateStdWindow( HWND_DESKTOP%@NL@%
- , WS_VISIBLE | FS_BORDER%@NL@%
- , &ulFCF%@NL@%
- , szTitle%@NL@%
- , NULL%@NL@%
- , 0L%@NL@%
- , NULL%@NL@%
- , IDR_CALC%@NL@%
- , &hwndCalc);%@NL@%
- %@NL@%
- WinSetWindowPos( hwndCalcFrame%@NL@%
- , (HWND)NULL%@NL@%
- , 2%@NL@%
- , 2%@NL@%
- , CXCHARS * sCharWidth%@NL@%
- , CYCHARS * sCharHeight%@NL@%
- + (SHORT)WinQuerySysValue( HWND_DESKTOP%@NL@%
- , SV_CYTITLEBAR )%@NL@%
- + (SHORT)WinQuerySysValue( HWND_DESKTOP%@NL@%
- , SV_CYMENU )%@NL@%
- , SWP_MOVE | SWP_SIZE );%@NL@%
- %@NL@%
- while (WinGetMsg( hab, &qmsg, NULL, 0, 0))%@NL@%
- WinDispatchMsg( hab, &qmsg);%@NL@%
- %@NL@%
- exit: %@AB@%/* clean up */%@AE@%%@NL@%
- if (hdcSqr) %@AB@%/* square-root bitmap */%@AE@%%@NL@%
- {%@NL@%
- GpiDestroyPS( hpsSqr);%@NL@%
- if (hbmSqr)%@NL@%
- GpiDeleteBitmap( hbmSqr);%@NL@%
- }%@NL@%
- %@NL@%
- if (hdcLocal) %@AB@%/* keypad button */%@AE@%%@NL@%
- {%@NL@%
- GpiDestroyPS( hpsLocal);%@NL@%
- if (hbmLocal)%@NL@%
- GpiDeleteBitmap( hbmLocal);%@NL@%
- }%@NL@%
- %@NL@%
- WinDestroyWindow(hwndCalcFrame);%@NL@%
- %@NL@%
- WinDestroyMsgQueue(hmqCalc);%@NL@%
- WinTerminate(hab);%@NL@%
- %@NL@%
- DosExit(EXIT_PROCESS, 0); %@AB@%/* exit without error */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* Calc Window Procedure */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- MRESULT EXPENTRY%@NL@%
- CalcWndProc(hwnd, msg, mp1, mp2)%@NL@%
- %@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- RECTL rclPaint;%@NL@%
- WPOINT wpt;%@NL@%
- BOOL fClip;%@NL@%
- USHORT usFmtInfo;%@NL@%
- RECTL rcl;%@NL@%
- SIZEL sizl;%@NL@%
- %@NL@%
- switch (msg)%@NL@%
- {%@NL@%
- case WM_CREATE:%@NL@%
- hdcCalc = WinOpenWindowDC( hwnd);%@NL@%
- WinQueryWindowRect( hwnd, &rcl);%@NL@%
- sizl.cx = rcl.xRight - rcl.xLeft;%@NL@%
- sizl.cy = rcl.yTop - rcl.yBottom;%@NL@%
- hpsCalc = GpiCreatePS( hab%@NL@%
- , hdcCalc%@NL@%
- , &sizl%@NL@%
- , GPIA_ASSOC | PU_PELS );%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- WinDestroyPointer(hptrFinger);%@NL@%
- GpiDestroyPS( hpsSqr);%@NL@%
- GpiDeleteBitmap( hbmSqr);%@NL@%
- GpiDestroyPS( hpsLocal);%@NL@%
- GpiDeleteBitmap( hbmLocal);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_INITMENU:%@NL@%
- fClip = FALSE;%@NL@%
- if (WinOpenClipbrd( hab))%@NL@%
- {%@NL@%
- fClip = WinQueryClipbrdFmtInfo( hab, CF_TEXT, &usFmtInfo);%@NL@%
- WinCloseClipbrd( hab);%@NL@%
- }%@NL@%
- WinSendMsg((HWND)mp2, MM_SETITEMATTR,%@NL@%
- (MPARAM) MAKELONG(CMD_PASTE, TRUE),%@NL@%
- (MPARAM) MAKELONG(MIA_DISABLED, fClip ? 0 : MIA_DISABLED));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- hps = WinBeginPaint(hwnd, NULL, &rclPaint);%@NL@%
- CalcPaint( hwnd, hps); %@AB@%/* re-draw calculator */%@AE@%%@NL@%
- WinEndPaint(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- if (fError)%@NL@%
- break;%@NL@%
- switch(LOUSHORT(mp1))%@NL@%
- {%@NL@%
- case CMD_COPY:%@NL@%
- DataXCopy(); %@AB@%/* copy to clipboard */%@AE@%%@NL@%
- break;%@NL@%
- case CMD_PASTE:%@NL@%
- DataXPaste(); %@AB@%/* paste from clipboard */%@AE@%%@NL@%
- break;%@NL@%
- case CMD_EXIT:%@NL@%
- WinPostMsg( hwndCalcFrame, WM_QUIT, 0L, 0L);%@NL@%
- break;%@NL@%
- case CMD_ABOUT:%@NL@%
- WinDlgBox( HWND_DESKTOP%@NL@%
- , hwndCalcFrame%@NL@%
- , (PFNWP)AboutDlgProc%@NL@%
- , NULL%@NL@%
- , 1%@NL@%
- , (PSZ)NULL );%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CLOSE:%@NL@%
- WinPostMsg(hwndCalcFrame, WM_QUIT, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MOUSEMOVE:%@NL@%
- WinSetPointer( HWND_DESKTOP, hptrFinger);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1DOWN:%@NL@%
- wpt.x = LOUSHORT(mp1);%@NL@%
- wpt.y = HIUSHORT(mp1);%@NL@%
- ProcessKey( &wpt);%@NL@%
- goto dwp;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CHAR:%@NL@%
- if (SHORT1FROMMP(mp1) & KC_KEYUP)%@NL@%
- {%@NL@%
- if (CHAR4FROMMP(mp1) == uchMScan)%@NL@%
- fMDown = FALSE; %@AB@%/* 'm' key went up */%@AE@%%@NL@%
- }%@NL@%
- else %@NL@%
- {%@NL@%
- if (SHORT1FROMMP(mp1) & KC_CHAR)%@NL@%
- {%@NL@%
- if (InterpretChar((UCHAR)SHORT1FROMMP(mp2)))%@NL@%
- { %@NL@%
- UpdateDisplay();%@NL@%
- }%@NL@%
- else %@NL@%
- {%@NL@%
- if (((UCHAR)SHORT1FROMMP(mp2)== 'm') || ((UCHAR)SHORT1FROMMP(mp2)== 'M'))%@NL@%
- {%@NL@%
- uchMScan = CHAR4FROMMP(mp1); %@AB@%/* save 'm' key scan code */%@AE@%%@NL@%
- fMDown = TRUE; %@AB@%/* 'm' key went down */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ACTIVATE:%@NL@%
- if (HIUSHORT(mp1))%@NL@%
- WinSetFocus( HWND_DESKTOP, hwndCalc);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_SETFOCUS:%@NL@%
- if ((HWNDFROMMP(mp1)==hwndCalc) && !mp2);%@NL@%
- fMDown = FALSE; %@AB@%/* since we are losing focus */%@AE@%%@NL@%
- break;%@NL@%
- %@NL@%
- dwp:%@NL@%
- default:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* translate & interpret keys (ie. locate in logical keyboard) */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- BOOL%@NL@%
- InterpretChar( ch)%@NL@%
- %@NL@%
- CHAR ch;%@NL@%
- {%@NL@%
- BOOL fDone;%@NL@%
- NPCH pchStep;%@NL@%
- INT i;%@NL@%
- %@NL@%
- fDone = FALSE;%@NL@%
- pchStep = achKeys;%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case 'n':%@NL@%
- ch = szPlusMinus[0];%@NL@%
- break;%@NL@%
- case 27: %@AB@%/* xlate Escape into 'c' */%@AE@%%@NL@%
- ch = 'c';%@NL@%
- break;%@NL@%
- case '\r': %@AB@%/* xlate Enter into '=' */%@AE@%%@NL@%
- ch = '=';%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if (fMDown) %@AB@%/* Do memory keys */%@AE@%%@NL@%
- {%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case 'c':%@NL@%
- case 'C':%@NL@%
- ch = '\274';%@NL@%
- break;%@NL@%
- case 'r':%@NL@%
- case 'R':%@NL@%
- ch = '\273';%@NL@%
- break;%@NL@%
- case '+':%@NL@%
- ch = '\272';%@NL@%
- break;%@NL@%
- case '-':%@NL@%
- ch = '\271';%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- while (!fDone && *pchStep)%@NL@%
- {%@NL@%
- if ((CHAR) *pchStep++ == ch)%@NL@%
- fDone = TRUE; %@AB@%/* char found in logical keyboard */%@AE@%%@NL@%
- }%@NL@%
- if (fDone)%@NL@%
- {%@NL@%
- chLastKey = chCurrKey;%@NL@%
- i = pchStep - achKeys - 1;%@NL@%
- FlipKey( hpsCalc, i/6, i%6);%@NL@%
- Evaluate( achKeys[i]);%@NL@%
- }%@NL@%
- return (fDone);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* briefly reverse the shading on one of the keys */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- FlipKey( hps, iRow, iCol)%@NL@%
- %@NL@%
- HPS hps;%@NL@%
- INT iRow, iCol;%@NL@%
- {%@NL@%
- RECTL rcl;%@NL@%
- %@NL@%
- rcl.xLeft = (iCol * 6 * sCharWidth) + (14 * sCharWidth / 10);%@NL@%
- rcl.yBottom = (165 * sCharHeight / 100) + (2 * iRow * sCharHeight);%@NL@%
- rcl.xRight = rcl.xLeft + (11 * sCharWidth / 3);%@NL@%
- rcl.yTop = rcl.yBottom + (7 * sCharHeight / 4);%@NL@%
- WinInvertRect( hps, &rcl);%@NL@%
- DosSleep( 50L);%@NL@%
- WinInvertRect( hps, &rcl);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* compute whether a point is over a button and flash the button if so */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- BOOL%@NL@%
- FlashSqr( hps, pwpt)%@NL@%
- %@NL@%
- HPS hps;%@NL@%
- PWPOINT pwpt;%@NL@%
- {%@NL@%
- INT iRow, iCol;%@NL@%
- BOOL fDone;%@NL@%
- %@NL@%
- %@AB@%/* find x range */%@AE@%%@NL@%
- fDone = FALSE;%@NL@%
- iCol = 0;%@NL@%
- iRow = 3;%@NL@%
- while (!fDone && iCol<6)%@NL@%
- {%@NL@%
- if (pwpt->x < (iCol * 6 * sCharWidth)%@NL@%
- + (14 * sCharWidth / 10)%@NL@%
- + (11*sCharWidth/3) )%@NL@%
- {%@NL@%
- if (pwpt->x > (iCol * 6 * sCharWidth) + (14 * sCharWidth / 10))%@NL@%
- fDone = TRUE;%@NL@%
- else%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- else%@NL@%
- iCol++;%@NL@%
- }%@NL@%
- if (!fDone)%@NL@%
- return FALSE;%@NL@%
- fDone = FALSE;%@NL@%
- while (!fDone && iRow >= 0)%@NL@%
- {%@NL@%
- if (pwpt->y > ((165 * sCharHeight / 100) + (2 * iRow * sCharHeight)))%@NL@%
- {%@NL@%
- if (pwpt->y < (165 * sCharHeight / 100)%@NL@%
- + (2 * iRow * sCharHeight)%@NL@%
- + (7 * sCharHeight / 4) )%@NL@%
- fDone = TRUE;%@NL@%
- else%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- else%@NL@%
- iRow--;%@NL@%
- }%@NL@%
- if (!fDone)%@NL@%
- return FALSE;%@NL@%
- pwpt->x = iCol;%@NL@%
- pwpt->y = iRow;%@NL@%
- FlipKey( hps, iRow, iCol);%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* which key is point on? */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- CHAR%@NL@%
- Translate( pwpt)%@NL@%
- %@NL@%
- PWPOINT pwpt;%@NL@%
- {%@NL@%
- return( achKeys[ pwpt->y * 6 + pwpt->x]);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* invoke flashing, point-to-key translation, and result-display update */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- ProcessKey( pwpt)%@NL@%
- %@NL@%
- PWPOINT pwpt;%@NL@%
- {%@NL@%
- BOOL fFlashed;%@NL@%
- %@NL@%
- chLastKey = chCurrKey;%@NL@%
- fFlashed = FlashSqr( hpsCalc, pwpt);%@NL@%
- %@NL@%
- if (fFlashed)%@NL@%
- Evaluate( (BYTE)Translate( pwpt));%@NL@%
- UpdateDisplay();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* draw a blank key */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- FrameKey(hps, iRow, iCol)%@NL@%
- %@NL@%
- HPS hps;%@NL@%
- INT iRow, iCol;%@NL@%
- {%@NL@%
- POINTL aptl[3];%@NL@%
- %@NL@%
- aptl[0].x = (iCol * 6 * sCharWidth) + (14 * sCharWidth / 10);%@NL@%
- aptl[0].y = (165 * sCharHeight / 100) + (2 * iRow * sCharHeight);%@NL@%
- aptl[1].x = (11 * sCharWidth / 3) + (aptl[0].x);%@NL@%
- aptl[1].y = (7 * sCharHeight / 4) + (aptl[0].y);%@NL@%
- aptl[2].x = 0;%@NL@%
- aptl[2].y = 0;%@NL@%
- GpiBitBlt( hps, hpsLocal, 3L, aptl, ROP_SRCCOPY, BBO_IGNORE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* draw the keys and fill in numbers */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- DrawNumbers(hps)%@NL@%
- %@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- INT iRow, iCol;%@NL@%
- %@NL@%
- %@AB@%/* Draw the keys and fill in the numbers we can */%@AE@%%@NL@%
- for (iRow = 0; iRow < 4; iRow++)%@NL@%
- {%@NL@%
- for (iCol = 0; iCol < 6; iCol++)%@NL@%
- {%@NL@%
- FrameKey( hps, iRow, iCol);%@NL@%
- CalcTextOut( hps%@NL@%
- , (iCol * 6 * sCharWidth)%@NL@%
- + (WIDTHCONST * sCharWidth / 10)%@NL@%
- , (iRow + 1) * 2 * sCharHeight%@NL@%
- , (PSZ)(achDKeys + (iRow * 6) + iCol)%@NL@%
- , 1 );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* redraw the whole calculator */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- CalcPaint( hwnd, hps)%@NL@%
- %@NL@%
- HWND hwnd;%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- RECTL rclDst;%@NL@%
- CHARBUNDLE cbnd;%@NL@%
- INT iX, iY;%@NL@%
- %@NL@%
- WinQueryWindowRect( hwnd, &rclDst);%@NL@%
- WinFillRect( hps, &rclDst, CLR_GREEN);%@NL@%
- %@NL@%
- DrawNumbers(hps);%@NL@%
- CalcTextOut(hps, iX = (11 * sCharWidth / 5) + 1, iY = 2 * sCharHeight,%@NL@%
- (PSZ)"M-", 2);%@NL@%
- CalcTextOut(hps, iX, iY + 2 * sCharHeight, (PSZ)"M+", 2);%@NL@%
- CalcTextOut(hps, iX, iY + 4 * sCharHeight, (PSZ)"MR", 2);%@NL@%
- CalcTextOut(hps, iX, iY + 6 * sCharHeight, (PSZ)"MC", 2);%@NL@%
- %@NL@%
- %@AB@%/* Draw the minus of the plus/minus button */%@AE@%%@NL@%
- cbnd.usBackMixMode = FM_LEAVEALONE;%@NL@%
- GpiSetAttrs( hps, PRIM_CHAR, CBB_BACK_MIX_MODE, 0L, &cbnd);%@NL@%
- iX = (3 * 6 * sCharWidth) + (WIDTHCONST * sCharWidth / 10);%@NL@%
- CalcTextOut( hps, iX, iY + sCharHeight / 4, (PSZ)"_", 1);%@NL@%
- %@NL@%
- %@AB@%/* Draw the square root bitmap */%@AE@%%@NL@%
- rclDst.xLeft = 160 * sCharWidth / 5;%@NL@%
- rclDst.yBottom = 31 * sCharHeight / 4;%@NL@%
- rclDst.xRight = rclDst.xLeft + 2 * sCharWidth;%@NL@%
- rclDst.yTop = rclDst.yBottom + (3 * sCharHeight / 2);%@NL@%
- WinDrawBitmap( hps%@NL@%
- , hbmSqr%@NL@%
- , NULL%@NL@%
- , (PPOINTL)&rclDst%@NL@%
- , CLR_WHITE%@NL@%
- , CLR_BLACK%@NL@%
- , DBM_STRETCH );%@NL@%
- %@NL@%
- UpdateDisplay();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* initialize the bitmaps for a blank key and for the square-root sign */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- BOOL%@NL@%
- PSInit()%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- FONTMETRICS fm;%@NL@%
- POINTL ptl;%@NL@%
- SIZEL sizl;%@NL@%
- BITMAPINFOHEADER bmp;%@NL@%
- POINTL aptl[4];%@NL@%
- LONG alCaps[2];%@NL@%
- %@NL@%
- %@AB@%/**************************************************************************/%@AE@%%@NL@%
- %@AB@%/* compute the units of horizontal and vertical distance based on font */%@AE@%%@NL@%
- %@AB@%/**************************************************************************/%@AE@%%@NL@%
- hps = WinGetPS( HWND_DESKTOP);%@NL@%
- GpiQueryFontMetrics( hps, (LONG)sizeof(FONTMETRICS), &fm);%@NL@%
- sCharHeight = (SHORT)(fm.lEmHeight); %@AB@%/* avg height of uppercase character */%@AE@%%@NL@%
- sCharWidth = (SHORT)(fm.lEmInc); %@AB@%/* usually 'M' increment */%@AE@%%@NL@%
- WinReleasePS( hps);%@NL@%
- %@NL@%
- %@AB@%/**************************************************************************/%@AE@%%@NL@%
- %@AB@%/* prepare the square root bitmap */%@AE@%%@NL@%
- %@AB@%/**************************************************************************/%@AE@%%@NL@%
- hdcSqr = DevOpenDC( hab, OD_MEMORY, "*", 3L, (PDEVOPENDATA)&dop, NULL);%@NL@%
- if( !hdcSqr)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- sizl.cx = sizl.cy = 0L;%@NL@%
- hpsSqr = GpiCreatePS( hab%@NL@%
- , hdcSqr%@NL@%
- , &sizl%@NL@%
- , PU_PELS | GPIT_MICRO | GPIA_ASSOC );%@NL@%
- hbmSqr = GpiLoadBitmap( hpsSqr, NULL, IDB_SQR, 0L, 0L);%@NL@%
- %@NL@%
- %@AB@%/**************************************************************************/%@AE@%%@NL@%
- %@AB@%/* prepare the bitmap of a blank key */%@AE@%%@NL@%
- %@AB@%/**************************************************************************/%@AE@%%@NL@%
- hdcLocal = DevOpenDC( hab, OD_MEMORY, "*", 3L, (PDEVOPENDATA)&dop, NULL);%@NL@%
- if( !hdcLocal)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- sizl.cx = sizl.cy = 0L;%@NL@%
- hpsLocal = GpiCreatePS( hab%@NL@%
- , hdcLocal%@NL@%
- , &sizl%@NL@%
- , PU_PELS | GPIT_MICRO | GPIA_ASSOC );%@NL@%
- bmp.cbFix = 12;%@NL@%
- bmp.cx = 11 * sCharWidth / 3;%@NL@%
- bmp.cy = sCharHeight * 2;%@NL@%
- DevQueryCaps( hdcLocal, CAPS_COLOR_PLANES, 2L, alCaps);%@NL@%
- bmp.cPlanes = (USHORT)alCaps[0];%@NL@%
- bmp.cBitCount = (USHORT)alCaps[1];%@NL@%
- hbmLocal = GpiCreateBitmap( hpsLocal, &bmp, 0L, NULL, NULL);%@NL@%
- if( !hbmLocal )%@NL@%
- return(FALSE);%@NL@%
- GpiSetBitmap( hpsLocal, hbmLocal);%@NL@%
- %@NL@%
- aptl[0].x = aptl[0].y = 0;%@NL@%
- aptl[1].x = 11 * sCharWidth / 3;%@NL@%
- aptl[1].y = 7 * sCharHeight / 4;%@NL@%
- aptl[2].x = aptl[2].y = 0;%@NL@%
- aptl[3].x = aptl[1].x;%@NL@%
- aptl[3].y = aptl[1].y;%@NL@%
- GpiSetColor( hpsLocal, CLR_GREEN); %@AB@%/* match the background to client */%@AE@%%@NL@%
- GpiBitBlt( hpsLocal, NULL, 2L, aptl, ROP_PATCOPY, BBO_IGNORE);%@NL@%
- %@NL@%
- %@AB@%/* Draw the rounded rect */%@AE@%%@NL@%
- ptl.x = 0;%@NL@%
- ptl.y = 0;%@NL@%
- GpiSetCurrentPosition( hpsLocal, &ptl);%@NL@%
- ptl.x = (11 * sCharWidth / 3) - 1;%@NL@%
- ptl.y = (7 * sCharHeight / 4) - 1;%@NL@%
- GpiSetColor( hpsLocal, CLR_WHITE); %@AB@%/* white interior */%@AE@%%@NL@%
- GpiBox( hpsLocal%@NL@%
- , DRO_FILL%@NL@%
- , &ptl%@NL@%
- , (LONG)sCharWidth%@NL@%
- , (LONG)(sCharHeight / 2) );%@NL@%
- ptl.x = 0;%@NL@%
- ptl.y = 0;%@NL@%
- GpiSetCurrentPosition( hpsLocal, &ptl);%@NL@%
- ptl.x = (11 * sCharWidth / 3) - 1;%@NL@%
- ptl.y = (7 * sCharHeight / 4) - 1;%@NL@%
- GpiSetColor( hpsLocal, CLR_BLACK); %@AB@%/* black border */%@AE@%%@NL@%
- GpiBox( hpsLocal%@NL@%
- , DRO_OUTLINE%@NL@%
- , &ptl%@NL@%
- , (LONG)sCharWidth%@NL@%
- , (LONG)(sCharHeight / 2) );%@NL@%
- return( TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CALCMATH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CALC\CALCMATH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header *********************************/%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* Module Name: calcmath.c - Calc application */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* OS/2 Presentation Manager version of Calc, ported from Windows version */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* Created by Microsoft Corporation, 1987 */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WINCLIPBOARD %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@NL@%
- extern BOOL fValueInMemory;%@NL@%
- extern CHAR chLastKey;%@NL@%
- extern CHAR szreg1[20], szreg2[20], szmem[20];%@NL@%
- extern HWND hwndCalc;%@NL@%
- extern CHAR szregx[];%@NL@%
- extern HAB hab;%@NL@%
- BOOL fReadNumber;%@NL@%
- CHAR PendingOperation;%@NL@%
- BOOL fFirstOperand, fError;%@NL@%
- CHAR szresult[20];%@NL@%
- SEL sel;%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%tolower(x) (((x) >= 'A') && ((x)<='Z')) ? (x) - 'A' + 'a' : (x) %@NL@%
- %@AI@%#define %@AE@%MAXINT (double)999999999 %@NL@%
- %@AI@%#define %@AE@%MININT (double)-999999999 %@NL@%
- %@AI@%#define %@AE@%ABS(x) (((x) >= (double)0) ? (x) : (-(x))) %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- extern VOID UpdateDisplay( VOID);%@NL@%
- extern BOOL InterpretChar( CHAR);%@NL@%
- %@NL@%
- VOID AppendNumber( BYTE);%@NL@%
- VOID BinaryOperator( CHAR);%@NL@%
- VOID Clear( VOID);%@NL@%
- VOID DataXCopy( VOID);%@NL@%
- VOID DataXPaste( VOID);%@NL@%
- VOID Equilibrate( VOID);%@NL@%
- VOID Evaluate( BYTE);%@NL@%
- VOID FarStrcpy( PSZ, PSZ);%@NL@%
- NPCH ftoa( double);%@NL@%
- VOID InitCalc( VOID);%@NL@%
- VOID MClear( VOID);%@NL@%
- VOID MMinus( VOID);%@NL@%
- VOID MPlus( VOID);%@NL@%
- VOID Negate( VOID);%@NL@%
- VOID Number( CHAR);%@NL@%
- VOID Percent( VOID);%@NL@%
- VOID reverse( NPCH);%@NL@%
- VOID Simplify( VOID);%@NL@%
- VOID SquareRoot( VOID);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID FarStrcpy( pszDest, pszSrc)%@NL@%
- PSZ pszDest, pszSrc;%@NL@%
- {%@NL@%
- while( *pszDest++ = *pszSrc++);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- reverse( s)%@NL@%
- %@NL@%
- NPCH s;%@NL@%
- {%@NL@%
- CHAR ch;%@NL@%
- register INT iHead, iTail;%@NL@%
- %@NL@%
- for (iHead = 0, iTail = strlen(s) - 1; iHead<iTail; iHead++, iTail-- ) {%@NL@%
- ch = s[iHead];%@NL@%
- s[iHead] = s[iTail];%@NL@%
- s[iTail] = ch;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- NPCH%@NL@%
- ftoa( dblNum)%@NL@%
- %@NL@%
- double dblNum;%@NL@%
- {%@NL@%
- sprintf( szresult, "%.8f", dblNum );%@NL@%
- return (szresult);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- Negate()%@NL@%
- {%@NL@%
- CHAR sztemp[ 20 ];%@NL@%
- %@NL@%
- if (szreg1[0] == '-')%@NL@%
- strcpy(szreg1, (&szreg1[1])); %@AB@%/* get rid of minus sign */%@AE@%%@NL@%
- else if (szreg1[0] != '0' || (strlen(szreg1) > 2)) { %@AB@%/* can't negate zero */%@AE@%%@NL@%
- sztemp[0] = '-';%@NL@%
- strcpy(&sztemp[1], szreg1);%@NL@%
- strcpy(szreg1, sztemp);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- Number( ch)%@NL@%
- %@NL@%
- CHAR ch;%@NL@%
- {%@NL@%
- register INT iLen, iSize;%@NL@%
- %@NL@%
- iSize = 9;%@NL@%
- if (szreg1[0] == '-') iSize++;%@NL@%
- if (strchr(szreg1, '.')) iSize++;%@NL@%
- iLen = strlen(szreg1 );%@NL@%
- if (iLen == iSize) return;%@NL@%
- if (iLen == 1 && szreg1[0] == '0') iLen--;%@NL@%
- szreg1[ iLen ] = ch;%@NL@%
- szreg1[min(iLen + 1, 11)] = 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- AppendNumber ( b)%@NL@%
- %@NL@%
- BYTE b;%@NL@%
- {%@NL@%
- if (b == '.') { %@AB@%/* if no decimal, add one at end */%@AE@%%@NL@%
- if (!strchr(szreg1, '.')) %@NL@%
- strcat(szreg1, ".");%@NL@%
- }%@NL@%
- else if ( b == 0xb1 )%@NL@%
- Negate();%@NL@%
- else%@NL@%
- Number(b);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- Equilibrate()%@NL@%
- {%@NL@%
- double dblResult;%@NL@%
- double dblX1, dblX2;%@NL@%
- %@NL@%
- if (chLastKey == '=') return;%@NL@%
- dblResult = (double)atof(szreg1);%@NL@%
- dblX1 = (double)atof(szreg1);%@NL@%
- dblX2 = (double)atof(szreg2);%@NL@%
- %@NL@%
- switch (PendingOperation) {%@NL@%
- case '+':%@NL@%
- if (dblX2>(double)0) { %@AB@%/* check for overflow */%@AE@%%@NL@%
- if (dblX1>(double)0) {%@NL@%
- if (dblX1 > (MAXINT - dblX2))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- else if (dblX2 < (double)0) {%@NL@%
- if (dblX1 < (double)0) {%@NL@%
- if ( dblX1 < (MININT - dblX2))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- if (!fError)%@NL@%
- dblResult = dblX2 + dblX1;%@NL@%
- break;%@NL@%
- case '-':%@NL@%
- if (dblX2 < (double)0) {%@NL@%
- if (dblX1 > (double)0) {%@NL@%
- if (dblX1 > (dblX2 - MININT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- else if (dblX2 > (double)0) {%@NL@%
- if (dblX1 < (double)0) {%@NL@%
- if (dblX1 < (dblX2 - MAXINT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- if (!fError) %@NL@%
- dblResult = dblX2 - dblX1;%@NL@%
- break;%@NL@%
- case '/':%@NL@%
- if (dblX1 == (double)0.0)%@NL@%
- fError = TRUE;%@NL@%
- else if (dblX2 > (double)0) {%@NL@%
- if (dblX1 > (double)0) {%@NL@%
- if (dblX1 < (dblX2 / MAXINT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- else { %@AB@%/* dblX1 < 0 here */%@AE@%%@NL@%
- if (dblX1 > (dblX2 / MININT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- else { %@AB@%/* dblX2 < 0 here */%@AE@%%@NL@%
- if (dblX1 < (double)0) {%@NL@%
- if (dblX1 > (dblX2 / MAXINT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- else { %@AB@%/* dblX1 > 0 here */%@AE@%%@NL@%
- if (dblX1 < (dblX2 / MININT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- if (!fError)%@NL@%
- dblResult = dblX2 / dblX1;%@NL@%
- break;%@NL@%
- case '*':%@NL@%
- if (dblX1 == (double)0) return;%@NL@%
- if (ABS(dblX2) > (double)1) {%@NL@%
- if (ABS(dblX1) > (double)1) {%@NL@%
- if (ABS(dblX1) > (MAXINT / ABS(dblX2)))%@NL@%
- fError = TRUE;%@NL@%
- } %@NL@%
- } %@NL@%
- if (!fError) dblResult = dblX2 * dblX1;%@NL@%
- break;%@NL@%
- }%@NL@%
- if (!fError) {%@NL@%
- strcpy(szreg1, ftoa((double)dblResult));%@NL@%
- strcpy( szreg2, szreg1 );%@NL@%
- }%@NL@%
- Simplify();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- SquareRoot()%@NL@%
- {%@NL@%
- double dblResult;%@NL@%
- %@NL@%
- dblResult = (double)atof(szreg1);%@NL@%
- if (dblResult < 0.0) {%@NL@%
- fError = TRUE;%@NL@%
- return;%@NL@%
- }%@NL@%
- if ((dblResult == 0.0) || ((chLastKey == 'q') && (dblResult == 1.0)))%@NL@%
- return;%@NL@%
- if ((dblResult < (double) 1.00000002) && (dblResult > (double) 1.0))%@NL@%
- dblResult = (double)1.0;%@NL@%
- else%@NL@%
- dblResult = sqrt(dblResult);%@NL@%
- strcpy( szreg1, ftoa((double)dblResult));%@NL@%
- if (atof( szreg1 ) == 0.0)%@NL@%
- strcpy(szreg1, "0.");%@NL@%
- Simplify();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- BinaryOperator( ch)%@NL@%
- %@NL@%
- CHAR ch;%@NL@%
- {%@NL@%
- if (fFirstOperand) {%@NL@%
- fFirstOperand = FALSE;%@NL@%
- strcpy(szreg2, szreg1);%@NL@%
- }%@NL@%
- else {%@NL@%
- Equilibrate();%@NL@%
- }%@NL@%
- PendingOperation = ch;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- Clear()%@NL@%
- {%@NL@%
- fReadNumber = FALSE;%@NL@%
- fFirstOperand = TRUE;%@NL@%
- strcpy(szreg1, "0.");%@NL@%
- if (fError || chLastKey == 'c'){%@NL@%
- strcpy(szreg2, "0.");%@NL@%
- PendingOperation = NULL;%@NL@%
- }%@NL@%
- fError = FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- %@AB@%/* trash out trailing zeros, if a '.' is in the number */%@AE@%%@NL@%
- %@AB@%/* and leading zeros in all cases. */%@AE@%%@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- Simplify()%@NL@%
- {%@NL@%
- register INT iLen, iCount;%@NL@%
- CHAR achLocal[20];%@NL@%
- %@NL@%
- iCount = 0;%@NL@%
- strcpy(achLocal, szreg1);%@NL@%
- if (atof(achLocal) != 0.0) {%@NL@%
- while (achLocal[iCount++] == '0');%@NL@%
- strcpy(szreg1, &achLocal[iCount-1] );%@NL@%
- }%@NL@%
- if (strchr(szreg1, '.')) {%@NL@%
- iLen = strlen(szreg1);%@NL@%
- while (szreg1[--iLen] == '0');%@NL@%
- szreg1[min( iLen + 1, 11)] = 0; %@AB@%/* null terminate */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- DataXPaste()%@NL@%
- {%@NL@%
- PSZ psz;%@NL@%
- ULONG ulText;%@NL@%
- register CHAR ch;%@NL@%
- %@NL@%
- if (WinOpenClipbrd( hab))%@NL@%
- {%@NL@%
- ulText = WinQueryClipbrdData( hab, CF_TEXT);%@NL@%
- if (ulText)%@NL@%
- {%@NL@%
- psz = MAKEP( (SEL)ulText, 0);%@NL@%
- while (*psz)%@NL@%
- {%@NL@%
- ch = (CHAR) (tolower(*psz));%@NL@%
- if (ch == 'm')%@NL@%
- {%@NL@%
- psz++;%@NL@%
- switch (tolower(*psz))%@NL@%
- {%@NL@%
- case '-':%@NL@%
- ch = '\271';%@NL@%
- break;%@NL@%
- case '+':%@NL@%
- ch = '\272';%@NL@%
- break;%@NL@%
- case 'r':%@NL@%
- ch = '\273';%@NL@%
- break;%@NL@%
- case 'c':%@NL@%
- ch = '\274';%@NL@%
- break;%@NL@%
- default:%@NL@%
- ch = ' ';%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- psz++;%@NL@%
- InterpretChar(ch);%@NL@%
- UpdateDisplay();%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- WinCloseClipbrd( hab);%@NL@%
- InterpretChar('=');%@NL@%
- UpdateDisplay();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- DataXCopy()%@NL@%
- {%@NL@%
- PSZ pszText;%@NL@%
- %@NL@%
- if (WinOpenClipbrd( hab))%@NL@%
- {%@NL@%
- WinEmptyClipbrd( hab);%@NL@%
- DosAllocSeg( 20, (SEL FAR *)&sel, SEG_GIVEABLE);%@NL@%
- if (sel == NULL) return;%@NL@%
- pszText = MAKEP(sel, 0);%@NL@%
- FarStrcpy( pszText, (PSZ)szreg1);%@NL@%
- WinSetClipbrdData( hab, (ULONG)sel, CF_TEXT, CFI_SELECTOR);%@NL@%
- WinCloseClipbrd( hab);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- MPlus()%@NL@%
- {%@NL@%
- double dblX1, dblX2, dblResult;%@NL@%
- %@NL@%
- dblX2 = atof(szmem);%@NL@%
- dblX1 = atof(szreg1);%@NL@%
- %@NL@%
- if (dblX2>(double)0) { %@AB@%/* check for overflow */%@AE@%%@NL@%
- if (dblX1>(double)0) {%@NL@%
- if (dblX1 > (MAXINT - dblX2))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- else if (dblX2 < (double)0) {%@NL@%
- if (dblX1 < (double)0) {%@NL@%
- if ( dblX1 < (MININT - dblX2))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- if (!fError) {%@NL@%
- dblResult = dblX2 + dblX1;%@NL@%
- strcpy( szmem, ftoa((double)dblResult));%@NL@%
- }%@NL@%
- if (dblResult == (double)0.0)%@NL@%
- fValueInMemory = FALSE; %@NL@%
- else fValueInMemory = TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- MClear()%@NL@%
- {%@NL@%
- strcpy(szmem, "0."); %@NL@%
- fValueInMemory = FALSE; %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- MMinus()%@NL@%
- {%@NL@%
- double dblX1, dblX2, dblResult;%@NL@%
- %@NL@%
- dblX2 = atof(szmem);%@NL@%
- dblX1 = atof(szreg1);%@NL@%
- if (dblX2 < (double)0) {%@NL@%
- if (dblX1 > (double)0) {%@NL@%
- if (dblX1 > (dblX2 - MININT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- else if (dblX2 > (double)0) {%@NL@%
- if (dblX1 < (double)0) {%@NL@%
- if (dblX1 < (dblX2 - MAXINT))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- if (!fError) {%@NL@%
- dblResult = dblX2 - dblX1;%@NL@%
- strcpy( szmem, ftoa((double)dblResult));%@NL@%
- }%@NL@%
- if (dblResult == (double)0.0)%@NL@%
- fValueInMemory = FALSE; %@NL@%
- else fValueInMemory = TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- Evaluate( bCommand)%@NL@%
- %@NL@%
- BYTE bCommand;%@NL@%
- {%@NL@%
- switch( bCommand ) {%@NL@%
- case '0': case '1': case '2': case '3': case '4': case '5':%@NL@%
- case '6': case '7': case '8': case '9': case '.': case 0xb1:%@NL@%
- case 'n': %@AB@%/* n = 'negate' from keyboard */%@AE@%%@NL@%
- if ( fReadNumber )%@NL@%
- AppendNumber( bCommand );%@NL@%
- else {%@NL@%
- %@AB@%/* if starting a new number */%@AE@%%@NL@%
- if (bCommand != 0xb1)%@NL@%
- strcpy(szreg1, "0");%@NL@%
- AppendNumber( bCommand );%@NL@%
- }%@NL@%
- if (bCommand != 0xb1)%@NL@%
- fReadNumber = TRUE;%@NL@%
- break;%@NL@%
- case '+': case '-': case '/': case '*': case 'p':%@NL@%
- BinaryOperator(bCommand);%@NL@%
- fReadNumber = FALSE;%@NL@%
- break;%@NL@%
- case '=':%@NL@%
- fReadNumber = FALSE;%@NL@%
- Equilibrate();%@NL@%
- PendingOperation = NULL;%@NL@%
- break;%@NL@%
- case 'q':%@NL@%
- SquareRoot();%@NL@%
- fReadNumber = FALSE;%@NL@%
- break;%@NL@%
- case 0xBB: %@AB@%/* MR */%@AE@%%@NL@%
- strcpy(szreg1, szmem);%@NL@%
- fReadNumber = FALSE;%@NL@%
- Simplify();%@NL@%
- break;%@NL@%
- case 0xBA: %@AB@%/* M+ */%@AE@%%@NL@%
- MPlus();%@NL@%
- fReadNumber = FALSE;%@NL@%
- Simplify();%@NL@%
- break;%@NL@%
- case 0xB9: %@AB@%/* M- */%@AE@%%@NL@%
- MMinus();%@NL@%
- fReadNumber = FALSE;%@NL@%
- Simplify();%@NL@%
- break;%@NL@%
- case 0xBC:%@NL@%
- MClear(); %@AB@%/* MC */%@AE@%%@NL@%
- break;%@NL@%
- case '%':%@NL@%
- Percent();%@NL@%
- fReadNumber = FALSE;%@NL@%
- break;%@NL@%
- case 'c':%@NL@%
- Clear();%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- Percent()%@NL@%
- {%@NL@%
- double dblX1, dblX2, dblResult;%@NL@%
- %@NL@%
- dblX1 = atof(szreg1) / 100.0;%@NL@%
- dblX2 = atof(szreg2);%@NL@%
- if (ABS(dblX2) > (double)1) {%@NL@%
- if (ABS(dblX1) > (double)1) {%@NL@%
- if (dblX1 > (MAXINT / dblX2))%@NL@%
- fError = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- if (!fError) {%@NL@%
- dblResult = dblX2 * dblX1;%@NL@%
- strcpy( szreg1, ftoa((double)dblResult));%@NL@%
- }%@NL@%
- Simplify();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/******************************************************************************/%@AE@%%@NL@%
- VOID%@NL@%
- InitCalc()%@NL@%
- {%@NL@%
- fReadNumber = FALSE;%@NL@%
- fError = FALSE;%@NL@%
- fFirstOperand = TRUE;%@NL@%
- PendingOperation = 0;%@NL@%
- strcpy(szreg1, "0.");%@NL@%
- strcpy(szmem, "0.");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CASCADE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CASCADE\CASCADE.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_PM %@NL@%
- %@AI@%#include %@AE@%<OS2.H> %@NL@%
- %@AI@%#include %@AE@%"Cascade.H" %@NL@%
- %@NL@%
- char szAppName[] = "Cascade";%@NL@%
- char szAppTitle[] = "Cascading Menu Example";%@NL@%
- %@NL@%
- HAB hAB;%@NL@%
- HMQ hmqMsgQueue;%@NL@%
- HWND hWndMain,%@NL@%
- hWndFrame;%@NL@%
- %@NL@%
- int cdecl main()%@NL@%
- {%@NL@%
- QMSG qmsg;%@NL@%
- ULONG ctlData = FCF_STANDARD & ~FCF_ACCELTABLE;%@NL@%
- %@NL@%
- hAB = WinInitialize (0);%@NL@%
- %@NL@%
- hmqMsgQueue = WinCreateMsgQueue (hAB, 0);%@NL@%
- %@NL@%
- if (!WinRegisterClass (hAB,%@NL@%
- szAppName,%@NL@%
- WndProc,%@NL@%
- CS_SYNCPAINT | CS_SIZEREDRAW,%@NL@%
- 0)) {%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- hWndFrame = WinCreateStdWindow ( HWND_DESKTOP,%@NL@%
- WS_VISIBLE,%@NL@%
- &ctlData,%@NL@%
- szAppName,%@NL@%
- NULL,%@NL@%
- 0L,%@NL@%
- 0,%@NL@%
- ID_RESOURCE,%@NL@%
- &hWndMain);%@NL@%
- WinSetWindowText (hWndFrame, szAppTitle);%@NL@%
- WinShowWindow (hWndFrame, TRUE);%@NL@%
- %@NL@%
- while ( WinGetMsg (hAB, &qmsg, NULL, 0, 0)) {%@NL@%
- WinDispatchMsg (hAB, &qmsg);%@NL@%
- }%@NL@%
- %@NL@%
- WinDestroyWindow (hWndFrame);%@NL@%
- WinDestroyMsgQueue (hmqMsgQueue);%@NL@%
- WinTerminate (hAB);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*-------------------------------------------------------------------*/%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/*-------------------------------------------------------------------*/%@AE@%%@NL@%
- %@NL@%
- BOOL CheckAll (HWND hMenu, int item, BOOL check);%@NL@%
- BOOL CheckAll (HWND hMenu, int item, BOOL check)%@NL@%
- {%@NL@%
- int mPos,max,test;%@NL@%
- MENUITEM mi;%@NL@%
- char szText[20];%@NL@%
- MPARAM mp1, mp2;%@NL@%
- %@NL@%
- max =(int) SHORT1FROMMR( WinSendMsg (hMenu, MM_QUERYITEMCOUNT, 0L, 0L) ); %@NL@%
- %@NL@%
- for (mPos=0; mPos!=(int) max; mPos++) {%@NL@%
- test =(int) SHORT1FROMMR( WinSendMsg (hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(mPos), 0L) );%@NL@%
- WinSendMsg (hMenu, MM_QUERYITEMTEXT, MPFROM2SHORT(test,sizeof(szText)), MPFROMP(szText));%@NL@%
- if (test == item) {%@NL@%
- mp1 = MPFROM2SHORT (test, TRUE);%@NL@%
- if (check)%@NL@%
- mp2 = MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED);%@NL@%
- else%@NL@%
- mp2 = MPFROM2SHORT(MIA_CHECKED, 0);%@NL@%
- WinPostMsg (hMenu, MM_SETITEMATTR, mp1, mp2);%@NL@%
- return TRUE;%@NL@%
- } else {%@NL@%
- WinSendMsg (hMenu, MM_QUERYITEM, MPFROM2SHORT(test,FALSE), (MPARAM)&mi);%@NL@%
- if (mi.hwndSubMenu) {%@NL@%
- if (CheckAll(mi.hwndSubMenu, item, check)) {%@NL@%
- mp1 = MPFROM2SHORT (test, TRUE);%@NL@%
- if (check)%@NL@%
- mp2 = MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED);%@NL@%
- else%@NL@%
- mp2 = MPFROM2SHORT(MIA_CHECKED, 0);%@NL@%
- WinPostMsg (hMenu, MM_SETITEMATTR, mp1, mp2);%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*-------------------------------------------------------------------*/%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/*-------------------------------------------------------------------*/%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY WndProc (hWnd, msg, mp1, mp2)%@NL@%
- HWND hWnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1, mp2;%@NL@%
- {%@NL@%
- HPS hPS;%@NL@%
- HWND hMenu;%@NL@%
- static int prevFont = 0;%@NL@%
- int thisItem;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- thisItem = SHORT1FROMMP(mp1);%@NL@%
- switch (thisItem) {%@NL@%
- case IDM_ABOUT:%@NL@%
- WinMessageBox (HWND_DESKTOP, hWnd,%@NL@%
- "Sample PM Application",%@NL@%
- szAppTitle, 1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);%@NL@%
- break;%@NL@%
- default:%@NL@%
- if ((thisItem >= IDM_FIRSTFONT) && (thisItem<= IDM_LASTFONT)) {%@NL@%
- hMenu = WinWindowFromID (%@NL@%
- WinQueryWindow (hWnd, QW_PARENT, FALSE),%@NL@%
- FID_MENU);%@NL@%
- CheckAll (hMenu, prevFont, FALSE);%@NL@%
- CheckAll (hMenu, thisItem, TRUE);%@NL@%
- prevFont = thisItem;%@NL@%
- } else {%@NL@%
- DosBeep(600,60);%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CLOSE:%@NL@%
- WinPostMsg (hWnd, WM_QUIT, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ERASEBACKGROUND:%@NL@%
- return ((MRESULT) TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- hPS = WinBeginPaint (hWnd, NULL, (PWRECT)NULL);%@NL@%
- WinEndPaint (hPS);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return (WinDefWindowProc (hWnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return 0L;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHASER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CHASER\CHASER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SWARM%@NL@%
- %@AB@% * Created by Microsoft Corp. 1986%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * the idea behind this game is as follows:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * You have a collection of objects in the center of the playing field%@NL@%
- %@AB@% * that you are trying to protect (just one object in current version). You%@NL@%
- %@AB@% * control your own movements with the mouse. A number of "chasers" start%@NL@%
- %@AB@% * around the edges of the field and begin moving towards the objects%@NL@%
- %@AB@% * you want to protect. If you move the mouse on top of a chaser and click%@NL@%
- %@AB@% * the left button, the chaser will be killed and disappear from the screen.%@NL@%
- %@AB@% * But as you close in on the chaser, it will detect your presence and try%@NL@%
- %@AB@% * to dodge you. Meanwhile the other chasers will continue to go after%@NL@%
- %@AB@% * your objects. If one of the chasers reaches an object, it will begin%@NL@%
- %@AB@% * dragging it away to the edge of the screen (currently the game just%@NL@%
- %@AB@% * ends when the single object is reached). When all objects are dragged%@NL@%
- %@AB@% * away, the game ends. If a chaser is killed while dragging an object, the%@NL@%
- %@AB@% * object is left where it is and must be protected in place - player cannot%@NL@%
- %@AB@% * move objects. If you kill all the chasers, a new group of faster ones%@NL@%
- %@AB@% * will be spawned (currently the speed is constant). Your score is how%@NL@%
- %@AB@% * many chasers you can kill (no score currently kept), so there is no%@NL@%
- %@AB@% * advantage in sitting on the object for long periods.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Swarm demonstrates several capabilities of OS/2 and the philosphy behind%@NL@%
- %@AB@% * them. This program is made of three components: Initialization, the%@NL@%
- %@AB@% * mouse driven thread and the attacker thread. The attacker thread is%@NL@%
- %@AB@% * launched as many times as there are attackers in a game. Launching%@NL@%
- %@AB@% * the attacker several times takes full advantage of the OS to schedule%@NL@%
- %@AB@% * resources. The programmer can think of the problem as only one attacker.%@NL@%
- %@AB@% * The system handles multiple instances of the thread.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * As the main loop launches threads it puts an ID code into the thread's%@NL@%
- %@AB@% * stack. The code is used to index into the universe data.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * A ram semaphore is used to control access to global data.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * This demonstration shows the use of the following OS/2 system calls:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Tasking: VIO API: Mouse API:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * DosSemRequest() VioScrollUp() MouOpen()%@NL@%
- %@AB@% * DosSemClear() VioWrtCellStr() MouSetPtrPos()%@NL@%
- %@AB@% * DosCreateThread() VioSetCurType() MouReadEventQue()%@NL@%
- %@AB@% * DosExit() VioSetMode()%@NL@%
- %@AB@% * DosSleep()%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<os2def.h> %@NL@%
- %@AI@%#define %@AE@%INCL_DOSPROCESS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSSEMAPHORES %@NL@%
- %@AI@%#include %@AE@%<bsedos.h> %@NL@%
- %@AI@%#define %@AE@%INCL_SUB %@NL@%
- %@AI@%#include %@AE@%<bsesub.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#undef %@AE@%NULL %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% STACKSIZE 200 %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% DANGERZONE 3 %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% LONGNAP 500L %@NL@%
- %@AI@%#define %@AE@% SHORTNAP 150L %@NL@%
- %@NL@%
- WAIT (-1L) %@AB@%/* Wait for ram Semaphore */%@AE@%%@NL@%
- %@NL@%
- CHASER 8 %@AB@%/* Number of chasers */%@AE@%%@NL@%
- %@NL@%
- SCREEN_HEIGHT 24 %@AB@%/* Default screen size */%@AE@%%@NL@%
- %@AI@%#define %@AE@% SCREEN_WIDTH 79 %@NL@%
- %@NL@%
- GOAL univ[CHASER] %@AB@%/* Macros for constant stuff */%@AE@%%@NL@%
- %@AI@%#define %@AE@% ME univ[ID] %@NL@%
- %@AI@%#define %@AE@% MOUSE univ[CHASER+1] %@NL@%
- %@NL@%
- ALIVE 1 %@AB@%/* Flags for attackers/goal */%@AE@%%@NL@%
- %@AI@%#define %@AE@% DEAD 0 %@NL@%
- %@NL@%
- char Chaser[2] = { 0xE8, 0x20 }; %@AB@%/* character and attribute */%@AE@%%@NL@%
- char Prize[2] = { 0x03, 0x2C }; %@AB@%/* for our various objects */%@AE@%%@NL@%
- char Blank[2] = { 0x20, 0x22 };%@NL@%
- char Blood[2] = { 0x20, 0x44 };%@NL@%
- %@NL@%
- struct { %@AB@%/* Universe structure and array */%@AE@%%@NL@%
- int row; %@AB@%/* univ[0] = chaser */%@AE@%%@NL@%
- int col; %@AB@%/* univ[n-1] = chaser */%@AE@%%@NL@%
- int state; %@AB@%/* univ[n] = GOAL */%@AE@%%@NL@%
- } univ[CHASER+1]; %@AB@%/* univ[n+1]= MOUSE */%@AE@%%@NL@%
- %@NL@%
- short ScreenHeight, %@AB@%/* Screen attributes */%@AE@%%@NL@%
- ScreenWidth;%@NL@%
- %@NL@%
- HMOU Mouse; %@AB@%/* place for mouse handle */%@AE@%%@NL@%
- ULONG Shortnap; %@AB@%/* Sleep times for chasers */%@AE@%%@NL@%
- ULONG Longnap;%@NL@%
- ULONG Semaphore = 0; %@AB@%/* Ram semaphore */%@AE@%%@NL@%
- %@NL@%
- struct _VIOCURSORINFO NewCur; %@AB@%/* struct for setting cursor type */%@AE@%%@NL@%
- struct _VIOCURSORINFO OldCur;%@NL@%
- %@NL@%
- struct _VIOMODEINFO modedata; %@AB@%/* Data saves for VIO mode */%@AE@%%@NL@%
- struct _VIOMODEINFO OldVioMode;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Define all procedures before main.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Defender();%@NL@%
- void CleanUp();%@NL@%
- int InitGame();%@NL@%
- void chaserthread();%@NL@%
- int ParseCmdLine(int,char **);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * main(ac,av)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Top level procedure and MOUSE thread for the GAME demo.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int main(ac, av)%@NL@%
- int ac;%@NL@%
- char *av[];%@NL@%
- {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Parse the command line and perform some initialization.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (ParseCmdLine(ac,av)) {%@NL@%
- printf("usage: %s [24|43] [F|M|S]\n",av[0]);%@NL@%
- DosExit(EXIT_THREAD,1);%@NL@%
- }%@NL@%
- if (InitGame()) %@AB@%/* Init game, exit if some problem */%@AE@%%@NL@%
- DosExit(EXIT_PROCESS,1);%@NL@%
- %@NL@%
- Defender(); %@AB@%/* Run mouse loop (defend against the swarm) */%@AE@%%@NL@%
- %@NL@%
- CleanUp();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Defender()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * This is the main loop of the mouse control thread.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The semaphore is used to prevent the other threads from time slicing %@NL@%
- %@AB@% * while this routine is examining and/or modifying the universe. The %@NL@%
- %@AB@% * Semaphore is grabbed after the read of the Mouse queue so we don't tie%@NL@%
- %@AB@% * up the attackers while waiting for a mouse event.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Defender()%@NL@%
- {%@NL@%
- USHORT ReadType = 1, %@AB@%/* Wait for mouse events */%@AE@%%@NL@%
- alive,%@NL@%
- i;%@NL@%
- struct _MOUEVENTINFO MouInfo; %@AB@%/* mouse event packet structure */%@AE@%%@NL@%
- %@NL@%
- alive = CHASER;%@NL@%
- %@NL@%
- do {%@NL@%
- MouReadEventQue( &MouInfo, &ReadType, Mouse); %@AB@%/* read where mouse is */%@AE@%%@NL@%
- %@NL@%
- DosSemRequest( &Semaphore, WAIT);%@NL@%
- %@NL@%
- if( MouInfo.fs & 1) { %@AB@%/* If the mouse has moved */%@AE@%%@NL@%
- MOUSE.row = MouInfo.row;%@NL@%
- MOUSE.col = MouInfo.col;%@NL@%
- }%@NL@%
- if( MouInfo.fs & 4 ) { %@AB@%/* if left button pressed, */%@AE@%%@NL@%
- for (i = 0; i < CHASER; i++ ) {%@NL@%
- if( ( MOUSE.row == univ[i].row ) &&%@NL@%
- ( MOUSE.col == univ[i].col ) && %@AB@%/* see if we hit one */%@AE@%%@NL@%
- ( univ[i].state == ALIVE) ) {%@NL@%
- univ[i].state = DEAD; %@NL@%
- %@NL@%
- DosBeep(300,75); %@AB@%/* make a dying sound */%@AE@%%@NL@%
- DosBeep(600,75);%@NL@%
- DosBeep(300,85);%@NL@%
- %@NL@%
- alive--; %@AB@%/* Decrease number alive */%@AE@%%@NL@%
- break; %@AB@%/* Can only kill one at a time */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- if( MouInfo.fs & 16 ) %@AB@%/* If right button pressed... */%@AE@%%@NL@%
- break; %@AB@%/* End game, clean up */%@AE@%%@NL@%
- %@NL@%
- DosSemClear(&Semaphore);%@NL@%
- }%@NL@%
- while (GOAL.state == ALIVE && alive); %@AB@%/* loop till all are dead */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This thread manages the individual attackers. It is spun off as%@NL@%
- %@AB@% * many times as needed for a game.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The interaction of the mouse cursor and the chaser character is sort%@NL@%
- %@AB@% * of funny, hence the funny code, below. The mouse cursor seems to%@NL@%
- %@AB@% * remember what was under it when it was written. Hence we cannot erase%@NL@%
- %@AB@% * the chaser if the mouse is "sitting" on it. If we do, then when the%@NL@%
- %@AB@% * mouse moves it will re-write the original object. This shows up as%@NL@%
- %@AB@% * phantom chasers.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void far chasethread(ID) %@AB@%/* code that controls each "chaser" */%@AE@%%@NL@%
- int ID;%@NL@%
- {%@NL@%
- short row, col; %@AB@%/* Our current position */%@AE@%%@NL@%
- short deltaX, deltaY; %@AB@%/* how far from the mouse are we? */%@AE@%%@NL@%
- short danger; %@AB@%/* flag to indicate not far enough! */%@AE@%%@NL@%
- short m; %@AB@%/* general purpose indexes */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Print out the initial chaser character */%@AE@%%@NL@%
- %@NL@%
- VioWrtCellStr( Chaser, 2, ME.row, ME.col, 0 );%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Keep running as long as the goal and myself haven't been killed.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (;;) {%@NL@%
- %@NL@%
- row = ME.row; %@AB@%/* Grab the current position */%@AE@%%@NL@%
- col = ME.col;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If mouse is sitting upon the chaser, do nothing. Allow%@NL@%
- %@AB@% * the player some time to kill the chaser%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((MOUSE.row == row) && (MOUSE.col == col)) {%@NL@%
- DosSleep( 1L );%@NL@%
- continue;%@NL@%
- }%@NL@%
- DosSemRequest(&Semaphore, WAIT);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If either the GOAL or Myself is dead, exit loop and clean up.%@NL@%
- %@AB@% * This wasn't tested in the for loop since we don't want to exit%@NL@%
- %@AB@% * if the MOUSE is sitting on the chaser.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (ME.state != ALIVE || GOAL.state != ALIVE)%@NL@%
- break;%@NL@%
- %@NL@%
- deltaX = MOUSE.col - col; %@AB@%/* calculate how far we are */%@AE@%%@NL@%
- deltaY = MOUSE.row - row;%@NL@%
- %@NL@%
- if (((deltaX < -DANGERZONE) || (DANGERZONE < deltaX)) ||%@NL@%
- ((deltaY < -DANGERZONE) || (DANGERZONE < deltaY))) {%@NL@%
- %@NL@%
- danger = 0;%@NL@%
- %@NL@%
- if(GOAL.row < row) %@AB@%/* Creep towards the GOAL */%@AE@%%@NL@%
- row--;%@NL@%
- else if (GOAL.row > row)%@NL@%
- row++;%@NL@%
- if(GOAL.col < col)%@NL@%
- col--;%@NL@%
- else if(GOAL.col > col)%@NL@%
- col++;%@NL@%
- }%@NL@%
- else {%@NL@%
- danger = 1; %@AB@%/* Run away from the mouse */%@AE@%%@NL@%
- %@NL@%
- if ((MOUSE.row > row) && (row > 0))%@NL@%
- row--;%@NL@%
- else if ((MOUSE.row < row) && (row < ScreenHeight))%@NL@%
- row++;%@NL@%
- if ((MOUSE.col > col) && (col < ScreenWidth))%@NL@%
- col--;%@NL@%
- else if ((MOUSE.col < col) && (col > 0))%@NL@%
- col++;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * A quick and Dirty hack to prevent chasers from merging%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (m = 0; m < CHASER; m++ ) {%@NL@%
- if (univ[m].state == ALIVE &&%@NL@%
- univ[m].row == row &&%@NL@%
- univ[m].col == col &&%@NL@%
- m != ID) {%@NL@%
- row += 1;%@NL@%
- col += 3;%@NL@%
- }%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Zap the old chaser and print the new. Release the semaphore%@NL@%
- %@AB@% * after this, there can be no undesirable interactions now.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- VioWrtCellStr( Blank, 2, ME.row, ME.col, 0 );%@NL@%
- VioWrtCellStr( Chaser, 2, row, col, 0 );%@NL@%
- %@NL@%
- DosSemClear(&Semaphore);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Update the current location%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ME.row = row;%@NL@%
- ME.col = col;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * See if we have reached the GOAL, if so eat it and exit%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((row == GOAL.row) && (col == GOAL.col)) {%@NL@%
- VioWrtCellStr( Blank, 2, row, col, 0 );%@NL@%
- DosBeep(600,175);%@NL@%
- DosBeep(1200,175); %@AB@%/* if we reach the prize, let out a yell */%@AE@%%@NL@%
- DosBeep(600,185); %@AB@%/* paint the screen red and end the game */%@AE@%%@NL@%
- DosBeep(1200,175);%@NL@%
- VioScrollUp( 0, 0, -1, -1, -1, Blood, 0 );%@NL@%
- GOAL.state = DEAD;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Sleep an amount of time that varies depending%@NL@%
- %@AB@% * upon the danger level%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( danger )%@NL@%
- DosSleep(Shortnap);%@NL@%
- else%@NL@%
- DosSleep(Longnap);%@NL@%
- %@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * chaser is now dead or the game is over.%@NL@%
- %@AB@% * Erase its body and terminate the thread. Release the semaphore.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosSemClear(&Semaphore);%@NL@%
- %@NL@%
- if (GOAL.state == ALIVE) {%@NL@%
- VioWrtCellStr(Blank, 2, ME.row, ME.col, 0 );%@NL@%
- }%@NL@%
- DosExit( EXIT_THREAD ,0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * InitGame()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Initialize the GOAL, MOUSE and the CHASERS, launch each chase thread.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Returns an error if any internal processing errors%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int InitGame()%@NL@%
- {%@NL@%
- struct _PTRLOC InitMouPos;%@NL@%
- void far chasethread(); %@AB@%/* code to control chasers */%@AE@%%@NL@%
- PBYTE Tstack; %@AB@%/* stack for new threads */%@AE@%%@NL@%
- unsigned chaseID;%@NL@%
- int i, rc;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Clear the screen.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- VioScrollUp( 0, 0, -1, -1, -1, Blank, 0 );%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Draw the prize%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GOAL.row = ScreenHeight/2;%@NL@%
- GOAL.col = ScreenWidth /2;%@NL@%
- GOAL.state = ALIVE;%@NL@%
- VioWrtCellStr(Prize, 2, GOAL.row, GOAL.col, 0 );%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Open the mouse pointer device and set it's location.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MouOpen( 0L, &Mouse );%@NL@%
- InitMouPos.row = GOAL.row;%@NL@%
- InitMouPos.col = GOAL.col;%@NL@%
- MouSetPtrPos( &InitMouPos, Mouse);%@NL@%
- MouDrawPtr(Mouse);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * A simple minded initialization for the start of each chaser.%@NL@%
- %@AB@% * Some sort of random placement (based upon system time?) would%@NL@%
- %@AB@% * be nice.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- univ[0].row = 0; univ[0].col = 0;%@NL@%
- univ[1].row = 0; univ[1].col = 25;%@NL@%
- univ[2].row = 0; univ[2].col = 55;%@NL@%
- univ[3].row = 0; univ[3].col = 79;%@NL@%
- univ[4].row = ScreenHeight; univ[4].col = 0;%@NL@%
- univ[5].row = ScreenHeight; univ[5].col = 25;%@NL@%
- univ[6].row = ScreenHeight; univ[6].col = 55;%@NL@%
- univ[7].row = ScreenHeight; univ[7].col = 79;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Grab the semaphore to prevent chaser from running until we are done.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosSemRequest(&Semaphore, WAIT);%@NL@%
- %@NL@%
- for( i = 0; i < CHASER; i++ ) { %@AB@%/* for each of our threads... */%@AE@%%@NL@%
- univ[i].state = ALIVE; %@AB@%/* Set each one alive */%@AE@%%@NL@%
- Tstack = (PBYTE)malloc(sizeof(int) * STACKSIZE);%@NL@%
- if (Tstack == NULL ) { %@AB@%/* Create a stack */%@AE@%%@NL@%
- printf( "thread %d stack malloc failed\n", i );%@NL@%
- return(1);%@NL@%
- }%@NL@%
- Tstack += sizeof(int)*STACKSIZE; %@AB@%/* set stack pointer to correct end */%@AE@%%@NL@%
- *--Tstack = HIBYTE(i);%@NL@%
- *--Tstack = LOBYTE(i); %@AB@%/* Push the ID on as a parameter */%@AE@%%@NL@%
- %@NL@%
- rc = DosCreateThread(chasethread, &chaseID, Tstack);%@NL@%
- if(rc) {%@NL@%
- printf( "create of thread %d failed, error: %d\n", i, rc );%@NL@%
- return (1);%@NL@%
- }%@NL@%
- }%@NL@%
- DosSemClear(&Semaphore);%@NL@%
- %@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * CleanUp()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Routine to reset the Video modes back to where they were.%@NL@%
- %@AB@% * (As best as possible).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void CleanUp()%@NL@%
- {%@NL@%
- char blank[2];%@NL@%
- %@NL@%
- DosSleep(1L); %@AB@%/* Yield the machine so attacker can clean up */%@AE@%%@NL@%
- VioSetMode( &OldVioMode, 0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% blank[0] = ' ';%@NL@%
- %@AB@% blank[1] = OldVioMode.color;%@NL@%
- %@AB@% VioScrollUp( 0, 0, -1, -1, -1, blank, 0 );%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- VioSetCurType( &OldCur, 0);%@NL@%
- DosExit(EXIT_PROCESS,0); %@AB@%/* Exit and terminate all threads. */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ParseCmdLine(ac, av)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Parses the command line arguments and sets up the game accordingly%@NL@%
- %@AB@% *%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int ParseCmdLine(ac,av)%@NL@%
- int ac;%@NL@%
- char **av;%@NL@%
- {%@NL@%
- struct _VIOMODEINFO modedata;%@NL@%
- int VioMode;%@NL@%
- %@NL@%
- Longnap = LONGNAP;%@NL@%
- Shortnap = SHORTNAP;%@NL@%
- ScreenWidth = SCREEN_WIDTH;%@NL@%
- ScreenHeight = SCREEN_HEIGHT;%@NL@%
- VioMode = 25;%@NL@%
- %@NL@%
- while(--ac) {%@NL@%
- av++;%@NL@%
- switch(**av) {%@NL@%
- case 'f':%@NL@%
- case 'F':%@NL@%
- Longnap = LONGNAP / 2;%@NL@%
- Shortnap= SHORTNAP/ 2;%@NL@%
- break;%@NL@%
- case 'm':%@NL@%
- case 'M':%@NL@%
- Longnap = LONGNAP;%@NL@%
- Shortnap= SHORTNAP;%@NL@%
- break;%@NL@%
- case 's':%@NL@%
- case 'S':%@NL@%
- Longnap = LONGNAP * 2;%@NL@%
- Shortnap= SHORTNAP* 2;%@NL@%
- break;%@NL@%
- case '4': %@AB@%/* Assume 43 line mode was wanted */%@AE@%%@NL@%
- ScreenHeight = 42;%@NL@%
- ScreenWidth = 79;%@NL@%
- VioMode = 43;%@NL@%
- break;%@NL@%
- case '2':%@NL@%
- ScreenHeight = 24;%@NL@%
- ScreenWidth = 79;%@NL@%
- VioMode = 25;%@NL@%
- break;%@NL@%
- default:%@NL@%
- return(1);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- VioGetCurType(&OldCur, 0); %@AB@%/* Save old cursor */%@AE@%%@NL@%
- %@NL@%
- modedata.cb = sizeof(modedata); %@AB@%/* change mode as needed */%@AE@%%@NL@%
- VioGetMode( &modedata, 0);%@NL@%
- OldVioMode = modedata;%@NL@%
- modedata.row = VioMode;%@NL@%
- VioSetMode( &modedata, 0);%@NL@%
- %@NL@%
- NewCur.yStart = 0;%@NL@%
- NewCur.cEnd = 0;%@NL@%
- NewCur.cx = 1;%@NL@%
- NewCur.attr = -1;%@NL@%
- %@NL@%
- VioSetCurType( &NewCur, 0 ); %@AB@%/* make cursor go away */%@AE@%%@NL@%
- %@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CIRCLEQ.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\COMTALK\CIRCLEQ.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Circular Queue buffer implementation (which gets read by AVIO module)%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_DOSSEMAPHORES %@NL@%
- <os2.h> %@AB@%/* Need USHORT for global.h */%@AE@%%@NL@%
- <string.h> %@AB@%/* One strcpy call */%@AE@%%@NL@%
- %@AI@%#include %@AE@%"global.h" %@NL@%
- %@AI@%#include %@AE@%"circleq.h" %@NL@%
- %@NL@%
- TIMEOUT 1000L %@AB@%/* A second */%@AE@%%@NL@%
- %@NL@%
- LineInfo aliRing[QUEUESIZE]; %@AB@%/* The Circular Queue...*/%@AE@%%@NL@%
- int iHead, iTail;%@NL@%
- BOOL fFirst; %@AB@%/* Are we just starting? */%@AE@%%@NL@%
- LONG lSemMyQueue; %@AB@%/* Queue lock */%@AE@%%@NL@%
- %@NL@%
- void LineCopy(Line, Line);%@NL@%
- void QueFill(void);%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%QueLock() DosSemRequest(&lSemMyQueue, -1L) %@NL@%
- %@AI@%#define %@AE@%QueUnlock() DosSemClear(&lSemMyQueue) %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%Fix(n) (((n) >= 0) ? (n) : ((n) + QUEUESIZE)) %@NL@%
- %@AI@%#define %@AE@%Circle(x) ((x) % QUEUESIZE) %@NL@%
- %@AI@%#define %@AE@%Incr(x) (x = Circle(x + 1)) %@NL@%
- %@AI@%#define %@AE@%Decr(x) (x = (x > 0) ? (x - 1) : (QUEUESIZE - 1)) %@NL@%
- %@NL@%
- void QueFill(void) {%@NL@%
- int i, j;%@NL@%
- %@NL@%
- for (i = 0; i < 25; i++) {%@NL@%
- aliRing[i].cch = MAXLINELEN;%@NL@%
- for (j = 0; j < MAXLINELEN; j++)%@NL@%
- aliRing[i].szText[j] = (char) (((i * j) % 10) + '0');%@NL@%
- }%@NL@%
- iHead = 0; iTail = 24;%@NL@%
- }%@NL@%
- %@NL@%
- void QueInit(void) {%@NL@%
- int i;%@NL@%
- %@NL@%
- fFirst = TRUE;%@NL@%
- QueLock();%@NL@%
- iHead = 0; iTail = 0;%@NL@%
- for (i = 0; i < QUEUESIZE; i++) aliRing[i].cch = 0;%@NL@%
- QueUnlock();%@NL@%
- }%@NL@%
- %@NL@%
- void QueAdvance(int n) {%@NL@%
- QueLock();%@NL@%
- iHead = Circle(iHead + n);%@NL@%
- QueUnlock();%@NL@%
- }%@NL@%
- %@NL@%
- Line QueQuery(int LineNum) { return &aliRing[Circle(iHead + LineNum)]; }%@NL@%
- %@NL@%
- BOOL QueInsertLine(Line pli) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Return FALSE if we try to overwrite the head%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- QueLock();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the queue%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (fFirst) fFirst = FALSE;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Increment TAIL, act if queue full%@NL@%
- %@AB@% Overwrite if last entry was incomplete%@NL@%
- %@AB@% */%@AE@%%@NL@%
- else if (aliRing[iTail].fComplete && (Incr(iTail) == iHead)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% We are overflowing...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Decr(iTail);%@NL@%
- QueUnlock();%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Insert the element%@NL@%
- %@AB@% */%@AE@%%@NL@%
- LineCopy(pli, &aliRing[iTail]);%@NL@%
- QueUnlock();%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- BOOL QueCompleteLine(void) { return aliRing[iTail].fComplete; }%@NL@%
- %@NL@%
- void LineCopy(Line pliSrc, Line pliDst) {%@NL@%
- int i;%@NL@%
- %@NL@%
- pliDst->fDrawn = pliSrc->fDrawn;%@NL@%
- pliDst->fComplete = pliSrc->fComplete;%@NL@%
- pliDst->cch = pliSrc->cch;%@NL@%
- for (i = 0; i < (int) pliSrc->cch; i++) pliDst->szText[i] = pliSrc->szText[i];%@NL@%
- }%@NL@%
- %@NL@%
- int QueUpdateHead(int nRows, BOOL bPage, BOOL bPaging) {%@NL@%
- int i, nLines;%@NL@%
- %@NL@%
- nLines = Fix(Circle(iTail - iHead));%@NL@%
- nLines = (nLines >= nRows) ? (nLines - nRows + 1) : 0;%@NL@%
- if ((nLines = Min(nLines, nRows)) > 0) {%@NL@%
- if (bPage) {%@NL@%
- if (nLines < nRows) {%@NL@%
- QueLock();%@NL@%
- for (i = nLines; i < nRows; i++)%@NL@%
- aliRing[Circle(iHead + nRows + i)].cch = 0;%@NL@%
- QueUnlock();%@NL@%
- }%@NL@%
- nLines = nRows;%@NL@%
- }%@NL@%
- else if (bPaging) nLines = 0;%@NL@%
- QueLock();%@NL@%
- iHead = Circle(iHead + nLines);%@NL@%
- QueUnlock();%@NL@%
- }%@NL@%
- return nLines;%@NL@%
- }%@NL@%
- %@NL@%
- Line QueLastLine(void) {%@NL@%
- QueLock();%@NL@%
- aliRing[iTail].szText[aliRing[iTail].cch] = '\0';%@NL@%
- QueUnlock();%@NL@%
- return &aliRing[iTail];%@NL@%
- }%@NL@%
- %@NL@%
- int QuePageUp(int nRows) {%@NL@%
- int i, nLines;%@NL@%
- %@NL@%
- QueLock();%@NL@%
- nLines = Min((QUEUESIZE - 1) - Fix(Circle(iTail - iHead)), nRows);%@NL@%
- if (nLines) {%@NL@%
- iHead = Fix(Circle(iHead - nLines));%@NL@%
- for (i = 0; i < nLines; i++)%@NL@%
- aliRing[Circle(iHead + nRows + i)].fDrawn = FALSE;%@NL@%
- }%@NL@%
- QueUnlock();%@NL@%
- return nLines;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CLIPFILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CLIPVIEW\CLIPFILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * CLIPFILE.C -- File handling for ClipView%@NL@%
- %@AB@% * Created by Microsoft Corporation, 1989%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * This file contains one routine: SaveClipboard(), which uses%@NL@%
- %@AB@% * the OPENDLG library to put up a File...Save... dialog box.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * After getting a file name, it tries to save the current rendered format.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_BITMAPFILEFORMAT %@NL@%
- %@AI@%#define %@AE@% INCL_DOSFILEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_DOSMEMMGR %@NL@%
- %@AI@%#define %@AE@%INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@% INCL_GPIMETAFILES %@NL@%
- %@AI@%#define %@AE@% INCL_WINCLIPBOARD %@NL@%
- %@AI@%#define %@AE@% INCL_WINERRORS %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<opendlg.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"clipview.h" %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Globals%@NL@%
- %@AB@% */%@AE@%%@NL@%
- extern HAB vhab; %@AB@%/* Anchor block */%@AE@%%@NL@%
- extern HWND vhwndClient; %@AB@%/* Main client area */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%CHK(f) fSuccess = fSuccess && (f) %@NL@%
- %@AI@%#define %@AE@%LOADSTRING(id, sz) WinLoadString(vhab, (HMODULE) NULL, id, MAXLEN, sz) %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Private function prototypes%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL SaveText(HFILE hf, PSZ pszText);%@NL@%
- %@NL@%
- BOOL SaveClipboard(HWND hwnd, USHORT usFormat) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save the clipboard contents in several formats.%@NL@%
- %@AB@% The "Save BITMAP" code is similar to that in the LINEFRAC sample.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL fSuccess = TRUE; %@AB@%/* Did we succeed in saving? */%@AE@%%@NL@%
- ULONG hItem; %@AB@%/* Handle from QueryClipbrdData */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Variables needed for File...Save... dialog.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DLF dlf; %@AB@%/* Dialog file */%@AE@%%@NL@%
- HFILE hf; %@AB@%/* Handle to output file */%@AE@%%@NL@%
- UCHAR szExt[8]; %@AB@%/* Default extension */%@AE@%%@NL@%
- UCHAR szInst[MAXLEN]; %@AB@%/* Instructions */%@AE@%%@NL@%
- UCHAR szMessage[MAXLEN]; %@AB@%/* Various messages */%@AE@%%@NL@%
- UCHAR szTitle[MAXTITLELEN];%@AB@%/* Application title */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Variables needed for saving Metafiles%@NL@%
- %@AB@% */%@AE@%%@NL@%
- HMF hmfCopy; %@AB@%/* Clipboard metafile copy */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Variables needed for saving BITMAPs%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BITMAPINFOHEADER bmp; %@AB@%/* Header to be queried */%@AE@%%@NL@%
- HDC hdcMemory; %@AB@%/* Memory DC for the BITMAP */%@AE@%%@NL@%
- HPS hpsMemory; %@AB@%/* ...and it's associated PS */%@AE@%%@NL@%
- PBITMAPFILEHEADER pbfh; %@AB@%/* bmp + color table */%@AE@%%@NL@%
- POINTL ptlOrigin; %@AB@%/* Bitmap origin */%@AE@%%@NL@%
- SEL selBuffer; %@AB@%/* Selector to actual BITMAP */%@AE@%%@NL@%
- SEL selHeader; %@AB@%/* Selector for the BMP header */%@AE@%%@NL@%
- SIZEL sizl; %@AB@%/* Used in PS creation */%@AE@%%@NL@%
- ULONG cbBuffer; %@AB@%/* No. of bytes in buffer */%@AE@%%@NL@%
- USHORT cbExtra; %@AB@%/* No. of bytes in "final" segment */%@AE@%%@NL@%
- USHORT cbHeader; %@AB@%/* No. of bytes in header */%@AE@%%@NL@%
- USHORT cbWrite1; %@AB@%/* No. of bytes to be written... */%@AE@%%@NL@%
- USHORT cbWrite2; %@AB@%/* ...in the two-part sel writes */%@AE@%%@NL@%
- USHORT cbWritten; %@AB@%/* No. of bytes actually written */%@AE@%%@NL@%
- USHORT cSegs; %@AB@%/* No. of segments to write */%@AE@%%@NL@%
- USHORT i; %@AB@%/* Which segment is being written? */%@AE@%%@NL@%
- USHORT usHugeShift;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open the clipboard%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!WinOpenClipbrd(vhab))%@NL@%
- return FALSE;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the clipboard data%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hItem = WinQueryClipbrdData(vhab, usFormat)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Put up the Save... file dialog with the appropriate extensions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch (usFormat) {%@NL@%
- case CF_TEXT:%@NL@%
- case CF_DSPTEXT: strcpy(szExt, "\\*.TXT"); break;%@NL@%
- %@NL@%
- case CF_BITMAP:%@NL@%
- case CF_DSPBITMAP: strcpy(szExt, "\\*.BMP"); break;%@NL@%
- %@NL@%
- case CF_METAFILE:%@NL@%
- case CF_DSPMETAFILE: strcpy(szExt, "\\*.MET"); break;%@NL@%
- %@NL@%
- default: strcpy(szExt, "\\*.*"); break;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Put the string "Saving Format: <format>" in the Save dialog box%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GetFormatName(usFormat, szMessage);%@NL@%
- LOADSTRING(IDS_SAVETITLE, szTitle);%@NL@%
- strcat(szTitle, szMessage);%@NL@%
- %@NL@%
- LOADSTRING(IDS_APPNAME, szMessage);%@NL@%
- LOADSTRING(IDS_INST, szInst);%@NL@%
- %@NL@%
- SetupDLF(&dlf, DLG_SAVEDLG, &hf,%@NL@%
- (PSZ) szExt, (PSZ) szMessage, (PSZ) szTitle, (PSZ) szInst);%@NL@%
- %@NL@%
- dlf.szFileName[0] = dlf.szOpenFile[0] = '\0';%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Put up a Save file dialog, and respond appropriately to%@NL@%
- %@AB@% the return status.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch (DlgFile(hwnd, &dlf)) {%@NL@%
- case TDF_ERRMEM:%@NL@%
- case TDF_INVALID:%@NL@%
- case TDF_NOSAVE:%@NL@%
- fSuccess = FALSE;%@NL@%
- %@NL@%
- %@AB@%/* fall through... */%@AE@%%@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if (fSuccess) {%@NL@%
- switch (usFormat) {%@NL@%
- %@NL@%
- case CF_TEXT:%@NL@%
- case CF_DSPTEXT:%@NL@%
- CHK(SaveText(hf, MAKEP((SEL) hItem, 0)));%@NL@%
- DosClose(hf);%@NL@%
- break;%@NL@%
- %@NL@%
- case CF_BITMAP:%@NL@%
- case CF_DSPBITMAP:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the Memory DC and its PS%@NL@%
- %@AB@% */%@AE@%%@NL@%
- sizl.cx = sizl.cy = 0L;%@NL@%
- hdcMemory = DevOpenDC(vhab, OD_MEMORY, "*", 0L, NULL, NULL);%@NL@%
- hpsMemory = GpiCreatePS(vhab, hdcMemory, &sizl,%@NL@%
- GPIA_ASSOC | GPIT_MICRO | PU_PELS);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Draw the BITMAP into the Memory DC%@NL@%
- %@AB@% */%@AE@%%@NL@%
- CHK(GpiSetBitmap(hpsMemory, (HBITMAP) hItem) != HBM_ERROR);%@NL@%
- ptlOrigin.x = ptlOrigin.y = 0L;%@NL@%
- CHK(WinDrawBitmap(hpsMemory, (HBITMAP) hItem, NULL,%@NL@%
- &ptlOrigin, CLR_BLACK, CLR_BACKGROUND, DBM_NORMAL));%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get information about the BITMAP%@NL@%
- %@AB@% */%@AE@%%@NL@%
- CHK(GpiQueryBitmapParameters((HBITMAP) hItem, &bmp) == GPI_OK);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute the size of the buffer, and allocate%@NL@%
- %@AB@% Make sure that > 64K BITMAPs are handled%@NL@%
- %@AB@% (this code is from LFFILE.C)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cbBuffer = ( ((((ULONG)bmp.cBitCount*(ULONG) bmp.cx)+31L)/32L)%@NL@%
- * 4L * (ULONG) bmp.cy * (ULONG) bmp.cPlanes );%@NL@%
- cSegs = (USHORT) (cbBuffer >> 16);%@NL@%
- cbExtra = (USHORT) (cbBuffer & 0xFFFFL);%@NL@%
- CHK(!DosAllocHuge(cSegs, cbExtra, &selBuffer, 0, 0));%@NL@%
- CHK(!DosGetHugeShift(&usHugeShift));%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute the size of the BITMAPFILEHEADER + color table...%@NL@%
- %@AB@% ...then allocate it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cbHeader = (USHORT) (sizeof(BITMAPFILEHEADER)%@NL@%
- + (sizeof(RGB) << bmp.cBitCount));%@NL@%
- CHK(!DosAllocSeg(cbHeader, &selHeader, SEG_NONSHARED));%@NL@%
- pbfh = MAKEP(selHeader, 0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Copy the BITMAP information from the BITMAPINFOHEADER%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pbfh->bmp.cbFix = 12;%@NL@%
- pbfh->bmp.cx = bmp.cx;%@NL@%
- pbfh->bmp.cy = bmp.cy;%@NL@%
- pbfh->bmp.cPlanes = bmp.cPlanes;%@NL@%
- pbfh->bmp.cBitCount = bmp.cBitCount;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the actual BITMAP bits%@NL@%
- %@AB@% */%@AE@%%@NL@%
- CHK(GpiQueryBitmapBits(hpsMemory, 0L, (LONG) bmp.cy,%@NL@%
- MAKEP(selBuffer, 0), (PBITMAPINFO) &(pbfh->bmp))%@NL@%
- != GPI_ALTERROR);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set up the file header%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pbfh->usType = BFT_BMAP;%@NL@%
- pbfh->cbSize = cbHeader + cbBuffer;%@NL@%
- pbfh->xHotspot = bmp.cx / 2; %@AB@%/* Anywhere will do */%@AE@%%@NL@%
- pbfh->yHotspot = bmp.cy / 2;%@NL@%
- pbfh->offBits = cbHeader;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Blast the BITMAP to a file...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ...first, the header...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- CHK(!DosWrite(hf, pbfh, cbHeader, &cbWritten));%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ...then, the possibly large BITMAP itself%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (i = 0; i <= cSegs; ++i) {%@NL@%
- if (i < cSegs) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If we a 64K segment, write it in two%@NL@%
- %@AB@% parts. This must be done because%@NL@%
- %@AB@% DosWrite() can only write 64K - 1%@NL@%
- %@AB@% characters at once.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cbWrite1 = cbWrite2 = 0x8000;%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% The last segment is always small enough%@NL@%
- %@AB@% to write entirely.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cbWrite1 = cbExtra; cbWrite2 = 0;%@NL@%
- }%@NL@%
- %@NL@%
- if (cbWrite1) {%@NL@%
- CHK(!DosWrite(hf,%@NL@%
- MAKEP((selBuffer + (i << usHugeShift)), 0),%@NL@%
- cbWrite1, &cbWritten));%@NL@%
- if (cbWrite2) {%@NL@%
- CHK(!DosWrite(hf,%@NL@%
- MAKEP((selBuffer + (i<<usHugeShift)),cbWrite1),%@NL@%
- cbWrite2, &cbWritten));%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clean up%@NL@%
- %@AB@%%@NL@%
- %@AB@% Error codes are not checked here because the file has%@NL@%
- %@AB@% already been saved.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosClose(hf);%@NL@%
- GpiSetBitmap(hpsMemory, NULL);%@NL@%
- GpiDestroyPS(hpsMemory);%@NL@%
- DevCloseDC(hdcMemory);%@NL@%
- break;%@NL@%
- %@NL@%
- case CF_METAFILE:%@NL@%
- case CF_DSPMETAFILE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save metafile%@NL@%
- %@AB@%%@NL@%
- %@AB@% We close and delete the file, because GpiSaveMetaFile()%@NL@%
- %@AB@% only allows the user to create a new file.%@NL@%
- %@AB@%%@NL@%
- %@AB@% We copy the metafile because GpiSaveMetafile()%@NL@%
- %@AB@% removes the data from the application's memory.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosClose(hf);%@NL@%
- CHK(!DosDelete(dlf.szFileName, 0L));%@NL@%
- CHK((hmfCopy = GpiCopyMetaFile((HMF) hItem)) != GPI_ERROR);%@NL@%
- CHK(GpiSaveMetaFile(hmfCopy, dlf.szFileName) != GPI_ERROR);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% It may be reasonable to add support for other formats%@NL@%
- %@AB@% here, by saving a bitmap of the current window contents.%@NL@%
- %@AB@%%@NL@%
- %@AB@% But for now, close the file and return an error message.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosClose(hf);%@NL@%
- fSuccess = FALSE;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- } else%@NL@%
- fSuccess = FALSE; %@AB@%/* Couldn't query the clipboard format! */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clean up%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinCloseClipbrd(vhab);%@NL@%
- return fSuccess;%@NL@%
- }%@NL@%
- %@NL@%
- BOOL SaveText(HFILE hf, PSZ pszText) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save text format%@NL@%
- %@AB@%%@NL@%
- %@AB@% Count the number of characters, then write them.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- PSZ pszCounter; %@AB@%/* Temporary to count chars in sel */%@AE@%%@NL@%
- ULONG ulcch = 0; %@AB@%/* The number of characters */%@AE@%%@NL@%
- USHORT cbWritten; %@AB@%/* No. of bytes actually written */%@AE@%%@NL@%
- %@NL@%
- pszCounter = pszText;%@NL@%
- while (*pszCounter++) ulcch++;%@NL@%
- %@NL@%
- return(!DosWrite(hf, pszText, (USHORT) ulcch, &cbWritten));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CLIPVIEW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CLIPVIEW\CLIPVIEW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * CLIPVIEW.C -- Clipboard Viewing application%@NL@%
- %@AB@% * Created by Microsoft Corporation, 1989%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * This program registers itself as the clipboard viewer, if no clipboard%@NL@%
- %@AB@% * viewer exists. Then, it intercepts WM_DRAWCLIPBOARD messages.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * This file contains the routines which handle the client/frame windows,%@NL@%
- %@AB@% * the dialog routines, and the clipboard rendering code.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@% INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@% INCL_GPIMETAFILES %@NL@%
- %@AI@%#define %@AE@%INCL_WINATOM %@NL@%
- %@AI@%#define %@AE@% INCL_WINCLIPBOARD %@NL@%
- %@AI@%#define %@AE@% INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINLISTBOXES %@NL@%
- %@AI@%#define %@AE@% INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@% INCL_WINMLE %@NL@%
- %@AI@%#define %@AE@% INCL_WINSCROLLBARS %@NL@%
- %@AI@%#define %@AE@% INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@% INCL_WINWINDOWMGR %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"clipview.h" %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Globals%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BITMAPINFOHEADER vbmp; // Dimensions of current BITMAP%@NL@%
- BOOL vfUpdate = FALSE; // Are we updating the clipboard?%@NL@%
- BOOL vfViewBitmap = FALSE; // Are we currently viewing a...?%@NL@%
- HAB vhab; // Anchor block%@NL@%
- HDC vhdcMemory; // A memory DC for BitBlt-ing images%@NL@%
- HDC vhdcWindow = NULL; // Client window DC%@NL@%
- HMQ vhmqClip; // Message queue%@NL@%
- HPS vhpsMemory; // A PS associated with vhdcMemory%@NL@%
- HWND vhwndClient; // Main client area%@NL@%
- HWND vhwndClipFrame = NULL; // Main frame window%@NL@%
- HWND vhwndHSB = NULL; // Horizontal scroll bar%@NL@%
- HWND vhwndMLE = NULL; // Handle to the MLE%@NL@%
- HWND vhwndTitlebar = NULL; // Title-bar handle%@NL@%
- HWND vhwndVSB = NULL; // Vertical scroll bar%@NL@%
- SHORT vcMaxHSB; // Maximum scroll range for HSB%@NL@%
- SHORT vcMaxVSB; // ...and for the VSB%@NL@%
- SHORT vcUpdate = -1; // Counter for scroll bar updating%@NL@%
- USHORT vausFormats[MAXFORMATS]; // All available formats%@NL@%
- USHORT vcFmts; // How many formats?%@NL@%
- USHORT vusFormat; // What is the current format?%@NL@%
- USHORT vfsFmtInfo; // Clipboard Format Information%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%LOADSTRING(id, sz) WinLoadString(vhab, (HMODULE) NULL, id, MAXLEN, sz) %@NL@%
- %@AI@%#define %@AE@%MESSAGE(sz) WinMessageBox(HWND_DESKTOP, vhwndClient, sz, NULL, 0, \ %@NL@%
- MB_OK | MB_ICONASTERISK | MB_SYSTEMMODAL);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Main routine...initializes window and message queue%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int cdecl main( ) {%@NL@%
- QMSG qmsg; %@AB@%/* Message queue */%@AE@%%@NL@%
- ULONG ctldata; %@AB@%/* FCF_ flags */%@AE@%%@NL@%
- BOOL fViewer; %@AB@%/* Does a viewer already exist? */%@AE@%%@NL@%
- UCHAR szAlready[MAXLEN]; %@AB@%/* Already extant... message */%@AE@%%@NL@%
- UCHAR szClassName[MAXLEN]; %@AB@%/* New class name */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Start up our PM application%@NL@%
- %@AB@% */%@AE@%%@NL@%
- vhab = WinInitialize(0);%@NL@%
- vhmqClip = WinCreateMsgQueue(vhab, 0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% We create the client window first to try to avoid%@NL@%
- %@AB@% synchronization problems.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- LOADSTRING(IDS_CLIPCLASS, szClassName);%@NL@%
- if (!WinRegisterClass( vhab, (PCH)szClassName, (PFNWP)ClipWndProc,%@NL@%
- CS_SIZEREDRAW, 0))%@NL@%
- return( 0 );%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Create the window (hidden)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ctldata = (FCF_STANDARD | FCF_HORZSCROLL | FCF_VERTSCROLL)%@NL@%
- & ~(FCF_ACCELTABLE);%@NL@%
- %@NL@%
- vhwndClipFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &ctldata,%@NL@%
- szClassName, "",%@NL@%
- WS_VISIBLE, (HMODULE) NULL, ID_RESOURCE,%@NL@%
- (PHWND) &vhwndClient );%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If there is no other clipboard viewer...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (fViewer = !WinQueryClipbrdViewer(vhab, FALSE)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ...we'll be the viewer. Show the clipboard window.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSetClipbrdViewer(vhab, vhwndClient);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Poll messages from event queue%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while( WinGetMsg( vhab, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )%@NL@%
- WinDispatchMsg( vhab, (PQMSG)&qmsg );%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Stop being the clipboard viewer.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (vhwndMLE)%@NL@%
- WinDestroyWindow(vhwndMLE);%@NL@%
- WinSetClipbrdViewer(vhab, NULL);%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ...otherwise, notify the user, then terminate.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- LOADSTRING(IDS_ALREADY, szAlready);%@NL@%
- MESSAGE(szAlready);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clean up%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinDestroyWindow( vhwndClipFrame );%@NL@%
- WinDestroyMsgQueue( vhmqClip );%@NL@%
- WinTerminate( vhab );%@NL@%
- %@NL@%
- return !fViewer;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK ClipWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@%%@NL@%
- %@AB@% * This routine processes WM_COMMAND, WM_CREATE, WM_DRAWCLIPBOARD, WM_PAINT.%@NL@%
- %@AB@% * Everything else is passed to the Default Window Procedure.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- HPS hpsWindow;%@NL@%
- RECTL rcl;%@NL@%
- SWP swp;%@NL@%
- SIZEL sizl;%@NL@%
- UCHAR szMessage[MAXLEN];%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- %@NL@%
- case WM_CREATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Create a memory DC/PS to BitBlt BITMAPs around.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- sizl.cx = sizl.cy = 0L;%@NL@%
- vhdcMemory = DevOpenDC(vhab, OD_MEMORY, "*", 0L, NULL, NULL);%@NL@%
- vhpsMemory = GpiCreatePS(vhab, vhdcMemory, &sizl,%@NL@%
- GPIA_ASSOC | GPIF_DEFAULT | GPIT_MICRO | PU_PELS);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (COMMANDMSG(&msg)->cmd) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog box%@NL@%
- %@AB@% */%@AE@%%@NL@%
- case IDM_ABOUT:%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc,%@NL@%
- (HMODULE) NULL, IDD_ABOUT, NULL);%@NL@%
- return 0;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Render... dialog box%@NL@%
- %@AB@% */%@AE@%%@NL@%
- case IDM_RENDER:%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, RenderDlgProc,%@NL@%
- (HMODULE) NULL, IDD_RENDER, NULL);%@NL@%
- return 0;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save... dialog box%@NL@%
- %@AB@% */%@AE@%%@NL@%
- case IDM_SAVE:%@NL@%
- if (!SaveClipboard(hwnd, vusFormat)) {%@NL@%
- LOADSTRING(IDS_NOTSAVED, szMessage);%@NL@%
- MESSAGE(szMessage);%@NL@%
- }%@NL@%
- return 0;%@NL@%
- %@NL@%
- default: break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ERASEBACKGROUND:%@NL@%
- return (MRESULT) TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- %@AB@%/* Open the presentation space */%@AE@%%@NL@%
- hpsWindow = WinBeginPaint(hwnd, NULL, &rcl);%@NL@%
- %@NL@%
- %@AB@%/* Fill in the background */%@AE@%%@NL@%
- WinFillRect(hpsWindow, &rcl, CLR_BACKGROUND);%@NL@%
- %@NL@%
- %@AB@%/* Paint in the clipboard */%@AE@%%@NL@%
- UpdateScreen(hwnd, vusFormat);%@NL@%
- %@NL@%
- %@AB@%/* Finish painting */%@AE@%%@NL@%
- WinEndPaint(hpsWindow);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DRAWCLIPBOARD:%@NL@%
- %@AB@%/* Update the clipboard contents */%@AE@%%@NL@%
- GetAllFormats();%@NL@%
- vfUpdate = TRUE;%@NL@%
- WinPostMsg(hwnd, WM_PAINT, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_HSCROLL:%@NL@%
- if (vfViewBitmap) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Handle the appropriate scrolling messages%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DoScrolling(hwnd, TRUE, HIUSHORT(mp2));%@NL@%
- } else%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If an ownerdraw format, let the owner handle it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SendOwnerMsg(WM_HSCROLLCLIPBOARD, (MPARAM) hwnd, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_VSCROLL:%@NL@%
- if (vfViewBitmap) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Handle the appropriate scrolling messages%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DoScrolling(hwnd, FALSE, HIUSHORT(mp2));%@NL@%
- } else%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If an ownerdraw format, let the owner handle it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SendOwnerMsg(WM_VSCROLLCLIPBOARD, (MPARAM) hwnd, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_SIZE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If the MLE is processing a text selector,%@NL@%
- %@AB@% tell it to resize itself. If we have%@NL@%
- %@AB@% owner-draw data, tell the clipboard owner.%@NL@%
- %@AB@% If we have a BITMAP, readjust the scroll%@NL@%
- %@AB@% bar ranges.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (vhwndMLE) {%@NL@%
- WinQueryWindowPos(vhwndMLE, &swp);%@NL@%
- swp.cx = SHORT1FROMMP(mp2);%@NL@%
- swp.cy = SHORT2FROMMP(mp2);%@NL@%
- WinSetMultWindowPos(vhab, &swp, 1);%@NL@%
- } else if (vfViewBitmap) {%@NL@%
- WinQueryWindowPos(hwnd, &swp);%@NL@%
- if ((vcMaxHSB = vbmp.cx - swp.cx) < 0)%@NL@%
- vcMaxHSB = 0;%@NL@%
- if ((vcMaxVSB = vbmp.cy - swp.cy) < 0)%@NL@%
- vcMaxVSB = 0;%@NL@%
- WinSendMsg(vhwndHSB, SBM_SETSCROLLBAR,%@NL@%
- 0L, MPFROM2SHORT(0, vcMaxHSB));%@NL@%
- WinSendMsg(vhwndVSB, SBM_SETSCROLLBAR,%@NL@%
- MPFROMSHORT(vcMaxVSB),%@NL@%
- MPFROM2SHORT(0, vcMaxVSB));%@NL@%
- } else {%@NL@%
- rcl.xLeft = rcl.yBottom = 0L;%@NL@%
- rcl.xLeft = (LONG) SHORT1FROMMP(mp2) - 1;%@NL@%
- rcl.yTop = (LONG) SHORT2FROMMP(mp2) - 1;%@NL@%
- SendOwnerMsg(WM_SIZECLIPBOARD, (MPARAM) hwnd, &rcl);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefWindowProc(hwnd, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- return 0L;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK RenderDlgProc(HWND hwndDlg, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Render... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HWND hwndListbox; %@AB@%/* Listbox of possible formats */%@AE@%%@NL@%
- UCHAR szFmtName[MAXLEN]; %@AB@%/* Format name */%@AE@%%@NL@%
- UCHAR szMessage[MAXLEN];%@NL@%
- USHORT i;%@NL@%
- USHORT usFormat; %@AB@%/* Format to render */%@AE@%%@NL@%
- MRESULT mrItem; %@AB@%/* Which listbox item selected? */%@AE@%%@NL@%
- %@NL@%
- switch(msg) {%@NL@%
- %@NL@%
- case WM_INITDLG:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Put all the possible formats into the listbox, and%@NL@%
- %@AB@% select the first item by default.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndListbox = WinWindowFromID(hwndDlg, IDL_RENDER);%@NL@%
- WinSendMsg(hwndListbox, LM_DELETEALL, 0L, 0L);%@NL@%
- for (i = 0; i < vcFmts; i++) {%@NL@%
- GetFormatName(vausFormats[i], szFmtName);%@NL@%
- WinSendMsg(hwndListbox, LM_INSERTITEM,%@NL@%
- MPFROMSHORT(LIT_END), MPFROMP((PVOID) szFmtName));%@NL@%
- }%@NL@%
- WinSendMsg(hwndListbox, LM_SELECTITEM, 0L, MPFROMSHORT(TRUE));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CONTROL:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If the user makes a selection, quit!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((SHORT1FROMMP(mp1) == IDL_RENDER)%@NL@%
- && (SHORT2FROMMP(mp1) == LN_ENTER))%@NL@%
- WinPostMsg(hwndDlg, WM_COMMAND, MPFROMSHORT(DID_OK), 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Since the user chose a selection, try to render it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndListbox = WinWindowFromID(hwndDlg, IDL_RENDER);%@NL@%
- mrItem = WinSendMsg(hwndListbox, LM_QUERYSELECTION, 0L, 0L);%@NL@%
- if (mrItem != (MRESULT) LIT_NONE) {%@NL@%
- usFormat = vausFormats[SHORT1FROMMR(mrItem)];%@NL@%
- if (usFormat != vusFormat) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If the clipboard format is not rendered,%@NL@%
- %@AB@% tell the user.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- vfUpdate = TRUE;%@NL@%
- if (!UpdateScreen(vhwndClient, usFormat)) {%@NL@%
- LOADSTRING(IDS_NODISPLAY, szMessage);%@NL@%
- MESSAGE(szMessage);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* fall through */%@AE@%%@NL@%
- %@NL@%
- case DID_CANCEL:%@NL@%
- WinDismissDlg(hwndDlg, TRUE);%@NL@%
- %@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hwndDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AboutDlgProc(HWND hwndDlg, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hwndDlg, TRUE);%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hwndDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- VOID ReadSelector(HWND hwndMLE, PSZ pszText) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Compute the length of the text selector, in bytes.%@NL@%
- %@AB@% Allocate space, and copy the text selector into an MLE.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- IPT ipt;%@NL@%
- ULONG ulcch = 0;%@NL@%
- PSZ pszCounter;%@NL@%
- %@NL@%
- pszCounter = pszText;%@NL@%
- while (*pszCounter++) ulcch++;%@NL@%
- WinSendMsg(hwndMLE, MLM_FORMAT, MPFROMSHORT(MLFIE_CFTEXT), 0L);%@NL@%
- WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT, pszText, (MPARAM) ulcch);%@NL@%
- WinSendMsg(hwndMLE, MLM_IMPORT, &ipt, (MPARAM) ulcch);%@NL@%
- }%@NL@%
- %@NL@%
- VOID FixFrame(VOID) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% This routine tells the frame to update the scroll bars.%@NL@%
- %@AB@%%@NL@%
- %@AB@% First, make it so that the scroll bars cannot update themselves.%@NL@%
- %@AB@% Let the frame update the controls. Then, re-enable the scroll bars.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (!(vcUpdate--)) {%@NL@%
- WinEnableWindowUpdate(vhwndHSB, FALSE);%@NL@%
- WinEnableWindowUpdate(vhwndVSB, FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- WinSendMsg(vhwndClipFrame, WM_UPDATEFRAME, MPFROMLONG(FCF_HORZSCROLL), 0L);%@NL@%
- WinSendMsg(vhwndClipFrame, WM_UPDATEFRAME, MPFROMLONG(FCF_VERTSCROLL), 0L);%@NL@%
- %@NL@%
- if (!(++vcUpdate)) {%@NL@%
- WinEnableWindowUpdate(vhwndHSB, TRUE);%@NL@%
- WinEnableWindowUpdate(vhwndVSB, TRUE);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- VOID NeedScrollBars(BOOL fNeed) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% This routine hides changes the scroll bar state to correspond with%@NL@%
- %@AB@% fNeed, showing or hiding them as necessary.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- static BOOL fNeeded = TRUE; %@AB@%/* The last scroll bar state */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the scroll bar handles, if we haven't already.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!vhwndHSB) {%@NL@%
- vhwndHSB = WinWindowFromID(vhwndClipFrame, FID_HORZSCROLL);%@NL@%
- vhwndVSB = WinWindowFromID(vhwndClipFrame, FID_VERTSCROLL);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Case 1: We need scroll bars, so enable them.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (fNeed) {%@NL@%
- if (!fNeeded) {%@NL@%
- WinSetParent(vhwndHSB, vhwndClipFrame, TRUE);%@NL@%
- WinSetParent(vhwndVSB, vhwndClipFrame, TRUE);%@NL@%
- FixFrame();%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Case 2: We don't need scroll bars, so hide them.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- } else {%@NL@%
- if (fNeeded) {%@NL@%
- WinSetParent(vhwndHSB, HWND_OBJECT, TRUE);%@NL@%
- WinSetParent(vhwndVSB, HWND_OBJECT, TRUE);%@NL@%
- FixFrame();%@NL@%
- }%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save state for next invocation%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fNeeded = fNeed;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% RenderFormat()%@NL@%
- %@AB@%%@NL@%
- %@AB@% Input: Clipboard format to render, and handle to client area%@NL@%
- %@AB@% Side effects: Renders the image in the client area%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL RenderFormat(HWND hwnd, USHORT usFormat) {%@NL@%
- BOOL fRendered = TRUE;%@NL@%
- HMF hmfCopy;%@NL@%
- HPS hpsWindow;%@NL@%
- LONG alOptions[8];%@NL@%
- RECTL rclWindow;%@NL@%
- SIZEL sizl;%@NL@%
- SWP swpWindow;%@NL@%
- ULONG hItem;%@NL@%
- POINTL aptl[3];%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open the clipboard%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!WinOpenClipbrd(vhab))%@NL@%
- return FALSE;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open up the window DC and PS%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!vhdcWindow)%@NL@%
- vhdcWindow = WinOpenWindowDC(hwnd);%@NL@%
- %@NL@%
- sizl.cx = sizl.cy = 0L;%@NL@%
- hpsWindow = GpiCreatePS(vhab, vhdcWindow, &sizl, GPIA_ASSOC | PU_ARBITRARY);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Enable the scroll bars, if necessary. This affects the size%@NL@%
- %@AB@% of the client area.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (vfUpdate)%@NL@%
- NeedScrollBars( (vfViewBitmap =%@NL@%
- (usFormat == CF_BITMAP) || (usFormat == CF_DSPBITMAP)) );%@NL@%
- %@NL@%
- WinQueryWindowRect(hwnd, &rclWindow);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the clipboard data%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryClipbrdFmtInfo(vhab, usFormat, &vfsFmtInfo);%@NL@%
- if (!(hItem = WinQueryClipbrdData(vhab, usFormat))) {%@NL@%
- fRendered = FALSE;%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Display the new format, as appropriate.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch (usFormat) {%@NL@%
- case CF_TEXT:%@NL@%
- case CF_DSPTEXT:%@NL@%
- if (vfUpdate) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Create a new MLE and read the text into it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- vhwndMLE = WinCreateWindow(hwnd, WC_MLE, "",%@NL@%
- WS_VISIBLE | MLS_READONLY | MLS_HSCROLL | MLS_VSCROLL,%@NL@%
- 0, 0,%@NL@%
- (SHORT) rclWindow.xRight, (SHORT) rclWindow.yTop,%@NL@%
- hwnd, HWND_TOP, 0, NULL, NULL);%@NL@%
- %@NL@%
- ReadSelector(vhwndMLE, MAKEP((SEL) hItem, 0));%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case CF_BITMAP:%@NL@%
- case CF_DSPBITMAP:%@NL@%
- if (vfUpdate) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the BITMAP dimensions, for scroll bar processing%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (GpiQueryBitmapParameters((HBITMAP) hItem, &vbmp)%@NL@%
- != GPI_OK) {%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set the scroll bar ranges from 0 to vbmp.max - client.max%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowPos(hwnd, &swpWindow);%@NL@%
- %@NL@%
- if ((vcMaxHSB = vbmp.cx - swpWindow.cx) < 0)%@NL@%
- vcMaxHSB = 0;%@NL@%
- if ((vcMaxVSB = vbmp.cy - swpWindow.cy) < 0)%@NL@%
- vcMaxVSB = 0;%@NL@%
- WinSendMsg(vhwndHSB, SBM_SETSCROLLBAR,%@NL@%
- 0L, MPFROM2SHORT(0, vcMaxHSB));%@NL@%
- WinSendMsg(vhwndVSB, SBM_SETSCROLLBAR,%@NL@%
- MPFROMSHORT(vcMaxVSB),%@NL@%
- MPFROM2SHORT(0, vcMaxVSB));%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Draw the BITMAP, based on the scroll bar settings.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GpiSetBitmap(vhpsMemory, (HBITMAP) hItem);%@NL@%
- %@NL@%
- aptl[0].x = rclWindow.xLeft; %@AB@%/* Target bottom left */%@AE@%%@NL@%
- aptl[0].y = rclWindow.yBottom;%@NL@%
- aptl[1].x = rclWindow.xRight; %@AB@%/* Target top right */%@AE@%%@NL@%
- aptl[1].y = rclWindow.yTop;%@NL@%
- %@AB@%/* Source bottom left */%@AE@%%@NL@%
- aptl[2].x = (LONG) WinSendMsg(vhwndHSB, SBM_QUERYPOS, 0L, 0L);%@NL@%
- aptl[2].y = vcMaxVSB%@NL@%
- - (LONG) WinSendMsg(vhwndVSB, SBM_QUERYPOS, 0L, 0L);%@NL@%
- %@NL@%
- GpiBitBlt(hpsWindow, vhpsMemory, 3L, aptl, ROP_SRCCOPY, 0L);%@NL@%
- GpiSetBitmap(vhpsMemory, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case CF_METAFILE:%@NL@%
- case CF_DSPMETAFILE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set up the alOptions for displaying the metafile, and%@NL@%
- %@AB@% let the system do the rest of the work.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- alOptions[PMF_SEGBASE] = 0L;%@NL@%
- alOptions[PMF_LOADTYPE] = LT_DEFAULT;%@NL@%
- alOptions[PMF_RESOLVE] = 0L;%@NL@%
- alOptions[PMF_LCIDS] = LC_LOADDISC;%@NL@%
- alOptions[PMF_RESET] = RES_DEFAULT;%@NL@%
- alOptions[PMF_SUPPRESS] = SUP_DEFAULT;%@NL@%
- alOptions[PMF_COLORTABLES] = CTAB_NOMODIFY;%@NL@%
- alOptions[PMF_COLORREALIZABLE] = CREA_DEFAULT;%@NL@%
- hmfCopy = GpiCopyMetaFile((HMF) hItem);%@NL@%
- GpiPlayMetaFile(hpsWindow, hmfCopy, 8L, alOptions, 0L, 0L, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case CF_EMPTY:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Don't do anything.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If it's an owner-draw format that we can display...%@NL@%
- %@AB@% ...try to get the owner to paint the clipboard.%@NL@%
- %@AB@% (return if we were successful or not)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fRendered = SendOwnerMsg(WM_PAINTCLIPBOARD, MPFROMHWND(hwnd), 0L);%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Tell everybody that the client area is valid now%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinValidateRect(hwnd, (PRECTL) NULL, FALSE);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clean up%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GpiAssociate(hpsWindow, NULL);%@NL@%
- GpiDestroyPS(hpsWindow);%@NL@%
- WinCloseClipbrd(vhab);%@NL@%
- return fRendered;%@NL@%
- }%@NL@%
- %@NL@%
- BOOL UpdateScreen(HWND hwnd, USHORT usFormat) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Render the format, change the title bar.%@NL@%
- %@AB@% The title bar will look like: "<appname> (<format>)"%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL fRendered = TRUE;%@NL@%
- HPS hpsWindow;%@NL@%
- RECTL rcl;%@NL@%
- UCHAR szFormat[MAXLEN];%@NL@%
- UCHAR szTitle[MAXTITLELEN];%@NL@%
- %@NL@%
- if (vfUpdate) {%@NL@%
- %@AB@%/* If the MLE exists, destroy it */%@AE@%%@NL@%
- if (vhwndMLE) {%@NL@%
- WinDestroyWindow(vhwndMLE);%@NL@%
- vhwndMLE = NULL;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Clear the client area */%@AE@%%@NL@%
- WinQueryWindowRect(hwnd, &rcl);%@NL@%
- WinInvalidateRect(hwnd, &rcl, FALSE);%@NL@%
- hpsWindow = WinBeginPaint(hwnd, NULL, NULL);%@NL@%
- WinFillRect(hpsWindow, &rcl, CLR_BACKGROUND);%@NL@%
- WinEndPaint(hpsWindow);%@NL@%
- }%@NL@%
- if (usFormat) // Check that usFormat != CF_EMPTY%@NL@%
- fRendered = RenderFormat(hwnd, usFormat);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set the title bar appropriately%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!vhwndTitlebar && vhwndClipFrame)%@NL@%
- vhwndTitlebar = WinWindowFromID(vhwndClipFrame, FID_TITLEBAR);%@NL@%
- %@NL@%
- if (vhwndTitlebar) {%@NL@%
- GetFormatName(usFormat, szFormat);%@NL@%
- LOADSTRING(IDS_APPNAME, szTitle);%@NL@%
- strcat(szTitle, "("); strcat(szTitle, szFormat); strcat(szTitle, ")");%@NL@%
- WinSetWindowText(vhwndTitlebar, szTitle);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Save the rendered format.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- vusFormat = usFormat;%@NL@%
- return fRendered;%@NL@%
- }%@NL@%
- %@NL@%
- VOID GetAllFormats(VOID) {%@NL@%
- USHORT usFormat; // Temporary used when enumerating%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Put ourselves into a clean state%@NL@%
- %@AB@% */%@AE@%%@NL@%
- usFormat = vcFmts = 0;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Cycle through the available clipboard formats%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while (usFormat = WinEnumClipbrdFmts(vhab, usFormat)) {%@NL@%
- vausFormats[vcFmts++] = usFormat;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set the current clipboard format to the first one, if possible%@NL@%
- %@AB@% (in preparation for the WM_PAINT which will follow).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- vusFormat = (vcFmts ? vausFormats[0] : CF_EMPTY);%@NL@%
- }%@NL@%
- %@NL@%
- VOID GetFormatName(USHORT usFormat, UCHAR szFmtName[]) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% GetFormatName()%@NL@%
- %@AB@%%@NL@%
- %@AB@% This routine returns a format name in szFmtName which corresponds%@NL@%
- %@AB@% to the format usFormat. Basically, either we know the format, or%@NL@%
- %@AB@% we get the name from the system atom table. If we can't find it,%@NL@%
- %@AB@% we set it to CF_UNKNOWN.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- switch (usFormat) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If we know the format, we can read it from the string table.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- case CF_EMPTY:%@NL@%
- case CF_TEXT:%@NL@%
- case CF_DSPTEXT:%@NL@%
- case CF_BITMAP:%@NL@%
- case CF_DSPBITMAP:%@NL@%
- case CF_METAFILE:%@NL@%
- case CF_DSPMETAFILE:%@NL@%
- LOADSTRING(usFormat, szFmtName);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the format name from the system atom table.%@NL@%
- %@AB@% If not found, tag it as an unknown format.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!WinQueryAtomName(WinQuerySystemAtomTable(),%@NL@%
- usFormat, szFmtName, MAXLEN))%@NL@%
- %@NL@%
- LOADSTRING(CF_UNKNOWN, szFmtName);%@NL@%
- %@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- BOOL SendOwnerMsg(USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- BOOL rc;%@NL@%
- HWND hwndOwner;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% If we are an OWNERDISPLAY format,%@NL@%
- %@AB@% lock the owner window, tell it to perform the operation, return%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ( rc = ( (vfsFmtInfo & CFI_OWNERDISPLAY)%@NL@%
- && (hwndOwner = WinQueryClipbrdOwner(vhab, TRUE)) ) ) {%@NL@%
- %@NL@%
- WinSendMsg(hwndOwner, msg, mp1, mp2);%@NL@%
- WinLockWindow(hwndOwner, FALSE);%@NL@%
- }%@NL@%
- return rc;%@NL@%
- }%@NL@%
- %@NL@%
- BOOL DoScrolling(HWND hwnd, BOOL fHorz, USHORT sbCmd) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% This routine depends on the fact that the thumb cannot be set past the%@NL@%
- %@AB@% range of the scroll bar. Since this is handled in the system SBM_SETPOS%@NL@%
- %@AB@% code already, we need not worry about it.%@NL@%
- %@AB@%%@NL@%
- %@AB@% We return TRUE if the scroll bar message is processed.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HWND hwndSB; %@AB@%/* Scroll bar handle */%@AE@%%@NL@%
- USHORT cpels; %@AB@%/* Page length/width for PAGExxxx commands */%@AE@%%@NL@%
- SWP swp; %@AB@%/* Dimensions of the client area */%@AE@%%@NL@%
- USHORT usOld; %@AB@%/* The current scroll bar position */%@AE@%%@NL@%
- USHORT usNew; %@AB@%/* The new scroll bar position */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set the scroll bar-specific parameters%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowPos(hwnd, &swp);%@NL@%
- if (fHorz) { %@AB@%/* Horizontal scroll bar */%@AE@%%@NL@%
- hwndSB = vhwndHSB;%@NL@%
- cpels = swp.cx;%@NL@%
- } else { %@AB@%/* Vertical scroll bar */%@AE@%%@NL@%
- hwndSB = vhwndVSB;%@NL@%
- cpels = swp.cy;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Handle both scroll bars with one common routine%@NL@%
- %@AB@%%@NL@%
- %@AB@% Basically, the scroll bar has been set so that %@NL@%
- %@AB@% the thumb value corresponds to the offset that%@NL@%
- %@AB@% the bitmap is drawn from. So, to scroll by a%@NL@%
- %@AB@% page, compute the number of pels of the page,%@NL@%
- %@AB@% and move the thumb by that amount.%@NL@%
- %@AB@%%@NL@%
- %@AB@% This code is simplified by the fact that SB_SETPOS%@NL@%
- %@AB@% will not allow the thumb to be set outside of the%@NL@%
- %@AB@% range of the scroll bar, but will "stop" it at the%@NL@%
- %@AB@% appropriate bound.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- usOld = SHORT1FROMMR( WinSendMsg(hwndSB, SBM_QUERYPOS, 0L, 0L));%@NL@%
- %@NL@%
- switch (sbCmd) {%@NL@%
- case SB_PAGERIGHT: %@AB@%/* SB_PAGEDOWN */%@AE@%%@NL@%
- WinSendMsg(hwndSB, SBM_SETPOS, MPFROMSHORT(usOld + cpels), 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_PAGELEFT: %@AB@%/* SB_PAGEUP */%@AE@%%@NL@%
- WinSendMsg(hwndSB, SBM_SETPOS, MPFROMSHORT(usOld - cpels), 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_LINERIGHT: %@AB@%/* SB_LINEDOWN */%@AE@%%@NL@%
- WinSendMsg(hwndSB, SBM_SETPOS, MPFROMSHORT(usOld + LINE), 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_LINELEFT: %@AB@%/* SB_LINEUP */%@AE@%%@NL@%
- WinSendMsg(hwndSB, SBM_SETPOS, MPFROMSHORT(usOld - LINE), 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case SB_SLIDERPOSITION:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% It would be nice to be consistent with the other%@NL@%
- %@AB@% SB_ cases, but the problem is that when this message%@NL@%
- %@AB@% is sent, the position is *already* set to "usPosition".%@NL@%
- %@AB@%%@NL@%
- %@AB@% So, just invalidate the entire region, and hope that most%@NL@%
- %@AB@% of these types of operations will be large scrolls.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- // WinSendMsg(hwndSB, SBM_SETPOS, MPFROMSHORT(LOUSHORT(mp2)), 0L);%@NL@%
- WinInvalidateRect(hwnd, NULL, TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Now, we find out where the new thumb position is,%@NL@%
- %@AB@% scroll the window contents appropriately, and specify%@NL@%
- %@AB@% SW_INVALIDATERGN so that the remainder will be%@NL@%
- %@AB@% invalidated/repainted.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- usNew = SHORT1FROMMR( WinSendMsg(hwndSB, SBM_QUERYPOS, 0L, 0L));%@NL@%
- if (fHorz)%@NL@%
- WinScrollWindow(hwnd, (SHORT) (usOld - usNew), 0, %@NL@%
- NULL, NULL, NULL, NULL, SW_INVALIDATERGN);%@NL@%
- else%@NL@%
- WinScrollWindow(hwnd, 0, (SHORT) (usNew - usOld),%@NL@%
- NULL, NULL, NULL, NULL, SW_INVALIDATERGN);%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CLOCK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CLOCK\CLOCK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% clock.c Presentation Manager Analog Clock Application%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_PM %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"res.h" %@NL@%
- %@NL@%
- extern MRESULT EXPENTRY ClkWndProc ( HWND , USHORT , MPARAM , MPARAM ) ;%@NL@%
- %@NL@%
- int cdecl main ( int argc , char * argv [ ] ) ;%@NL@%
- BOOL ClkInit ( VOID ) ;%@NL@%
- HWND hwndFrame ;%@NL@%
- HAB hab ;%@NL@%
- HMQ hmq ;%@NL@%
- HSWITCH hsw ;%@NL@%
- extern HPS hps ;%@NL@%
- BOOL fStartAsIcon = FALSE ;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% main(argc, argv) Main program%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- int cdecl main ( int argc , char * argv [ ] )%@NL@%
- {%@NL@%
- QMSG qmsg ;%@NL@%
- %@NL@%
- %@AB@%/* have we been asked to start ourselves as an icon? */%@AE@%%@NL@%
- if (argc > 0) {%@NL@%
- if ( strcmpi ( argv [ 1 ] , "iconic" ) == 0 )%@NL@%
- fStartAsIcon = TRUE ;%@NL@%
- }%@NL@%
- %@NL@%
- if ( ClkInit ( ) ) {%@NL@%
- %@NL@%
- while ( WinGetMsg ( hab , & qmsg , NULL , 0 , 0 ) )%@NL@%
- WinDispatchMsg ( hab , & qmsg ) ;%@NL@%
- %@NL@%
- %@AB@%/* Clean up code */%@AE@%%@NL@%
- GpiDestroyPS( hps );%@NL@%
- WinRemoveSwitchEntry ( hsw ) ;%@NL@%
- WinDestroyWindow ( hwndFrame ) ;%@NL@%
- WinDestroyMsgQueue ( hmq ) ;%@NL@%
- WinTerminate ( hab ) ;%@NL@%
- }%@NL@%
- %@NL@%
- return 0 ;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ClkInit() Clock Initialization routine%@NL@%
- %@AB@% Returns TRUE if successful.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL ClkInit ( )%@NL@%
- {%@NL@%
- %@AB@%/* application name, switch list info, and frame creation flags */%@AE@%%@NL@%
- static PSZ pszClkName = "Clock" ;%@NL@%
- static SWCNTRL swctl = { 0 , 0 , 0 , 0 , 0 , SWL_VISIBLE ,%@NL@%
- SWL_JUMPABLE , "Clock" , 0 } ;%@NL@%
- static LONG fcf = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_MINMAX%@NL@%
- | FCF_SYSMENU ;%@NL@%
- %@NL@%
- HWND hwndClient ;%@NL@%
- PID pid ;%@NL@%
- TID tid ;%@NL@%
- %@NL@%
- if ( ( hab = WinInitialize ( 0 ) ) == NULL )%@NL@%
- return FALSE ;%@NL@%
- %@NL@%
- if ( ( hmq = WinCreateMsgQueue ( hab , 0 ) ) == NULL ) {%@NL@%
- WinTerminate ( hab ) ;%@NL@%
- return FALSE ;%@NL@%
- }%@NL@%
- %@NL@%
- if ( ! WinRegisterClass ( hab , pszClkName , ClkWndProc ,%@NL@%
- CS_SIZEREDRAW , 0 ) ) {%@NL@%
- WinDestroyMsgQueue ( hmq ) ;%@NL@%
- WinTerminate ( hab ) ;%@NL@%
- return FALSE ;%@NL@%
- }%@NL@%
- %@NL@%
- hwndFrame = WinCreateStdWindow ( HWND_DESKTOP , ( ULONG ) NULL , & fcf ,%@NL@%
- pszClkName , pszClkName , WS_VISIBLE ,%@NL@%
- (HMODULE) NULL , ID_RESOURCE , & hwndClient ) ;%@NL@%
- %@NL@%
- if ( hwndFrame == NULL ) {%@NL@%
- WinDestroyMsgQueue ( hmq ) ;%@NL@%
- WinTerminate ( hab ) ;%@NL@%
- return FALSE ;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* add ourselves to the switch list */%@AE@%%@NL@%
- WinQueryWindowProcess ( hwndFrame , & pid , & tid ) ;%@NL@%
- swctl . hwnd = hwndFrame ;%@NL@%
- swctl . idProcess = pid ;%@NL@%
- hsw = WinAddSwitchEntry ( & swctl ) ;%@NL@%
- %@NL@%
- return TRUE ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COMPORT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\COMTALK\COMPORT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% comport.c -- This file contains the sources for COM port manipulation.%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@% INCL_DOSFILEMGR %@NL@%
- %@AI@%#define %@AE@% INCL_DOSDEVICES %@NL@%
- %@AI@%#define %@AE@% INCL_DOSDEVIOCTL %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%"global.h" %@NL@%
- %@AI@%#include %@AE@%"comport.h" %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Constants%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- XON 0x11 %@AB@%/* Ctrl Q */%@AE@%%@NL@%
- XOFF 0x13 %@AB@%/* Ctrl S */%@AE@%%@NL@%
- char CRLF[2] = { 0x0d, 0x0a };%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Variables%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- DCBINFO dcbinfo; %@AB@%/* Device control block for Ioctl 53H, 73H */%@AE@%%@NL@%
- HFILE hPort;%@NL@%
- LINECONTROL lnctlBuf;%@NL@%
- int rc;%@NL@%
- USHORT usErrWord;%@NL@%
- %@NL@%
- int ComFlush(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Flush the COM port with Category 11 functions%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BYTE Data, Zero = 0;%@NL@%
- %@NL@%
- %@AB@%/* Call Category 11 Functions 1H, 2H Flush Input, Output Buffers */%@AE@%%@NL@%
- if (rc = DosDevIOCtl(&Data, &Zero, 0x01, 11, hPort)) return rc;%@NL@%
- if (rc = DosDevIOCtl(&Data, &Zero, 0x02, 11, hPort)) return rc;%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- int ComInit(COM comTerm) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Open the COM port according to the specifications%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT action;%@NL@%
- %@NL@%
- %@AB@%/* Get File Handle for COM port (shared read/write access) */%@AE@%%@NL@%
- if (rc = DosOpen(comTerm.szPort,&hPort, &action, 0L, 0, 0x0001, 0x0042, 0L))%@NL@%
- return rc;%@NL@%
- %@NL@%
- %@AB@%/* Call Category 1 Function 41H Set Baud Rate */%@AE@%%@NL@%
- if (rc = DosDevIOCtl(NULL, &comTerm.usBaud, 0x41, 1, hPort)) return rc;%@NL@%
- %@NL@%
- %@AB@%/* Call Category 1 Function 42H Set Line Characteristics */%@AE@%%@NL@%
- lnctlBuf.bDataBits = comTerm.bData;%@NL@%
- lnctlBuf.bParity = comTerm.bParity;%@NL@%
- lnctlBuf.bStopBits = (BYTE) (comTerm.bStop - 20); %@AB@%/* IDD_ONESTOP = 20 */%@AE@%%@NL@%
- if (rc = DosDevIOCtl(NULL, &lnctlBuf, 0x42, 1, hPort)) return rc;%@NL@%
- %@NL@%
- %@AB@%/* Call Category 1 Function 73H Query Device Control Block */%@AE@%%@NL@%
- if (rc = DosDevIOCtl(&dcbinfo, 0L, 0x73, 1, hPort)) return rc;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do we want software handshaking?%@NL@%
- %@AB@% */%@AE@%%@NL@%
- dcbinfo.fbFlowReplace &= ~(0x03); %@AB@%/* Clear bits 0 and 1 */%@AE@%%@NL@%
- dcbinfo.fbFlowReplace |=%@NL@%
- (comTerm.fSoftware) ? (MODE_AUTO_TRANSMIT | MODE_AUTO_RECEIVE) : 0;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Do we want hardware handshaking?%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AB@%/* Turn on DTR, if appropriate */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake &= ~(0x03); %@AB@%/* Clear bits 0 and 1 */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake |= ((comTerm.fHardware) ? MODE_DTR_CONTROL : 0);%@NL@%
- %@NL@%
- %@AB@%/* Turn on RTS, if appropriate */%@AE@%%@NL@%
- dcbinfo.fbFlowReplace &= ~(0xc0); %@AB@%/* Clear bits 6 and 7 */%@AE@%%@NL@%
- dcbinfo.fbFlowReplace |= ((comTerm.fHardware) ? MODE_RTS_CONTROL : 0);%@NL@%
- %@NL@%
- %@AB@%/* Adjust CTS output handshaking */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake &= ~MODE_CTS_HANDSHAKE; %@AB@%/* Clear bit 3 */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake |= ((comTerm.fHardware)?MODE_CTS_HANDSHAKE:0);%@NL@%
- %@NL@%
- %@AB@%/* Adjust DSR output handshaking */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake &= ~MODE_DSR_HANDSHAKE; %@AB@%/* Clear bit 4 */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake |= ((comTerm.fHardware)?MODE_DSR_HANDSHAKE:0);%@NL@%
- %@NL@%
- %@AB@%/* Turn off DCD output handshaking */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake &= ~MODE_DCD_HANDSHAKE; %@AB@%/* Clear bit 5 */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Adjust DSR input sensitivity */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake &= ~MODE_DSR_SENSITIVITY; %@AB@%/* Clear bit 6 */%@AE@%%@NL@%
- dcbinfo.fbCtlHndShake |= ((comTerm.fHardware)?MODE_DSR_SENSITIVITY:0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set the line to Wait for Character, Read mode%@NL@%
- %@AB@% */%@AE@%%@NL@%
- dcbinfo.fbTimeout &= ~(0x06); %@AB@%/* Clear bits, then set */%@AE@%%@NL@%
- dcbinfo.fbTimeout |= MODE_WAIT_READ_TIMEOUT;%@NL@%
- dcbinfo.usReadTimeout = -1; %@AB@%/* Never! */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Call Category 1 Function 53H Set Device Control Block */%@AE@%%@NL@%
- if (rc = DosDevIOCtl(0L, &dcbinfo, 0x53, 1, hPort)) return rc;%@NL@%
- %@NL@%
- %@AB@%/* Get ready to start */%@AE@%%@NL@%
- return ComFlush();%@NL@%
- }%@NL@%
- %@NL@%
- USHORT ComRead(Line pli) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Reads all characters present%@NL@%
- %@AB@% Returns: 0 if successful%@NL@%
- %@AB@% nonzero (Dos Error or Com Error Word) if unsuccessful%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AB@%/* Read from the port... And snatch as many as you can! (blocking read) */%@AE@%%@NL@%
- if (rc = DosRead(hPort, pli->szText, MAXLINELEN, &(pli->cch))) return rc;%@NL@%
- %@NL@%
- %@AB@%/* Check the COM Error Word */%@AE@%%@NL@%
- if (rc = DosDevIOCtl(&usErrWord, NULL, 0x6d, 1, hPort)) return rc;%@NL@%
- %@NL@%
- %@AB@%/* ...then return it */%@AE@%%@NL@%
- return usErrWord;%@NL@%
- }%@NL@%
- %@NL@%
- int ComWrite(char ch) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Write a character at a time%@NL@%
- %@AB@%%@NL@%
- %@AB@% Okay as long as you don't type too fast%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT nCharsWritten;%@NL@%
- %@NL@%
- return DosWrite(hPort, &ch, 1, &nCharsWritten);%@NL@%
- }%@NL@%
- %@NL@%
- int ComClose(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Close the COM port%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- if (rc = ComFlush()) return rc;%@NL@%
- return DosClose(hPort);%@NL@%
- } %@NL@%
- %@NL@%
- int ComBreak(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set BREAK mode ON%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT ComErr;%@NL@%
- %@NL@%
- %@AB@%/* Call Category 1 Function 4BH -- Set Break On */%@AE@%%@NL@%
- return DosDevIOCtl(&ComErr, NULL, 0x4b, 1, hPort);%@NL@%
- }%@NL@%
- %@NL@%
- int ComUnbreak(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set BREAK mode OFF%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- USHORT ComErr;%@NL@%
- %@NL@%
- %@AB@%/* Call Category 1 Function 45H -- Set Break Off */%@AE@%%@NL@%
- return DosDevIOCtl(&ComErr, NULL, 0x45, 1, hPort);%@NL@%
- }%@NL@%
- %@NL@%
- int ComError(void) { return (int) usErrWord; }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COMTALK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\COMTALK\COMTALK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% comtalk.c -- Main routines%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%%@NL@%
- %@AB@% This file contains the sources for the dialog box manipulation, and menu%@NL@%
- %@AB@% managment, and other aspects of interfacing with the user.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_WIN %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- "comtalk.h" %@AB@%/* definition of COM from Global, and Resource IDs */%@AE@%%@NL@%
- "avio.h" %@AB@%/* Routines needed to manage AVIO Presentation Space */%@AE@%%@NL@%
- "threads.h" %@AB@%/* Thread initialization and control routines */%@AE@%%@NL@%
- <stdio.h> %@AB@%/* Only needed for file I/O */%@AE@%%@NL@%
- <string.h> %@AB@%/* one strcpy call */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Variables%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- CHAR szCaption[] = "";%@NL@%
- HAB hAB;%@NL@%
- COM comTerm;%@NL@%
- COM comTemp;%@NL@%
- HWND hWndMenu;%@NL@%
- CLASSINFO clsi;%@NL@%
- PFNWP pfnOldFrameWndProc;%@NL@%
- BOOL fConnected = FALSE;%@NL@%
- BOOL fPaging;%@NL@%
- int iUpdate;%@NL@%
- BOOL fFreeze = TRUE;%@NL@%
- int iError;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Macros%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%InRange(x, a, b) ((x >= a) && (x <= b)) %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Shorthand for sending messages, querying%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%Parent(h) \ %@NL@%
- WinQueryWindow(h, QW_PARENT, FALSE)%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%EnableMenuItem(id) \ %@NL@%
- WinSendMsg(hWndMenu, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), \%@NL@%
- MPFROM2SHORT(MIA_DISABLED,0))%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%DisableMenuItem(id) \ %@NL@%
- WinSendMsg(hWndMenu, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), \%@NL@%
- MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED))%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%CheckMenuItem(id) \ %@NL@%
- WinSendMsg(hWndMenu, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), \%@NL@%
- MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)) %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%UnCheckMenuItem(id) \ %@NL@%
- WinSendMsg(hWndMenu, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), \%@NL@%
- MPFROM2SHORT(MIA_CHECKED, 0))%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%PushButton(h, id) \ %@NL@%
- WinSendDlgItemMsg(h, id, BM_SETCHECK, MPFROM2SHORT(TRUE, 0), 0L) %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%Valid(bData, bStop) \ %@NL@%
- (((bData == IDD_FIVE) && (bStop != IDD_TWOSTOP)) \%@NL@%
- || ((bData != IDD_FIVE) && (bStop != IDD_ONEFIVE)))%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%ErrMsg(h, s) \ %@NL@%
- WinMessageBox(HWND_DESKTOP, h, s, NULL, 0, MB_OK | MB_ICONEXCLAMATION)%@NL@%
- %@NL@%
- char Ctrl(char ch) {%@NL@%
- return (CHAR) ((('a' <= ch) && (ch <= 'z')) ? (ch - 'a' + '\001') :%@NL@%
- ((('A' <= ch) && (ch <= 'Z')) ? (ch - 'A' + '\001') : ch));%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Local/Private routines%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- void ReadOpts(HWND);%@NL@%
- void InitTerm(void);%@NL@%
- void Initialize(HWND);%@NL@%
- void ChangeSystemMenu(HWND);%@NL@%
- BOOL Filter(USHORT, char, USHORT);%@NL@%
- %@NL@%
- void main (void) {%@NL@%
- static CHAR szClientClass[] = "Terminal";%@NL@%
- HMQ hmq;%@NL@%
- HWND hWndClient, hWndFrame;%@NL@%
- QMSG qmsg;%@NL@%
- ULONG flFrameFlags = FCF_STANDARD | FCF_HORZSCROLL | FCF_VERTSCROLL;%@NL@%
- ULONG flFrameStyle = WS_VISIBLE | FS_SCREENALIGN;%@NL@%
- %@NL@%
- hAB = WinInitialize(0);%@NL@%
- hmq = WinCreateMsgQueue(hAB, 0);%@NL@%
- %@NL@%
- WinRegisterClass(hAB, szClientClass, ClientWndProc, CS_SYNCPAINT, 0);%@NL@%
- %@NL@%
- hWndFrame = WinCreateStdWindow(HWND_DESKTOP, flFrameStyle,%@NL@%
- &flFrameFlags, szClientClass, szCaption,%@NL@%
- 0L, (HMODULE) NULL, ID_RESOURCE, &hWndClient);%@NL@%
- %@NL@%
- %@AB@%/* Setup AVIO PS and force a paint */%@AE@%%@NL@%
- AvioInit(hWndFrame, hWndClient);%@NL@%
- WinSendMsg(hWndClient, WM_PAINT, NULL, NULL);%@NL@%
- %@NL@%
- %@AB@%/* Try to subclass the Frame window... */%@AE@%%@NL@%
- pfnOldFrameWndProc = WinSubclassWindow(hWndFrame, NewFrameWndProc);%@NL@%
- %@NL@%
- while (WinGetMsg(hAB, &qmsg, NULL, 0, 0)) WinDispatchMsg(hAB, &qmsg);%@NL@%
- %@NL@%
- %@AB@%/* Blast the AVIO PS */%@AE@%%@NL@%
- AvioClose();%@NL@%
- %@NL@%
- WinDestroyWindow(hWndFrame);%@NL@%
- WinDestroyMsgQueue(hmq);%@NL@%
- WinTerminate(hAB);%@NL@%
- DosExit(EXIT_PROCESS, 0);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK ClientWndProc(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Window Procedure which traps messages to the Client area%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- switch (msg) {%@NL@%
- case WM_AVIOUPDATE:%@NL@%
- fNoUpdate = AvioUpdateLines(FALSE, &fPaging);%@NL@%
- if (fConnected && fPaging) {%@NL@%
- CheckMenuItem(IDM_PAGING);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MSGBOX:%@NL@%
- iUpdate = (int)SHORT1FROMMP( mp2);%@NL@%
- switch ((int)SHORT1FROMMP(mp1)) {%@NL@%
- case (int) MBE_COMREAD:%@NL@%
- if (iError = iUpdate) EnableMenuItem(IDM_ERRORS);%@NL@%
- iUpdate = 0;%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- ErrMsg(hWnd, aszMessage[SHORT1FROMMP(mp1)]);%@NL@%
- break;%@NL@%
- }%@NL@%
- if (iUpdate) { %@AB@%/* Page down because queue is full */%@AE@%%@NL@%
- fNoUpdate = AvioUpdateLines(TRUE, &fPaging);%@NL@%
- if (fConnected && fPaging) CheckMenuItem(IDM_PAGING);%@NL@%
- else UnCheckMenuItem(IDM_PAGING);%@NL@%
- ThdReset();%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CREATE:%@NL@%
- ChangeSystemMenu(hWnd);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the Dialog Options%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Initialize(hWnd);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get the Handle so you can enable/disable menu items%@NL@%
- %@AB@% Thanks again to Charles Petzold%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hWndMenu = WinWindowFromID(Parent(hWnd), FID_MENU);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Disable some entries (can do this in the resource file)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DisableMenuItem(IDM_CLOSE);%@NL@%
- DisableMenuItem(IDM_BREAK);%@NL@%
- DisableMenuItem(IDM_COMMANDMENU);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT: %@AB@%/* Paint the AVIO way! */%@AE@%%@NL@%
- AvioPaint(hWnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_SIZE: %@AB@%/* Size the AVIO way! */%@AE@%%@NL@%
- fNoUpdate = AvioUpdateLines(FALSE, &fPaging);%@NL@%
- if (fConnected && fPaging) {%@NL@%
- CheckMenuItem(IDM_PAGING);%@NL@%
- }%@NL@%
- return AvioSize(hWnd, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_HSCROLL:%@NL@%
- AvioScroll(HIUSHORT(mp2), LOUSHORT(mp2), TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_VSCROLL:%@NL@%
- AvioScroll(HIUSHORT(mp2), LOUSHORT(mp2), FALSE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ERASEBACKGROUND:%@NL@%
- return 0;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (COMMANDMSG(&msg)->cmd) {%@NL@%
- case IDM_ABOUT:%@NL@%
- WinDlgBox(HWND_DESKTOP, hWnd, AboutDlgProc,%@NL@%
- (HMODULE) NULL, IDD_ABOUT, NULL);%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_HELP:%@NL@%
- WinDlgBox(HWND_DESKTOP, hWnd, AboutDlgProc,%@NL@%
- (HMODULE) NULL, IDD_MAINHELPBOX, NULL);%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_SETTINGS:%@NL@%
- WinDlgBox(HWND_DESKTOP, hWnd, SetDlgProc,%@NL@%
- (HMODULE) NULL, IDD_SET, NULL);%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_CONNECT:%@NL@%
- AvioStartup(hWnd);%@NL@%
- ThdInitialize(hWnd, comTerm); %@AB@%/* Spawn 3 threads */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Disable/Enable Menu Items%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DisableMenuItem(IDM_CONNECT);%@NL@%
- DisableMenuItem(IDM_SETTINGS);%@NL@%
- DisableMenuItem(IDM_ERRORS);%@NL@%
- %@NL@%
- EnableMenuItem(IDM_CLOSE);%@NL@%
- EnableMenuItem(IDM_BREAK);%@NL@%
- EnableMenuItem(IDM_COMMANDMENU);%@NL@%
- fConnected = TRUE;%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_CLOSE:%@NL@%
- fConnected = FALSE;%@NL@%
- ThdTerminate(); %@AB@%/* Might have to wait? */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Update menu items%@NL@%
- %@AB@% */%@AE@%%@NL@%
- UnCheckMenuItem(IDM_BREAK);%@NL@%
- %@NL@%
- DisableMenuItem(IDM_CLOSE);%@NL@%
- DisableMenuItem(IDM_BREAK);%@NL@%
- DisableMenuItem(IDM_COMMANDMENU);%@NL@%
- %@NL@%
- EnableMenuItem(IDM_CONNECT);%@NL@%
- EnableMenuItem(IDM_SETTINGS);%@NL@%
- %@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_BREAK:%@NL@%
- ThdDoBreak();%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_ERRORS:%@NL@%
- if (iError & 1)%@NL@%
- ErrMsg(hWnd, "Receive Queue Overrun");%@NL@%
- if (iError & 2)%@NL@%
- ErrMsg(hWnd, "Receive Hardware Overrun");%@NL@%
- if (iError & 4)%@NL@%
- ErrMsg(hWnd, "Parity Error");%@NL@%
- if (iError & 8)%@NL@%
- ErrMsg(hWnd, "Framing Error");%@NL@%
- DisableMenuItem(IDM_ERRORS);%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_PAGE:%@NL@%
- fNoUpdate = AvioUpdateLines(TRUE, &fPaging);%@NL@%
- if (fPaging) CheckMenuItem(IDM_PAGING);%@NL@%
- else UnCheckMenuItem(IDM_PAGING);%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_UP:%@NL@%
- AvioPageUp();%@NL@%
- return 0;%@NL@%
- %@NL@%
- case IDM_PAGING:%@NL@%
- if (fPaging = !fPaging) {%@NL@%
- CheckMenuItem(IDM_PAGING);%@NL@%
- } else {%@NL@%
- UnCheckMenuItem(IDM_PAGING);%@NL@%
- }%@NL@%
- return 0;%@NL@%
- %@NL@%
- default: return 0;%@NL@%
- }%@NL@%
- %@NL@%
- case WM_CHAR: %@AB@%/* Put characters in typeahead buffer */%@AE@%%@NL@%
- if (fConnected && !(CHARMSG(&msg)->fs & KC_KEYUP)) %@NL@%
- if (Filter( CHARMSG(&msg)->fs,%@NL@%
- (char) CHARMSG(&msg)->chr,%@NL@%
- CHARMSG(&msg)->vkey))%@NL@%
- ErrMsg(hWnd, "Error Writing COM Port");%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_TRACKFRAME:%@NL@%
- AvioTrackFrame(hWnd, mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MINMAXFRAME: %@AB@%/* Trap MAXIMIZE messages */%@AE@%%@NL@%
- AvioMinMax((PSWP) mp1);%@NL@%
- %@NL@%
- default: return WinDefWindowProc(hWnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AboutDlgProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Dialog box control for the ABOUT COMTALK... dialog box%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hDlg, TRUE); break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- void WriteOpts(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Write Settings to file COMTALK.INI%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- FILE *fp;%@NL@%
- %@NL@%
- fp = fopen("comtalk.ini", "w+");%@NL@%
- fprintf(fp, "%d %d %d %d %d %d %d %s\n", comTerm.usBaud, comTerm.bParity,%@NL@%
- comTerm.bData, comTerm.bStop, comTerm.fWrap,%@NL@%
- comTerm.fHardware, comTerm.fSoftware, comTerm.szPort);%@NL@%
- fclose(fp);%@NL@%
- }%@NL@%
- %@NL@%
- void ReadOpts(HWND hWnd) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Read Settings from COMTALK.INI%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- FILE *fp;%@NL@%
- %@NL@%
- %@AB@%/* Use InitTerm() if we have reading problems */%@AE@%%@NL@%
- if ((fp = fopen("comtalk.ini", "r")) == NULL) InitTerm();%@NL@%
- else if (fscanf(fp, "%d%d%d%d%d%d%d%s", &comTerm.usBaud, &comTerm.bParity,%@NL@%
- &comTerm.bData, &comTerm.bStop, &comTerm.fWrap,%@NL@%
- &comTerm.fHardware, &comTerm.fSoftware, comTerm.szPort) == EOF)%@NL@%
- InitTerm();%@NL@%
- if (!Valid(comTerm.bData, comTerm.bStop)) {%@NL@%
- ErrMsg(hWnd, "Invalid terminal setting");%@NL@%
- InitTerm();%@NL@%
- }%@NL@%
- fclose(fp);%@NL@%
- }%@NL@%
- %@NL@%
- void InitTerm(void) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Initialize the TERM structure to DosDevIOCtl defaults%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- strcpy(comTerm.szPort, "com1");%@NL@%
- comTerm.usBaud = 9600; comTerm.bParity = IDD_EVENP;%@NL@%
- comTerm.bData = IDD_SEVEN; comTerm.bStop = IDD_ONESTOP;%@NL@%
- comTerm.fWrap = comTerm.fSoftware = TRUE; comTerm.fHardware = FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK SetDlgProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% The Settings Dialog Box control routine%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL rc;%@NL@%
- BYTE bTemp;%@NL@%
- %@NL@%
- switch(msg) {%@NL@%
- case WM_INITDLG:%@NL@%
- WinSetDlgItemText(hDlg, IDD_PORT, comTerm.szPort);%@NL@%
- WinSetDlgItemShort(hDlg, IDD_BAUD, comTerm.usBaud, FALSE);%@NL@%
- %@NL@%
- PushButton(hDlg, comTerm.bParity);%@NL@%
- PushButton(hDlg, comTerm.bData);%@NL@%
- PushButton(hDlg, comTerm.bStop);%@NL@%
- if (comTerm.fWrap) PushButton(hDlg, IDD_WRAP);%@NL@%
- if (comTerm.fHardware) PushButton(hDlg, IDD_HW);%@NL@%
- if (comTerm.fSoftware) PushButton(hDlg, IDD_SW);%@NL@%
- %@NL@%
- comTemp.bParity = comTerm.bParity;%@NL@%
- comTemp.bData = comTerm.bData;%@NL@%
- comTemp.bStop = comTerm.bStop;%@NL@%
- comTemp.fWrap = comTerm.fWrap;%@NL@%
- comTemp.fHardware = comTerm.fHardware;%@NL@%
- comTemp.fSoftware = comTerm.fSoftware;%@NL@%
- break; %@NL@%
- %@NL@%
- case WM_HELP:%@NL@%
- WinDlgBox(HWND_DESKTOP, hDlg, AboutDlgProc,%@NL@%
- (HMODULE) NULL, IDD_SETHELPBOX, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CONTROL:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% The fact that these are AutoRadioButtons makes life easy.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- bTemp = (BYTE) SHORT1FROMMP(mp1); %@AB@%/* Which button pushed? */%@AE@%%@NL@%
- if InRange(bTemp, IDD_NOP, IDD_SPACEP) %@NL@%
- { %@NL@%
- comTemp.bParity = bTemp; %@NL@%
- } %@NL@%
- else %@NL@%
- {%@NL@%
- if InRange(bTemp, IDD_FIVE, IDD_EIGHT) %@NL@%
- {%@NL@%
- comTemp.bData = bTemp;%@NL@%
- } %@NL@%
- else %@NL@%
- {%@NL@%
- if InRange(bTemp, IDD_ONESTOP, IDD_TWOSTOP) %@NL@%
- {%@NL@%
- comTemp.bStop = bTemp;%@NL@%
- }%@NL@%
- else %@NL@%
- {%@NL@%
- switch (bTemp) {%@NL@%
- case IDD_WRAP: comTemp.fWrap = !comTemp.fWrap; break;%@NL@%
- case IDD_HW : comTemp.fHardware = !comTemp.fHardware; break;%@NL@%
- case IDD_SW : comTemp.fSoftware = !comTemp.fSoftware; break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- case WM_COMMAND: %@AB@%/* Ready to exit... */%@AE@%%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case IDD_SAVE:%@NL@%
- case DID_OK:%@NL@%
- if (!Valid(comTemp.bData, comTemp.bStop)) {%@NL@%
- ErrMsg(hDlg,"Data and Stop Bits Incompatible");%@NL@%
- break; %@AB@%/* No-op...Dialog not dismissed */%@AE@%%@NL@%
- }%@NL@%
- WinQueryDlgItemText(hDlg, IDD_PORT, 5, comTerm.szPort);%@NL@%
- WinQueryDlgItemShort(hDlg, IDD_BAUD, &comTerm.usBaud, rc);%@NL@%
- comTerm.bParity = comTemp.bParity;%@NL@%
- comTerm.bData = comTemp.bData;%@NL@%
- comTerm.bStop = comTemp.bStop;%@NL@%
- comTerm.fWrap = comTemp.fWrap;%@NL@%
- comTerm.fHardware = comTemp.fHardware;%@NL@%
- comTerm.fSoftware = comTemp.fSoftware;%@NL@%
- if (COMMANDMSG(&msg)->cmd == IDD_SAVE) WriteOpts();%@NL@%
- case DID_CANCEL: WinDismissDlg(hDlg, FALSE);%@NL@%
- default: break;%@NL@%
- }%@NL@%
- break;%@NL@%
- default: return WinDefDlgProc(hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- void Initialize(HWND hWnd) {%@NL@%
- ReadOpts(hWnd);%@NL@%
- fPaging = FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- void ChangeSystemMenu(HWND hWnd) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Insert items into the System Menu (with thanks to Charles Petzold)%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- static CHAR *x[2] = { NULL, "~About ComTalk..." }; %@AB@%/* Items to add */%@AE@%%@NL@%
- static MENUITEM mi[2] = { %@AB@%/* The RESOURCE definitions */%@AE@%%@NL@%
- MIT_END, MIS_SEPARATOR, 0x0000, 0, NULL, 0,%@NL@%
- MIT_END, MIS_TEXT, 0x0000, IDM_ABOUT, NULL, 0%@NL@%
- };%@NL@%
- HWND hSM, hSSM; %@AB@%/* Menu and submenu handles */%@AE@%%@NL@%
- MENUITEM miSM; %@AB@%/* System Menu Menuitem */%@AE@%%@NL@%
- SHORT idSM; %@AB@%/* ID of the System Menu */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Get ahold of the system menu%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hSM = WinWindowFromID(Parent(hWnd), FID_SYSMENU);%@NL@%
- idSM = SHORT1FROMMR( WinSendMsg(hSM, MM_ITEMIDFROMPOSITION, NULL, NULL));%@NL@%
- WinSendMsg(hSM, MM_QUERYITEM, MPFROM2SHORT(idSM, FALSE), MPFROMP(&miSM));%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Manipulate the System SubMenu%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hSSM = miSM.hwndSubMenu;%@NL@%
- WinSendMsg(hSSM, MM_INSERTITEM, MPFROMP(mi), MPFROMP(x[0]));%@NL@%
- WinSendMsg(hSSM, MM_INSERTITEM, MPFROMP(mi+1), MPFROMP(x[1]));%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK NewFrameWndProc(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Force the frame to stay small enough%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- BOOL rc; %@AB@%/* Return code for WM_QueryTrackInfo */%@AE@%%@NL@%
- %@NL@%
- switch(msg) {%@NL@%
- case WM_ADJUSTWINDOWPOS: %@AB@%/* Calculate, then show scrollbars */%@AE@%%@NL@%
- AvioAdjustFrame(mp1);%@NL@%
- break;%@NL@%
- case WM_QUERYTRACKINFO:%@NL@%
- rc = (BOOL)SHORT1FROMMR ((*pfnOldFrameWndProc)(hWnd, msg, mp1, mp2));%@NL@%
- AvioQueryTrackInfo((PTRACKINFO) mp2);%@NL@%
- return (MRESULT) rc;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- return (*pfnOldFrameWndProc)(hWnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- %@NL@%
- BOOL Filter(USHORT fs, char ch, USHORT vkey) {%@NL@%
- BOOL rc = FALSE;%@NL@%
- %@NL@%
- if (fs & KC_VIRTUALKEY) {%@NL@%
- switch(vkey) {%@NL@%
- case VK_HOME:%@NL@%
- if (fs & KC_CTRL) rc = ThdPutString("\033[2J",4);%@NL@%
- return (rc || ThdPutString("\033[H", 3));%@NL@%
- case VK_UP:%@NL@%
- return ThdPutString("\033[A", 3);%@NL@%
- case VK_DOWN:%@NL@%
- return ThdPutString("\033[B", 3);%@NL@%
- case VK_RIGHT:%@NL@%
- return ThdPutString("\033[C", 3);%@NL@%
- case VK_LEFT:%@NL@%
- return ThdPutString("\033[D", 3);%@NL@%
- default: break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if (fs & KC_CTRL) {%@NL@%
- switch (ch) {%@NL@%
- case 'l':%@NL@%
- case 'L': AvioRedraw();%@NL@%
- case '\0': return FALSE; break;%@NL@%
- default: ch = Ctrl(ch); break;%@NL@%
- }%@NL@%
- } else {%@NL@%
- switch (ch) {%@NL@%
- case '\0': return FALSE; break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- }%@NL@%
- return(rc || ThdPutChar(ch));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CPGREP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CPGREP\CPGREP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* cpgrep - string searches%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Created by Microsoft Corp. 1986%@NL@%
- %@AB@% *%@NL@%
- %@AB@% *%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@% <os2def.h> %@NL@%
- %@AI@%#define %@AE@%INCL_DOSPROCESS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSSEMAPHORES %@NL@%
- %@AI@%#define %@AE@%INCL_DOSQUEUES %@NL@%
- %@AI@%#define %@AE@%INCL_DOSMEMMGR %@NL@%
- %@AI@%#define %@AE@%INCL_DOSMISC %@NL@%
- %@AI@%#include %@AE@% <bsedos.h> %@NL@%
- %@AI@%#include %@AE@% <stdio.h> %@NL@%
- %@AI@%#include %@AE@% <fcntl.h> %@NL@%
- %@AI@%#include %@AE@% <ctype.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% BEGLINE 0x40 %@NL@%
- %@AI@%#define %@AE@% DEBUG 0x08 %@NL@%
- %@AI@%#define %@AE@% ENDLINE 0x80 %@NL@%
- %@AI@%#define %@AE@% FILBUFLEN (SECTORLEN*30) %@NL@%
- %@AI@%#define %@AE@% FILNAMLEN 80 %@NL@%
- %@AI@%#define %@AE@% INVERT 0x10 %@NL@%
- %@AI@%#define %@AE@% ISCOT 0x0002 %@NL@%
- %@AI@%#define %@AE@% LG2SECLEN 9 %@NL@%
- %@AI@%#define %@AE@% LINELEN 128 %@NL@%
- %@AI@%#define %@AE@% LINENOS 0x04 %@NL@%
- %@AI@%#define %@AE@% LNOLEN 8 %@NL@%
- %@AI@%#define %@AE@% MAXSTRLEN 128 %@NL@%
- %@AI@%#define %@AE@% NAMEONLY 0x02 %@NL@%
- %@AI@%#define %@AE@% OUTBUFLEN (SECTORLEN*4) %@NL@%
- %@AI@%#define %@AE@% SECTORLEN (1 << LG2SECLEN) %@NL@%
- %@AI@%#define %@AE@% SHOWNAME 0x01 %@NL@%
- %@AI@%#define %@AE@% STKLEN 256 %@NL@%
- %@AI@%#define %@AE@% TIMER 0x20 %@NL@%
- %@AI@%#define %@AE@% TRTABLEN 256 %@NL@%
- %@AI@%#define %@AE@% s_text(x) (((char *)(x)) - ((x)->s_must)) %@NL@%
- %@NL@%
- typedef struct stringnode%@NL@%
- {%@NL@%
- struct stringnode *s_alt; %@AB@%/* List of alternates */%@AE@%%@NL@%
- struct stringnode *s_suf; %@AB@%/* List of suffixes */%@AE@%%@NL@%
- int s_must; %@AB@%/* Length of portion that must match */%@AE@%%@NL@%
- }%@NL@%
- STRINGNODE;%@NL@%
- %@NL@%
- char filbuf[(FILBUFLEN + 2)*2];%@NL@%
- char *bufptr[] = { filbuf, filbuf + FILBUFLEN + 2 };%@NL@%
- char outbuf[OUTBUFLEN*2];%@NL@%
- char *obuf[] = { outbuf, outbuf + OUTBUFLEN };%@NL@%
- char *optr[] = { outbuf, outbuf + OUTBUFLEN };%@NL@%
- USHORT ocnt[] = { OUTBUFLEN, OUTBUFLEN };%@NL@%
- int oi = 0;%@NL@%
- char transtab[TRTABLEN] = { 0 };%@NL@%
- STRINGNODE *stringlist[TRTABLEN/2];%@NL@%
- USHORT arrc; %@AB@%/* I/O return code for DosRead */%@AE@%%@NL@%
- USHORT awrc; %@AB@%/* I/O return code for DosWrite */%@AE@%%@NL@%
- int casesen = 1; %@AB@%/* Assume case-sensitivity */%@AE@%%@NL@%
- USHORT cbread; %@AB@%/* Bytes read by DosRead */%@AE@%%@NL@%
- USHORT cbwrite; %@AB@%/* Bytes written by DosWrite */%@AE@%%@NL@%
- int clists = 1; %@AB@%/* One is first available index */%@AE@%%@NL@%
- int flags; %@AB@%/* Flags */%@AE@%%@NL@%
- int lineno; %@AB@%/* Current line number */%@AE@%%@NL@%
- char pmode; %@AB@%/* Protected mode flag */%@AE@%%@NL@%
- LONG readdone; %@AB@%/* Async read done semaphore */%@AE@%%@NL@%
- LONG readpending; %@AB@%/* Async read pending semaphore */%@AE@%%@NL@%
- int status = 1; %@AB@%/* Assume failure */%@AE@%%@NL@%
- char *t2buf; %@AB@%/* Async read buffer */%@AE@%%@NL@%
- USHORT t2buflen; %@AB@%/* Async read buffer length */%@AE@%%@NL@%
- HFILE t2fd; %@AB@%/* Async read file */%@AE@%%@NL@%
- char *t3buf; %@AB@%/* Async write buffer */%@AE@%%@NL@%
- USHORT t3buflen; %@AB@%/* Async write buffer length */%@AE@%%@NL@%
- HFILE t3fd; %@AB@%/* Async write file */%@AE@%%@NL@%
- LONG writedone; %@AB@%/* Async write done semaphore */%@AE@%%@NL@%
- LONG writepending; %@AB@%/* Async write pending semaphore */%@AE@%%@NL@%
- char target[MAXSTRLEN];%@NL@%
- %@AB@%/* Last string added */%@AE@%%@NL@%
- int targetlen; %@AB@%/* Length of last string added */%@AE@%%@NL@%
- %@NL@%
- int countlines(); %@AB@%/* See CPGREPSB.ASM */%@AE@%%@NL@%
- int countmatched(); %@AB@%/* See CPGREPSB.ASM */%@AE@%%@NL@%
- char *findlist(); %@AB@%/* See CPGREPSB.ASM */%@AE@%%@NL@%
- char *findone(); %@AB@%/* See CPGREPSB.ASM */%@AE@%%@NL@%
- void flush1buf(); %@AB@%/* See below */%@AE@%%@NL@%
- int grepbuffer(); %@AB@%/* See below */%@AE@%%@NL@%
- int revfind(); %@AB@%/* See CPGREPSB.ASM */%@AE@%%@NL@%
- void write1buf(); %@AB@%/* See below */%@AE@%%@NL@%
- char *(*find)() = findlist;%@NL@%
- void (*flush1)() = flush1buf;%@NL@%
- int (*grep)() = grepbuffer;%@NL@%
- void (*write1)() = write1buf;%@NL@%
- %@NL@%
- void freenode(x)%@NL@%
- register STRINGNODE *x; %@AB@%/* Pointer to node to free */%@AE@%%@NL@%
- {%@NL@%
- register STRINGNODE *y; %@AB@%/* Pointer to next node in list */%@AE@%%@NL@%
- %@NL@%
- while(x != NULL) %@AB@%/* While not at end of list */%@AE@%%@NL@%
- {%@NL@%
- if(x->s_suf != NULL) freenode(x->s_suf);%@NL@%
- %@AB@%/* Free suffix list */%@AE@%%@NL@%
- y = x; %@AB@%/* Save pointer */%@AE@%%@NL@%
- x = x->s_alt; %@AB@%/* Move down the list */%@AE@%%@NL@%
- free(y); %@AB@%/* Free the node */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- STRINGNODE *newnode(s,n)%@NL@%
- char *s; %@AB@%/* String */%@AE@%%@NL@%
- int n; %@AB@%/* Length of string */%@AE@%%@NL@%
- {%@NL@%
- register STRINGNODE *new; %@AB@%/* Pointer to new node */%@AE@%%@NL@%
- char *t; %@AB@%/* String pointer */%@AE@%%@NL@%
- char *malloc(); %@AB@%/* Storage allocator */%@AE@%%@NL@%
- %@NL@%
- if((t = malloc(sizeof(STRINGNODE) + n + (n & 1))) == NULL)%@NL@%
- { %@AB@%/* If allocation fails */%@AE@%%@NL@%
- fprintf(stderr,"Out of memory\n");%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Print error message and die */%@AE@%%@NL@%
- }%@NL@%
- if(n & 1) ++t; %@AB@%/* END of string word-aligned */%@AE@%%@NL@%
- strncpy(t,s,n); %@AB@%/* Copy string text */%@AE@%%@NL@%
- new = (STRINGNODE *)(t + n); %@AB@%/* Set pointer to node */%@AE@%%@NL@%
- new->s_alt = NULL; %@AB@%/* No alternates yet */%@AE@%%@NL@%
- new->s_suf = NULL; %@AB@%/* No suffixes yet */%@AE@%%@NL@%
- new->s_must = n; %@AB@%/* Set string length */%@AE@%%@NL@%
- return(new); %@AB@%/* Return pointer to new node */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void reallocnode(node,s,n)%@NL@%
- register STRINGNODE *node; %@AB@%/* Pointer to node */%@AE@%%@NL@%
- char *s; %@AB@%/* String */%@AE@%%@NL@%
- register int n; %@AB@%/* Length of string */%@AE@%%@NL@%
- {%@NL@%
- if(n > node->s_must) %@AB@%/* If node must grow */%@AE@%%@NL@%
- {%@NL@%
- fprintf(stderr,"Internal error\n");%@NL@%
- %@AB@%/* Error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Error exit */%@AE@%%@NL@%
- }%@NL@%
- node->s_must = n; %@AB@%/* Set new length */%@AE@%%@NL@%
- memcpy(s_text(node),s,n); %@AB@%/* Copy new text */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void addstring(s,n)%@NL@%
- char *s; %@AB@%/* String to add */%@AE@%%@NL@%
- int n; %@AB@%/* Length of string */%@AE@%%@NL@%
- {%@NL@%
- register STRINGNODE *cur; %@AB@%/* Current string */%@AE@%%@NL@%
- register STRINGNODE **pprev; %@AB@%/* Pointer to previous link */%@AE@%%@NL@%
- STRINGNODE *new; %@AB@%/* New string */%@AE@%%@NL@%
- int i; %@AB@%/* Index */%@AE@%%@NL@%
- int j; %@AB@%/* Count */%@AE@%%@NL@%
- int k; %@AB@%/* Count */%@AE@%%@NL@%
- %@NL@%
- if(n <= 0 || n > 127) return; %@AB@%/* Should never happen */%@AE@%%@NL@%
- i = transtab[*s]; %@AB@%/* Get current index */%@AE@%%@NL@%
- if(i == 0) %@AB@%/* If no existing list */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We have to start a new list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if((i = clists++) >= TRTABLEN/2)%@NL@%
- { %@AB@%/* If too many string lists */%@AE@%%@NL@%
- fprintf(stderr,"Too many string lists\n");%@NL@%
- %@AB@%/* Error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- stringlist[i] = NULL; %@AB@%/* Initialize */%@AE@%%@NL@%
- transtab[*s] = i; %@AB@%/* Set pointer to new list */%@AE@%%@NL@%
- if(!casesen && isalpha(*s)) transtab[*s ^ '\x20'] = i;%@NL@%
- %@AB@%/* Set pointer for other case */%@AE@%%@NL@%
- }%@NL@%
- else if(stringlist[i] == NULL) return;%@NL@%
- %@AB@%/* Check for existing 1-byte string */%@AE@%%@NL@%
- if(--n == 0) %@AB@%/* If 1-byte string */%@AE@%%@NL@%
- {%@NL@%
- freenode(stringlist[i]); %@AB@%/* Free any existing stuff */%@AE@%%@NL@%
- stringlist[i] = NULL; %@AB@%/* No record here */%@AE@%%@NL@%
- return; %@AB@%/* Done */%@AE@%%@NL@%
- }%@NL@%
- ++s; %@AB@%/* Skip first char */%@AE@%%@NL@%
- pprev = stringlist + i; %@AB@%/* Get pointer to link */%@AE@%%@NL@%
- cur = *pprev; %@AB@%/* Get pointer to node */%@AE@%%@NL@%
- while(cur != NULL) %@AB@%/* Loop to traverse match tree */%@AE@%%@NL@%
- {%@NL@%
- i = (n > cur->s_must)? cur->s_must: n;%@NL@%
- %@AB@%/* Find minimum of string lengths */%@AE@%%@NL@%
- matchstrings(s,s_text(cur),i,&j,&k);%@NL@%
- %@AB@%/* Compare the strings */%@AE@%%@NL@%
- if(j == 0) %@AB@%/* If complete mismatch */%@AE@%%@NL@%
- {%@NL@%
- if(k < 0) break; %@AB@%/* Break if insertion point found */%@AE@%%@NL@%
- pprev = &(cur->s_alt); %@AB@%/* Get pointer to alternate link */%@AE@%%@NL@%
- cur = *pprev; %@AB@%/* Follow the link */%@AE@%%@NL@%
- }%@NL@%
- else if(i == j) %@AB@%/* Else if strings matched */%@AE@%%@NL@%
- {%@NL@%
- if(i == n) %@AB@%/* If new is prefix of current */%@AE@%%@NL@%
- {%@NL@%
- reallocnode(cur,s_text(cur),n);%@NL@%
- %@AB@%/* Shorten text of node */%@AE@%%@NL@%
- if(cur->s_suf != NULL) %@AB@%/* If there are suffixes */%@AE@%%@NL@%
- {%@NL@%
- freenode(cur->s_suf);%@NL@%
- %@AB@%/* Suffixes no longer needed */%@AE@%%@NL@%
- cur->s_suf = NULL;%@NL@%
- }%@NL@%
- return; %@AB@%/* All done */%@AE@%%@NL@%
- }%@NL@%
- pprev = &(cur->s_suf); %@AB@%/* Get pointer to suffix link */%@AE@%%@NL@%
- if((cur = *pprev) == NULL) return;%@NL@%
- %@AB@%/* Done if current is prefix of new */%@AE@%%@NL@%
- s += i; %@AB@%/* Skip matched portion */%@AE@%%@NL@%
- n -= i;%@NL@%
- }%@NL@%
- else %@AB@%/* Else partial match */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We must split an existing node.%@NL@%
- %@AB@% * This is the trickiest case.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- new = newnode(s_text(cur) + j,cur->s_must - j);%@NL@%
- %@AB@%/* Unmatched part of current string */%@AE@%%@NL@%
- reallocnode(cur,s_text(cur),j);%@NL@%
- %@AB@%/* Set length to matched portion */%@AE@%%@NL@%
- new->s_suf = cur->s_suf; %@AB@%/* Current string's suffixes */%@AE@%%@NL@%
- if(k < 0) %@AB@%/* If new preceded current */%@AE@%%@NL@%
- {%@NL@%
- cur->s_suf = newnode(s + j,n - j);%@NL@%
- %@AB@%/* FIrst suffix is new string */%@AE@%%@NL@%
- cur->s_suf->s_alt = new;%@AB@%/* Alternate is part of current */%@AE@%%@NL@%
- }%@NL@%
- else %@AB@%/* Else new followed current */%@AE@%%@NL@%
- {%@NL@%
- new->s_alt = newnode(s + j,n - j);%@NL@%
- %@AB@%/* Unmatched new string is alternate */%@AE@%%@NL@%
- cur->s_suf = new; %@AB@%/* New suffix list */%@AE@%%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- }%@NL@%
- *pprev = newnode(s,n); %@AB@%/* Set pointer to new node */%@AE@%%@NL@%
- (*pprev)->s_alt = cur; %@AB@%/* Attach alternates */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- int addfancy(buffer,buflen,seplist)%@NL@%
- register char *buffer; %@AB@%/* Buffer */%@AE@%%@NL@%
- int buflen; %@AB@%/* Length of buffer */%@AE@%%@NL@%
- char *seplist; %@AB@%/* List of separators */%@AE@%%@NL@%
- {%@NL@%
- register char *bufend; %@AB@%/* Pointer to end of buffer */%@AE@%%@NL@%
- int strcnt = 0; %@AB@%/* String count */%@AE@%%@NL@%
- int len; %@AB@%/* String length */%@AE@%%@NL@%
- char c; %@AB@%/* One char buffer */%@AE@%%@NL@%
- %@NL@%
- bufend = buffer + buflen; %@AB@%/* Set end pointer */%@AE@%%@NL@%
- while(buffer < bufend) %@AB@%/* Loop through all strings */%@AE@%%@NL@%
- {%@NL@%
- len = strncspn(buffer,seplist,bufend - buffer);%@NL@%
- %@AB@%/* Length of string */%@AE@%%@NL@%
- if(flags & ENDLINE) %@AB@%/* If match must be at end of line */%@AE@%%@NL@%
- {%@NL@%
- c = buffer[len]; %@AB@%/* Save 1st character past string */%@AE@%%@NL@%
- buffer[len++] = '\r'; %@AB@%/* Carriage return marks end of line */%@AE@%%@NL@%
- }%@NL@%
- if(findlist(buffer,buffer + len) == NULL)%@NL@%
- { %@AB@%/* If no match within string */%@AE@%%@NL@%
- addstring(buffer,len); %@AB@%/* Add string to list */%@AE@%%@NL@%
- if(strcnt++ == 0) %@AB@%/* If first string */%@AE@%%@NL@%
- {%@NL@%
- memcpy(target,buffer,len);%@NL@%
- %@AB@%/* Save first string in buffer */%@AE@%%@NL@%
- targetlen = len; %@AB@%/* Remember length */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- buffer += len; %@AB@%/* Skip over string */%@AE@%%@NL@%
- if(flags & ENDLINE) (--buffer)[0] = c;%@NL@%
- %@AB@%/* Restore saved character */%@AE@%%@NL@%
- buffer += strnspn(buffer,seplist,bufend - buffer);%@NL@%
- %@AB@%/* Skip over trailing separators */%@AE@%%@NL@%
- }%@NL@%
- return(strcnt); %@AB@%/* Return string count */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- int addplain(buffer,buflen,seplist)%@NL@%
- register char *buffer; %@AB@%/* String list buffer */%@AE@%%@NL@%
- int buflen; %@AB@%/* Buffer length */%@AE@%%@NL@%
- char *seplist; %@AB@%/* List of separators */%@AE@%%@NL@%
- {%@NL@%
- int strcnt; %@AB@%/* String count */%@AE@%%@NL@%
- register int len; %@AB@%/* String length */%@AE@%%@NL@%
- char c; %@AB@%/* One char buffer */%@AE@%%@NL@%
- %@NL@%
- strcnt = 0;%@NL@%
- while((len = strncspn(buffer,seplist,buflen)) > 0)%@NL@%
- { %@AB@%/* While not at end of input list */%@AE@%%@NL@%
- if(flags & ENDLINE) %@AB@%/* If match must be at end of line */%@AE@%%@NL@%
- {%@NL@%
- c = buffer[len]; %@AB@%/* Save 1st character past string */%@AE@%%@NL@%
- buffer[len++] = '\r'; %@AB@%/* Carriage return marks end of line */%@AE@%%@NL@%
- }%@NL@%
- if(strcnt == 0) %@AB@%/* Save first string */%@AE@%%@NL@%
- {%@NL@%
- strncpy(target,buffer,len); %@AB@%/* Save string in buffer */%@AE@%%@NL@%
- targetlen = len; %@AB@%/* Save string length */%@AE@%%@NL@%
- }%@NL@%
- addstring(buffer,len); %@AB@%/* Add the string to the table */%@AE@%%@NL@%
- if(flags & ENDLINE) buffer[--len] = c;%@NL@%
- %@AB@%/* Restore saved character */%@AE@%%@NL@%
- buffer += len; %@AB@%/* Skip the string */%@AE@%%@NL@%
- buflen -= len;%@NL@%
- len = strnspn(buffer,seplist,buflen);%@NL@%
- %@AB@%/* Skip separators */%@AE@%%@NL@%
- buffer += len;%@NL@%
- buflen -= len;%@NL@%
- ++strcnt; %@AB@%/* Increment string count */%@AE@%%@NL@%
- }%@NL@%
- return(strcnt); %@AB@%/* Return string count */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void dumplist(node,indent)%@NL@%
- register STRINGNODE *node; %@AB@%/* Pointer to list to dump */%@AE@%%@NL@%
- int indent; %@AB@%/* Current length of buffer */%@AE@%%@NL@%
- {%@NL@%
- int i; %@AB@%/* Counter */%@AE@%%@NL@%
- %@NL@%
- while(node != NULL) %@AB@%/* While not at end of list */%@AE@%%@NL@%
- {%@NL@%
- for(i = 0; i < indent; ++i) fputc(' ',stderr);%@NL@%
- fwrite(s_text(node),sizeof(char),node->s_must,stderr);%@NL@%
- fprintf(stderr,"\n");%@NL@%
- if(node->s_suf != NULL)%@NL@%
- dumplist(node->s_suf,indent + node->s_must);%@NL@%
- %@AB@%/* Recurse to do suffixes */%@AE@%%@NL@%
- node = node->s_alt; %@AB@%/* Do next alternate in list */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void dumpstrings()%@NL@%
- {%@NL@%
- int i; %@AB@%/* Index */%@AE@%%@NL@%
- %@NL@%
- for(i = 0; i < TRTABLEN; ++i) %@AB@%/* Loop through translation table */%@AE@%%@NL@%
- {%@NL@%
- if(transtab[i] == 0) continue; %@AB@%/* Skip null entries */%@AE@%%@NL@%
- fprintf(stderr,"%c\n",i); %@AB@%/* Print the first byte */%@AE@%%@NL@%
- dumplist(stringlist[transtab[i]],1);%@NL@%
- %@AB@%/* Dump the list */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- HFILE openfile(name)%@NL@%
- char *name; %@AB@%/* File name */%@AE@%%@NL@%
- {%@NL@%
- HFILE fd; %@AB@%/* File descriptor */%@AE@%%@NL@%
- %@NL@%
- if((fd = open(name,0)) == -1) %@AB@%/* If error opening file */%@AE@%%@NL@%
- {%@NL@%
- fprintf(stderr,"Cannot open %s\r\n",name);%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- }%@NL@%
- return(fd); %@AB@%/* Return file descriptor */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void far thread2() %@AB@%/* Read thread */%@AE@%%@NL@%
- {%@NL@%
- while(DosSemRequest( &readpending, -1L) == 0)%@NL@%
- { %@AB@%/* While there is work to do */%@AE@%%@NL@%
- arrc = DosRead( t2fd, t2buf, t2buflen, &cbread);%@NL@%
- %@AB@%/* Do the read */%@AE@%%@NL@%
- DosSemClear( &readdone); %@AB@%/* Signal read completed */%@AE@%%@NL@%
- }%@NL@%
- fprintf(stderr,"Thread 2: DosSemRequest failed\n");%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void far thread3() %@AB@%/* Write thread */%@AE@%%@NL@%
- {%@NL@%
- while(DosSemRequest((long far *) &writepending,-1L) == 0)%@NL@%
- { %@AB@%/* While there is work to do */%@AE@%%@NL@%
- awrc = DosWrite(t3fd, t3buf, t3buflen, &cbwrite);%@NL@%
- %@AB@%/* Do the write */%@AE@%%@NL@%
- DosSemClear( &writedone); %@AB@%/* Signal write completed */%@AE@%%@NL@%
- }%@NL@%
- fprintf(stderr,"Thread 3: DosSemRequest failed\n");%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void startread(fd,buffer,buflen)%@NL@%
- HFILE fd; %@AB@%/* File handle */%@AE@%%@NL@%
- char *buffer; %@AB@%/* Buffer */%@AE@%%@NL@%
- USHORT buflen; %@AB@%/* Buffer length */%@AE@%%@NL@%
- {%@NL@%
- if(pmode) %@AB@%/* If protected mode */%@AE@%%@NL@%
- {%@NL@%
- if(DosSemRequest( &readdone, -1L) != 0)%@NL@%
- { %@AB@%/* If we fail to get the semaphore */%@AE@%%@NL@%
- fprintf(stderr,"DosSemRequest failed\n");%@NL@%
- %@AB@%/* Error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- t2fd = fd; %@AB@%/* Set parameters for read */%@AE@%%@NL@%
- t2buf = buffer;%@NL@%
- t2buflen = buflen;%@NL@%
- DosSemClear( &readpending); %@AB@%/* Wake thread 2 for read */%@AE@%%@NL@%
- DosSleep(0L); %@AB@%/* Yield the CPU */%@AE@%%@NL@%
- }%@NL@%
- else arrc = DosRead( fd, buffer, buflen, &cbread);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- int finishread()%@NL@%
- {%@NL@%
- if(pmode && DosSemWait( &readdone, -1L) != 0)%@NL@%
- { %@AB@%/* If protected mode and wait fails */%@AE@%%@NL@%
- fprintf(stderr,"DosSemWait failed\n");%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- return((arrc == 0)? cbread: -1); %@AB@%/* Return number of bytes read */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void startwrite(fd,buffer,buflen)%@NL@%
- HFILE fd; %@AB@%/* File handle */%@AE@%%@NL@%
- char *buffer; %@AB@%/* Buffer */%@AE@%%@NL@%
- USHORT buflen; %@AB@%/* Buffer length */%@AE@%%@NL@%
- {%@NL@%
- if(pmode) %@AB@%/* If protected mode */%@AE@%%@NL@%
- {%@NL@%
- if(DosSemRequest( &writedone, -1L) != 0)%@NL@%
- { %@AB@%/* If we fail to get the semaphore */%@AE@%%@NL@%
- fprintf(stderr,"DosSemRequest failed\n");%@NL@%
- %@AB@%/* Error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- t3fd = fd; %@AB@%/* Set parameters for write */%@AE@%%@NL@%
- t3buf = buffer;%@NL@%
- t3buflen = buflen;%@NL@%
- DosSemClear( &writepending); %@AB@%/* Wake thread 3 for read */%@AE@%%@NL@%
- DosSleep(0L); %@AB@%/* Yield the CPU */%@AE@%%@NL@%
- }%@NL@%
- else awrc = DosWrite(fd, buffer, buflen, &cbwrite);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- int finishwrite()%@NL@%
- {%@NL@%
- if(pmode && DosSemWait( &writedone, -1L) != 0)%@NL@%
- { %@AB@%/* If protected mode and wait fails */%@AE@%%@NL@%
- fprintf(stderr,"DosSemWait failed\n");%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- return((awrc == 0)? cbwrite: -1); %@AB@%/* Return number of bytes written */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void write1nobuf(buffer,buflen)%@NL@%
- char *buffer; %@AB@%/* Buffer */%@AE@%%@NL@%
- USHORT buflen; %@AB@%/* Buffer length */%@AE@%%@NL@%
- {%@NL@%
- int cb; %@AB@%/* Count of bytes written */%@AE@%%@NL@%
- %@NL@%
- if( DosWrite(1, buffer, buflen, &cb) != 0 || cb != buflen)%@NL@%
- %@AB@%/* If write fails */%@AE@%%@NL@%
- {%@NL@%
- fprintf(stderr,"write error %d\n",awrc);%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void write1buf(buffer,buflen)%@NL@%
- char *buffer; %@AB@%/* Buffer */%@AE@%%@NL@%
- USHORT buflen; %@AB@%/* Buffer length */%@AE@%%@NL@%
- {%@NL@%
- USHORT cb; %@AB@%/* Byte count */%@AE@%%@NL@%
- %@NL@%
- while(buflen > 0) %@AB@%/* While bytes remain */%@AE@%%@NL@%
- {%@NL@%
- if(awrc != 0) %@AB@%/* If previous write failed */%@AE@%%@NL@%
- {%@NL@%
- fprintf(stderr,"write error %d\n",awrc);%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- if((cb = ocnt[oi]) == 0) %@AB@%/* If buffer full */%@AE@%%@NL@%
- {%@NL@%
- startwrite(1,obuf[oi],OUTBUFLEN);%@NL@%
- %@AB@%/* Write the buffer */%@AE@%%@NL@%
- ocnt[oi] = OUTBUFLEN; %@AB@%/* Reset count and pointer */%@AE@%%@NL@%
- optr[oi] = obuf[oi];%@NL@%
- oi ^= 1; %@AB@%/* Switch buffers */%@AE@%%@NL@%
- cb = ocnt[oi]; %@AB@%/* Get space remaining */%@AE@%%@NL@%
- }%@NL@%
- if(cb > buflen) cb = buflen; %@AB@%/* Get minimum */%@AE@%%@NL@%
- memcpy(optr[oi],buffer,cb); %@AB@%/* Copy bytes to buffer */%@AE@%%@NL@%
- ocnt[oi] -= cb; %@AB@%/* Update buffer length and pointers */%@AE@%%@NL@%
- optr[oi] += cb;%@NL@%
- buflen -= cb;%@NL@%
- buffer += cb;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void flush1nobuf()%@NL@%
- {%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void flush1buf()%@NL@%
- {%@NL@%
- int cb; %@AB@%/* Byte count */%@AE@%%@NL@%
- %@NL@%
- if((cb = OUTBUFLEN - ocnt[oi]) > 0) %@AB@%/* If buffer not empty */%@AE@%%@NL@%
- {%@NL@%
- startwrite(1,obuf[oi],cb); %@AB@%/* Start write */%@AE@%%@NL@%
- if(finishwrite() != cb) %@AB@%/* If write failed */%@AE@%%@NL@%
- {%@NL@%
- fprintf(stderr,"write error %d\n",awrc);%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- int grepnull(cp,endbuf,name)%@NL@%
- register char *cp; %@AB@%/* Buffer pointer */%@AE@%%@NL@%
- char *endbuf; %@AB@%/* End of buffer */%@AE@%%@NL@%
- char *name; %@AB@%/* File name */%@AE@%%@NL@%
- {%@NL@%
- return(0); %@AB@%/* Do nothing */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- int grepbuffer(startbuf,endbuf,name)%@NL@%
- char *startbuf; %@AB@%/* Start of buffer */%@AE@%%@NL@%
- char *endbuf; %@AB@%/* End of buffer */%@AE@%%@NL@%
- char *name; %@AB@%/* File name */%@AE@%%@NL@%
- {%@NL@%
- register char *cp; %@AB@%/* Buffer pointer */%@AE@%%@NL@%
- char *lastmatch; %@AB@%/* Last matching line */%@AE@%%@NL@%
- int linelen; %@AB@%/* Line length */%@AE@%%@NL@%
- int namlen = 0; %@AB@%/* Length of name */%@AE@%%@NL@%
- char lnobuf[LNOLEN]; %@AB@%/* Line number buffer */%@AE@%%@NL@%
- char nambuf[LINELEN];%@AB@%/* Name buffer */%@AE@%%@NL@%
- %@NL@%
- cp = startbuf; %@AB@%/* Initialize to start of buffer */%@AE@%%@NL@%
- lastmatch = cp; %@AB@%/* No previous match yet */%@AE@%%@NL@%
- while((cp = (*find)(cp,endbuf)) != NULL)%@NL@%
- { %@AB@%/* While matches are found */%@AE@%%@NL@%
- if((flags & BEGLINE) && cp[-1] != '\n' && cp > startbuf)%@NL@%
- { %@AB@%/* If begin line conditions not met */%@AE@%%@NL@%
- ++cp; %@AB@%/* Skip first char of match */%@AE@%%@NL@%
- continue; %@AB@%/* Keep looking */%@AE@%%@NL@%
- }%@NL@%
- status = 0; %@AB@%/* Match found */%@AE@%%@NL@%
- if(flags & NAMEONLY) %@AB@%/* If filename only wanted */%@AE@%%@NL@%
- {%@NL@%
- (*write1)(nambuf,sprintf(nambuf,"%s\r\n",name));%@NL@%
- %@AB@%/* Print the name */%@AE@%%@NL@%
- return(1); %@AB@%/* Punt remainder of buffer */%@AE@%%@NL@%
- }%@NL@%
- cp -= revfind(cp,'\n',cp - startbuf);%@NL@%
- %@AB@%/* Point at last linefeed */%@AE@%%@NL@%
- if(*cp == '\n') ++cp; %@AB@%/* Point at start of line */%@AE@%%@NL@%
- if(flags & SHOWNAME) %@AB@%/* If name wanted */%@AE@%%@NL@%
- {%@NL@%
- if(namlen == 0) namlen = sprintf(nambuf,"%s:",name);%@NL@%
- %@AB@%/* Format name if not done already */%@AE@%%@NL@%
- (*write1)(nambuf,namlen); %@AB@%/* Show name */%@AE@%%@NL@%
- }%@NL@%
- if(flags & LINENOS) %@AB@%/* If line number wanted */%@AE@%%@NL@%
- {%@NL@%
- lineno += countlines(lastmatch,cp);%@NL@%
- %@AB@%/* Count lines since last match */%@AE@%%@NL@%
- (*write1)(lnobuf,sprintf(lnobuf,"%d:",lineno));%@NL@%
- %@AB@%/* Print line number */%@AE@%%@NL@%
- lastmatch = cp; %@AB@%/* New last match */%@AE@%%@NL@%
- }%@NL@%
- linelen = strncspn(cp,"\n",endbuf - cp) + 1;%@NL@%
- %@AB@%/* Calculate line length */%@AE@%%@NL@%
- (*write1)(cp,linelen); %@AB@%/* Print the line */%@AE@%%@NL@%
- cp += linelen; %@AB@%/* Skip the line */%@AE@%%@NL@%
- }%@NL@%
- if(flags & LINENOS) lineno += countlines(lastmatch,endbuf);%@NL@%
- %@AB@%/* Count remaining lines in buffer */%@AE@%%@NL@%
- return(0); %@AB@%/* Keep searching */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void showv(name,lastmatch,thismatch)%@NL@%
- char *name;%@NL@%
- register char *lastmatch;%@NL@%
- char *thismatch;%@NL@%
- {%@NL@%
- register int linelen;%@NL@%
- int namlen = 0; %@AB@%/* Length of name */%@AE@%%@NL@%
- char lnobuf[LNOLEN]; %@AB@%/* Line number buffer */%@AE@%%@NL@%
- char nambuf[LINELEN];%@AB@%/* Name buffer */%@AE@%%@NL@%
- %@NL@%
- if(flags & (SHOWNAME | LINENOS))%@NL@%
- {%@NL@%
- while(lastmatch < thismatch)%@NL@%
- {%@NL@%
- if(flags & SHOWNAME) %@AB@%/* If name wanted */%@AE@%%@NL@%
- {%@NL@%
- if(namlen == 0) namlen = sprintf(nambuf,"%s:",name);%@NL@%
- %@AB@%/* Format name if not done already */%@AE@%%@NL@%
- (*write1)(nambuf,namlen);%@NL@%
- %@AB@%/* Write the name */%@AE@%%@NL@%
- }%@NL@%
- if(flags & LINENOS)%@NL@%
- {%@NL@%
- (*write1)(lnobuf,sprintf(lnobuf,"%d:",lineno++));%@NL@%
- }%@NL@%
- linelen = strncspn(lastmatch,"\n",thismatch - lastmatch) + 1;%@NL@%
- (*write1)(lastmatch,linelen);%@NL@%
- lastmatch += linelen;%@NL@%
- }%@NL@%
- }%@NL@%
- else (*write1)(lastmatch,thismatch - lastmatch);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- int grepvbuffer(startbuf,endbuf,name)%@NL@%
- char *startbuf; %@AB@%/* Start of buffer */%@AE@%%@NL@%
- char *endbuf; %@AB@%/* End of buffer */%@AE@%%@NL@%
- char *name; %@AB@%/* File name */%@AE@%%@NL@%
- {%@NL@%
- register char *cp; %@AB@%/* Buffer pointer */%@AE@%%@NL@%
- register char *lastmatch; %@AB@%/* Pointer to line after last match */%@AE@%%@NL@%
- %@NL@%
- cp = startbuf; %@AB@%/* Initialize to start of buffer */%@AE@%%@NL@%
- lastmatch = cp;%@NL@%
- while((cp = (*find)(cp,endbuf)) != NULL)%@NL@%
- {%@NL@%
- if((flags & BEGLINE) && cp[-1] != '\n' && cp > startbuf)%@NL@%
- { %@AB@%/* If begin line conditions not met */%@AE@%%@NL@%
- ++cp; %@AB@%/* Skip first char of match */%@AE@%%@NL@%
- continue; %@AB@%/* Keep looking */%@AE@%%@NL@%
- }%@NL@%
- status = 1; %@AB@%/* Match found */%@AE@%%@NL@%
- if(flags & NAMEONLY) return(1); %@AB@%/* Skip rest of file if NAMEONLY */%@AE@%%@NL@%
- cp -= revfind(cp,'\n',cp - startbuf);%@NL@%
- %@AB@%/* Point at last linefeed */%@AE@%%@NL@%
- if(*cp == '\n') ++cp; %@AB@%/* Point at start of line */%@AE@%%@NL@%
- showv(name,lastmatch,cp); %@AB@%/* Show from last match to this */%@AE@%%@NL@%
- cp += strncspn(cp,"\n",endbuf - cp) + 1;%@NL@%
- %@AB@%/* Skip over line with match */%@AE@%%@NL@%
- lastmatch = cp; %@AB@%/* New "last" match */%@AE@%%@NL@%
- ++lineno; %@AB@%/* Increment line count */%@AE@%%@NL@%
- }%@NL@%
- if(!(flags & NAMEONLY)) showv(name,lastmatch,endbuf);%@NL@%
- %@AB@%/* Show buffer tail if not NAMEONLY */%@AE@%%@NL@%
- return(0); %@AB@%/* Keep searching file */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void qgrep(name,fd)%@NL@%
- char *name; %@AB@%/* File name */%@AE@%%@NL@%
- HFILE fd; %@AB@%/* File descriptor */%@AE@%%@NL@%
- {%@NL@%
- register int cb; %@AB@%/* Byte count */%@AE@%%@NL@%
- register char *cp; %@AB@%/* Buffer pointer */%@AE@%%@NL@%
- char *endbuf; %@AB@%/* End of buffer */%@AE@%%@NL@%
- int taillen; %@AB@%/* Length of buffer tail */%@AE@%%@NL@%
- int bufi; %@AB@%/* Buffer index */%@AE@%%@NL@%
- char line[LINELEN]; %@AB@%/* Line buffer */%@AE@%%@NL@%
- %@NL@%
- lineno = 1; %@AB@%/* File starts on line 1 */%@AE@%%@NL@%
- taillen = 0; %@AB@%/* No buffer tail yet */%@AE@%%@NL@%
- bufi = 0; %@AB@%/* Initialize buffer index */%@AE@%%@NL@%
- cp = bufptr[0]; %@AB@%/* Initialize to start of buffer */%@AE@%%@NL@%
- finishread(); %@AB@%/* Make sure no I/O activity */%@AE@%%@NL@%
- arrc = DosRead( fd, cp, FILBUFLEN, &cbread);%@NL@%
- %@AB@%/* Do first read synchronously */%@AE@%%@NL@%
- while((cb = finishread()) + taillen > 0)%@NL@%
- { %@AB@%/* While search incomplete */%@AE@%%@NL@%
- if(cb == 0) %@AB@%/* If buffer tail is all that's left */%@AE@%%@NL@%
- {%@NL@%
- taillen = 0; %@AB@%/* Set tail length to zero */%@AE@%%@NL@%
- *cp++ = '\r'; %@AB@%/* Add end of line sequence */%@AE@%%@NL@%
- *cp++ = '\n';%@NL@%
- endbuf = cp; %@AB@%/* Note end of buffer */%@AE@%%@NL@%
- }%@NL@%
- else %@AB@%/* Else start next read */%@AE@%%@NL@%
- {%@NL@%
- taillen = revfind(cp + cb - 1,'\n',cb);%@NL@%
- %@AB@%/* Find length of partial line */%@AE@%%@NL@%
- endbuf = cp + cb - taillen; %@AB@%/* Get pointer to end of buffer */%@AE@%%@NL@%
- cp = bufptr[bufi ^ 1]; %@AB@%/* Pointer to other buffer */%@AE@%%@NL@%
- memcpy(cp,endbuf,taillen); %@AB@%/* Copy tail to head of other buffer */%@AE@%%@NL@%
- cp += taillen; %@AB@%/* Skip over tail */%@AE@%%@NL@%
- startread(fd,cp,(FILBUFLEN - taillen) & (~0 << LG2SECLEN));%@NL@%
- %@AB@%/* Start next read */%@AE@%%@NL@%
- }%@NL@%
- if((*grep)(bufptr[bufi],endbuf,name)) return;%@NL@%
- %@AB@%/* Done if NAMEONLY and match found */%@AE@%%@NL@%
- bufi ^= 1; %@AB@%/* Switch buffers */%@AE@%%@NL@%
- }%@NL@%
- if((flags & (NAMEONLY | INVERT)) == (NAMEONLY | INVERT))%@NL@%
- (*write1)(line,sprintf(line,"%s\r\n",name));%@NL@%
- %@AB@%/* Write name if -lv */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void usage(verbose)%@NL@%
- int verbose; %@AB@%/* Verbose message flag */%@AE@%%@NL@%
- {%@NL@%
- static char *opts[] =%@NL@%
- {%@NL@%
- "-? - print this message",%@NL@%
- "-B - match pattern if at beginning of line",%@NL@%
- "-E - match pattern if at end of line",%@NL@%
- "-l - print only file name if file contains match",%@NL@%
- "-n - print line number before each matching line",%@NL@%
- "-v - print only lines not containing a match",%@NL@%
- "-x - print lines that match exactly (-BE)",%@NL@%
- "-y - treat upper and lower case as equivalent",%@NL@%
- "-e - treat next argument as the search string",%@NL@%
- "-f - read search strings from file named by next argument",%@NL@%
- "-i - read file list from file named by next argument",%@NL@%
- 0%@NL@%
- };%@NL@%
- register char **opt = opts; %@AB@%/* Option list */%@AE@%%@NL@%
- %@NL@%
- fprintf(stderr,"usage: CPGREP [-?BElnvxy][-e][-f <file>][-i <file>][<strings>][<files>]\n");%@NL@%
- if(verbose) %@AB@%/* If verbose message wanted */%@AE@%%@NL@%
- {%@NL@%
- while(*opt != 0) fprintf(stderr,"%s\n",*opt++);%@NL@%
- %@AB@%/* Print option list */%@AE@%%@NL@%
- }%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Error exit */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void main(argc,argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- register char *cp;%@NL@%
- HFILE fd;%@NL@%
- FILE *fi;%@NL@%
- char filnam[FILNAMLEN];%@NL@%
- USHORT handType;%@NL@%
- USHORT handAttrib;%@NL@%
- int i;%@NL@%
- char *inpfile = NULL;%@NL@%
- int j;%@NL@%
- char *seplist = " \t";%@NL@%
- int strcnt;%@NL@%
- char *strfile = NULL;%@NL@%
- long start; %@AB@%/* Start time */%@AE@%%@NL@%
- int (*add)();%@NL@%
- BYTE t2stk[2*STKLEN]; %@AB@%/* Read thread stack */%@AE@%%@NL@%
- BYTE t3stk[2*STKLEN]; %@AB@%/* Write thread stack */%@AE@%%@NL@%
- long time(); %@AB@%/* Time and date in seconds */%@AE@%%@NL@%
- %@NL@%
- DosGetMachineMode((char far *) &pmode);%@NL@%
- flags = 0;%@NL@%
- for(i = 1; i < argc && argv[i][0] == '-'; ++i)%@NL@%
- {%@NL@%
- switch(argv[i][1])%@NL@%
- {%@NL@%
- case 'f':%@NL@%
- case 'i':%@NL@%
- if(i == argc - 1)%@NL@%
- {%@NL@%
- fprintf(stderr,"File name missing after -%c\n",argv[i][1]);%@NL@%
- DosExit( EXIT_PROCESS, 2);%@NL@%
- }%@NL@%
- if(argv[i++][1] == 'i') inpfile = argv[i];%@NL@%
- else strfile = argv[i];%@NL@%
- break;%@NL@%
- %@NL@%
- case '?':%@NL@%
- case 'B':%@NL@%
- case 'E':%@NL@%
- case 'N':%@NL@%
- case 'S':%@NL@%
- case 'd':%@NL@%
- case 'l':%@NL@%
- case 'n':%@NL@%
- case 't':%@NL@%
- case 'v':%@NL@%
- case 'x':%@NL@%
- case 'y':%@NL@%
- for(cp = &argv[i][1]; *cp != '\0'; ++cp)%@NL@%
- {%@NL@%
- switch(*cp)%@NL@%
- {%@NL@%
- case '?':%@NL@%
- usage(1); %@AB@%/* Verbose usage message */%@AE@%%@NL@%
- %@NL@%
- case 'B':%@NL@%
- flags |= BEGLINE;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'E':%@NL@%
- flags |= ENDLINE;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'N':%@NL@%
- grep = grepnull;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'S':%@NL@%
- pmode = 0; %@AB@%/* Force synchronous I/O */%@AE@%%@NL@%
- break;%@NL@%
- %@NL@%
- case 'd':%@NL@%
- flags |= DEBUG;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'l':%@NL@%
- flags |= NAMEONLY;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'n':%@NL@%
- flags |= LINENOS;%@NL@%
- break;%@NL@%
- %@NL@%
- case 't':%@NL@%
- flags |= TIMER;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'v':%@NL@%
- status = 0; %@AB@%/* Assume success */%@AE@%%@NL@%
- flags |= INVERT;%@NL@%
- grep = grepvbuffer;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'x':%@NL@%
- flags |= BEGLINE | ENDLINE;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'y':%@NL@%
- casesen = 0;%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- fprintf(stderr,"-%c ignored\n",*cp);%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case 'e':%@NL@%
- if(strfile == NULL)%@NL@%
- {%@NL@%
- ++i;%@NL@%
- seplist = ""; %@AB@%/* Allow anything in string */%@AE@%%@NL@%
- goto endfor0;%@NL@%
- }%@NL@%
- %@AB@%/* Drop through to "default" */%@AE@%%@NL@%
- %@NL@%
- default:%@NL@%
- fprintf(stderr,"%s ignored\n",argv[i]);%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- endfor0:%@NL@%
- %@NL@%
- if(i == argc && strfile == NULL) usage(0);%@NL@%
- %@AB@%/* Simple usage message if arg error */%@AE@%%@NL@%
- if(flags & TIMER) start = time(NULL);%@NL@%
- %@AB@%/* Get start time if timer on */%@AE@%%@NL@%
- if(pmode) %@AB@%/* Initialize semaphores and threads */%@AE@%%@NL@%
- {%@NL@%
- TID threadId;%@NL@%
- %@NL@%
- DosSemClear( &readdone);%@NL@%
- DosSemClear( &writedone);%@NL@%
- DosSemSet( &readpending);%@NL@%
- DosSemSet( &writepending);%@NL@%
- if(DosCreateThread(thread2, &threadId, t2stk + 2*STKLEN) != 0 ||%@NL@%
- DosCreateThread(thread3, &threadId, t3stk + 2*STKLEN) != 0)%@NL@%
- { %@AB@%/* If thread creation fails */%@AE@%%@NL@%
- fprintf(stderr,"Failed to create child threads\n");%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- setmode(fileno(stdout),O_BINARY);%@NL@%
- add = addplain; %@AB@%/* Assume plain string adds */%@AE@%%@NL@%
- if(strfile != NULL) %@AB@%/* If strings from file */%@AE@%%@NL@%
- {%@NL@%
- if(!(flags & BEGLINE)) add = addfancy;%@NL@%
- %@AB@%/* Try to add intelligently */%@AE@%%@NL@%
- if((fd = open(strfile,0)) == -1)%@NL@%
- { %@AB@%/* If open fails */%@AE@%%@NL@%
- fprintf(stderr,"Cannot read strings from %s\n",strfile);%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Print message and die */%@AE@%%@NL@%
- }%@NL@%
- for(cp = filbuf, j = 0; (j = read(fd,cp,FILBUFLEN*2 - j)) > 0; cp += j);%@NL@%
- %@AB@%/* Read strings file into buffer */%@AE@%%@NL@%
- j = cp - filbuf; %@AB@%/* Get total length of buffer */%@AE@%%@NL@%
- close(fd); %@AB@%/* Close strings file */%@AE@%%@NL@%
- filbuf[j] = '\0'; %@AB@%/* Null-terminate the buffer */%@AE@%%@NL@%
- cp = filbuf; %@AB@%/* Set pointer to string list */%@AE@%%@NL@%
- seplist = "\r\n"; %@AB@%/* Only '\r' and '\n' are separators */%@AE@%%@NL@%
- }%@NL@%
- else %@AB@%/* Else strings on command line */%@AE@%%@NL@%
- {%@NL@%
- cp = argv[i++]; %@AB@%/* Set pointer to strings */%@AE@%%@NL@%
- j = strlen(cp); %@AB@%/* Get length of strings */%@AE@%%@NL@%
- }%@NL@%
- if((strcnt = (*add)(cp,j,seplist)) == 0)%@NL@%
- { %@AB@%/* If no strings */%@AE@%%@NL@%
- fprintf(stderr,"No search strings\n");%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Print error message and die */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Check type of handle for std. out.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if(DosQHandType(fileno(stdout), &handType, &handAttrib) != 0)%@NL@%
- { %@AB@%/* If error */%@AE@%%@NL@%
- fprintf(stderr,"Standard output bad handle\n");%@NL@%
- %@AB@%/* Print error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Die */%@AE@%%@NL@%
- }%@NL@%
- if(handType != 0 && (handAttrib & ISCOT))%@NL@%
- { %@AB@%/* If handle is console output */%@AE@%%@NL@%
- write1 = write1nobuf; %@AB@%/* Use unbuffered output */%@AE@%%@NL@%
- flush1 = flush1nobuf;%@NL@%
- }%@NL@%
- %@NL@%
- if(strcnt > 1) %@AB@%/* If more than one string */%@AE@%%@NL@%
- {%@NL@%
- if(flags & DEBUG) %@AB@%/* Print debug info maybe */%@AE@%%@NL@%
- {%@NL@%
- fprintf(stderr,"Here are the strings:\n");%@NL@%
- dumpstrings();%@NL@%
- }%@NL@%
- }%@NL@%
- else if(casesen) find = findone; %@AB@%/* Else use findone() */%@AE@%%@NL@%
- if(inpfile != NULL) %@AB@%/* If file list from file */%@AE@%%@NL@%
- {%@NL@%
- flags |= SHOWNAME; %@AB@%/* Always show name of file */%@AE@%%@NL@%
- if((fi = fopen(inpfile,"r")) == NULL)%@NL@%
- { %@AB@%/* If open fails */%@AE@%%@NL@%
- fprintf(stderr,"Cannot read file list from %s\r\n",inpfile);%@NL@%
- %@AB@%/* Error message */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, 2); %@AB@%/* Error exit */%@AE@%%@NL@%
- }%@NL@%
- while(fgets(filnam,FILNAMLEN,fi) != NULL)%@NL@%
- { %@AB@%/* While there are names */%@AE@%%@NL@%
- filnam[strcspn(filnam,"\r\n")] = '\0';%@NL@%
- %@AB@%/* Null-terminate the name */%@AE@%%@NL@%
- if((fd = openfile(filnam)) == -1) continue;%@NL@%
- %@AB@%/* Skip file if it cannot be opened */%@AE@%%@NL@%
- qgrep(filnam,fd); %@AB@%/* Do the work */%@AE@%%@NL@%
- close(fd); %@AB@%/* Close the file */%@AE@%%@NL@%
- }%@NL@%
- fclose(fi); %@AB@%/* Close the list file */%@AE@%%@NL@%
- }%@NL@%
- else if(i == argc)%@NL@%
- {%@NL@%
- flags &= ~(NAMEONLY | SHOWNAME);%@NL@%
- setmode(fileno(stdin),O_BINARY);%@NL@%
- qgrep(NULL,fileno(stdin));%@NL@%
- }%@NL@%
- if(argc > i + 1) flags |= SHOWNAME;%@NL@%
- for(; i < argc; ++i)%@NL@%
- {%@NL@%
- if((fd = openfile(argv[i])) == -1) continue;%@NL@%
- qgrep(argv[i],fd);%@NL@%
- close(fd);%@NL@%
- }%@NL@%
- (*flush1)();%@NL@%
- if(flags & TIMER) fprintf(stderr,"%ld seconds\n",time(NULL) - start);%@NL@%
- %@AB@%/* Print elapsed time if timer on */%@AE@%%@NL@%
- DosExit( EXIT_PROCESS, status);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CPGREPSB.ASM%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CPGREP\CPGREPSB.ASM%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Created by Microsoft Corp. 1986%@AE@%%@NL@%
- name cpgrepsub%@NL@%
- %@NL@%
- retlen equ 2 %@AB@%; Size of return address on stack%@AE@%%@NL@%
- %@NL@%
- dgroup group _data%@NL@%
- %@NL@%
- extrn _casesen: word %@AB@%; Case-sensitivity flag%@AE@%%@NL@%
- extrn _stringlist: word %@AB@%; Table of string lists%@AE@%%@NL@%
- extrn _target: byte %@AB@%; Target string%@AE@%%@NL@%
- extrn _targetlen: word %@AB@%; Length of target string%@AE@%%@NL@%
- extrn _transtab: byte %@AB@%; Translation table for _findlist%@AE@%%@NL@%
- %@NL@%
- %@AB@%; This segment is puposely word-aligned. See note%@AE@%%@NL@%
- %@AB@%; in _findlist below.%@AE@%%@NL@%
- %@NL@%
- _text segment word public 'code'%@NL@%
- assume cs:_text, ds:dgroup, es:nothing, ss:dgroup%@NL@%
- %@NL@%
- %@AB@%; char *findone(buffer,bufend)%@AE@%%@NL@%
- %@AB@%; char *buffer /* Buffer in which to search */%@AE@%%@NL@%
- %@AB@%; char *bufend; /* End of buffer */%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; NOTE: targetlen MUST BE greater than zero%@AE@%%@NL@%
- %@NL@%
- buffer equ word ptr [bp+retlen+2]%@NL@%
- bufend equ word ptr [bp+retlen+4]%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public _findone%@NL@%
- _findone proc near%@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- push di%@NL@%
- push si%@NL@%
- push es%@NL@%
- push ds %@AB@%; ES = DS%@AE@%%@NL@%
- pop es%@NL@%
- mov cx,bufend %@AB@%; CX = end of buffer%@AE@%%@NL@%
- mov di,buffer %@AB@%; ES:DI = buffer%@AE@%%@NL@%
- sub cx,di %@AB@%; CX = length of buffer%@AE@%%@NL@%
- jbe sfnomatch %@AB@%; length less than or equal to zero%@AE@%%@NL@%
- mov dx,_targetlen %@AB@%; DX = length of target%@AE@%%@NL@%
- dec dx %@AB@%; Decrement it%@AE@%%@NL@%
- sub cx,dx %@AB@%; target must fit in buffer%@AE@%%@NL@%
- jbe sfnomatch %@AB@%; (no match if buffer too short)%@AE@%%@NL@%
- %@NL@%
- %@AB@%; CX = buffer length%@AE@%%@NL@%
- %@AB@%; DX = target length (minus first character)%@AE@%%@NL@%
- %@AB@%; ES:DI = buffer pointer%@AE@%%@NL@%
- %@NL@%
- sf0: jcxz sfnomatch %@AB@%; No match if count zero%@AE@%%@NL@%
- mov si,offset dgroup:_target %@AB@%; DS:SI = target%@AE@%%@NL@%
- lodsb %@AB@%; AL = first byte of target%@AE@%%@NL@%
- repne scasb %@AB@%; Look for first character%@AE@%%@NL@%
- jne sfnomatch %@AB@%; jump if not found%@AE@%%@NL@%
- mov bx,cx %@AB@%; BX = buffer length%@AE@%%@NL@%
- mov ax,di %@AB@%; AX = buffer pointer%@AE@%%@NL@%
- mov cx,dx %@AB@%; Get count for cmpsb%@AE@%%@NL@%
- or cx,cx %@AB@%; Zero? (JCXZ doesn't set flag)%@AE@%%@NL@%
- je sf1 %@AB@%; yes, skip compare%@AE@%%@NL@%
- repe cmpsb %@AB@%; Do string compare%@AE@%%@NL@%
- sf1: mov di,ax %@AB@%; DI = buffer pointer%@AE@%%@NL@%
- mov cx,bx %@AB@%; CX = buffer length%@AE@%%@NL@%
- jne sf0 %@AB@%; Loop if no match%@AE@%%@NL@%
- dec ax %@AB@%; AX = offset of start of match%@AE@%%@NL@%
- jmp short sf4%@NL@%
- %@NL@%
- sfnomatch:%@NL@%
- xor ax,ax %@AB@%; No match%@AE@%%@NL@%
- sf4: pop es%@NL@%
- pop si%@NL@%
- pop di%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- _findone endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; int revfind(s,c,slen)%@AE@%%@NL@%
- %@AB@%; char *s; /* String to search */%@AE@%%@NL@%
- %@AB@%; int c; /* Char to search for */%@AE@%%@NL@%
- %@AB@%; int slen; /* Length of s */%@AE@%%@NL@%
- %@NL@%
- s equ [bp+retlen+2]%@NL@%
- c equ [bp+retlen+4]%@NL@%
- slen equ [bp+retlen+6]%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public _revfind%@NL@%
- _revfind proc near%@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- push di%@NL@%
- push es%@NL@%
- push ds%@NL@%
- pop es%@NL@%
- mov di,s%@NL@%
- mov ax,c%@NL@%
- mov cx,slen%@NL@%
- jcxz rf1%@NL@%
- std%@NL@%
- repne scasb%@NL@%
- cld%@NL@%
- mov cx,s%@NL@%
- jne rf0%@NL@%
- inc di%@NL@%
- rf0: sub cx,di%@NL@%
- rf1: mov ax,cx%@NL@%
- pop es%@NL@%
- pop di%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- _revfind endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; int countlines(start,finish)%@AE@%%@NL@%
- %@AB@%; char *start;%@AE@%%@NL@%
- %@AB@%; char *finish;%@AE@%%@NL@%
- %@NL@%
- start equ [bp+retlen+2]%@NL@%
- finish equ [bp+retlen+4]%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public _countlines%@NL@%
- _countlines proc near%@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- push di%@NL@%
- push es%@NL@%
- push ds%@NL@%
- pop es%@NL@%
- xor dx,dx %@AB@%; Accumulate count in DX%@AE@%%@NL@%
- mov di,start %@AB@%; ES:DI points to start%@AE@%%@NL@%
- mov cx,finish %@AB@%; Put length in CX%@AE@%%@NL@%
- sub cx,di%@NL@%
- jbe cl1 %@AB@%; branch if no bytes%@AE@%%@NL@%
- mov al,0Ah %@AB@%; Search for linefeeds%@AE@%%@NL@%
- cl0: jcxz cl1 %@AB@%; Exit loop if count zero%@AE@%%@NL@%
- repne scasb %@AB@%; Do search%@AE@%%@NL@%
- jne cl1 %@AB@%; branch if none found%@AE@%%@NL@%
- inc dx %@AB@%; Increment count%@AE@%%@NL@%
- jmp short cl0 %@AB@%; Loop%@AE@%%@NL@%
- cl1: mov ax,dx %@AB@%; Return line count in AX%@AE@%%@NL@%
- pop es%@NL@%
- pop di%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- _countlines endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; char *findlist(buffer,bufend)%@AE@%%@NL@%
- %@AB@%; char *buffer; /* Buffer to search */%@AE@%%@NL@%
- %@AB@%; char *bufend; /* End of buffer */%@AE@%%@NL@%
- %@NL@%
- savesi equ word ptr [bp-2]%@NL@%
- endbyte equ byte ptr [bp-4]%@NL@%
- %@NL@%
- stringnode struc%@NL@%
- s_alt dw ? %@AB@%; List of alternate portions%@AE@%%@NL@%
- s_suf dw ? %@AB@%; Pointer to suffix string list%@AE@%%@NL@%
- s_must dw ? %@AB@%; Length of portion that must match%@AE@%%@NL@%
- stringnode ends%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- flworker dw findsubi, findsub %@AB@%; Worker dispatch table%@AE@%%@NL@%
- %@NL@%
- public _findlist%@NL@%
- _findlist proc near%@NL@%
- ASSUME DS:DGROUP, ES:NOTHING, SS:DGROUP%@NL@%
- %@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- sub sp,4 %@AB@%; Make room for local vars%@AE@%%@NL@%
- push di%@NL@%
- push si%@NL@%
- push ds%@NL@%
- pop es%@NL@%
- ASSUME ES:DGROUP%@NL@%
- %@NL@%
- %@AB@%; We mark the end of our search buffer with 0FFh so that%@AE@%%@NL@%
- %@AB@%; any comparisons that might run past the end of the buffer%@AE@%%@NL@%
- %@AB@%; will fail on the 0FFh. We choose 0FFh so that if the%@AE@%%@NL@%
- %@AB@%; comparison fails on it, it will always appear as though%@AE@%%@NL@%
- %@AB@%; the string in the buffer is greater that the string in%@AE@%%@NL@%
- %@AB@%; the search list. This will prevent us from stopping%@AE@%%@NL@%
- %@AB@%; the search too soon. Of course, we must restore the byte%@AE@%%@NL@%
- %@AB@%; when we're done.%@AE@%%@NL@%
- %@NL@%
- mov bx,bufend %@AB@%; BX = end of buffer%@AE@%%@NL@%
- mov al,0FFh %@AB@%; End marker%@AE@%%@NL@%
- xchg byte ptr [bx],al %@AB@%; AL = byte after end of buffer%@AE@%%@NL@%
- mov endbyte,al %@AB@%; Save the byte%@AE@%%@NL@%
- %@NL@%
- mov cx,bx %@AB@%; CX = end of buffer%@AE@%%@NL@%
- mov si,buffer %@AB@%; SI = buffer%@AE@%%@NL@%
- sub cx,si %@AB@%; CX = buffer length%@AE@%%@NL@%
- jbe fl1 %@AB@%; no match if empty buffer%@AE@%%@NL@%
- mov bx,offset dgroup:_transtab %@AB@%; BX = translation table address%@AE@%%@NL@%
- %@NL@%
- mov di,_casesen %@AB@%; Get flag%@AE@%%@NL@%
- shl di,1 %@AB@%; Scale to word index%@AE@%%@NL@%
- call cs:flworker[di] %@AB@%; Call helper%@AE@%%@NL@%
- jc fl1 %@AB@%; branch if no match%@AE@%%@NL@%
- %@NL@%
- %@AB@%; We have a match%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; SI = offset of first character past end of matched string%@AE@%%@NL@%
- %@AB@%; savesi = offset of first character past start of matched string%@AE@%%@NL@%
- %@NL@%
- mov ax,savesi %@AB@%; AX = 1st char past start%@AE@%%@NL@%
- dec ax %@AB@%; AX = start of matched string%@AE@%%@NL@%
- jmp short fl2%@NL@%
- %@NL@%
- %@AB@%; We did not find a match%@AE@%%@NL@%
- %@NL@%
- fl1:%@NL@%
- xor ax,ax %@AB@%; Return NULL%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Restore end byte before leaving%@AE@%%@NL@%
- %@NL@%
- fl2:%@NL@%
- mov bx,bufend %@AB@%; BX = end of buffer%@AE@%%@NL@%
- mov dl,endbyte %@AB@%; DL = end byte%@AE@%%@NL@%
- mov [bx],dl %@AB@%; Restore byte%@AE@%%@NL@%
- %@NL@%
- pop si%@NL@%
- pop di%@NL@%
- mov sp,bp%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- %@NL@%
- _findlist endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%;*** findsub - case-sensitive worker for _findlist%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; This function does most of the work for%@AE@%%@NL@%
- %@AB@%; case-sensitive multi-string searches.%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; ENTRY BX = address of translation table%@AE@%%@NL@%
- %@AB@%; CX = number of bytes left in buffer%@AE@%%@NL@%
- %@AB@%; DS:SI = buffer pointer%@AE@%%@NL@%
- %@AB@%; SS:BP = pointer to stack frame for _findlist%@AE@%%@NL@%
- %@AB@%; EXIT Carry set%@AE@%%@NL@%
- %@AB@%; No match%@AE@%%@NL@%
- %@AB@%; Carry clear%@AE@%%@NL@%
- %@AB@%; DS:SI = pointer to first character after match%@AE@%%@NL@%
- %@AB@%; USES AX, CX, DX, DI, SI, Flags%@AE@%%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public findsub, fs0, fs1, fs2, fs3, fs4, fs5, fs6%@NL@%
- findsub proc near%@NL@%
- ASSUME DS:DGROUP, ES:DGROUP, SS:DGROUP%@NL@%
- %@NL@%
- fs0:%@NL@%
- xor ax,ax %@AB@%; AH = 0%@AE@%%@NL@%
- %@NL@%
- %@AB@%; AH = 0%@AE@%%@NL@%
- %@AB@%; BX = address of translation table%@AE@%%@NL@%
- %@AB@%; CX = number of bytes left in buffer%@AE@%%@NL@%
- %@AB@%; SI = buffer pointer%@AE@%%@NL@%
- %@AB@%; DS = ES = SS = DGROUP%@AE@%%@NL@%
- %@NL@%
- fs1:%@NL@%
- lodsb %@AB@%; Character in AL%@AE@%%@NL@%
- xlat byte ptr [bx] %@AB@%; Translate character to index%@AE@%%@NL@%
- or al,al %@AB@%; Zero means invalid 1st byte%@AE@%%@NL@%
- loopz fs1 %@AB@%; if so, try next character%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Either the zero bit is set, meaning the buffer is empty,%@AE@%%@NL@%
- %@AB@%; or the zero bit is clear, meaning we have a valid first%@AE@%%@NL@%
- %@AB@%; character. Either way, CX has been decremented.%@AE@%%@NL@%
- %@NL@%
- jz fs6 %@AB@%; branch if buffer empty%@AE@%%@NL@%
- mov savesi,si %@AB@%; Save buffer pointer%@AE@%%@NL@%
- shl ax,1 %@AB@%; Scale to word index%@AE@%%@NL@%
- mov di,ax%@NL@%
- mov di,_stringlist[di] %@AB@%; DI points to string record%@AE@%%@NL@%
- or di,di %@AB@%; One byte match? (OR clears carry)%@AE@%%@NL@%
- jz fs3 %@AB@%; yes, skip ahead%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Loop to search for match.%@AE@%%@NL@%
- %@AB@%; BX = address of translation table%@AE@%%@NL@%
- %@AB@%; DI = pointer to string record%@AE@%%@NL@%
- %@AB@%; SI = pointer into buffer%@AE@%%@NL@%
- %@NL@%
- fs2:%@NL@%
- mov cx,[di].s_must %@AB@%; CX = length of string%@AE@%%@NL@%
- sub di,cx %@AB@%; DI = pointer to string%@AE@%%@NL@%
- mov dx,si %@AB@%; Save pointer to start of suffix%@AE@%%@NL@%
- repe cmpsb %@AB@%; Strings match?%@AE@%%@NL@%
- ja fs4 %@AB@%; no, try alternate if follows%@AE@%%@NL@%
- jb fs5 %@AB@%; no, cannot be in this list%@AE@%%@NL@%
- add di,cx %@AB@%; DI = pointer to string record%@AE@%%@NL@%
- mov di,[di].s_suf %@AB@%; Get pointer to suffix string list%@AE@%%@NL@%
- or di,di %@AB@%; Is there one? (OR clears carry)%@AE@%%@NL@%
- jnz fs2 %@AB@%; yes, keep looking%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Match found%@AE@%%@NL@%
- %@NL@%
- fs3:%@NL@%
- ret %@AB@%; no, we have a match%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Try alternate suffix%@AE@%%@NL@%
- %@NL@%
- fs4:%@NL@%
- add di,cx %@AB@%; DI = pointer to string record%@AE@%%@NL@%
- mov di,[di].s_alt %@AB@%; Get pointer to alternate%@AE@%%@NL@%
- mov si,dx %@AB@%; Restore SI to start of suffix%@AE@%%@NL@%
- or di,di %@AB@%; Is there one?%@AE@%%@NL@%
- jnz fs2 %@AB@%; yes, loop%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Try new first character%@AE@%%@NL@%
- %@NL@%
- fs5:%@NL@%
- mov cx,bufend %@AB@%; CX = end of buffer%@AE@%%@NL@%
- mov si,savesi %@AB@%; Restore SI to saved value%@AE@%%@NL@%
- sub cx,si %@AB@%; CX = length of buffer%@AE@%%@NL@%
- ja short fs0 %@AB@%; Try next character in buffer%@AE@%%@NL@%
- %@NL@%
- %@AB@%; No match%@AE@%%@NL@%
- %@NL@%
- fs6:%@NL@%
- stc %@AB@%; No match%@AE@%%@NL@%
- ret%@NL@%
- %@NL@%
- findsub endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%;*** findsubi - case-insensitive worker for _findlist%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; This function does most of the work for%@AE@%%@NL@%
- %@AB@%; case-insensitive multi-string searches.%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; ENTRY BX = address of translation table%@AE@%%@NL@%
- %@AB@%; CX = number of bytes left in buffer%@AE@%%@NL@%
- %@AB@%; DS:SI = buffer pointer%@AE@%%@NL@%
- %@AB@%; SS:BP = pointer to stack frame for _findlist%@AE@%%@NL@%
- %@AB@%; EXIT Carry set%@AE@%%@NL@%
- %@AB@%; No match%@AE@%%@NL@%
- %@AB@%; Carry clear%@AE@%%@NL@%
- %@AB@%; DS:SI = pointer to first character after match%@AE@%%@NL@%
- %@AB@%; USES AX, CX, DX, DI, SI, Flags%@AE@%%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public findsubi%@NL@%
- findsubi proc near%@NL@%
- ASSUME DS:DGROUP, ES:DGROUP, SS:DGROUP%@NL@%
- %@NL@%
- fsi0:%@NL@%
- xor ax,ax %@AB@%; AH = 0%@AE@%%@NL@%
- %@NL@%
- %@AB@%; AH = 0%@AE@%%@NL@%
- %@AB@%; BX = address of translation table%@AE@%%@NL@%
- %@AB@%; CX = number of bytes left in buffer%@AE@%%@NL@%
- %@AB@%; SI = buffer pointer%@AE@%%@NL@%
- %@AB@%; DS = ES = SS = DGROUP%@AE@%%@NL@%
- %@NL@%
- fsi1:%@NL@%
- lodsb %@AB@%; Character in AL%@AE@%%@NL@%
- xlat byte ptr [bx] %@AB@%; Translate character to index%@AE@%%@NL@%
- or al,al %@AB@%; Zero means invalid 1st byte%@AE@%%@NL@%
- loopz fsi1 %@AB@%; if so, try next character%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Either the zero bit is set, meaning the buffer is empty,%@AE@%%@NL@%
- %@AB@%; or the zero bit is clear, meaning we have a valid first%@AE@%%@NL@%
- %@AB@%; character. Either way, CX has been decremented.%@AE@%%@NL@%
- %@NL@%
- jz fsi7 %@AB@%; branch if buffer empty%@AE@%%@NL@%
- mov savesi,si %@AB@%; Save buffer pointer%@AE@%%@NL@%
- shl ax,1 %@AB@%; Scale to word index%@AE@%%@NL@%
- mov di,ax%@NL@%
- mov di,_stringlist[di] %@AB@%; DI points to string record%@AE@%%@NL@%
- or di,di %@AB@%; One byte match? (OR clears carry)%@AE@%%@NL@%
- jz fsi4 %@AB@%; yes, skip ahead%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Loop to search for match.%@AE@%%@NL@%
- %@AB@%; BX = address of translation table%@AE@%%@NL@%
- %@AB@%; DI = pointer to string record%@AE@%%@NL@%
- %@AB@%; SI = pointer into buffer%@AE@%%@NL@%
- %@NL@%
- fsi2:%@NL@%
- mov cx,[di].s_must %@AB@%; CX = length of string%@AE@%%@NL@%
- sub di,cx %@AB@%; DI = pointer to string%@AE@%%@NL@%
- mov dx,si %@AB@%; Save pointer to start of suffix%@AE@%%@NL@%
- fsi3: lodsb %@AB@%; Byte in AL, SI = SI + 1%@AE@%%@NL@%
- mov ah,[di] %@AB@%; Byte in AH, DI = DI + 1%@AE@%%@NL@%
- inc di%@NL@%
- or ax,2020h %@AB@%; Fold bytes onto lower case%@AE@%%@NL@%
- cmp al,ah %@AB@%; Compare bytes%@AE@%%@NL@%
- loope fsi3 %@AB@%; Loop while same%@AE@%%@NL@%
- ja fsi5 %@AB@%; no, try alternate if follows%@AE@%%@NL@%
- jb fsi6 %@AB@%; no, cannot be in this list%@AE@%%@NL@%
- add di,cx %@AB@%; DI = pointer to string record%@AE@%%@NL@%
- mov di,[di].s_suf %@AB@%; Get pointer to suffix string list%@AE@%%@NL@%
- or di,di %@AB@%; Is there one? (OR clears carry)%@AE@%%@NL@%
- jnz fsi2 %@AB@%; yes, keep looking%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Match found%@AE@%%@NL@%
- %@NL@%
- fsi4:%@NL@%
- ret %@AB@%; no, we have a match%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Try alternate suffix%@AE@%%@NL@%
- %@NL@%
- fsi5:%@NL@%
- add di,cx %@AB@%; DI = pointer to string record%@AE@%%@NL@%
- mov di,[di].s_alt %@AB@%; Get pointer to alternate%@AE@%%@NL@%
- mov si,dx %@AB@%; Restore SI to start of suffix%@AE@%%@NL@%
- or di,di %@AB@%; Is there one?%@AE@%%@NL@%
- jnz fsi2 %@AB@%; yes, loop%@AE@%%@NL@%
- %@NL@%
- %@AB@%; Try new first character%@AE@%%@NL@%
- %@NL@%
- fsi6:%@NL@%
- mov cx,bufend %@AB@%; CX = end of buffer%@AE@%%@NL@%
- mov si,savesi %@AB@%; Restore SI to saved value%@AE@%%@NL@%
- sub cx,si %@AB@%; CX = length of buffer%@AE@%%@NL@%
- ja short fsi0 %@AB@%; Try next character in buffer%@AE@%%@NL@%
- %@NL@%
- %@AB@%; No match%@AE@%%@NL@%
- %@NL@%
- fsi7:%@NL@%
- stc %@AB@%; No match%@AE@%%@NL@%
- ret%@NL@%
- %@NL@%
- findsubi endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; int strnspn(s,t,n)%@AE@%%@NL@%
- %@AB@%; char *s; /* String to search */%@AE@%%@NL@%
- %@AB@%; char *t; /* Target list */%@AE@%%@NL@%
- %@AB@%; int n; /* Length of s */%@AE@%%@NL@%
- %@NL@%
- s equ word ptr [bp+retlen+2]%@NL@%
- t equ word ptr [bp+retlen+4]%@NL@%
- n equ word ptr [bp+retlen+6]%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public _strnspn%@NL@%
- _strnspn proc near%@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- push di%@NL@%
- push si%@NL@%
- push ds%@NL@%
- pop es%@NL@%
- cld%@NL@%
- mov bx,t %@AB@%; BX = t%@AE@%%@NL@%
- mov di,bx %@AB@%; DI = t%@AE@%%@NL@%
- xor al,al %@AB@%; Search for 0 byte%@AE@%%@NL@%
- mov cx,0FFFFh%@NL@%
- repne scasb%@NL@%
- dec di %@AB@%; Back up to 0%@AE@%%@NL@%
- sub di,bx %@AB@%; DI = length of t%@AE@%%@NL@%
- jz spn1 %@AB@%; Done if length of t is 0%@AE@%%@NL@%
- mov dx,di %@AB@%; DX = length of t%@AE@%%@NL@%
- mov si,s %@AB@%; SI = s%@AE@%%@NL@%
- mov cx,n %@AB@%; CX = length of s%@AE@%%@NL@%
- jcxz spn1 %@AB@%; Check for null string%@AE@%%@NL@%
- push bp%@NL@%
- spn0: lodsb %@AB@%; AL = next char in s%@AE@%%@NL@%
- mov bp,cx %@AB@%; BP = length of s%@AE@%%@NL@%
- mov cx,dx %@AB@%; CX = length of t%@AE@%%@NL@%
- mov di,bx %@AB@%; DI = t%@AE@%%@NL@%
- repne scasb %@AB@%; Scan until match found%@AE@%%@NL@%
- mov cx,bp %@AB@%; CX = length of s%@AE@%%@NL@%
- loope spn0 %@AB@%; Loop if match found%@AE@%%@NL@%
- pop bp%@NL@%
- je spn1 %@AB@%; Skip ahead if end of s reached%@AE@%%@NL@%
- dec si %@AB@%; Back up one char%@AE@%%@NL@%
- spn1: sub si,s %@AB@%; SI = length of prefix%@AE@%%@NL@%
- mov ax,si %@AB@%; AX = length of prefix%@AE@%%@NL@%
- pop si%@NL@%
- pop di%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- _strnspn endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; int strncspn(s,t,n)%@AE@%%@NL@%
- %@AB@%; char *s; /* String to search */%@AE@%%@NL@%
- %@AB@%; char *t; /* Target list */%@AE@%%@NL@%
- %@AB@%; int n; /* Length of s */%@AE@%%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public _strncspn%@NL@%
- _strncspn proc near%@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- push di%@NL@%
- push si%@NL@%
- push ds%@NL@%
- pop es%@NL@%
- cld%@NL@%
- mov bx,t %@AB@%; BX = t%@AE@%%@NL@%
- mov di,bx %@AB@%; DI = t%@AE@%%@NL@%
- xor al,al %@AB@%; Search for 0 byte%@AE@%%@NL@%
- mov cx,0FFFFh%@NL@%
- repne scasb%@NL@%
- dec di %@AB@%; Back up to 0%@AE@%%@NL@%
- sub di,bx %@AB@%; DI = length of t%@AE@%%@NL@%
- mov ax,n %@AB@%; Assume length of t is 0%@AE@%%@NL@%
- jz cspn2 %@AB@%; Done if length of t is 0%@AE@%%@NL@%
- mov dx,di %@AB@%; DX = length of t%@AE@%%@NL@%
- mov si,s %@AB@%; SI = s%@AE@%%@NL@%
- mov cx,ax %@AB@%; CX = length of s%@AE@%%@NL@%
- jcxz cspn1 %@AB@%; Check for null string%@AE@%%@NL@%
- push bp%@NL@%
- cspn0: lodsb %@AB@%; AL = next char in s%@AE@%%@NL@%
- mov bp,cx %@AB@%; BP = length of s%@AE@%%@NL@%
- mov cx,dx %@AB@%; CX = length of t%@AE@%%@NL@%
- mov di,bx %@AB@%; DI = t%@AE@%%@NL@%
- repne scasb %@AB@%; Scan until match found%@AE@%%@NL@%
- mov cx,bp %@AB@%; CX = length of s%@AE@%%@NL@%
- loopne cspn0 %@AB@%; Loop if match not found%@AE@%%@NL@%
- pop bp%@NL@%
- jne cspn1 %@AB@%; Skip ahead if end of s reached%@AE@%%@NL@%
- dec si %@AB@%; Back up one char%@AE@%%@NL@%
- cspn1: sub si,s %@AB@%; SI = length of prefix%@AE@%%@NL@%
- mov ax,si %@AB@%; AX = length of prefix%@AE@%%@NL@%
- cspn2: pop si%@NL@%
- pop di%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- _strncspn endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; cmpsen - case-sensitive comparison%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; ENTRY DS:SI = buffer%@AE@%%@NL@%
- %@AB@%; ES:DI = string%@AE@%%@NL@%
- %@AB@%; CX = length of string%@AE@%%@NL@%
- %@AB@%; EXIT CX = length of string unused%@AE@%%@NL@%
- %@AB@%; DI = unused portion of string%@AE@%%@NL@%
- %@AB@%; Z set%@AE@%%@NL@%
- %@AB@%; match found%@AE@%%@NL@%
- %@AB@%; Z clear%@AE@%%@NL@%
- %@AB@%; no match%@AE@%%@NL@%
- %@AB@%; USES CX, DI, SI, Flags%@AE@%%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- cmpsen proc near%@NL@%
- repe cmpsb%@NL@%
- ret%@NL@%
- cmpsen endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; cmpinsen - case-insensitive comparison%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; ENTRY DS:SI = buffer%@AE@%%@NL@%
- %@AB@%; ES:DI = string%@AE@%%@NL@%
- %@AB@%; CX = length of string%@AE@%%@NL@%
- %@AB@%; EXIT CX = length of string unused%@AE@%%@NL@%
- %@AB@%; DI = unused portion of string%@AE@%%@NL@%
- %@AB@%; Z set%@AE@%%@NL@%
- %@AB@%; match found%@AE@%%@NL@%
- %@AB@%; Z clear%@AE@%%@NL@%
- %@AB@%; no match%@AE@%%@NL@%
- %@AB@%; USES AX, CX, DI, SI, Flags%@AE@%%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- cmpinsen proc near%@NL@%
- cmpi0: lodsb %@AB@%; Byte in AL, SI = SI + 1%@AE@%%@NL@%
- mov ah,[di] %@AB@%; Byte in AH, DI = DI + 1%@AE@%%@NL@%
- inc di%@NL@%
- or ax,2020h %@AB@%; Fold bytes onto lower case%@AE@%%@NL@%
- cmp al,ah %@AB@%; Compare bytes%@AE@%%@NL@%
- loope cmpi0 %@AB@%; Loop while same%@AE@%%@NL@%
- ret%@NL@%
- cmpinsen endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; void matchstrings(s1,s2,len,nmatched,leg)%@AE@%%@NL@%
- %@AB@%; char *s1; /* First string */%@AE@%%@NL@%
- %@AB@%; char *s2; /* Second string */%@AE@%%@NL@%
- %@AB@%; int len; /* Length */%@AE@%%@NL@%
- %@AB@%; int *nmatched; /* Number of bytes matched */%@AE@%%@NL@%
- %@AB@%; int *leg; /* Less than, equal, greater than */%@AE@%%@NL@%
- %@NL@%
- cm_s1 equ word ptr [bp+retlen+2]%@NL@%
- cm_s2 equ word ptr [bp+retlen+4]%@NL@%
- cm_len equ word ptr [bp+retlen+6]%@NL@%
- cm_nmatched equ word ptr [bp+retlen+8]%@NL@%
- cm_leg equ word ptr [bp+retlen+10]%@NL@%
- %@NL@%
- EVEN%@NL@%
- %@NL@%
- public _matchstrings%@NL@%
- _matchstrings proc near%@NL@%
- ASSUME DS:DGROUP, ES:NOTHING, SS:DGROUP%@NL@%
- %@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- push di%@NL@%
- push si%@NL@%
- push ds%@NL@%
- pop es%@NL@%
- ASSUME ES:DGROUP%@NL@%
- mov di,cm_s2%@NL@%
- mov si,cm_s1%@NL@%
- mov cx,cm_len%@NL@%
- cmp _casesen,0%@NL@%
- je cm0%@NL@%
- call cmpsen%@NL@%
- jmp short cm1%@NL@%
- cm0: call cmpinsen%@NL@%
- cm1: mov bx,cm_leg%@NL@%
- mov word ptr [bx],0 %@AB@%; Assume equal%@AE@%%@NL@%
- jz cm2 %@AB@%; yes, skip ahead%@AE@%%@NL@%
- mov word ptr [bx],1 %@AB@%; Assume greater than%@AE@%%@NL@%
- jg cm1a %@AB@%; yes, skip ahead%@AE@%%@NL@%
- mov word ptr [bx],-1 %@AB@%; Less than%@AE@%%@NL@%
- cm1a: dec si%@NL@%
- cm2: sub si,cm_s1%@NL@%
- mov bx,cm_nmatched%@NL@%
- mov [bx],si%@NL@%
- pop si%@NL@%
- pop di%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- %@NL@%
- _matchstrings endp%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%; int strcmp(s1,s2)%@AE@%%@NL@%
- %@AB@%; char *s1; /* First string */%@AE@%%@NL@%
- %@AB@%; char *s2; /* Second string */%@AE@%%@NL@%
- %@NL@%
- public _strcmp%@NL@%
- _strcmp proc near%@NL@%
- push bp%@NL@%
- mov bp,sp%@NL@%
- push di%@NL@%
- push si%@NL@%
- push ds%@NL@%
- pop es%@NL@%
- mov si,[bp+4] %@AB@%; DS:SI = s1%@AE@%%@NL@%
- mov di,[bp+6] %@AB@%; ES:DI = s2%@AE@%%@NL@%
- sc0: lodsb %@AB@%; AL = *s1++%@AE@%%@NL@%
- scasb %@AB@%; AL - *s2++%@AE@%%@NL@%
- jne sc1 %@AB@%; branch if no match%@AE@%%@NL@%
- or al,al %@AB@%; End of s1?%@AE@%%@NL@%
- jne sc0 %@AB@%; no, loop%@AE@%%@NL@%
- cbw %@AB@%; AX = 0%@AE@%%@NL@%
- jmp short sc2 %@AB@%; Exit%@AE@%%@NL@%
- sc1: mov ax,1 %@AB@%; Assume s1 > s2%@AE@%%@NL@%
- jg sc2 %@AB@%; yes, branch%@AE@%%@NL@%
- neg ax %@AB@%; s1 < s2%@AE@%%@NL@%
- sc2: pop si%@NL@%
- pop di%@NL@%
- pop bp%@NL@%
- ret%@NL@%
- _strcmp endp%@NL@%
- %@NL@%
- %@NL@%
- public _bpt%@NL@%
- _bpt proc near%@NL@%
- int 3%@NL@%
- ret%@NL@%
- _bpt endp%@NL@%
- %@NL@%
- _text ends%@NL@%
- %@NL@%
- _data segment word public 'data'%@NL@%
- _data ends%@NL@%
- %@NL@%
- end%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DATA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\OPENDLG\DATA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* DATA.C -- This file contains per process global variables%@NL@%
- %@AB@%* Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NO_DOS %@NL@%
- %@AI@%#define %@AE@%NO_GPI %@NL@%
- %@AI@%#include %@AE@%"tool.h" %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% This library uses a NON SHARED DATA selector. This means each%@NL@%
- %@AB@% process using the library gets its own selector, and also that%@NL@%
- %@AB@% values cannot be shared and must be recreated for each process.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- HMODULE vhModule; %@AB@%/* Library module handle */%@AE@%%@NL@%
- HHEAP vhheap; %@AB@%/* Library heap */%@AE@%%@NL@%
- %@NL@%
- PSTR vrgsz[CSTRINGS]; %@AB@%/* Array of pointer to our strings (indexed%@NL@%
- %@AB@% by IDS_... */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DCALC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CALC\DCALC\DCALC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: dcalc.c - Dialog form of the Calc application%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* OS/2 Presentation Manager version of Calc, ported from Windows version%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_DEV %@NL@%
- %@AI@%#define %@AE@%INCL_DOSPROCESS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSSEMAPHORES %@NL@%
- %@AI@%#define %@AE@%INCL_DOSNLS %@NL@%
- %@AI@%#define %@AE@%INCL_ERRORS %@NL@%
- %@AI@%#define %@AE@%INCL_WINBUTTONS %@NL@%
- %@AI@%#define %@AE@%INCL_WINCLIPBOARD %@NL@%
- %@AI@%#define %@AE@%INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WINSWITCHLIST %@NL@%
- %@AI@%#define %@AE@%INCL_WINTRACKRECT %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%"dcalc.h" %@NL@%
- %@NL@%
- %@AB@%/************* GLOBAL VARIABLES */%@AE@%%@NL@%
- %@NL@%
- char chLastKey, currkey;%@NL@%
- char szCalcClass[] = "Calculator";%@NL@%
- char szTitle[30];%@NL@%
- char szreg1[20], szreg2[20], szmem[20], szregx[20];%@NL@%
- %@AB@%/* hope 20 is enough for kanji error string */%@AE@%%@NL@%
- char szErrorString[20], szPlusMinus[2];%@NL@%
- short charwidth, charheight;%@NL@%
- int aspectx, aspecty, nchszstr;%@NL@%
- extern BOOL fError = FALSE;%@NL@%
- BOOL fValueInMemory = FALSE;%@NL@%
- BOOL fMDown = FALSE;%@NL@%
- UCHAR mScan = 0;%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TOLOWER(x) ( (((x) >= 'A') && ((x) <= 'Z')) ? (x)|0x20 : (x)) %@NL@%
- %@AI@%#define %@AE@%WIDTHCONST 28 %@NL@%
- %@AI@%#define %@AE@%CXCHARS 37 %@NL@%
- %@AI@%#define %@AE@%CYCHARS 13 %@NL@%
- %@NL@%
- HAB hab;%@NL@%
- HDC hdcLocal; %@AB@%/* Local used for button bitmap */%@AE@%%@NL@%
- HPS hpsLocal;%@NL@%
- HDC hdcSqr; %@AB@%/* Sqr used for square-root bitmap */%@AE@%%@NL@%
- HPS hpsSqr;%@NL@%
- HBITMAP hbmLocal, hbmSqr;%@NL@%
- HMQ hmqCalc = NULL;%@NL@%
- %@NL@%
- HWND hwndCalc = NULL,%@NL@%
- hwndMenu = NULL;%@NL@%
- %@NL@%
- HPOINTER hptrFinger = NULL,%@NL@%
- hptrIcon = NULL;%@NL@%
- %@NL@%
- DEVOPENSTRUC dop = %@AB@%/* used by DevOpenDC */%@AE@%%@NL@%
- {%@NL@%
- NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL%@NL@%
- };%@NL@%
- %@NL@%
- static char bButtonValues[] = %@AB@%/* Button values */%@AE@%%@NL@%
- {%@NL@%
- 0xBC, 0xBB, 0xBA, 0xB9, '0', '1', '2', '3', '4',%@NL@%
- '5', '6', '7', '8', '9', '.', '/', '*', '-',%@NL@%
- '+', 'q', '%', 'c', '=', 0xB1, NULL%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/************* PROCEDURE DECLARATIONS */%@AE@%%@NL@%
- %@NL@%
- MPARAM EXPENTRY AboutDlgProc(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- BOOL CalcInit(VOID);%@NL@%
- VOID CalcPaint( HWND, HPS);%@NL@%
- MRESULT EXPENTRY fnDlgCalc(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- VOID cdecl main(VOID);%@NL@%
- VOID DataXCopy( VOID);%@NL@%
- VOID DataXPaste( VOID);%@NL@%
- VOID DrawNumbers( HPS);%@NL@%
- VOID Evaluate(BYTE);%@NL@%
- VOID InitCalc( VOID);%@NL@%
- BOOL InterpretChar( CHAR);%@NL@%
- VOID ProcessKey(HWND, WPOINT *);%@NL@%
- char Translate(WPOINT *);%@NL@%
- VOID UpdateDisplay( VOID);%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/********************************************************************%@NL@%
- %@AB@% Write the appropriate number or error string to the display area%@NL@%
- %@AB@% and mark memory-in-use if appropriate.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- BYTE aszDisplayBuff[20];%@NL@%
- %@NL@%
- VOID UpdateDisplay()%@NL@%
- {%@NL@%
- strcpy(aszDisplayBuff, fError? "Error" :szreg1);%@NL@%
- strcat(aszDisplayBuff, fValueInMemory? " M" : " ");%@NL@%
- %@NL@%
- WinSetDlgItemText(hwndCalc, TXT_RESULT_DISPLAY, aszDisplayBuff);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/**********************************************************************%@NL@%
- %@AB@% Display helpful info%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- MPARAM EXPENTRY AboutDlgProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- if (msg == WM_COMMAND)%@NL@%
- {%@NL@%
- WinDismissDlg(hwnd, TRUE);%@NL@%
- return(MPFROMSHORT(TRUE));%@NL@%
- }%@NL@%
- else return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/**********************************************************************%@NL@%
- %@AB@% General initialization%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- BOOL CalcInit()%@NL@%
- {%@NL@%
- hab = WinInitialize(0);%@NL@%
- %@NL@%
- hmqCalc = WinCreateMsgQueue( hab, 0);%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/**********************************************************************%@NL@%
- %@AB@% main procedure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- VOID cdecl main()%@NL@%
- {%@NL@%
- QMSG qmsg;%@NL@%
- %@NL@%
- if (!CalcInit()) { %@AB@%/* general initialization */%@AE@%%@NL@%
- WinAlarm(HWND_DESKTOP, 0xffff);%@NL@%
- goto exit;%@NL@%
- }%@NL@%
- %@NL@%
- WinLoadDlg(HWND_DESKTOP, HWND_DESKTOP, fnDlgCalc, NULL, CALCDLG, NULL);%@NL@%
- %@NL@%
- if (hwndCalc)%@NL@%
- while (WinGetMsg( hab, (PQMSG)&qmsg, NULL, 0, 0))%@NL@%
- WinDispatchMsg( hab, (PQMSG)&qmsg);%@NL@%
- %@NL@%
- exit: %@AB@%/* clean up */%@AE@%%@NL@%
- %@NL@%
- if (hwndMenu) WinDestroyWindow(hwndMenu);%@NL@%
- %@NL@%
- WinDestroyMsgQueue(hmqCalc);%@NL@%
- WinTerminate(hab);%@NL@%
- %@NL@%
- DosExit(EXIT_PROCESS, 0); %@AB@%/* exit without error */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*************************************************************************%@NL@%
- %@AB@% Calc Dialog Window Procedure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- USHORT idProcess, idThread;%@NL@%
- SWCNTRL swc;%@NL@%
- HSWITCH hsw;%@NL@%
- USHORT usWidthCalc, usHeightCalc;%@NL@%
- %@NL@%
- MRESULT EXPENTRY fnDlgCalc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- RECTL rectl;%@NL@%
- BOOL fClip;%@NL@%
- USHORT fi, idCtrl;%@NL@%
- MRESULT mresult;%@NL@%
- USHORT afSWP;%@NL@%
- PSWP pswp;%@NL@%
- %@NL@%
- static BOOL fMinimized;%@NL@%
- %@NL@%
- %@NL@%
- switch (msg)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- %@NL@%
- %@AB@%/* Set up the global state assumed by the dialog.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndCalc = hwnd;%@NL@%
- hwndMenu = WinLoadMenu(hwnd, NULL, IDR_CALC);%@NL@%
- %@NL@%
- fMinimized = FALSE;%@NL@%
- %@NL@%
- hptrFinger = WinLoadPointer(HWND_DESKTOP, (HMODULE)NULL, IDP_FINGER);%@NL@%
- hptrIcon = WinLoadPointer(HWND_DESKTOP, (HMODULE)NULL, IDR_CALC);%@NL@%
- %@NL@%
- WinSetWindowULong(hwndCalc, QWL_STYLE,%@NL@%
- FS_ICON | WinQueryWindowULong(hwndCalc, QWL_STYLE)%@NL@%
- );%@NL@%
- %@NL@%
- WinSendMsg(hwndCalc, WM_SETICON, (MPARAM) hptrIcon, 0L);%@NL@%
- WinSendMsg(hwndCalc, WM_UPDATEFRAME, (MPARAM) 0L, 0L);%@NL@%
- %@NL@%
- WinQueryWindowRect(hwndCalc, &rectl);%@NL@%
- usWidthCalc= (SHORT) (rectl.xRight - rectl.xLeft);%@NL@%
- usHeightCalc= (SHORT) (rectl.yTop - rectl.yBottom);%@NL@%
- %@NL@%
- WinQueryWindowProcess(hwndCalc, &idProcess, &idThread);%@NL@%
- %@NL@%
- WinLoadString(NULL, NULL, 1, 30, (PSZ)szTitle);%@NL@%
- WinLoadString(NULL, NULL, 2, 20, (PSZ)szErrorString);%@NL@%
- WinLoadString(NULL, NULL, 3, 2, (PSZ)szPlusMinus);%@NL@%
- %@NL@%
- strcpy(swc.szSwtitle, szTitle);%@NL@%
- swc.hwnd = hwndCalc;%@NL@%
- swc.hwndIcon = hptrIcon;%@NL@%
- swc.hprog = (ULONG)NULL;%@NL@%
- swc.idProcess = idProcess;%@NL@%
- swc.idSession = (USHORT)0;%@NL@%
- swc.uchVisibility = SWL_VISIBLE;%@NL@%
- swc.fbJump = SWL_JUMPABLE;%@NL@%
- hsw = WinAddSwitchEntry((PSWCNTRL)&swc);%@NL@%
- %@NL@%
- InitCalc(); %@AB@%/* arithmetic initialization */%@AE@%%@NL@%
- %@NL@%
- WinSetActiveWindow(HWND_DESKTOP, hwndCalc);%@NL@%
- %@NL@%
- WinSetFocus(HWND_DESKTOP, hwndCalc);%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MINMAXFRAME:%@NL@%
- %@NL@%
- pswp= PVOIDFROMMP(mp1);%@NL@%
- %@NL@%
- if (pswp->fs & SWP_MINIMIZE) fMinimized= TRUE;%@NL@%
- else%@NL@%
- if (pswp->fs & SWP_RESTORE) fMinimized= FALSE;%@NL@%
- %@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- %@NL@%
- WinDestroyPointer(hptrIcon ); hptrIcon = NULL;%@NL@%
- WinDestroyPointer(hptrFinger); hptrFinger= NULL;%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- case WM_INITMENU:%@NL@%
- %@NL@%
- fClip = FALSE;%@NL@%
- %@NL@%
- if (WinOpenClipbrd(NULL))%@NL@%
- {%@NL@%
- fClip = WinQueryClipbrdFmtInfo(NULL, CF_TEXT, (USHORT FAR *)&fi);%@NL@%
- WinCloseClipbrd(NULL);%@NL@%
- }%@NL@%
- %@NL@%
- WinSendMsg((HWND)mp2, MM_SETITEMATTR,%@NL@%
- (MPARAM) MAKELONG(CMD_PASTE, TRUE),%@NL@%
- (MPARAM) MAKELONG(MIA_DISABLED, fClip ? 0 : MIA_DISABLED));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ADJUSTWINDOWPOS:%@NL@%
- %@NL@%
- mresult= WinDefDlgProc(hwnd, msg, mp1, mp2);%@NL@%
- %@NL@%
- if (fMinimized) return(mresult);%@NL@%
- %@NL@%
- afSWP= (pswp= (PSWP) mp1)->fs;%@NL@%
- %@NL@%
- if ( afSWP & (SWP_SIZE | SWP_MAXIMIZE)%@NL@%
- && !(afSWP & SWP_MINIMIZE)%@NL@%
- )%@NL@%
- {%@NL@%
- pswp->y += pswp->cy - usHeightCalc;%@NL@%
- pswp->cx = usWidthCalc;%@NL@%
- pswp->cy = usHeightCalc;%@NL@%
- }%@NL@%
- %@NL@%
- return(mresult);%@NL@%
- %@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- %@NL@%
- fError = FALSE;%@NL@%
- %@NL@%
- idCtrl= SHORT1FROMMP(mp1);%@NL@%
- %@NL@%
- if ( SHORT1FROMMP(mp2) == BN_CLICKED%@NL@%
- && idCtrl >= BUTTON_MC%@NL@%
- && idCtrl <= BUTTON_CHANGE_SIGN%@NL@%
- )%@NL@%
- {%@NL@%
- Evaluate(bButtonValues[idCtrl-BUTTON_MC]);%@NL@%
- UpdateDisplay();%@NL@%
- }%@NL@%
- else%@NL@%
- switch(idCtrl)%@NL@%
- {%@NL@%
- case CMD_COPY:%@NL@%
- DataXCopy(); %@AB@%/* copy to clipboard */%@AE@%%@NL@%
- break;%@NL@%
- case CMD_PASTE:%@NL@%
- DataXPaste(); %@AB@%/* paste from clipboard */%@AE@%%@NL@%
- break;%@NL@%
- case CMD_EXIT:%@NL@%
- WinPostMsg(hwndCalc, WM_QUIT, 0L, 0L);%@NL@%
- break;%@NL@%
- case CMD_ABOUT:%@NL@%
- WinDlgBox(HWND_DESKTOP, hwndCalc, (PFNWP)AboutDlgProc, NULL,%@NL@%
- 1, (PSZ)NULL);%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CLOSE:%@NL@%
- WinPostMsg(hwndCalc, WM_QUIT, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CONTROLPOINTER:%@NL@%
- if (!fMinimized) return(hptrFinger);%@NL@%
- else return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- %@NL@%
- case WM_MOUSEMOVE:%@NL@%
- if (!fMinimized) WinSetPointer(HWND_DESKTOP, hptrFinger);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1DOWN:%@NL@%
- %@NL@%
- return(WinDefDlgProc(hwnd, WM_TRACKFRAME, (MPARAM) TF_MOVE, mp2));%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CHAR:%@NL@%
- %@NL@%
- fError = FALSE;%@NL@%
- if (SHORT1FROMMP(mp1) & KC_KEYUP)%@NL@%
- {%@NL@%
- if (CHAR4FROMMP(mp1) == mScan)%@NL@%
- fMDown = FALSE; %@AB@%/* 'm' key went up */%@AE@%%@NL@%
- }%@NL@%
- else %@NL@%
- {%@NL@%
- if (SHORT1FROMMP(mp1) & KC_CHAR)%@NL@%
- {%@NL@%
- if (InterpretChar((UCHAR)(ULONG)(mp2)))%@NL@%
- { %@NL@%
- UpdateDisplay();%@NL@%
- }%@NL@%
- else %@NL@%
- {%@NL@%
- if (((UCHAR)(ULONG)(mp2)== 'm') || ((UCHAR)(ULONG)(mp2)== 'M'))%@NL@%
- {%@NL@%
- mScan = CHAR4FROMMP(mp1); %@AB@%/* save 'm' key scan code */%@AE@%%@NL@%
- fMDown = TRUE; %@AB@%/* 'm' key went down */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- %@NL@%
- case WM_ERASEBACKGROUND:%@NL@%
- if (WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)%@NL@%
- WinValidateRect(hwnd, (PRECTL) mp2, TRUE);%@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_SETFOCUS:%@NL@%
- if ((HWNDFROMMP(mp1)==hwndCalc) && !mp2);%@NL@%
- fMDown = FALSE; %@AB@%/* since we are losing focus */%@AE@%%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*************************************************************************%@NL@%
- %@AB@% translate & interpret keys (ie. locate in logical keyboard)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- BOOL InterpretChar(ch)%@NL@%
- register CHAR ch;%@NL@%
- {%@NL@%
- BOOL fDone;%@NL@%
- CHAR *chstep;%@NL@%
- %@NL@%
- fDone = FALSE;%@NL@%
- chstep = bButtonValues;%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case 'n':%@NL@%
- ch = szPlusMinus[0];%@NL@%
- break;%@NL@%
- case 27: %@AB@%/* xlate Escape into 'c' */%@AE@%%@NL@%
- ch = 'c';%@NL@%
- break;%@NL@%
- case '\r': %@AB@%/* xlate Enter into '=' */%@AE@%%@NL@%
- ch = '=';%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if (fMDown) %@AB@%/* Do memory keys */%@AE@%%@NL@%
- {%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case 'c':%@NL@%
- case 'C':%@NL@%
- ch = '\274';%@NL@%
- break;%@NL@%
- case 'r':%@NL@%
- case 'R':%@NL@%
- ch = '\273';%@NL@%
- break;%@NL@%
- case '+':%@NL@%
- ch = '\272';%@NL@%
- break;%@NL@%
- case '-':%@NL@%
- ch = '\271';%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- while (!fDone && *chstep)%@NL@%
- {%@NL@%
- if (*chstep++ == ch)%@NL@%
- fDone = TRUE; %@AB@%/* char found in logical keyboard */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- if (fDone)%@NL@%
- {%@NL@%
- Evaluate(ch);%@NL@%
- }%@NL@%
- %@NL@%
- return (fDone);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DDEML.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DDEML.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DDE.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DDE Manager main module - Contains all exported Dde functions.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 12/12/88 Sanford Staab%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%* 4/5/89 sanfords removed need for hwndFrame registration parameter%@NL@%
- %@AB@%* 6/5/90 sanfords Fixed callbacks so they are blocked during%@NL@%
- %@AB@%* timeouts.%@NL@%
- %@AB@%* Fixed SendDDEInit allocation bug.%@NL@%
- %@AB@%* Added hApp to ConvInfo structure.%@NL@%
- %@AB@%* Allowed QueryConvInfo() to work on server hConvs.%@NL@%
- %@AB@%* Added FindFrame() to provide an hApp for Server%@NL@%
- %@AB@%* hConvs.%@NL@%
- %@AB@%* 6/14/90 sanfords Altered hDatas so they will work when shared%@NL@%
- %@AB@%* between threads of the same process. Also%@NL@%
- %@AB@%* added optimization to only have the hsz%@NL@%
- %@AB@%* in the hData for local conversations.%@NL@%
- %@AB@%* 6/21/90 sanfords Renamed APIs to Dde....%@NL@%
- %@AB@%* Finished DdeAppNameServer() implementation.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@AI@%#include %@AE@%"version.h" %@NL@%
- %@NL@%
- %@AB@%/****** Globals *******/%@AE@%%@NL@%
- %@NL@%
- HMODULE hmodDmg = 0; %@AB@%/* initialized by LoadProc on DLL initialization */%@AE@%%@NL@%
- PFNWP lpfnFrameWndProc = 0; %@AB@%/* system Frame window procedure */%@AE@%%@NL@%
- %@NL@%
- HHEAP hheapDmg = 0; %@AB@%/* main DLL heap */%@AE@%%@NL@%
- %@NL@%
- PHATOMTBL aAtbls;%@NL@%
- USHORT cAtbls = 0;%@NL@%
- USHORT iAtblCurrent = 0;%@NL@%
- USHORT cMonitor = 0;%@NL@%
- DOSFSRSEM FSRSemDmg; %@AB@%/* used to protect globals */%@AE@%%@NL@%
- USHORT cAtoms = 0; %@AB@%/* for debugging! */%@AE@%%@NL@%
- %@NL@%
- PAPPINFO pAppInfoList = NULL; %@AB@%/* registered thread data list */%@AE@%%@NL@%
- USHORT usHugeShift; %@AB@%/* for huge segment support */%@AE@%%@NL@%
- USHORT usHugeAdd; %@AB@%/* for huge segment support */%@AE@%%@NL@%
- COUNTRYCODE syscc;%@NL@%
- %@NL@%
- BOOL fInSubset(PCQDATA pcqd, ULONG afCmd);%@NL@%
- %@NL@%
- %@AB@%/* PUBDOC START *\%@NL@%
- %@AB@%DLL overview:%@NL@%
- %@AB@%%@NL@%
- %@AB@%This DLL supports standard DDE communication on behalf of its client%@NL@%
- %@AB@%applications. It is compatable with most existing DDE programs. The%@NL@%
- %@AB@%API interface features object-like abstractions that allow its implementation%@NL@%
- %@AB@%on and across a variety of platforms.%@NL@%
- %@AB@%%@NL@%
- %@AB@%Main features:%@NL@%
- %@AB@%%@NL@%
- %@AB@% * HSZ manager: Allows more efficient handling of numerous character%@NL@%
- %@AB@% strings without the limitations of the atom manager.%@NL@%
- %@AB@% %@NL@%
- %@AB@% * HDATA manager: Data container objects allow easy filling, accessing%@NL@%
- %@AB@% and reuse of huge amounts of data and allow a%@NL@%
- %@AB@% server to efficiently support several clients.%@NL@%
- %@AB@% %@NL@%
- %@AB@% * Controled initiates: Supports client to multi-server initiates and%@NL@%
- %@AB@% allows a client application to pick and choose which%@NL@%
- %@AB@% conversations to keep.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * Debugging support: Allows monitoring applications to be easily written%@NL@%
- %@AB@% and provides readable error messages. %@NL@%
- %@AB@%%@NL@%
- %@AB@% * Huge Segment support: Exports a useful huge segment copy function and%@NL@%
- %@AB@% properly handles huge data transfers.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * Synchronous communication: Clients may use a very simple form of%@NL@%
- %@AB@% transaction processing that requires little application%@NL@%
- %@AB@% support.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * Asynchronous communication: Clients may opt to use queued transfers%@NL@%
- %@AB@% freeing them to do other tasks in parellel with DDE.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * Callback control: Applications may selectively suspend DLL callbacks%@NL@%
- %@AB@% to themselves when in time critical sections. Selected%@NL@%
- %@AB@% conversations can be blocked while being serviced so%@NL@%
- %@AB@% others can be processed by the same thread.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * registration notification: All applications using this DLL are notified%@NL@%
- %@AB@% whenever any other application registers or unregisters%@NL@%
- %@AB@% itself with this DLL. This enables nameserver support%@NL@%
- %@AB@% for DDE.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * multiple DDE entity support: An application can register itself with%@NL@%
- %@AB@% any number of application names and can change what%@NL@%
- %@AB@% application names it responds to at any time. Each%@NL@%
- %@AB@% registered thread is a seperate DDE entity.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * advise loop control: Advise loops are tracked by the DLL, however%@NL@%
- %@AB@% server applications have complete control over%@NL@%
- %@AB@% advise loop initiation.%@NL@%
- %@AB@%%@NL@%
- %@AB@% * network agent support: Special agent applications can register with this%@NL@%
- %@AB@% DLL to represent multiple applications on other machines%@NL@%
- %@AB@% or platforms.%@NL@%
- %@AB@% %@NL@%
- %@AB@%API specifications:%@NL@%
- %@AB@%%@NL@%
- %@AB@%Callback function:%@NL@%
- %@AB@% %@NL@%
- %@AB@%EXPENTRY Callback(%@NL@%
- %@AB@%HCONV hConv, // holds server conversation handle in most cases%@NL@%
- %@AB@%HSZ hszTopic, // holds topic hsz for transaction%@NL@%
- %@AB@%HSZ hszItem, // holds item or application hsz for transaction%@NL@%
- %@AB@%USHORT usFormat, // holds data format when applicable%@NL@%
- %@AB@%USHORT usType, // holds transaction type code%@NL@%
- %@AB@%HDMGDATA hDmgData); // holds incomming data in most cases%@NL@%
- %@AB@%%@NL@%
- %@AB@%This is the definition of the data call-back function that an%@NL@%
- %@AB@%application must export so that the DDE can initiate interaction%@NL@%
- %@AB@%with the application when necessary. This function is refered to in%@NL@%
- %@AB@%the DdeInitialize() call.%@NL@%
- %@AB@%%@NL@%
- %@AB@%The application callback function is very much like a PM window %@NL@%
- %@AB@%procedure for DDE. The usType specifies the type of transaction being %@NL@%
- %@AB@%done. By ANDing this parameter with XCLASS_MASK and comparing the %@NL@%
- %@AB@%result with the XCLASS_ constants, the transaction return type %@NL@%
- %@AB@%expected can be classified.%@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_ constants also may contain the XTYPF_NOBLOCK flag. The presence%@NL@%
- %@AB@%of this flag indicates that the CBR_BLOCK return value from the callback%@NL@%
- %@AB@%will not be honored by the DDE. (see DdeEnableCallback() for more%@NL@%
- %@AB@%information on this concept.)%@NL@%
- %@AB@%%@NL@%
- %@AB@%The various transactions are explained below:%@NL@%
- %@AB@%%@NL@%
- %@AB@%%@NL@%
- %@AB@%-----XCLASS_NOTIFICATION class:%@NL@%
- %@AB@% These are strictly notification messages to an application. The return%@NL@%
- %@AB@% value is ignored except in the case of CBR_BLOCK. (if the notification%@NL@%
- %@AB@% is blockable)%@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_RTNPKT%@NL@%
- %@AB@%%@NL@%
- %@AB@% This transaction is sent to agent applications. hDmgData contains a %@NL@%
- %@AB@% packet to send to the agent who's handle is in the hszItem parameter. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_REGISTER%@NL@%
- %@AB@%%@NL@%
- %@AB@% Another server name has just been registered with the DLL application %@NL@%
- %@AB@% name server. hszItem is set to the application name being %@NL@%
- %@AB@% registered. If this is NULL, an application has registered itself as %@NL@%
- %@AB@% WILD. hDmgData is set to the application handle that registered.%@NL@%
- %@AB@% This is not blockable by CBR_BLOCK because no hConv is %@NL@%
- %@AB@% associated with it. Only if all callbacks are disabled is this %@NL@%
- %@AB@% transaction blocked.%@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_UNREGISTER%@NL@%
- %@AB@%%@NL@%
- %@AB@% Another server application has just unregistered a name with this %@NL@%
- %@AB@% DLL. hszItem is set to the application name being unregistered.%@NL@%
- %@AB@% hDmgData is set to the app handle of the unregistering application.%@NL@%
- %@AB@% This is not blockable by CBR_BLOCK because no hConv is associated %@NL@%
- %@AB@% with it. Only if all callbacks are disabled is this transaction %@NL@%
- %@AB@% blocked.%@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_INIT_CONFIRM%@NL@%
- %@AB@%%@NL@%
- %@AB@% Sent to let a server know that a conversation on application hszItem %@NL@%
- %@AB@% and Topic hszTopic has been established on hConv. hConv uniquely %@NL@%
- %@AB@% identifies this conversation from the server's prospective. This %@NL@%
- %@AB@% call cannot be blocked because it is part of the DDE initiate %@NL@%
- %@AB@% sequence. This callback is generated by the results of XTYP_INIT and %@NL@%
- %@AB@% XTYP_WILDINIT callbacks. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_TERM%@NL@%
- %@AB@%%@NL@%
- %@AB@% This is a notification telling a server application that a %@NL@%
- %@AB@% conversation has been terminated. hConv is set to identify which %@NL@%
- %@AB@% conversation was terminated. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_ADVSTOP%@NL@%
- %@AB@%%@NL@%
- %@AB@% This notifies a server that an advise loop is stopping. hszTopic, %@NL@%
- %@AB@% hszItem, and usFormat identify the advise loop within hConv. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_XFERCOMPLETE%@NL@%
- %@AB@%%@NL@%
- %@AB@% This notifictaion is sent to a client when an asynchronous data %@NL@%
- %@AB@% DdeClientXfer() transaction is completed. hDmgData is the client %@NL@%
- %@AB@% queue ID of the completed transaction. hConv is the client %@NL@%
- %@AB@% conversation handle. %@NL@%
- %@AB@% %@NL@%
- %@AB@%XTYP_MONITOR%@NL@%
- %@AB@%%@NL@%
- %@AB@% This notifies an app registered as DMGCMD_MONITOR of DDE data that is %@NL@%
- %@AB@% being transmitted. hDmgData contains a text string representing the %@NL@%
- %@AB@% transaction suitable for printing on a terminal, file, or window. %@NL@%
- %@AB@% Note that this monitors ALL DDE communication and may be extensive. %@NL@%
- %@AB@% This call cannot be delayed by disabled callbacks. This transaction %@NL@%
- %@AB@% is not blockable. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_ACK%@NL@%
- %@AB@%%@NL@%
- %@AB@% This notifies a server that it has received an acknowledge from data %@NL@%
- %@AB@% it has sent a client. The hConv, topic, item, and format are set %@NL@%
- %@AB@% apropriately. LOUSHORT(hDmgData) will contain the dde flags from the %@NL@%
- %@AB@% ack. %@NL@%
- %@AB@%%@NL@%
- %@AB@%-----XCLASS_DATA class:%@NL@%
- %@AB@%%@NL@%
- %@AB@% Transactions in this class are expected to return an HDMGDATA or 0 as %@NL@%
- %@AB@% apropriate. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_PKT%@NL@%
- %@AB@%%@NL@%
- %@AB@% This transaction is sent to agent applications. hDmgData contains a %@NL@%
- %@AB@% packet to send. hszItem contains the agent handle to send the data %@NL@%
- %@AB@% to. hConv is set to the associated conversation handle. The return %@NL@%
- %@AB@% packet received from the partner agent should be returned. This %@NL@%
- %@AB@% call is blockable.%@NL@%
- %@AB@%%@NL@%
- %@AB@% If blocked, the conversation will be unblocked and processed by %@NL@%
- %@AB@% DdeProcessPkt() when the return packet is received. It is a good %@NL@%
- %@AB@% idea for the agent to remember the hConv parameter in case the return %@NL@%
- %@AB@% packet does not arrive within a reasonable amount of time via %@NL@%
- %@AB@% XTYP_RTNPKT. If an agent determines that it wishes to kill a %@NL@%
- %@AB@% conversation, it should call DdeDisconnect(). %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_REQUEST%@NL@%
- %@AB@%XTYP_ADVREQ%@NL@%
- %@AB@%%@NL@%
- %@AB@% Data is being requested from a server application. The function %@NL@%
- %@AB@% should create a hDmgData using the DdePutData() function and %@NL@%
- %@AB@% return it. XTYP_ADVREQ origonates from a DdePostAdvise() call %@NL@%
- %@AB@% while XTYP_REQUEST origonates from a client data request. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_WILDINIT%@NL@%
- %@AB@%%@NL@%
- %@AB@% This is asking a DDE server permission to make multiple connections %@NL@%
- %@AB@% with a specific client.%@NL@%
- %@AB@%%@NL@%
- %@AB@% hszItem may be the application name the client is requesting or it %@NL@%
- %@AB@% may be NULL indicating a wild application name. hszTopic may be the %@NL@%
- %@AB@% Topic requested or NULL indicating a wild topic. If not NULL, %@NL@%
- %@AB@% hDmgData contains a CONVCONTEXT structure. All other parameters are %@NL@%
- %@AB@% 0 or NULL.%@NL@%
- %@AB@%%@NL@%
- %@AB@% For local initiates, (initiates with the server application itself) %@NL@%
- %@AB@% The server should return a 0 terminated (ie hszApp = hszTopic = 0) %@NL@%
- %@AB@% array of HSZPAIR structures using DdePutData() and %@NL@%
- %@AB@% DdeAddData(). Each hsz pair represents an app/topic the server %@NL@%
- %@AB@% wishes to support. Each created conversation will result in an %@NL@%
- %@AB@% XTYP_INIT_CONFIRM notification. If 0 is returned, no connections are %@NL@%
- %@AB@% made with the requesting client. This call is made even if callbacks %@NL@%
- %@AB@% are disabled due the the synchronous nature of DDE initiates. This %@NL@%
- %@AB@% callback cannot be blocked by returning CBR_BLOCK. %@NL@%
- %@AB@%%@NL@%
- %@AB@% Agent applications may also process this transaction as a %@NL@%
- %@AB@% representative initiate. The agent is expected to package this %@NL@%
- %@AB@% transaction using DdeCreateInitPkt() and broadcast it to all %@NL@%
- %@AB@% apropriate agents along its communication channel. It then must %@NL@%
- %@AB@% collect the return packets and for each packet and call %@NL@%
- %@AB@% DdeProcessPkt(). Representative initiates are synchronous in that %@NL@%
- %@AB@% the agent cannot return from this callback until all initiate return %@NL@%
- %@AB@% packets are returned. Representative initiates do NOT result in any %@NL@%
- %@AB@% XTYP_INIT_CONFIRM notifications to the agent. The agent is then free %@NL@%
- %@AB@% to process this transaction for local connections as described. %@NL@%
- %@AB@%%@NL@%
- %@AB@%-----XCLASS_BOOL class:%@NL@%
- %@AB@%%@NL@%
- %@AB@% Transactions in this class expect a BOOL return of TRUE or FALSE. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_INIT%@NL@%
- %@AB@%%@NL@%
- %@AB@% This is a query asking a DDE server permission to connect to a %@NL@%
- %@AB@% specific client. hszItem is set to the Application name. hszTopic %@NL@%
- %@AB@% is set to the topic name. hDmgData if not NULL, contains CONVCONTEXT %@NL@%
- %@AB@% data. All other parameters are 0 or NULL. A TRUE return value %@NL@%
- %@AB@% allows the Dde to start up a server on the app/topic specified. %@NL@%
- %@AB@% This will result in an XTYP_INIT_CONFIRM callback. This call is made %@NL@%
- %@AB@% even if callbacks are disabled due the the synchronous nature of DDE %@NL@%
- %@AB@% initiates. %@NL@%
- %@AB@% %@NL@%
- %@AB@% Agent applications may process this transaction as a representative %@NL@%
- %@AB@% transaction. The agent is expected to package this transaction using %@NL@%
- %@AB@% DdeCreateInitPkt() and broadcast it to all apropriate agents along %@NL@%
- %@AB@% its communication channel. It then must collect the return packets %@NL@%
- %@AB@% and for each packet call DdeProcessPkt(). This will NOT result in %@NL@%
- %@AB@% any XTYP_INIT_CONFIRM notifications to the agent. The agent is then %@NL@%
- %@AB@% free to process this transaction for local connections. %@NL@%
- %@AB@%%@NL@%
- %@AB@% A FALSE return implies no local initiate permissions are granted.%@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_ADVSTART%@NL@%
- %@AB@%%@NL@%
- %@AB@% This transaction requests permission to start a DDE advise loop with %@NL@%
- %@AB@% a server. The hszTopic, hszItem, and usFormat identify the advise %@NL@%
- %@AB@% loop. If FALSE is returned, the advise loop will not be started. %@NL@%
- %@AB@%%@NL@%
- %@AB@%-----XCLASS_FLAGS Class:%@NL@%
- %@AB@%%@NL@%
- %@AB@% Transactions in this class have hDmgData set. An application should %@NL@%
- %@AB@% use the DLL Data functions to extract the data from hDmgData. The %@NL@%
- %@AB@% return value should be the DDE fsStatus flags the app desires to %@NL@%
- %@AB@% return to the client application. If DDE_FACK is set, DDE_FBUSY and %@NL@%
- %@AB@% DDE_FNOTPROCESSED are ignored. %@NL@%
- %@AB@%%@NL@%
- %@AB@% The only flags the Dde expects to be returned are:%@NL@%
- %@AB@% DDE_FACK%@NL@%
- %@AB@% DDE_FBUSY%@NL@%
- %@AB@% DDE_FNOTPROCESSED%@NL@%
- %@AB@% any DDE_APPSTATUS bits%@NL@%
- %@AB@% %@NL@%
- %@AB@% All other bits will be stripped out by the Dde before sending an %@NL@%
- %@AB@% ack message. %@NL@%
- %@AB@%%@NL@%
- %@AB@% A 0 return is equivalent to DDE_NOTPROCESSED. %@NL@%
- %@AB@%%@NL@%
- %@AB@%XTYP_EXEC%@NL@%
- %@AB@%%@NL@%
- %@AB@% hDmgData contains an execute string from a client. hConv, hszTopic, %@NL@%
- %@AB@% hszItem are set. If the WM_DDE_EXECUTE message received had the same %@NL@%
- %@AB@% string for the itemname as for the data, hszItem will be 0L. This %@NL@%
- %@AB@% provides for EXCEL EXECUTE compatibility without requireing the %@NL@%
- %@AB@% creation of an HSZ for the data string. Applications are advised to %@NL@%
- %@AB@% ignore the hszItem parameter for execute transactions since newer DDE %@NL@%
- %@AB@% specifications ignore this value. %@NL@%
- %@AB@% %@NL@%
- %@AB@%XTYP_POKE%@NL@%
- %@AB@%%@NL@%
- %@AB@% Similar to XTYP_EXEC but hDmgData contains data poked to the server. %@NL@%
- %@AB@% %@NL@%
- %@AB@%XTYP_ADVDATA - advise data for a client!%@NL@%
- %@AB@%%@NL@%
- %@AB@% Note that XTYP_ADVDATA is for advise loop data intended for the %@NL@%
- %@AB@% CLIENT not the server. If the advise loop in progress is of the %@NL@%
- %@AB@% NODATA type, hDmgData will be 0. %@NL@%
- %@AB@%%@NL@%
- %@AB@%-----Agent Transfers:%@NL@%
- %@AB@%%@NL@%
- %@AB@% A DDE agent application is one which registers itself with the %@NL@%
- %@AB@% DMGCMD_AGENT flag. Agent applications represent any number of other %@NL@%
- %@AB@% applications across its communications channel. Agent applications %@NL@%
- %@AB@% are only allowed to communicate locally with other non-agent %@NL@%
- %@AB@% applications. This prevents communication loops from forming across %@NL@%
- %@AB@% communication channels. Any number of agents may register with the %@NL@%
- %@AB@% DLL but each agent should represent a different communication %@NL@%
- %@AB@% channel, one which is orthogonal to all other agents. It is the %@NL@%
- %@AB@% users responsability to only start up orthogonal agents. %@NL@%
- %@AB@%%@NL@%
- %@AB@% Agents are responsible for handling and updating any DDE nameservers %@NL@%
- %@AB@% associated with their communicaton channels. Since agent %@NL@%
- %@AB@% applications can converse directly with non-agent applications, they %@NL@%
- %@AB@% can set up advise loops on the SysTopic/Topics items of local %@NL@%
- %@AB@% applications to update the nameserver for the communication channel %@NL@%
- %@AB@% if they wish to support DDE topics. This may be impossible with some %@NL@%
- %@AB@% DDE applications which either do not support the SysTopic/Topics item %@NL@%
- %@AB@% or which have an unenumerable set of topics they support. For %@NL@%
- %@AB@% application name servers the DdeAppNameServer() function is %@NL@%
- %@AB@% provided to give agents a local application name server from which to %@NL@%
- %@AB@% draw on. %@NL@%
- %@AB@%%@NL@%
- %@AB@% In general, an agent administers two classes of conversations. One %@NL@%
- %@AB@% is direct conversations with itself and local non-agent applications. %@NL@%
- %@AB@% These transactions would be handled by the agent exactly like any %@NL@%
- %@AB@% non-agent application would handle them. %@NL@%
- %@AB@%%@NL@%
- %@AB@% The other class is representative conversations which the agent %@NL@%
- %@AB@% passes over its communication channel. In general, representative %@NL@%
- %@AB@% conversation callbacks to the agent are only XTYP_PKT or XTYP_RTNPKT %@NL@%
- %@AB@% type transactions or specially handled initiate transactions. %@NL@%
- %@AB@%%@NL@%
- %@AB@% Agent applications are responsible for providing a unique ULONG agent %@NL@%
- %@AB@% handle for every agent it is communicating with on its communication %@NL@%
- %@AB@% channel. The handle is provided by the agent whenever it calls %@NL@%
- %@AB@% DdeProcessPkt(). Agent handles need not be global to the channel %@NL@%
- %@AB@% since only the agent that created the handle will be expected to use %@NL@%
- %@AB@% it. Agent handles should not change over the life of a conversation.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Should it be necessary to allow agents to alter or convert packet %@NL@%
- %@AB@% data, the format of the packets can be documented later. %@NL@%
- %@AB@%%@NL@%
- %@AB@% To show how an agent would handle its callback function, the %@NL@%
- %@AB@% following pseudo code is offered as a model: %@NL@%
- %@AB@%%@NL@%
- %@AB@%ReceivePkt(pBits, cb, hAgentFrom) \\ gets called when a packet arrives %@NL@%
- %@AB@%{%@NL@%
- %@AB@% hPkt = DdePutData(pBits, cb, 0, 0, 0, 0);%@NL@%
- %@AB@% if (hDmgData = ProcessPkt(hPkt, hAgentFrom))%@NL@%
- %@AB@% PassPkt(hDmgData, hAgentFrom); \\ agent function to send pkt %@NL@%
- %@AB@%}%@NL@%
- %@AB@% %@NL@%
- %@AB@%AgentCallback(hConv, hszTopic, hszItem, usFormat, usType, hDmgData)%@NL@%
- %@AB@%{%@NL@%
- %@AB@% switch (usType) {%@NL@%
- %@AB@% case XTYP_INIT:%@NL@%
- %@AB@% case XTYP_WILDINIT:%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% \\ process representative initiates%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% QueryInterestedAgents(hszApp, hszTopic, pAgents);%@NL@%
- %@AB@% hDmgData = DdeCreateInitPkt(hszTopic, hszItem, hDmgData);%@NL@%
- %@AB@% BroadcastPkt(hDmgData, pAgents);%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% \\ agent blocks here till all are in or timeout.%@NL@%
- %@AB@% \\ Packets get sent to ReceivePkt()%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% CollectRtnPkts(pAgents); %@NL@%
- %@AB@% \\ %@NL@%
- %@AB@% \\ now agent does his own processing of local inits.%@NL@%
- %@AB@% \\ retval == 0 if not interested.%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% return(retval);%@NL@%
- %@AB@% break;%@NL@%
- %@AB@%%@NL@%
- %@AB@% case XTYP_RTNPKT:%@NL@%
- %@AB@% RemoveFromDeadCheckQ(hConv);%@NL@%
- %@AB@% PassPkt(hDmgData, hszItem); \\ hDmgData==Pkt, hszItem==hAgentTo %@NL@%
- %@AB@% return(0);%@NL@%
- %@AB@% break;%@NL@%
- %@AB@% %@NL@%
- %@AB@% case XTYP_PKT:%@NL@%
- %@AB@% if (FindIgnoreList(hConv) { \\ was this unblocked due to no rtn pkt? %@NL@%
- %@AB@% RemoveFromIgnoreList(hConv);%@NL@%
- %@AB@% return(0); \\ rtn pkt failure.%@NL@%
- %@AB@% }%@NL@%
- %@AB@% if (!PassPkt(hDmgData, hszItem)) \\ hDmgData==Pkt, hszItem==hAgentTo %@NL@%
- %@AB@% return(0); \\ packet send failure. %@NL@%
- %@AB@% AddToDeadCheckQ(hConv, timenow());%@NL@%
- %@AB@% return(CBR_BLOCK); \\ will be unblocked and handled by ProcessPkt() %@NL@%
- %@AB@% break;%@NL@%
- %@AB@%%@NL@%
- %@AB@% case XTYP_REGISTER:%@NL@%
- %@AB@% case XTYP_UNREGISTER:%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% \\ agent updates its communications name server.%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% return(0);%@NL@%
- %@AB@% break;%@NL@%
- %@AB@%%@NL@%
- %@AB@% default:%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% \\ the rest would reference local conversatoins that the agent%@NL@%
- %@AB@% \\ is maintaining.%@NL@%
- %@AB@% \\%@NL@%
- %@AB@% break;%@NL@%
- %@AB@% }%@NL@%
- %@AB@%}%@NL@%
- %@AB@%%@NL@%
- %@AB@%UnblockDeadTransaction(hConv) \\ called when no rtn pkt for hConv has been%@NL@%
- %@AB@% \\ received for a long time. %@NL@%
- %@AB@%{%@NL@%
- %@AB@% RemoveFromDeadCheckQ(hConv);%@NL@%
- %@AB@% AddToIgnoreList(hConv);%@NL@%
- %@AB@% DdeEnableCallback(CBK_ENABLE, hConv);%@NL@%
- %@AB@%}%@NL@%
- %@AB@%%@NL@%
- %@AB@%\* PUBDOC END */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* USHORT EXPENTRY DdeInitialize(pfnCallback, afCmd, ulRes)%@NL@%
- %@AB@%* PFNCALLBACK pfnCallback; // address to application callback function%@NL@%
- %@AB@%* ULONG afCmd; // registration command flags%@NL@%
- %@AB@%* ULONG ulRes; // currently reserved, must be 0L.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* This API is used to initialize the DDEML for an application thread.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* afCmd - is a set of DMGCMD_ flags for special initialization instructions.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* DMGCMD_AGENT%@NL@%
- %@AB@%* The registering application represents more than one DDE application.%@NL@%
- %@AB@%* Agents are never allowed to establish a conversation with%@NL@%
- %@AB@%* another agent. See Agent Transactions.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* DMGCMD_MONITOR%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This defines the registered application as a DDE transaction %@NL@%
- %@AB@%* monitor. This is primarily used for debugging DDE %@NL@%
- %@AB@%* applications. A monitoring application will have its Callback %@NL@%
- %@AB@%* function called every time a DDE message is sent.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* This flag is exclusive of all others. No other flags should be%@NL@%
- %@AB@%* or'ed in with this one.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* DMGCMD_CLIENTONLY%@NL@%
- %@AB@%* This should be specified when the application only intends to%@NL@%
- %@AB@%* be a DDE client. This reduces the resource consumption of the DLL.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Registration is on a per-thread basis. Thus a multi-threaded application%@NL@%
- %@AB@%* could register several threads as seperate DDE entities. %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* returns any applicable DMGERR_ error code or 0 on success.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Most other DLL APIs will fail if the calling thread has not called this.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Registration causes the following windows to be created:%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* HWND_OBJECT%@NL@%
- %@AB@%* hwndDmg(s)%@NL@%
- %@AB@%* hwndClient(s)%@NL@%
- %@AB@%* hwndTopicServer(s)%@NL@%
- %@AB@%* hwndServer(s)%@NL@%
- %@AB@%* hwndMonitor(s)%@NL@%
- %@AB@%* HWND_DESKTOP%@NL@%
- %@AB@%* hwndFrame(s)%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* See api.doc file for usage info.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- USHORT EXPENTRY DdeInitialize(pfnCallback, afCmd, ulRes)%@NL@%
- PFNCALLBACK pfnCallback;%@NL@%
- ULONG afCmd;%@NL@%
- ULONG ulRes; %@NL@%
- {%@NL@%
- if (ulRes != 0L || CheckSel(SELECTOROF(pfnCallback)) == 0)%@NL@%
- return(DMGERR_INVALIDPARAMETER);%@NL@%
- %@NL@%
- return(Register(pfnCallback, afCmd, ulRes, FALSE));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- USHORT EXPENTRY Register(pfnCallback, afCmd, ulRes, f32bit)%@NL@%
- PFNCALLBACK pfnCallback;%@NL@%
- ULONG afCmd;%@NL@%
- ULONG ulRes;%@NL@%
- BOOL f32bit; %@AB@%/* set if calling app is a 32bit app. */%@AE@%%@NL@%
- {%@NL@%
- BOOL fInit;%@NL@%
- PAPPINFO pai = 0L, paiT;%@NL@%
- PIDINFO pidInfo;%@NL@%
- USHORT usRet = DMGERR_PMWIN_ERROR;%@NL@%
- ULONG ctlFlags;%@NL@%
- CLASSINFO ci;%@NL@%
- USHORT cb;%@NL@%
- %@NL@%
- UNUSED ulRes;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- if (fInit = (hheapDmg == 0L)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * First time only%@NL@%
- %@AB@% */%@AE@%%@NL@%
- syscc.codepage = syscc.country = 0;%@NL@%
- DosGetCtryInfo(sizeof(COUNTRYCODE), &syscc, (PCOUNTRYINFO)&syscc, &cb);%@NL@%
- if (DosGetHugeShift(&usHugeShift))%@NL@%
- goto Abort;%@NL@%
- usHugeAdd = (1 << usHugeShift) - 1;%@NL@%
- if (!(hheapDmg = MyCreateHeap(0, 4096, 0, 0, 0, HEAPFLAGS)))%@NL@%
- goto Abort;%@NL@%
- if (!WinQueryClassInfo(DMGHAB, WC_FRAME, &ci))%@NL@%
- goto Abort;%@NL@%
- lpfnFrameWndProc = ci.pfnWindowProc;%@NL@%
- if (!AddAtomTable(TRUE)) %@NL@%
- goto Abort;%@NL@%
- } else {%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) != NULL) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * re-registration%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return(DMGERR_DLL_USAGE);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * share the main heap with this process.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (DosGetSeg(SELECTOROF(hheapDmg))) {%@NL@%
- SemLeave();%@NL@%
- return(DMGERR_PMWIN_ERROR);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- if (DosGetPID(&pidInfo))%@NL@%
- goto Abort;%@NL@%
- %@NL@%
- if (!(pai = (PAPPINFO)FarAllocMem(hheapDmg, sizeof(APPINFO))))%@NL@%
- goto Abort;%@NL@%
- %@NL@%
- if (!(pai->hheapApp = MyCreateHeap(0, 4096, 0, 0, 0, HEAPFLAGS))) {%@NL@%
- FarFreeMem(hheapDmg, pai, sizeof(APPINFO));%@NL@%
- pai = 0L;%@NL@%
- goto Abort;%@NL@%
- }%@NL@%
- %@NL@%
- pai->pAppNamePile = NULL; %@AB@%/* responds to nothing */%@AE@%%@NL@%
- pai->pSvrTopicList = CreateLst(pai->hheapApp, sizeof(HWNDHSZLI));%@NL@%
- pai->pHDataPile = CreatePile(pai->hheapApp, sizeof(HDMGDATA), 8);%@NL@%
- pai->afCmd = (USHORT)afCmd | (f32bit ? DMGCMD_32BIT : 0);%@NL@%
- pai->hwndDmg =%@NL@%
- pai->hwndFrame =%@NL@%
- pai->hwndMonitor =%@NL@%
- pai->hwndTimer = 0;%@NL@%
- pai->pid = pidInfo.pid;%@NL@%
- pai->tid = pidInfo.tid;%@NL@%
- pai->pfnCallback = pfnCallback;%@NL@%
- pai->cInCallback = 0;%@NL@%
- pai->LastError = DMGERR_NO_ERROR;%@NL@%
- pai->fEnableCB = TRUE;%@NL@%
- pai->plstCB = CreateLst(pai->hheapApp, sizeof(CBLI));%@NL@%
- pai->plstCBExceptions = NULL;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * make nextThread link.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- paiT = pAppInfoList;%@NL@%
- while (paiT && paiT->pid != pai->pid) {%@NL@%
- paiT = paiT->next;%@NL@%
- }%@NL@%
- pai->nextThread = paiT; %@AB@%/* paiT is NULL or of the same process */%@AE@%%@NL@%
- %@NL@%
- if (paiT) {%@NL@%
- while (paiT->nextThread->tid != pai->nextThread->tid) {%@NL@%
- paiT = paiT->nextThread;%@NL@%
- }%@NL@%
- paiT->nextThread = pai;%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We must reregister each class for each process that invokes this%@NL@%
- %@AB@% * DLL because we can't register public classes unless we are the%@NL@%
- %@AB@% * shell.%@NL@%
- %@AB@% * Since pai->nextThread is NULL, this is a new process.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinRegisterClass(0, SZCLIENTCLASS, ClientWndProc, 0L, 4);%@NL@%
- WinRegisterClass(0, SZSERVERCLASS, ServerWndProc, 0L, 4);%@NL@%
- WinRegisterClass(0, SZDMGCLASS, DmgWndProc, 0L, 4);%@NL@%
- WinRegisterClass(0, SZDEFCLASS, WinDefWindowProc, 0L, 4);%@NL@%
- }%@NL@%
- %@NL@%
- pai->next = pAppInfoList;%@NL@%
- pAppInfoList = pai;%@NL@%
- %@NL@%
- if ((pai->hwndDmg = WinCreateWindow(HWND_OBJECT, SZDMGCLASS, "", 0L,%@NL@%
- 0, 0, 0, 0, (HWND)NULL, HWND_BOTTOM, WID_APPROOT, 0L, 0L)) == 0L) {%@NL@%
- goto Abort;%@NL@%
- }%@NL@%
- %@NL@%
- if (pai->afCmd & DMGCMD_MONITOR) {%@NL@%
- WinRegisterClass(0, SZMONITORCLASS, MonitorWndProc, 0L, 4);%@NL@%
- if ((pai->hwndMonitor = WinCreateWindow(HWND_OBJECT, SZMONITORCLASS, NULL,%@NL@%
- 0L, 0, 0, 0, 0, (HWND)NULL, HWND_BOTTOM, WID_MONITOR, 0L, 0L))%@NL@%
- == 0L) {%@NL@%
- goto Abort;%@NL@%
- }%@NL@%
- if (++cMonitor) {%@NL@%
- WinSetHook(DMGHAB, NULL, HK_INPUT, (PFN)DdePostHookProc, hmodDmg);%@NL@%
- WinSetHook(DMGHAB, NULL, HK_SENDMSG, (PFN)DdeSendHookProc, hmodDmg);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * create an invisible top-level frame for initiates. (if server ok)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- usRet = DMGERR_PMWIN_ERROR;%@NL@%
- if (!(afCmd & DMGCMD_CLIENTONLY)) {%@NL@%
- ctlFlags = 0;%@NL@%
- if ((pai->hwndFrame = WinCreateStdWindow(HWND_DESKTOP, 0L, &ctlFlags,%@NL@%
- (PSZ)NULL, "", 0L, (HMODULE)NULL, 0, (PHWND)NULL)) == (HWND)NULL)%@NL@%
- goto Abort;%@NL@%
- WinSubclassWindow(pai->hwndFrame, subframeWndProc);%@NL@%
- }%@NL@%
- %@NL@%
- DosExitList(EXLST_ADD, (PFNEXITLIST)ExlstAbort);%@NL@%
- %@NL@%
- SemLeave();%@NL@%
- %@NL@%
- return(DMGERR_NO_ERROR);%@NL@%
- %@NL@%
- Abort:%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- if (pai)%@NL@%
- DdeUninitialize();%@NL@%
- else if (fInit && hheapDmg)%@NL@%
- hheapDmg = MyDestroyHeap(hheapDmg);%@NL@%
- return(usRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeUninitialize(void);%@NL@%
- %@AB@%* This uninitializes an application thread from the DDEML.%@NL@%
- %@AB@%* All DLL resources associated with the application are destroyed.%@NL@%
- %@AB@%* Most other APIs will fail if called after this API by the same thread.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeUninitialize()%@NL@%
- {%@NL@%
- PAPPINFO pai, paiT;%@NL@%
- PMYDDES pmyddes;%@NL@%
- PIDINFO pi;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- DosExitList(EXLST_REMOVE, (PFNEXITLIST)ExlstAbort);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * get us out of the semaphore!%@NL@%
- %@AB@% * !!! NOTE: semaphore tid id -1 during exitlist processing!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosGetPID(&pi);%@NL@%
- if (FSRSemDmg.cUsage > 0 && FSRSemDmg.pid == pi.pid &&%@NL@%
- (FSRSemDmg.tid == pi.tid || FSRSemDmg.tid == -1)) {%@NL@%
- while (FSRSemDmg.cUsage) {%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if (pai->hwndTimer)%@NL@%
- WinSendMsg(pai->hwndTimer, WM_TIMER, MPFROMSHORT(TID_ABORT), 0L);%@NL@%
- %@NL@%
- if (pai->hwndMonitor) {%@NL@%
- DestroyWindow(pai->hwndMonitor);%@NL@%
- if (!--cMonitor) {%@NL@%
- WinReleaseHook(DMGHAB, NULL, HK_INPUT, (PFN)DdePostHookProc, hmodDmg);%@NL@%
- WinReleaseHook(DMGHAB, NULL, HK_SENDMSG, (PFN)DdeSendHookProc, hmodDmg);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * inform others of DeRegistration%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pai->pAppNamePile != NULL) %@NL@%
- DdeAppNameServer(NULL, ANS_UNREGISTER);%@NL@%
- %@NL@%
- UnlinkAppInfo(pai);%@NL@%
- %@NL@%
- DestroyWindow(pai->hwndDmg);%@NL@%
- DestroyWindow(pai->hwndFrame);%@NL@%
- DestroyHwndHszList(pai->pSvrTopicList);%@NL@%
- while (PopPileSubitem(pai->pHDataPile, (PBYTE)&pmyddes)) {%@NL@%
- if (CheckSel(SELECTOROF(pmyddes)) > sizeof(MYDDES) &&%@NL@%
- pmyddes->magic == MYDDESMAGIC &&%@NL@%
- pmyddes->pai == pai) {%@NL@%
- pmyddes->fs &= ~HDATA_APPOWNED;%@NL@%
- }%@NL@%
- FreeData(pmyddes, pai);%@NL@%
- }%@NL@%
- DestroyPile(pai->pHDataPile);%@NL@%
- if (pai->nextThread) {%@NL@%
- paiT = pai;%@NL@%
- while (paiT->nextThread != pai) {%@NL@%
- paiT = paiT->nextThread;%@NL@%
- } %@NL@%
- paiT->nextThread = pai->nextThread;%@NL@%
- if (paiT->nextThread == paiT) {%@NL@%
- paiT->nextThread = NULL;%@NL@%
- }%@NL@%
- }%@NL@%
- MyDestroyHeap(pai->hheapApp);%@NL@%
- %@NL@%
- DestroyPile(pai->pAppNamePile);%@NL@%
- FarFreeMem(hheapDmg, (PBYTE)pai, sizeof(APPINFO));%@NL@%
- %@NL@%
- if (pAppInfoList == NULL) { %@AB@%/* last guy out? - turn the lights out. */%@AE@%%@NL@%
- while (cAtbls--)%@NL@%
- WinDestroyAtomTable(aAtbls[cAtbls]);%@NL@%
- hheapDmg = MyDestroyHeap(hheapDmg);%@NL@%
- } else %@NL@%
- DosFreeSeg(SELECTOROF(hheapDmg));%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HCONVLIST EXPENTRY DdeBeginEnumServers(%@NL@%
- %@AB@%* HSZ hszAppName, // app name to connect to, NULL is wild. %@NL@%
- %@AB@%* HSZ hszTopic, // topic name to connect to, NULL is wild. %@NL@%
- %@AB@%* HCONV hConvList, // previous hConvList for reenumeration, NULL for initial. %@NL@%
- %@AB@%* PCONVCONTEXT pCC, // language info or NULL for system default. %@NL@%
- %@AB@%* HAPP hApp); // target application handle or NULL for broadcast init. %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hszAppName - the DDE application name to connect to - may be 0 for wild.%@NL@%
- %@AB@%* hszTopic - the DDE topic name to connect to - may be 0 for wild.%@NL@%
- %@AB@%* hConvList - The conversation list handle to use for reenumeration.%@NL@%
- %@AB@%* If this is 0, a new hConvList is created.%@NL@%
- %@AB@%* pCC - pointer to CONVCONTEXT structure which provides conversation%@NL@%
- %@AB@%* information needed for international support. All DDEFMT_TEXT%@NL@%
- %@AB@%* strings within any conversation started by this call should use%@NL@%
- %@AB@%* the codepage referenced in this structure.%@NL@%
- %@AB@%* If NULL is given, the current system values are used.%@NL@%
- %@AB@%* hApp - if not NULL, this directs initiates to only be sent to hApp.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine connects all available conversations on the given %@NL@%
- %@AB@%* app/topic pair. Hsz values of 0 indicate wild names. On reenumeration%@NL@%
- %@AB@%* old hConv's are kept and any new ones created are added to the%@NL@%
- %@AB@%* list. Duplicate connections are avoided where possible. A%@NL@%
- %@AB@%* duplicate connection is one which is to the same process and%@NL@%
- %@AB@%* thread on the same application/topic names. If hApp is provided,%@NL@%
- %@AB@%* initiates are given only to that application.%@NL@%
- %@AB@%* Reenumeration is primarily intended as a response%@NL@%
- %@AB@%* to registration of a new app name to the system. Reenumeration%@NL@%
- %@AB@%* also removes any terminated conversations from the list.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns NULL on failure, hConvList on success.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HCONVLIST EXPENTRY DdeBeginEnumServers(hszAppName, hszTopic, hConvList,%@NL@%
- pCC, hApp)%@NL@%
- HSZ hszAppName; %@NL@%
- HSZ hszTopic; %@NL@%
- HWND hConvList; %@NL@%
- PCONVCONTEXT pCC; %@NL@%
- HAPP hApp; %@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- HCONV hConv, hConvNext, hConvNew;%@NL@%
- HCONVLIST hConvListNew;%@NL@%
- PCLIENTINFO pciOld, pciNew;%@NL@%
- PID pidOld, pidNew;%@NL@%
- TID tidOld, tidNew;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == 0)%@NL@%
- return(0);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * destroy any dead old clients%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hConvList) {%@NL@%
- hConv = WinQueryWindow(hConvList, QW_TOP, FALSE);%@NL@%
- while (hConv != NULL) {%@NL@%
- hConvNext = WinQueryWindow(hConv, QW_NEXT, FALSE);%@NL@%
- if (!((USHORT)WinSendMsg(hConv, UM_QUERY, MPFROMSHORT(Q_STATUS), 0L) &%@NL@%
- ST_CONNECTED))%@NL@%
- WinDestroyWindow(hConv);%@NL@%
- hConv = hConvNext;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if ((hConvListNew = WinCreateWindow(pai->hwndDmg, SZDEFCLASS, "", 0L,%@NL@%
- 0, 0, 0, 0, (HWND)NULL, HWND_BOTTOM, WID_CLROOT, 0L, 0L)) == NULL) {%@NL@%
- pai->LastError = DMGERR_PMWIN_ERROR;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- hConvNew = GetDDEClientWindow(hConvListNew, (HWND)hApp, NULL, hszAppName,%@NL@%
- hszTopic, pCC);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If no new hConvs created, quit now.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hConvNew == NULL) {%@NL@%
- if (hConvList && WinQueryWindow(hConvList, QW_TOP, FALSE) == NULL) {%@NL@%
- DestroyWindow(hConvList);%@NL@%
- hConvList = NULL;%@NL@%
- }%@NL@%
- if (hConvList == NULL)%@NL@%
- pai->LastError = DMGERR_NO_CONV_ESTABLISHED;%@NL@%
- return(hConvList);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * remove any new ones that duplicate old existing ones%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hConvList && (hConv = WinQueryWindow(hConvList, QW_TOP, FALSE))) {%@NL@%
- while (hConv) {%@NL@%
- hConvNext = WinQueryWindow(hConv, QW_NEXT, FALSE);%@NL@%
- pciOld = (PCLIENTINFO)WinQueryWindowULong(hConv, QWL_USER);%@NL@%
- if (!WinIsWindow(DMGHAB, pciOld->ci.hwndPartner)) {%@NL@%
- WinDestroyWindow(hConv);%@NL@%
- hConv = hConvNext;%@NL@%
- continue;%@NL@%
- }%@NL@%
- WinQueryWindowProcess(pciOld->ci.hwndPartner, &pidOld, &tidOld);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * destroy any new clients that are duplicates of the old ones.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hConvNew = WinQueryWindow(hConvListNew, QW_TOP, FALSE);%@NL@%
- while (hConvNew) {%@NL@%
- hConvNext = WinQueryWindow(hConvNew, QW_NEXT, FALSE);%@NL@%
- pciNew = (PCLIENTINFO)WinQueryWindowULong(hConvNew, QWL_USER);%@NL@%
- WinQueryWindowProcess(pciNew->ci.hwndPartner, &pidNew, &tidNew);%@NL@%
- if (pciOld->ci.hszServerApp == pciNew->ci.hszServerApp &&%@NL@%
- pciOld->ci.hszTopic == pciNew->ci.hszTopic &&%@NL@%
- pidOld == pidNew &&%@NL@%
- tidOld == tidNew) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * assume same app, same topic, same process, same thread%@NL@%
- %@AB@% * is a duplicate.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinDestroyWindow(hConvNew);%@NL@%
- }%@NL@%
- hConvNew = hConvNext;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * move the unique old client to the new list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSetParent(hConv, hConvListNew, FALSE);%@NL@%
- hConv = hConvNext;%@NL@%
- }%@NL@%
- WinDestroyWindow(hConvList);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If none are left, fail because no conversations were established.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (WinQueryWindow(hConvListNew, QW_TOP, FALSE) == NULL) {%@NL@%
- DestroyWindow(hConvListNew);%@NL@%
- pai->LastError = DMGERR_NO_CONV_ESTABLISHED;%@NL@%
- return(NULL);%@NL@%
- } else {%@NL@%
- return(hConvListNew);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HCONV EXPENTRY DdeGetNextServer(%@NL@%
- %@AB@%* HCONVLIST hConvList, // conversation list being traversed%@NL@%
- %@AB@%* HCONV hConvPrev) // previous conversation extracted or NULL for first%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hConvList - handle of conversation list returned by DdeBeginEnumServers().%@NL@%
- %@AB@%* hConvPrev - previous hConv returned by this API or 0 to start from the top%@NL@%
- %@AB@%* of hConvList.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API returns the next conversation handle associated with hConvList.%@NL@%
- %@AB@%* A 0 is returned if hConvPrev was the last conversation or if hConvList%@NL@%
- %@AB@%* has no active conversations within it.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HCONV EXPENTRY DdeGetNextServer(hConvList, hConvPrev)%@NL@%
- HCONVLIST hConvList;%@NL@%
- HCONV hConvPrev;%@NL@%
- {%@NL@%
- if (!WinIsWindow(DMGHAB, hConvList))%@NL@%
- return(NULL);%@NL@%
- if (hConvPrev == NULL)%@NL@%
- return(WinQueryWindow(hConvList, QW_TOP, FALSE));%@NL@%
- else%@NL@%
- return(WinQueryWindow(hConvPrev, QW_NEXT, FALSE));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeEndEnumServers(hConvList)%@NL@%
- %@AB@%* HCONVLIST hConvList; // conversation list to destroy.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hConvList - a conversation list handle returned by DdeBeginEnumServers().%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API destroys hConvList and terminates all conversations associated%@NL@%
- %@AB@%* with it. If an application wishes to save selected conversations within%@NL@%
- %@AB@%* hConvList, it should call DdeDisconnect() on all hConv's it does not%@NL@%
- %@AB@%* want to use and not call this API.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeEndEnumServers(hConvList)%@NL@%
- HCONVLIST hConvList;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- HCONV hConv, hConvNext;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(FALSE);%@NL@%
- if (WinIsWindow(DMGHAB, hConvList)) {%@NL@%
- hConv = WinQueryWindow(hConvList, QW_TOP, FALSE);%@NL@%
- while (hConv != NULL) {%@NL@%
- hConvNext = WinQueryWindow(hConv, QW_NEXT, FALSE);%@NL@%
- DestroyWindow(hConv);%@NL@%
- hConv = hConvNext;%@NL@%
- }%@NL@%
- DestroyWindow(hConvList);%@NL@%
- }%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HCONV EXPENTRY DdeConnect(hszAppName, hszTopic, pCC, hApp)%@NL@%
- %@AB@%* HSZ hszAppName; // app name to connect to, NULL is wild.%@NL@%
- %@AB@%* HSZ hszTopic; // topic name to connect to, NULL is wild.%@NL@%
- %@AB@%* PCONVCONTEXT pCC; // language information or NULL for sys default.%@NL@%
- %@AB@%* HAPP hApp; // target application or NULL for broadcast.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hszAppName - DDE application name to connect to.%@NL@%
- %@AB@%* hszTopic - DDE Topic name to connect to.%@NL@%
- %@AB@%* pCC - CONVCONTEXT information pertinant to this conversation.%@NL@%
- %@AB@%* If NULL, the current system information is used.%@NL@%
- %@AB@%* hApp - if not NULL, directs connection to a specific app.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns - the conversation handle of the connected conversation or 0 on error.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function allows the simpler aproach of allowing a client to%@NL@%
- %@AB@%* talk to the first server it finds on a topic. It is most efficient when%@NL@%
- %@AB@%* an hApp is provided.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/16/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HCONV EXPENTRY DdeConnect(hszAppName, hszTopic, pCC, hApp)%@NL@%
- HSZ hszAppName;%@NL@%
- HSZ hszTopic;%@NL@%
- PCONVCONTEXT pCC;%@NL@%
- HAPP hApp;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- HCONV hConv;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- hConv = GetDDEClientWindow(pai->hwndDmg, NULL, (HWND)hApp, hszAppName,%@NL@%
- hszTopic, pCC);%@NL@%
- %@NL@%
- if (hConv == 0)%@NL@%
- pai->LastError = DMGERR_NO_CONV_ESTABLISHED;%@NL@%
- %@NL@%
- return(hConv);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeDisconnect(hConv)%@NL@%
- %@AB@%* hConv; // conversation handle of conversation to terminate.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API terminates a conversation started by either DdeConnect() or%@NL@%
- %@AB@%* DdeBeginEnumServers(). hConv becomes invalid after this call.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If hConv is a server conversation, any transactions for that conversation%@NL@%
- %@AB@%* found on the server callback queue will be deleted prior to terminating%@NL@%
- %@AB@%* the conversation.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If hConv is a client conversation, any transactions on the Client Queue%@NL@%
- %@AB@%* are purged before termination.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Note that client conversations that are terminated from the server end%@NL@%
- %@AB@%* go into a dormant state but are still available so that DdeQueryConvInfo()%@NL@%
- %@AB@%* can be used to determine why a conversation is not working.%@NL@%
- %@AB@%* Server conversations will destroy themselves if terminated from a client.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns fSuccess%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/16/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeDisconnect(hConv)%@NL@%
- HCONV hConv;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- if (!WinIsWindow(DMGHAB, hConv)) {%@NL@%
- pai->LastError = DMGERR_NO_CONV_ESTABLISHED;%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- SemCheckOut();%@NL@%
- return((BOOL)WinSendMsg(hConv, UMCL_TERMINATE, 0L, 0L));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeQueryConvInfo(hConv, pConvInfo, idXfer)%@NL@%
- %@AB@%* HCONV hConv; // conversation hand to get info on.%@NL@%
- %@AB@%* PCONVINFO pConvInfo; // structure to hold info.%@NL@%
- %@AB@%* ULONG idXfer; // transaction ID if async, QID_SYNC if not.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hConv - conversation handle of a conversation to query.%@NL@%
- %@AB@%* pConvInfo - pointer to CONVINFO structure.%@NL@%
- %@AB@%* idXfer - Should be a QID_ constant or an ID returned from DdeCheckQueue().%@NL@%
- %@AB@%* if id is QID_SYNC, then the synchronous conversation state is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns - fSuccess. The CONVINFO structure is filled in with the%@NL@%
- %@AB@%* conversation's status on success.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Note that a client conversation may have several transactions in progress%@NL@%
- %@AB@%* at the same time. idXfer is used to choose which transaction to refer to.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hConv may be a client or server conversation handle. Server conversation%@NL@%
- %@AB@%* handles ignore idXfer.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeQueryConvInfo(hConv, pConvInfo, idXfer)%@NL@%
- HCONV hConv;%@NL@%
- PCONVINFO pConvInfo;%@NL@%
- ULONG idXfer;%@NL@%
- {%@NL@%
- PCLIENTINFO pci;%@NL@%
- PAPPINFO pai;%@NL@%
- PXADATA pxad;%@NL@%
- PCQDATA pqd;%@NL@%
- BOOL fClient;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) == 0)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * note that pci may actually be a psi if fClient is false. Since%@NL@%
- %@AB@% * the common info portions are identical, we don't care except%@NL@%
- %@AB@% * where data is extracted from non-common portions.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!WinIsWindow(DMGHAB, hConv) ||%@NL@%
- !(pci = (PCLIENTINFO)WinSendMsg(hConv, UM_QUERY, (MPARAM)Q_ALL, 0L)) ||%@NL@%
- !WinIsWindow(DMGHAB, pci->ci.hwndPartner)) {%@NL@%
- pai->LastError = DMGERR_NO_CONV_ESTABLISHED;%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- fClient = (BOOL)WinSendMsg(hConv, UM_QUERY, (MPARAM)Q_CLIENT, 0L);%@NL@%
- %@NL@%
- if (idXfer == QID_SYNC || !fClient) {%@NL@%
- pxad = &pci->ci.xad;%@NL@%
- } else {%@NL@%
- if (pci->pQ != NULL &&%@NL@%
- (pqd = (PCQDATA)Findqi(pci->pQ, idXfer))) {%@NL@%
- pxad = &pqd->xad;%@NL@%
- } else {%@NL@%
- pai->LastError = DMGERR_UNFOUND_QUEUE_ID;%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- }%@NL@%
- SemEnter();%@NL@%
- pConvInfo->cb = sizeof(CONVINFO);%@NL@%
- pConvInfo->hConvPartner = IsDdeWindow(pci->ci.hwndPartner);%@NL@%
- pConvInfo->hszAppName = pci->ci.hszServerApp;%@NL@%
- pConvInfo->hszAppPartner = fClient ? pci->ci.hszServerApp : 0;%@NL@%
- pConvInfo->hszTopic = pci->ci.hszTopic;%@NL@%
- pConvInfo->hAgent = pci->ci.hAgent;%@NL@%
- pConvInfo->hApp = pci->ci.hwndFrame;%@NL@%
- if (fClient) {%@NL@%
- pConvInfo->hszItem = pxad->pXferInfo->hszItem;%@NL@%
- pConvInfo->usFmt = pxad->pXferInfo->usFmt;%@NL@%
- pConvInfo->usType = pxad->pXferInfo->usType;%@NL@%
- pConvInfo->usConvst = pxad->state;%@NL@%
- pConvInfo->LastError = pxad->LastError;%@NL@%
- } else {%@NL@%
- pConvInfo->hszItem = NULL;%@NL@%
- pConvInfo->usFmt = 0;%@NL@%
- pConvInfo->usType = 0;%@NL@%
- pConvInfo->usConvst = pci->ci.xad.state;%@NL@%
- pConvInfo->LastError = pci->ci.pai->LastError;%@NL@%
- }%@NL@%
- pConvInfo->usStatus = pci->ci.fs;%@NL@%
- pConvInfo->fsContext = pci->ci.cc.fsContext;%@NL@%
- pConvInfo->idCountry = pci->ci.cc.idCountry;%@NL@%
- pConvInfo->usCodepage = pci->ci.cc.usCodepage;%@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdePostAdvise(hszTopic, hszItem)%@NL@%
- %@AB@%* HSZ hszTopic; // topic of changed data, NULL is all topics%@NL@%
- %@AB@%* HSZ hszItem; // item of changed data, NULL is all items%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Causes any clients who have advise loops running on the topic/item name%@NL@%
- %@AB@%* specified to receive the apropriate data messages they require.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This should be called by a server application anytime data associated with%@NL@%
- %@AB@%* a particular topic/item changes. This call results in XTYP_ADVREQ%@NL@%
- %@AB@%* callbacks being generated.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hszTopic and/or hszItem may be NULL if all topics or items are to be updated.%@NL@%
- %@AB@%* This will result in callbacks for all active advise loops that fit the%@NL@%
- %@AB@%* hszTopic/hszItem pair.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* The API is intended for SERVERS only!%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/16/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdePostAdvise(hszTopic, hszItem)%@NL@%
- HSZ hszTopic;%@NL@%
- HSZ hszItem;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- HWND hwndTopic;%@NL@%
- HWND hwndSvr;%@NL@%
- %@NL@%
- // LATER - add wild hsz support%@NL@%
- %@NL@%
- if (((pai = GetCurrentAppInfo(TRUE)) == 0))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- if (pai->afCmd & DMGCMD_CLIENTONLY) {%@NL@%
- pai->LastError = DMGERR_DLL_USAGE;%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- if ((hwndTopic = HwndFromHsz((HSZ)hszTopic, pai->pSvrTopicList)) == 0)%@NL@%
- return(TRUE);%@NL@%
- %@NL@%
- hwndSvr = WinQueryWindow(hwndTopic, QW_TOP, FALSE);%@NL@%
- while (hwndSvr) {%@NL@%
- WinPostMsg(hwndSvr, UMSR_POSTADVISE, MPFROMSHORT(hszItem), 0L);%@NL@%
- hwndSvr = WinQueryWindow(hwndSvr, QW_NEXT, FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HDMGDATA EXPENTRY DdeClientXfer(pSrc, cb, hConv, hszItem, usFmt,%@NL@%
- %@AB@%* usType, ulTimeout, pidXfer)%@NL@%
- %@AB@%* PBYTE pSrc; // data source, or NULL for non-data cases.%@NL@%
- %@AB@%* ULONG cb; // data size or 0 for non-data cases.%@NL@%
- %@AB@%* HCONV hConv; // associated conversation handle%@NL@%
- %@AB@%* HSZ hszItem; // item of transaction%@NL@%
- %@AB@%* USHORT usFmt; // format for transaction%@NL@%
- %@AB@%* USHORT usType; // transaction type code%@NL@%
- %@AB@%* ULONG ulTimeout; // timeout for synchronous, TIMEOUT_ASSYNC otherwise.%@NL@%
- %@AB@%* PULONG pidXfer; // OUTPUT: assync transfer id, NULL for no output.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API initiates a transaction from a client to the server connected%@NL@%
- %@AB@%* via the conversation specified by hConv.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Currently usType may be:%@NL@%
- %@AB@%* XTYP_REQUEST%@NL@%
- %@AB@%* XTYP_POKE%@NL@%
- %@AB@%* XTYP_EXEC%@NL@%
- %@AB@%* XTYP_ADVSTART%@NL@%
- %@AB@%* XTYP_ADVSTART | XTYPF_NODATA%@NL@%
- %@AB@%* XTYP_ADVSTART | XTYPF_ACKREQ%@NL@%
- %@AB@%* XTYP_ADVSTART | XTYPF_NODATA | XTYPF_ACKREQ%@NL@%
- %@AB@%* XTYP_ADVSTOP%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ulTimeout specifies the maximum time to wait for a response in miliseconds%@NL@%
- %@AB@%* and applies to synchronous transactions only.%@NL@%
- %@AB@%* if ulTimeout is TIMEOUT_ASSYNC, then the transfer is asynchronous and%@NL@%
- %@AB@%* pidXfer may point to where to place the client transaction queue item%@NL@%
- %@AB@%* ID created by this request.%@NL@%
- %@AB@%* pidXfer may be NULL if no ID is desired.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* If usType is XTYP_REQUEST, synchronous transfers return a valid hDmgData%@NL@%
- %@AB@%* on success which holds the data received from the request.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* if usType is XTYP_EXEC and hszItem==NULL (wild) and usFmt==DDEFMT_TEXT,%@NL@%
- %@AB@%* the item name will be changed to the same as the text data.%@NL@%
- %@AB@%* This allows for EXCEL and porthole WINDOWS compatability%@NL@%
- %@AB@%* for XTYP_EXEC transactions. It is suggested that applications always set%@NL@%
- %@AB@%* hszItem to NULL for XTYP_EXEC transactions and that servers ignore the%@NL@%
- %@AB@%* hszItem perameter in their callback for execute transactions.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns hDmgData or ACK DDE flags on Success, 0 on failure.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Note: the hDmgData passed in by this call is only valid for the duration%@NL@%
- %@AB@%* of the callback.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HDMGDATA EXPENTRY DdeClientXfer(pSrc, cb, hConv, hszItem, usFmt,%@NL@%
- usType, ulTimeout, pidXfer)%@NL@%
- PBYTE pSrc;%@NL@%
- ULONG cb;%@NL@%
- HCONV hConv;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT usFmt;%@NL@%
- USHORT usType;%@NL@%
- ULONG ulTimeout;%@NL@%
- PULONG pidXfer;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- XFERINFO xi;%@NL@%
- HDMGDATA hDmgData;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- if (!WinIsWindow(DMGHAB, hConv)) {%@NL@%
- pai->LastError = DMGERR_NO_CONV_ESTABLISHED;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- %@NL@%
- switch (usType) {%@NL@%
- case XTYP_REQUEST:%@NL@%
- case XTYP_POKE:%@NL@%
- case XTYP_EXEC:%@NL@%
- case XTYP_ADVSTART:%@NL@%
- case XTYP_ADVSTART | XTYPF_NODATA:%@NL@%
- case XTYP_ADVSTART | XTYPF_ACKREQ:%@NL@%
- case XTYP_ADVSTART | XTYPF_NODATA | XTYPF_ACKREQ:%@NL@%
- case XTYP_ADVSTOP:%@NL@%
- xi.pidXfer = pidXfer;%@NL@%
- xi.ulTimeout = ulTimeout;%@NL@%
- xi.usType = usType;%@NL@%
- xi.usFmt = usFmt;%@NL@%
- xi.hszItem = hszItem;%@NL@%
- xi.hConv = hConv;%@NL@%
- xi.cb = cb;%@NL@%
- xi.pData = pSrc; %@NL@%
- hDmgData = (HDMGDATA)WinSendMsg(hConv, UMCL_XFER, (MPARAM)&xi, 0L);%@NL@%
- if (ulTimeout == TIMEOUT_ASYNC) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Increment the count of hszItem incase the app frees it on%@NL@%
- %@AB@% * return. This will be decremented when the client Queue%@NL@%
- %@AB@% * entry is removed.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- IncHszCount(hszItem);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * add the hDmgData to the client's list of handles he needs%@NL@%
- %@AB@% * to eventually free.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((usType & XCLASS_DATA) && (CheckSel(SELECTOROF(hDmgData)))) {%@NL@%
- AddPileItem(pai->pHDataPile, (PBYTE)&hDmgData, CmpULONG);%@NL@%
- if (((PMYDDES)hDmgData)->magic == MYDDESMAGIC) {%@NL@%
- ((PMYDDES)hDmgData)->fs |= HDATA_READONLY;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- return(hDmgData);%@NL@%
- }%@NL@%
- pai->LastError = DMGERR_INVALIDPARAMETER;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* USHORT EXPENTRY DdeGetLastError(void)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API returns the most recent error registered by the DDE manager for%@NL@%
- %@AB@%* the current thread. This should be called anytime a DDE manager API%@NL@%
- %@AB@%* returns in a failed state.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns an error code which corresponds to a DMGERR_ constant found in%@NL@%
- %@AB@%* ddeml.h. This error code may be passed on to DdePostError() to%@NL@%
- %@AB@%* show the user the reason for the error or to DdeGetErrorString() to convert%@NL@%
- %@AB@%* the error code into an apropriate string.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- USHORT EXPENTRY DdeGetLastError(void)%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- SHORT err = DMGERR_DLL_NOT_INITIALIZED;%@NL@%
- %@NL@%
- pai = GetCurrentAppInfo(FALSE);%@NL@%
- %@NL@%
- if (pai) {%@NL@%
- err = pai->LastError;%@NL@%
- pai->LastError = DMGERR_NO_ERROR;%@NL@%
- }%@NL@%
- return(err);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* void EXPENTRY DdePostError(err)%@NL@%
- %@AB@%* ULONG err; // error code to post.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API puts up a message box describing the error who's code was%@NL@%
- %@AB@%* passed in.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/20/88 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void EXPENTRY DdePostError(err)%@NL@%
- USHORT err;%@NL@%
- {%@NL@%
- char szError[MAX_ERRSTR + 1];%@NL@%
- %@NL@%
- if (err < DMGERR_FIRST || err > DMGERR_LAST)%@NL@%
- return;%@NL@%
- WinLoadString(DMGHAB, hmodDmg, err, MAX_ERRSTR + 1, szError);%@NL@%
- WinMessageBox(HWND_DESKTOP, NULL, szError, SZERRCAPTION, 0,%@NL@%
- MB_OK | MB_ICONHAND | MB_SYSTEMMODAL);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* USHORT EXPENTRY DdeGetErrorString(err, cbMax, psz)%@NL@%
- %@AB@%* USHORT err; // error code to convert%@NL@%
- %@AB@%* USHORT cbMax; // size of string buffer provided by caller%@NL@%
- %@AB@%* PSZ psz; // string buffer address.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function fills psz with the error string referenced by err of up%@NL@%
- %@AB@%* to cbMax characters. All error strings are <= MAX_ERRSTR in length.%@NL@%
- %@AB@%* (not counting the NULL terminator.)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns length of copied string without NULL terminator or 0 on failure.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/20/88 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- USHORT EXPENTRY DdeGetErrorString(err, cbMax, psz)%@NL@%
- USHORT err;%@NL@%
- USHORT cbMax;%@NL@%
- PSZ psz;%@NL@%
- {%@NL@%
- if (err < DMGERR_FIRST || err > DMGERR_LAST)%@NL@%
- return(0);%@NL@%
- return(WinLoadString(DMGHAB, hmodDmg, err, cbMax, psz));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*\%@NL@%
- %@AB@%* HDATA stuff:%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Each thread has an hData list that contains all the hData's it has%@NL@%
- %@AB@%* been given by the DLL. This list indicates what hData's an app can%@NL@%
- %@AB@%* and must eventually free.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* If an app has multiple threads registered, each threads pai's are linked%@NL@%
- %@AB@%* via the nextThread pointer. The links are circular so the TID%@NL@%
- %@AB@%* should be used to know when all the lists are traversed.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Each hData contains the following flags:%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* HDATA_READONLY - set on any hData given to the DLL or created by the DLL.%@NL@%
- %@AB@%* This prevents AddData from working.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* HDATA_APPOWNED - set at creation time by app so app will keep access%@NL@%
- %@AB@%* until it frees it or unregistration happens.%@NL@%
- %@AB@%* This prevents the DLL from freeing the hData before an app is%@NL@%
- %@AB@%* through with it.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* HDATA_APPFREEABLE - set at creation time if logged into thread list.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Each hData also contains the pai of the thread that created the hData.%@NL@%
- %@AB@%* (set by PutData) If APPOWNED is set, this identifies the%@NL@%
- %@AB@%* owner thread as well.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* General rules for apps:%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* hDatas from DLL calls are the apps responsibility to free and are%@NL@%
- %@AB@%* only valid till passed back into the DLL or freed.%@NL@%
- %@AB@%* hDatas from callback calls are only valid during the callback.%@NL@%
- %@AB@%* hDatas created by an app but not APPOWNED are only valid till%@NL@%
- %@AB@%* passed into the DLL.%@NL@%
- %@AB@%* hDatas created by an app that are APPOWNED are valid until%@NL@%
- %@AB@%* the creating thread frees it or till that thread unregisters%@NL@%
- %@AB@%* itself.%@NL@%
- %@AB@%* A process will not loose access to an hData untill all threads that%@NL@%
- %@AB@%* have received the hData have freed it or passed it back to%@NL@%
- %@AB@%* the DLL (via callback)%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Register: DONE%@NL@%
- %@AB@%* creates hDataList for app/thread.%@NL@%
- %@AB@%* creates nextThread links if applicable.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* DdePutData: DONE%@NL@%
- %@AB@%* Only allows HDATA_APPOWNED flag%@NL@%
- %@AB@%* sets HDATA_APPFREEABLE flag%@NL@%
- %@AB@%* ...Falls into....%@NL@%
- %@AB@%* PutData: DONE%@NL@%
- %@AB@%* Allocates selector%@NL@%
- %@AB@%* sets creator pai%@NL@%
- %@AB@%* sets HDATA_ flags specified%@NL@%
- %@AB@%* if (HDATA_APPFREEABLE)%@NL@%
- %@AB@%* adds to hDataList. %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* DdeAddData: DONE%@NL@%
- %@AB@%* fails if HDATA_READONLY or a non-dll type selector%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Callback: DONE%@NL@%
- %@AB@%* Entry:%@NL@%
- %@AB@%* for hData to callback:%@NL@%
- %@AB@%* Sets HDATA_READONLY if hData valid DLL type selector.%@NL@%
- %@AB@%* (does NOT add hData to thread list so he can't free it during%@NL@%
- %@AB@%* the callback)%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Exit:%@NL@%
- %@AB@%* for hData to callback:%@NL@%
- %@AB@%* nothing.%@NL@%
- %@AB@%* for hData from callback:%@NL@%
- %@AB@%* verifies creator == current%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* DdeCreateInitPkt: DONE%@NL@%
- %@AB@%* DdeAppNameServer: NOT COMPLETE%@NL@%
- %@AB@%* DdeClientXfer: DONE%@NL@%
- %@AB@%* DdeCheckQ: DONE%@NL@%
- %@AB@%* if (valid selector)%@NL@%
- %@AB@%* add to thread list%@NL@%
- %@AB@%* if (valid DLL type selector)%@NL@%
- %@AB@%* Set READONLY flag.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* ProcessPkt: NOT IMP.%@NL@%
- %@AB@%* for hData in:%@NL@%
- %@AB@%* After used, calls FreeData()%@NL@%
- %@AB@%* for hData out:%@NL@%
- %@AB@%* before return, adds hData to thread list%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* MyPostMsg: DONE%@NL@%
- %@AB@%* gives if target process != current%@NL@%
- %@AB@%* if target process is not a DLL process/thread, expand hszItem.%@NL@%
- %@AB@%* calls FreeData() on current process if MDPM_FREEHDATA is set.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* DdeFreeData: DONE%@NL@%
- %@AB@%* if in thread list.%@NL@%
- %@AB@%* remove hData from list%@NL@%
- %@AB@%* if not in any thread lists for this process%@NL@%
- %@AB@%* free data%@NL@%
- %@AB@%* return pass%@NL@%
- %@AB@%* else %@NL@%
- %@AB@%* return fail%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* FreeData: DONE%@NL@%
- %@AB@%* if (DLL type selector && HDATA_APPOWNED && creator == current)%@NL@%
- %@AB@%* exit%@NL@%
- %@AB@%* remove hData from thread list if found%@NL@%
- %@AB@%* if not in any thread lists for this process%@NL@%
- %@AB@%* free data%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* UnRegister: DONE%@NL@%
- %@AB@%* for each item in the hDataList:%@NL@%
- %@AB@%* clear HDATA_APPOWNED flag if dll type selector and owned by this%@NL@%
- %@AB@%* thread.%@NL@%
- %@AB@%* FreeData()%@NL@%
- %@AB@%* destroy list%@NL@%
- %@AB@%* unlink from other thread lists%@NL@%
- %@AB@%* %@NL@%
- %@AB@%\*/%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HDMGDATA EXPENTRY DdePutData(pSrc, cb, cbOff, hszItem, usFmt, afCmd)%@NL@%
- %@AB@%* PBYTE pSrc; // address of data to place into data handle or NULL%@NL@%
- %@AB@%* ULONG cb; // amount of data to copy if pSrc is not NULL.%@NL@%
- %@AB@%* ULONG cbOff; // offset into data handle region to place pSrc data%@NL@%
- %@AB@%* HSZ hszItem; // item associated with this data%@NL@%
- %@AB@%* USHORT usFmt; // format associated with this data%@NL@%
- %@AB@%* USHORT afCmd; // HDATA_ flags.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* This api allows an application to create a hDmgData apropriate%@NL@%
- %@AB@%* for return from its call-back function.%@NL@%
- %@AB@%* The passed in data is stored into the hDmgData which is%@NL@%
- %@AB@%* returned on success. Any portions of the data handle not filled are%@NL@%
- %@AB@%* undefined. afCmd contains any of the HDATA_ constants described below:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* HDATA_APPOWNED%@NL@%
- %@AB@%* This declares the created data handle to be the responsability of%@NL@%
- %@AB@%* the application to free it. Application owned data handles may%@NL@%
- %@AB@%* be given to the DLL multiple times. This allows a server app to be%@NL@%
- %@AB@%* able to support many clients without having to recopy the data for%@NL@%
- %@AB@%* each request. If this flag is not specified, the data handle becomes%@NL@%
- %@AB@%* invalid once passed to the DLL via any API or the callback function.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* NOTES:%@NL@%
- %@AB@%* If an application expects this data handle to hold >64K of data via%@NL@%
- %@AB@%* DdeAddData(), it should specify a cb + cbOff to be as large as%@NL@%
- %@AB@%* the object is expected to get via DdeAddData() calls to avoid%@NL@%
- %@AB@%* unnecessary data copying or reallocation by the DLL.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* if psrc==NULL or cb == 0, no actual data copying takes place.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Data handles given to an application via the DdeClientXfer() or%@NL@%
- %@AB@%* DdeCheckQueue() functions are the responsability of the client%@NL@%
- %@AB@%* application to free and MUST NOT be returned from the callback%@NL@%
- %@AB@%* function as server data! The DLL will only accept data handles%@NL@%
- %@AB@%* returned from the callback function that were created by the%@NL@%
- %@AB@%* called application.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HDMGDATA EXPENTRY DdePutData(pSrc, cb, cbOff, hszItem, usFmt, afCmd)%@NL@%
- PBYTE pSrc;%@NL@%
- ULONG cb;%@NL@%
- ULONG cbOff;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT usFmt;%@NL@%
- USHORT afCmd;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if (!(pai = GetCurrentAppInfo(FALSE)))%@NL@%
- return(0L);;%@NL@%
- %@NL@%
- if (afCmd & ~(HDATA_APPOWNED)) {%@NL@%
- pai->LastError = DMGERR_INVALIDPARAMETER;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- return(PutData(pSrc, cb, cbOff, hszItem, usFmt, afCmd | HDATA_APPFREEABLE, pai));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HDMGDATA EXPENTRY DdeAddData(hDmgData, pSrc, cb, cbOff)%@NL@%
- %@AB@%* HDMGDATA hDmgData; // data handle to add data to%@NL@%
- %@AB@%* PBYTE pSrc; // pointer to data to add (if NULL, no data copying)%@NL@%
- %@AB@%* ULONG cb; // size of data to add%@NL@%
- %@AB@%* ULONG cbOff; // offset within hData to place data%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine allows an application to add data to a hDmgData it had%@NL@%
- %@AB@%* previously created using DdePutData(). The handle will be%@NL@%
- %@AB@%* grown as necessary to support the data addition. Data may be added%@NL@%
- %@AB@%* to a data handle multiple times and in any order of data locations.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Once a data handle is given to the DLL via return from the callback%@NL@%
- %@AB@%* function or via a DLL API, it becomes readonly. Further attempts to%@NL@%
- %@AB@%* add data to the hData by any process will fail.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This call will return 0 if it failed to allocate enough memory or if%@NL@%
- %@AB@%* the data handle is readonly. On success, the returned hDmgData should %@NL@%
- %@AB@%* replace the given hDmgData. On failure, the hDmgData given is left%@NL@%
- %@AB@%* in the state it was initially.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* NOTE: For huge segments, or segments expected to grow to greater than %@NL@%
- %@AB@%* 64K, it is best if DdePutData() be called with a cbOff + cb as %@NL@%
- %@AB@%* large as maximally expected so as not to force reallocation from a %@NL@%
- %@AB@%* normal to a huge segment in 16bit applications. This also avoids %@NL@%
- %@AB@%* the need of replaceing the hDmgData with the output each time%@NL@%
- %@AB@%* incase a new selector was needed to be allocated and copied to. %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/17/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HDMGDATA EXPENTRY DdeAddData(hDmgData, pSrc, cb, cbOff)%@NL@%
- HDMGDATA hDmgData;%@NL@%
- PBYTE pSrc;%@NL@%
- ULONG cb;%@NL@%
- ULONG cbOff;%@NL@%
- {%@NL@%
- %@AI@%#define %@AE@%pmyddes ((PMYDDES)hDmgData) %@NL@%
- %@AI@%#define %@AE@%selIn (SELECTOROF(hDmgData)) %@NL@%
- %@NL@%
- PAPPINFO pai;%@NL@%
- SEL sel;%@NL@%
- ULONG cbOffAbs;%@NL@%
- %@NL@%
- if (!(pai = GetCurrentAppInfo(FALSE)))%@NL@%
- return(0L);;%@NL@%
- %@NL@%
- if (!CheckSel(selIn) ||%@NL@%
- pmyddes->offszItemName != sizeof(MYDDES) ||%@NL@%
- pmyddes->magic != MYDDESMAGIC ||%@NL@%
- pmyddes->fs & HDATA_READONLY) {%@NL@%
- pai->LastError = DMGERR_INVALID_HDMGDATA;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- cbOffAbs = pmyddes->offabData + cbOff;%@NL@%
- if (pmyddes->cbData + pmyddes->offabData < cb + cbOffAbs) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * need to grow...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (cbOffAbs + cb > 0xFFFFL) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * going to be huge...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((pmyddes->offabData + pmyddes->cbData < 0xFFFFL) ||%@NL@%
- DosReallocHuge(HIUSHORT(cb + cbOffAbs),%@NL@%
- LOUSHORT(cb + cbOffAbs), selIn)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Either we can't grow a huge seg or we need to make one.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (DosAllocHuge(HIUSHORT(cb + cbOffAbs),%@NL@%
- LOUSHORT(cb + cbOffAbs), &sel, 0, SEG_GIVEABLE)) {%@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- CopyHugeBlock(hDmgData, MAKEP(sel, 0), pmyddes->cbData +%@NL@%
- sizeof(MYDDES) + 1);%@NL@%
- FindPileItem(pai->pHDataPile, CmpULONG, (PBYTE)&hDmgData,%@NL@%
- FPI_DELETE);%@NL@%
- DosFreeSeg(selIn);%@NL@%
- hDmgData = MAKEP(sel, 0);%@NL@%
- AddPileItem(pai->pHDataPile, (PBYTE)&hDmgData, NULL);%@NL@%
- }%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * not going to be huge%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (DosReallocSeg((USHORT)(cb + cbOffAbs), selIn)) { %@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- }%@NL@%
- pmyddes->cbData = cbOff + cb;%@NL@%
- }%@NL@%
- if (pSrc)%@NL@%
- CopyHugeBlock(pSrc, HugeOffset((PBYTE)hDmgData, cbOffAbs), cb);%@NL@%
- return(hDmgData);%@NL@%
- %@AI@%#undef %@AE@%selIn %@NL@%
- %@AI@%#undef %@AE@%pmyddes %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* ULONG EXPENTRY DdeGetData(hDmgData, pDst, cbMax, cbOff)%@NL@%
- %@AB@%* HDMGDATA hDmgData; // data handle to extract data from%@NL@%
- %@AB@%* PBYTE pDst; // destination for extracted data%@NL@%
- %@AB@%* ULONG cbMax; // destination buffer size%@NL@%
- %@AB@%* ULONG cbOff; // offset into data to start extraction%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This copies up to cbMax bytes of data contained in the hDmgData data handle%@NL@%
- %@AB@%* at offset cbOff into application memory pointed to by pDst.%@NL@%
- %@AB@%* If pDst == NULL, no copying is performed.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns the size of the data contained in the data handle remaining after%@NL@%
- %@AB@%* cbOff or 0 if hDmgData is invalid or cbOff is too large.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API supports HUGE segments in 16 bit applications.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- ULONG EXPENTRY DdeGetData(hDmgData, pDst, cbMax, cbOff)%@NL@%
- HDMGDATA hDmgData;%@NL@%
- PBYTE pDst;%@NL@%
- ULONG cbMax;%@NL@%
- ULONG cbOff;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) == NULL)%@NL@%
- return(0L);%@NL@%
- %@NL@%
- if (!CheckSel(SELECTOROF(hDmgData))) {%@NL@%
- pai->LastError = DMGERR_INVALID_HDMGDATA;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- if (cbOff >= ((PMYDDES)hDmgData)->cbData) {%@NL@%
- pai->LastError = DMGERR_INVALIDPARAMETER;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- cbMax = min(cbMax, ((PMYDDES)hDmgData)->cbData - cbOff);%@NL@%
- if (pDst == NULL) %@NL@%
- return(((PMYDDES)hDmgData)->cbData - cbOff); %@NL@%
- CopyHugeBlock(HugeOffset(DDES_PABDATA(hDmgData), cbOff), pDst, cbMax);%@NL@%
- return(cbMax);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* PBYTE EXPENTRY DdeAccessData(hDmgData)%@NL@%
- %@AB@%* HDMGDATA hDmgData; // data handle to access%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API returns a pointer to the data referenced by the data handle.%@NL@%
- %@AB@%* The pointer returned becomes invalid once the data handle is freed%@NL@%
- %@AB@%* or given to the DLL via callback return or API call.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* NOTE: applications MUST take care not to access beyond the limits of%@NL@%
- %@AB@%* the data handle. Only hDmgData's created by the application via%@NL@%
- %@AB@%* a DdePutData() call may write to this memory prior to passing on%@NL@%
- %@AB@%* to any DLL API or returning from the callback function. Any hDmgData%@NL@%
- %@AB@%* received from the DLL should be considered shared-readonly data and%@NL@%
- %@AB@%* should be treated as such. This applies whether the application owns%@NL@%
- %@AB@%* the data handle or not.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* 0L is returned on error.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 8/24/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PBYTE EXPENTRY DdeAccessData(hDmgData)%@NL@%
- HDMGDATA hDmgData;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) == NULL)%@NL@%
- return(0L);%@NL@%
- if (CheckSel(SELECTOROF(hDmgData))) {%@NL@%
- return(DDES_PABDATA(hDmgData));%@NL@%
- }%@NL@%
- pai->LastError = DMGERR_ACCESS_DENIED;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeFreeData(hDmgData)%@NL@%
- %@AB@%* HDMGDATA hDmgData; // data handle to destroy%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine should be called by an application wishing to release%@NL@%
- %@AB@%* custody of an hDmgData it owns.%@NL@%
- %@AB@%* An application owns any hDmgData%@NL@%
- %@AB@%* it created with the HDATA_APPOWNED flag or an hDmgData given to%@NL@%
- %@AB@%* it via DdeClientXfer(), DdeCheckQueue(), DdeAppNameServer(),%@NL@%
- %@AB@%* DdeCreateInitPkt() or DdeProcessPkt().%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns fSuccess. This function will fail if the hDmgData is not%@NL@%
- %@AB@%* owned by the calling app.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/14/88 Sanfords%@NL@%
- %@AB@%* 6/12/90 sanfords Fixed to work with non-DLL generated selectors%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeFreeData(hDmgData)%@NL@%
- HDMGDATA hDmgData;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- USHORT cbSel;%@NL@%
- TID tid;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- cbSel = CheckSel(SELECTOROF(hDmgData));%@NL@%
- if (!cbSel) {%@NL@%
- pai->LastError = DMGERR_INVALID_HDMGDATA;%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- SemEnter();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Apps can only free handles the DLL does not own or handles from external%@NL@%
- %@AB@% * non-DLL DDE apps.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!FindPileItem(pai->pHDataPile, CmpULONG, (PBYTE)&hDmgData, FPI_DELETE)) {%@NL@%
- pai->LastError = DMGERR_INVALID_HDMGDATA;%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- } %@NL@%
- %@NL@%
- tid = pai->tid;%@NL@%
- do {%@NL@%
- if (FindPileItem(pai->pHDataPile, CmpULONG, (PBYTE)&hDmgData, FPI_COUNT)) {%@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- pai = pai->nextThread;%@NL@%
- } while (pai && pai->tid != tid);%@NL@%
- DosFreeSeg(SELECTOROF(hDmgData));%@NL@%
- %@NL@%
- SemLeave();%@NL@%
- return(TRUE); %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeCopyBlock(pSrc, pDst, cb)%@NL@%
- %@AB@%* PBYTE pSrc; // source of copy%@NL@%
- %@AB@%* PBYTE pDst; // destination of copy%@NL@%
- %@AB@%* ULONG cb; // size in bytes of copy%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This copy utility can handle HUGE segments and can be used by any%@NL@%
- %@AB@%* application as a copy utility. This does not support overlapping huge%@NL@%
- %@AB@%* copies.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns fSuccess.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeCopyBlock(pSrc, pDst, cb)%@NL@%
- PBYTE pSrc;%@NL@%
- PBYTE pDst;%@NL@%
- ULONG cb;%@NL@%
- {%@NL@%
- return(CopyHugeBlock(pSrc, pDst, cb));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HSZ management notes:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* HSZs are used in this DLL to simplify string handling for applications%@NL@%
- %@AB@%* and for inter-process communication. Since many applications use a%@NL@%
- %@AB@%* fixed set of Application/Topic/Item names, it is convenient to convert%@NL@%
- %@AB@%* them to HSZs and allow quick comparisons for lookups. This also frees%@NL@%
- %@AB@%* the DLL up from having to constantly provide string buffers for copying%@NL@%
- %@AB@%* strings between itself and its clients.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* HSZs are the same as atoms except they have no restrictions on length or%@NL@%
- %@AB@%* number and are 32 bit values. They are case preserving and can be%@NL@%
- %@AB@%* compared directly for case sensitive comparisons or via DdeCmpHsz()%@NL@%
- %@AB@%* for case insensitive comparisons.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* When an application creates an HSZ via DdeGetHsz() or increments its%@NL@%
- %@AB@%* count via DdeIncHszCount() it is essentially claiming the HSZ for%@NL@%
- %@AB@%* its own use. On the other hand, when an application is given an%@NL@%
- %@AB@%* HSZ from the DLL via a callback, it is using another application's HSZ%@NL@%
- %@AB@%* and should not free that HSZ via DdeFreeHsz().%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The DLL insures that during the callback any HSZs given will remain%@NL@%
- %@AB@%* valid for the duration of the callback.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If an application wishes to keep that HSZ to use for itself as a%@NL@%
- %@AB@%* standard for future comparisons, it should increment its count so that,%@NL@%
- %@AB@%* should the owning application free it, the HSZ will not become invalid.%@NL@%
- %@AB@%* This also prevents an HSZ from changing its value. (ie, app A frees it%@NL@%
- %@AB@%* and then app B creates a new one that happens to use the same HSZ code,%@NL@%
- %@AB@%* then app C, which had the HSZ stored all along (but forgot to increment%@NL@%
- %@AB@%* its count) now is holding a handle to a different string.)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Applications may free HSZs they have created or incremented at any time%@NL@%
- %@AB@%* by calling DdeFreeHsz().%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The DLL internally increments HSZ counts while in use so that they will%@NL@%
- %@AB@%* not be destroyed until both the DLL and all applications concerned are%@NL@%
- %@AB@%* through with them.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* IT IS THE APPLICATIONS RESPONSIBILITY TO PROPERLY CREATE AND FREE HSZs!!%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HSZ EXPENTRY DdeGetHsz(psz, country, codepage)%@NL@%
- %@AB@%* PSZ psz; // string to HSZize.%@NL@%
- %@AB@%* USHORT country; // country ID to use in comparisons.%@NL@%
- %@AB@%* USHORT codepage; // codepage to use in comparisons.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine returns a string handle to the psz passed in.%@NL@%
- %@AB@%* 0 is returned on failure or for NULL strings.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If country is 0, the default system country code is used.%@NL@%
- %@AB@%* If codepage is 0, the default system codepage code is used.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* String handles are similar to atoms but without the 255%@NL@%
- %@AB@%* character limit on strings. String handles are case preserving.%@NL@%
- %@AB@%* see DdeCmpHsz().%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* String handles are consistant across all processes using the DLL.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HSZ EXPENTRY DdeGetHsz(psz, country, codepage)%@NL@%
- PSZ psz;%@NL@%
- USHORT country, codepage;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- return(GetHsz(psz, country, codepage, TRUE));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeFreeHsz(hsz)%@NL@%
- %@AB@%* HSZ hsz; // string handle to free%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function decrements the usage count for the HSZ given and frees%@NL@%
- %@AB@%* it if the count becomes 0.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeFreeHsz(hsz)%@NL@%
- HSZ hsz;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) == NULL)%@NL@%
- return(0);%@NL@%
- return(FreeHsz(hsz));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeIncHszCount(hsz)%@NL@%
- %@AB@%* HSZ hsz; // string handle to increment.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function increments the usage count for the HSZ given. This is%@NL@%
- %@AB@%* useful when an application wishes to keep an HSZ given to it in its%@NL@%
- %@AB@%* callback.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeIncHszCount(hsz)%@NL@%
- HSZ hsz;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(FALSE)) == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- return(IncHszCount(hsz));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* USHORT EXPENTRY DdeGetHszString(hsz, psz, cchMax)%@NL@%
- %@AB@%* HSZ hsz; // string handle to extract string from%@NL@%
- %@AB@%* PSZ psz; // buffer for case-sensitive string%@NL@%
- %@AB@%* ULONG cchMax; // buffer size.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This API is the inverse of DdeGetHsz(). The actual length of the%@NL@%
- %@AB@%* string (without NULL terminator) referenced by hsz is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* if psz is NULL, no string is returned in psz.%@NL@%
- %@AB@%* 0 is returned if hsz does not exist or is wild.%@NL@%
- %@AB@%* If hsz is wild, psz will be set to a 0 length string.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History: Created 5/10/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- USHORT EXPENTRY DdeGetHszString(hsz, psz, cchMax)%@NL@%
- HSZ hsz;%@NL@%
- PSZ psz;%@NL@%
- ULONG cchMax;%@NL@%
- {%@NL@%
- if (psz) {%@NL@%
- if (hsz) {%@NL@%
- return(QueryHszName(hsz, psz, (USHORT)cchMax));%@NL@%
- } else {%@NL@%
- *psz = '\0';%@NL@%
- return(0);%@NL@%
- }%@NL@%
- } else if (hsz) {%@NL@%
- return(QueryHszLength(hsz));%@NL@%
- } else {%@NL@%
- return(0);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* SHORT EXPENTRY DdeCmpHsz(hsz1, hsz2)%@NL@%
- %@AB@%* HSZ hsz1, hsz2; // string handles to compare.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine returns:%@NL@%
- %@AB@%* 0 if hsz1 is of equal rank to hsz2%@NL@%
- %@AB@%* -2 if hsz1 is invalid.%@NL@%
- %@AB@%* -1 if hsz1 is of lower rank than hsz2%@NL@%
- %@AB@%* 1 if hsz1 is of higher rank than hsz2.%@NL@%
- %@AB@%* 2 if hsz2 is invalid.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Note that direct comparison of hszs (ie (hsz1 == hsz2)) is a case sensitive%@NL@%
- %@AB@%* comparison. This function performs a case insensitive comparison. Thus%@NL@%
- %@AB@%* different valued hszs may actually be equal.%@NL@%
- %@AB@%* A ranking is provided for binary searching.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- SHORT EXPENTRY DdeCmpHsz(hsz1, hsz2)%@NL@%
- HSZ hsz1, hsz2;%@NL@%
- {%@NL@%
- return(CmpHsz(hsz1, hsz2));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* ULONG EXPENTRY DdeCheckQueue(hConv, phDmgData, idXfer, afCmd)%@NL@%
- %@AB@%* HCONV hConv; // related convesation handle%@NL@%
- %@AB@%* PHDMGDATA phDmgData; // OUTPUT: for resultant data handle, or NULL%@NL@%
- %@AB@%* ULONG idXfer; // transaction ID or QID_NEWEST or QID_OLDEST%@NL@%
- %@AB@%* ULONG afCmd; // queue operation code.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine checks a client conversation's assynchronous %@NL@%
- %@AB@%* transaction queue for queued transaction status. This allows a %@NL@%
- %@AB@%* client to extract data or monitor the status of any transaction %@NL@%
- %@AB@%* previously started asynchronously. (TIMEOUT_ASSYNC) hConv is %@NL@%
- %@AB@%* the client conversation who's queue is being checked. %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If phDmgData is not NULL and the referenced item has data to %@NL@%
- %@AB@%* return to the client, phDmgData is filled. Returned hDmgDatas %@NL@%
- %@AB@%* must be freed by the application. phDmgData will be filled with %@NL@%
- %@AB@%* 0L if no return data is applicable or if the transaction is not %@NL@%
- %@AB@%* complete. %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If the queue is not periodicly flushed by an application %@NL@%
- %@AB@%* issueing asynchronous transactions the queue is automaticly%@NL@%
- %@AB@%* flushed as needed. Oldest transactions are flushed first. %@NL@%
- %@AB@%* DdeProcessPkt() and DdeDisconnect() and DdeEndEnumServers%@NL@%
- %@AB@%* remove items from this queue. %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* idXfer is the transaction id returned by an asynchronous call to %@NL@%
- %@AB@%* DdeClientXfer().%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* afCmd = CQ_FLUSH - remove all items in the queue - return is fSuccess.%@NL@%
- %@AB@%* afCmd = CQ_REMOVE - the item referenced is removed from the queue.%@NL@%
- %@AB@%* afCmd = CQ_NEXT - references the idXfer AFTER (more recent than) the id %@NL@%
- %@AB@%* given. 0 is returned if the ID given was the newest in the %@NL@%
- %@AB@%* queue otherwise the next ID is returned.%@NL@%
- %@AB@%* afCmd = CQ_PREV - references the idXfer BEFORE (less recent than) the id %@NL@%
- %@AB@%* given. 0 is returned if the ID given was the oldest in the %@NL@%
- %@AB@%* queue otherwise the previous ID is returned.%@NL@%
- %@AB@%* afCmd = CQ_COUNT - returns the number of entries in the queue.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* By ORing in one of the following flags, the above flags can be %@NL@%
- %@AB@%* made to reference the apropriate subset of queue entries: %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* afCmd = CQ_ACTIVEONLY - incomplete active transactions only.%@NL@%
- %@AB@%* afCmd = CQ_COMPLETEDONLY - completed transactions only.%@NL@%
- %@AB@%* afCmd = CQ_FAILEDONLY - transactions which had protocol violations or%@NL@%
- %@AB@%* communication failures.%@NL@%
- %@AB@%* afCmd = CQ_INACTIVEONLY - The complement of CQ_ACTIVEONLY which is the%@NL@%
- %@AB@%* union of CQ_COMPLETEDONLY and CQ_FAILEDONLY.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* if phdmgdata = NULL, no hdmgdata is returned.%@NL@%
- %@AB@%* if idXfer == QID_NEWEST, the top-most (most recent) entry in the %@NL@%
- %@AB@%* queue is referenced.%@NL@%
- %@AB@%* if idXfer == QID_OLDEST, the bottom-most (oldest) entry ID is %@NL@%
- %@AB@%* referenced.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns the ID of the item processed if it applies, or the count %@NL@%
- %@AB@%* of items or fSuccess. %@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Standard usage examples:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* To get the state of the oldest transaction:%@NL@%
- %@AB@%* id = DdeCheckQueue(hConv, &hDmgData, QID_OLDEST, 0)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* To get and flush the next completed transaction data, if there is %@NL@%
- %@AB@%* any:%@NL@%
- %@AB@%* id = DdeCheckQueue(hConv, &hDmgData, QID_OLDEST, CQ_REMOVE | %@NL@%
- %@AB@%* CQ_INACTIVEONLY)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* To flush all successfully completed transactions:%@NL@%
- %@AB@%* DdeCheckQueue(hConv, NULL, QID_OLDEST, CQ_FLUSH | CQ_COMPLETEDONLY)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* To see if a specific transaction is complete, and if so, to get the%@NL@%
- %@AB@%* information and remove the transaction from the queue:%@NL@%
- %@AB@%* if (DdeCheckQueue(hConv, &hDmgData, id, CQ_REMOVE | CQ_INACTIVEONLY))%@NL@%
- %@AB@%* ProcessAndFreeData(hDmgData);%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History: Created 6/6/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- ULONG EXPENTRY DdeCheckQueue(hConv, phDmgData, idXfer, afCmd)%@NL@%
- HCONV hConv;%@NL@%
- PHDMGDATA phDmgData;%@NL@%
- ULONG idXfer;%@NL@%
- ULONG afCmd;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- PCLIENTINFO pci;%@NL@%
- PCQDATA pcqd, pcqdT, pcqdEnd;%@NL@%
- USHORT err;%@NL@%
- ULONG retVal = TRUE;%@NL@%
- int i;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == 0)%@NL@%
- return(0);%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- SemEnter();%@NL@%
- %@NL@%
- err = DMGERR_INVALIDPARAMETER;%@NL@%
- if (!WinIsWindow(DMGHAB, hConv) ||%@NL@%
- !(BOOL)WinSendMsg(hConv, UM_QUERY, (MPARAM)Q_CLIENT, 0L) ||%@NL@%
- idXfer == QID_SYNC) {%@NL@%
- goto failExit;%@NL@%
- }%@NL@%
- %@NL@%
- if (!(pci = (PCLIENTINFO)WinSendMsg(hConv, UM_QUERY, (MPARAM)Q_ALL, 0L))) %@NL@%
- goto failExit;%@NL@%
- %@NL@%
- err = DMGERR_UNFOUND_QUEUE_ID;%@NL@%
- if ((pcqd = (PCQDATA)Findqi(pci->pQ, idXfer)) == NULL)%@NL@%
- goto failExit;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * if referencing an end item, make sure it fits any subset flags.%@NL@%
- %@AB@% * If it doesn't we alter afCmd to force us to the first qualifying%@NL@%
- %@AB@% * entry in the correct direction.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!fInSubset(pcqd, afCmd)) {%@NL@%
- if (idXfer & (QID_OLDEST))%@NL@%
- afCmd |= CQ_NEXT;%@NL@%
- else if (idXfer & (QID_NEWEST))%@NL@%
- afCmd |= CQ_PREV;%@NL@%
- else if (!(afCmd & (CQ_NEXT | CQ_PREV | CQ_COUNT | CQ_FLUSH)))%@NL@%
- goto failExit;%@NL@%
- }%@NL@%
- %@NL@%
- if (afCmd & CQ_NEXT) {%@NL@%
- pcqdEnd = (PCQDATA)pci->pQ->pqiHead->next;%@NL@%
- if ((pcqd = (PCQDATA)pcqd->next) == pcqdEnd)%@NL@%
- goto failExit;%@NL@%
- while (!fInSubset(pcqd, afCmd)) {%@NL@%
- if ((pcqd = (PCQDATA)pcqd->next) == pcqdEnd)%@NL@%
- goto failExit;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if (afCmd & CQ_PREV) {%@NL@%
- pcqdEnd = (PCQDATA)pci->pQ->pqiHead;%@NL@%
- if ((pcqd = (PCQDATA)pcqd->prev) == pcqdEnd)%@NL@%
- goto failExit;%@NL@%
- while (!fInSubset(pcqd, afCmd)) {%@NL@%
- if ((pcqd = (PCQDATA)pcqd->prev) == pcqdEnd)%@NL@%
- goto failExit;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pcqd now points to the apropriate entry%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if (afCmd & CQ_COUNT) %@NL@%
- retVal = 0;%@NL@%
- else%@NL@%
- retVal = MAKEID(pcqd);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Fill phDmgData if specified.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (phDmgData != NULL)%@NL@%
- if ((pcqd->xad.state == CONVST_CONNECTED) &&%@NL@%
- CheckSel(SELECTOROF(pcqd->xad.pddes))) {%@NL@%
- *phDmgData = pcqd->xad.pddes;%@NL@%
- AddPileItem(pai->pHDataPile, (PBYTE)phDmgData, CmpULONG);%@NL@%
- if (((PMYDDES)*phDmgData)->magic == MYDDESMAGIC) {%@NL@%
- ((PMYDDES)*phDmgData)->fs |= HDATA_READONLY;%@NL@%
- }%@NL@%
- } else%@NL@%
- *phDmgData = NULL;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * remove pcqd if apropriate.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (afCmd & (CQ_REMOVE | CQ_FLUSH)) {%@NL@%
- if (!FindPileItem(pai->pHDataPile, CmpULONG, (PBYTE)&pcqd->xad.pddes,%@NL@%
- 0))%@NL@%
- FreeData((PMYDDES)pcqd->xad.pddes, pai);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Decrement the use count we incremented when the client started%@NL@%
- %@AB@% * this transaction.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- FreeHsz(pcqd->XferInfo.hszItem);%@NL@%
- Deleteqi(pci->pQ, MAKEID(pcqd));%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * go through entire list and flush or count if specified.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (afCmd & (CQ_FLUSH | CQ_COUNT)) {%@NL@%
- pcqd = (PCQDATA)pci->pQ->pqiHead;%@NL@%
- for (i = pci->pQ->cItems; i; i--) {%@NL@%
- if (fInSubset(pcqd, afCmd)) {%@NL@%
- if (afCmd & CQ_COUNT) %@NL@%
- retVal++;%@NL@%
- if (afCmd & CQ_FLUSH) {%@NL@%
- pcqdT = (PCQDATA)pcqd->next;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Only free the data if not logged - ie the user never got a%@NL@%
- %@AB@% * copy.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!FindPileItem(pci->ci.pai->pHDataPile, CmpULONG,%@NL@%
- (PBYTE)&pcqd->xad.pddes, 0))%@NL@%
- FreeData((PMYDDES)pcqd->xad.pddes, pai);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Decrement the use count we incremented when the client started%@NL@%
- %@AB@% * this transaction.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- FreeHsz(pcqd->XferInfo.hszItem);%@NL@%
- Deleteqi(pci->pQ, MAKEID(pcqd));%@NL@%
- pcqd = pcqdT;%@NL@%
- continue;%@NL@%
- }%@NL@%
- }%@NL@%
- pcqd = (PCQDATA)pcqd->next;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- SemLeave();%@NL@%
- SemCheckOut();%@NL@%
- return(retVal);%@NL@%
- %@NL@%
- failExit:%@NL@%
- pai->LastError = err;%@NL@%
- SemLeave();%@NL@%
- SemCheckOut();%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- BOOL fInSubset(pcqd, afCmd)%@NL@%
- PCQDATA pcqd;%@NL@%
- ULONG afCmd;%@NL@%
- {%@NL@%
- if (afCmd & CQ_ACTIVEONLY && (pcqd->xad.state <= CONVST_INIT1))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- if (afCmd & CQ_INACTIVEONLY && (pcqd->xad.state > CONVST_INIT1))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- if (afCmd & CQ_COMPLETEDONLY && (pcqd->xad.state != CONVST_CONNECTED))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- if (afCmd & CQ_FAILEDONLY && (pcqd->xad.state > CONVST_TERMINATED))%@NL@%
- return(FALSE);%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeEnableCallback(hConv, fEnable)%@NL@%
- %@AB@%* HCONV hConv; // server conversation handle to enable/disable or NULL %@NL@%
- %@AB@%* BOOL fEnable; // TRUE enables, FALSE disables callbacks.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine is used by an application that does not want to be interrupted%@NL@%
- %@AB@%* by DLL calls to its Callback function. When callbacks are disabled,%@NL@%
- %@AB@%* all non critical attempts to call the Callback function instead result in%@NL@%
- %@AB@%* the call being placed on a server transaction queue until callbacks are%@NL@%
- %@AB@%* reenabled. An application should reenable callbacks in a timely manner%@NL@%
- %@AB@%* to avoid causing synchronous clients to time out.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* note that DdeProcessPkt() has the side effect of unblocking and removing%@NL@%
- %@AB@%* items from the server transaction queue when processing return packets.%@NL@%
- %@AB@%* DdeDisconnect() and DdeEndEnumServers() have the side effect of removing%@NL@%
- %@AB@%* any transactions for the disconnected conversation.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If hConv is non-NULL, only the hConv conversation is affected.%@NL@%
- %@AB@%* If hConv is NULL, all conversations are affected.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Callbacks can also be disabled on return from the callback function by%@NL@%
- %@AB@%* returning the constant CBR_BLOCK. This has the same effect as%@NL@%
- %@AB@%* calling DdeEnableCallback(hConv, FALSE) except that the callback%@NL@%
- %@AB@%* returned from is placed back on the callback queue for later re-submission%@NL@%
- %@AB@%* to the callback function when the conversations callbacks are reenabled.%@NL@%
- %@AB@%* This allows a server that needs a long time to process a request to delay%@NL@%
- %@AB@%* returning the result without blocking within the callback function.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* No callbacks are made within this function.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Note: Callback transactions that have XTYPF_NOBLOCK set in their usType%@NL@%
- %@AB@%* parameter cannot be blocked by CBR_BLOCK.%@NL@%
- %@AB@%* These callbacks are issued to the server regardless of the state of%@NL@%
- %@AB@%* callback enableing.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* fSuccess is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%* History: Created 6/6/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL EXPENTRY DdeEnableCallback(hConv, fEnable)%@NL@%
- HCONV hConv;%@NL@%
- BOOL fEnable;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == 0)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- SemEnter();%@NL@%
- if (hConv == NULL) {%@NL@%
- pai->fEnableCB = fEnable = fEnable ? TRUE : FALSE;%@NL@%
- FlushLst(pai->plstCBExceptions);%@NL@%
- } else if (pai->fEnableCB != fEnable) {%@NL@%
- if (pai->plstCBExceptions == NULL) %@NL@%
- pai->plstCBExceptions = CreateLst(pai->hheapApp, sizeof(HWNDLI));%@NL@%
- AddHwndList((HWND)hConv, pai->plstCBExceptions);%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- if (fEnable)%@NL@%
- WinPostMsg(pai->hwndDmg, UM_CHECKCBQ, (MPARAM)pai, 0L);%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HDMGDATA EXPENTRY DdeAppNameServer(hszApp, afCmd);%@NL@%
- %@AB@%* HSZ hszApp; // referenced app name%@NL@%
- %@AB@%* USHORT afCmd; // action code.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Updates or queries the DDE DLL application name server. The DDE name%@NL@%
- %@AB@%* server acts as a filter for initiate messages on behalf of registered%@NL@%
- %@AB@%* applications and serves as a way for an application to determine what%@NL@%
- %@AB@%* other applications are available without the need for wild initiates.%@NL@%
- %@AB@%* Any change in the name server results in XTYP_REGISTER or XTYP_UNREGISTER%@NL@%
- %@AB@%* callbacks to all other applications. Agents will not be allowed to%@NL@%
- %@AB@%* know about any other agent registrations.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* afCmd:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ANS_REGISTER%@NL@%
- %@AB@%* Adds hszApp to the name server. hszApp cannot be NULL.%@NL@%
- %@AB@%* All other applications will receive a registration notification%@NL@%
- %@AB@%* if their callback filters allow it.%@NL@%
- %@AB@%* fSuccess is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ANS_UNREGISTER%@NL@%
- %@AB@%* Remove hszApp from the name server. If hszApp==NULL the name server%@NL@%
- %@AB@%* is cleared for the calling application.%@NL@%
- %@AB@%* All other applications will receive a deregistration notification%@NL@%
- %@AB@%* if their callback filters allow it.%@NL@%
- %@AB@%* fSuccess is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ANS_QUERYALLBUTME%@NL@%
- %@AB@%* Returns a zero terminated array of hszApps/hApp pairs registered with%@NL@%
- %@AB@%* the name server by all other applications.%@NL@%
- %@AB@%* (Agent applications do not see other agent registered names.)%@NL@%
- %@AB@%* If hszApp is set, only names matching* hszApp are placed into the list.%@NL@%
- %@AB@%* 0 is returned if no applicable names were found.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ANS_QUERYMINE%@NL@%
- %@AB@%* Returns a zero terminated array of hszApps registered with the name%@NL@%
- %@AB@%* server by the calling application. If hszApp is set, only names%@NL@%
- %@AB@%* matching hszApp are placed into the list. 0 is returned if no%@NL@%
- %@AB@%* applicable names were found.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The following flags may be ORed in with one of the above flags:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ANS_FILTERON%@NL@%
- %@AB@%* Turns on dde initiate callback filtering. Only wild app names or%@NL@%
- %@AB@%* those matching a registered name are given to the application for%@NL@%
- %@AB@%* initiate requests or registration notifications.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ANS_FILTEROFF%@NL@%
- %@AB@%* Turns off dde initiate callback filtering. All initiate requests%@NL@%
- %@AB@%* and registration notifications are passed onto the application.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* A 0 is returned on error.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HDMGDATA EXPENTRY DdeAppNameServer(hszApp, afCmd)%@NL@%
- HSZ hszApp;%@NL@%
- USHORT afCmd;%@NL@%
- {%@NL@%
- PAPPINFO pai, paiT;%@NL@%
- BOOL fAgent;%@NL@%
- HDMGDATA hData;%@NL@%
- HSZ hsz;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == 0)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- if (afCmd & ANS_FILTERON)%@NL@%
- pai->afCmd |= DMGCMD_FILTERINITS;%@NL@%
- %@NL@%
- if (afCmd & ANS_FILTEROFF) %@NL@%
- pai->afCmd &= ~DMGCMD_FILTERINITS;%@NL@%
- %@NL@%
- %@NL@%
- if (afCmd & (ANS_REGISTER | ANS_UNREGISTER)) {%@NL@%
- %@NL@%
- if (pai->afCmd & DMGCMD_CLIENTONLY) {%@NL@%
- pai->LastError = DMGERR_DLL_USAGE;%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- fAgent = pai->afCmd & DMGCMD_AGENT ? TRUE : FALSE;%@NL@%
- %@NL@%
- if (hszApp == NULL) {%@NL@%
- if (afCmd & ANS_REGISTER) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * registering NULL is not allowed!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pai->LastError = DMGERR_INVALIDPARAMETER;%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * unregistering NULL is just like unregistering each%@NL@%
- %@AB@% * registered name.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while (PopPileSubitem(pai->pAppNamePile, (PBYTE)&hsz)) {%@NL@%
- for (paiT = pAppInfoList; paiT; paiT = paiT->next) {%@NL@%
- if (pai == paiT || (fAgent && (paiT->afCmd & DMGCMD_AGENT))) %@NL@%
- continue;%@NL@%
- WinPostMsg(paiT->hwndFrame, UM_UNREGISTER, (MPARAM)hsz,%@NL@%
- (MPARAM)pai->hwndFrame);%@NL@%
- }%@NL@%
- }%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- if (afCmd & ANS_REGISTER) {%@NL@%
- if (pai->pAppNamePile == NULL) %@NL@%
- pai->pAppNamePile = CreatePile(hheapDmg, sizeof(HSZ), 8);%@NL@%
- AddPileItem(pai->pAppNamePile, (PBYTE)&hszApp, NULL);%@NL@%
- } else%@NL@%
- FindPileItem(pai->pAppNamePile, CmpULONG, (PBYTE)&hszApp,%@NL@%
- FPI_DELETE);%@NL@%
- %@NL@%
- for (paiT = pAppInfoList; paiT; paiT = paiT->next) {%@NL@%
- if (pai == paiT ||%@NL@%
- (fAgent && (paiT->afCmd & DMGCMD_AGENT))) {%@NL@%
- continue;%@NL@%
- }%@NL@%
- WinPostMsg(paiT->hwndFrame,%@NL@%
- afCmd & ANS_REGISTER ? UM_REGISTER : UM_UNREGISTER,%@NL@%
- (MPARAM)hszApp, (MPARAM)pai->hwndFrame);%@NL@%
- }%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- if (afCmd & ANS_QUERYMINE) {%@NL@%
- hData = PutData(NULL, 10L * sizeof(HSZ),%@NL@%
- 0L, 0L, 0, HDATA_APPOWNED | HDATA_APPFREEABLE, pai);%@NL@%
- if (QueryAppNames(pai, hData, hszApp, 0L)) {%@NL@%
- return(hData);%@NL@%
- } else {%@NL@%
- DdeFreeData(hData);%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if (afCmd & ANS_QUERYALLBUTME) {%@NL@%
- ULONG offAdd, offAddNew;%@NL@%
- %@NL@%
- hData = PutData(NULL, 10L * sizeof(HSZ),%@NL@%
- 0L, 0L, 0, HDATA_APPOWNED | HDATA_APPFREEABLE, pai);%@NL@%
- *((PHSZ)DDES_PABDATA((PDDESTRUCT)hData)) = 0L;%@NL@%
- SemEnter();%@NL@%
- paiT = pAppInfoList;%@NL@%
- offAdd = 0L;%@NL@%
- while (paiT) {%@NL@%
- if (paiT != pai &&%@NL@%
- !(fAgent && (paiT->afCmd & DMGCMD_AGENT))) {%@NL@%
- offAddNew = QueryAppNames(paiT, hData, hszApp, offAdd);%@NL@%
- if (offAddNew == 0 && offAddNew < offAdd) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * memory error most likely.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SemLeave();%@NL@%
- DdeFreeData(hData);%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- offAdd = offAddNew;%@NL@%
- }%@NL@%
- paiT = paiT->next;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(hData);%@NL@%
- }%@NL@%
- %@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HDMGDATA EXPENTRY DdeCreateInitPkt(%@NL@%
- %@AB@%* HSZ hszApp, // initiate app string%@NL@%
- %@AB@%* HSZ hszTopic, // initiate topic string%@NL@%
- %@AB@%* HDMGDATA hDmgData) // packet data containing language information.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine is called by agent applications from within their callback%@NL@%
- %@AB@%* functions which need to store transaction initiate data into a %@NL@%
- %@AB@%* network-portable packet. On return, HDMGDATA contains the packeted %@NL@%
- %@AB@%* data. The calling application must free this data handle when %@NL@%
- %@AB@%* through. Agents are given access to the app string so that they%@NL@%
- %@AB@%* can modify it if needed for their net protocol.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HDMGDATA EXPENTRY DdeCreateInitPkt(hszApp, hszTopic, hDmgData)%@NL@%
- HSZ hszApp;%@NL@%
- HSZ hszTopic;%@NL@%
- HDMGDATA hDmgData;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- hszApp;%@NL@%
- hszTopic;%@NL@%
- hDmgData;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Add hDataRet to thread list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pai->LastError = DMGERR_NOT_IMPLEMENTED;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* BOOL EXPENTRY DdeProcessPkt(%@NL@%
- %@AB@%* HDMGDATA hPkt, // packet from net to process%@NL@%
- %@AB@%* ULONG hAgentFrom); // foreign agent handle associated with this packet.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine is called by agent applications which have received a packet%@NL@%
- %@AB@%* from another agent. This call performs what actions are requested by the%@NL@%
- %@AB@%* hPkt. If the particular transaction can be done synchronously, a return%@NL@%
- %@AB@%* packet is returned. If not, an XTYP_RTNPKT callback will eventually be%@NL@%
- %@AB@%* sent to the agent and 0 is returned. 0 is also returned on error.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* hAgentFrom identifies the agent the packet came from.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This call should NOT be made from within a callback.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HDMGDATA EXPENTRY DdeProcessPkt(hPkt, hAgentFrom)%@NL@%
- HDMGDATA hPkt;%@NL@%
- ULONG hAgentFrom;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- hPkt;%@NL@%
- hAgentFrom;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(0);%@NL@%
- pai->LastError = DMGERR_NOT_IMPLEMENTED;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* ULONG EXPENTRY DdeQueryVersion()%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns the DLL version number: 0xjjmmuuppL%@NL@%
- %@AB@%* jj = major release;%@NL@%
- %@AB@%* mm = minor release;%@NL@%
- %@AB@%* uu = update number;%@NL@%
- %@AB@%* pp = platform ID; 1=OS/2, 2=DOS, 3=WINDOWS, 4=UNIX, 5=MAC, 6=SUN%@NL@%
- %@AB@%* %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- ULONG EXPENTRY DdeQueryVersion()%@NL@%
- {%@NL@%
- return(MAKEULONG(MAKESHORT(1, rup),MAKESHORT(rmm, rmj)));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* PUBDOC START%@NL@%
- %@AB@% * ----------------------- Platform specific APIs -----------------------%@NL@%
- %@AB@% * PUBDOC END%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HCONV EXPENTRY DdeConverseWithWindow(%@NL@%
- %@AB@%* HWND hwnd, // server window to converse with%@NL@%
- %@AB@%* HSZ hszApp, // app name to converse on%@NL@%
- %@AB@%* HSZ hszTopic, // topic name to converse on%@NL@%
- %@AB@%* PCONVCONTEXT pCC) // language information to converse on%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* This creates a pre-initiated client conversation with the given hwnd. %@NL@%
- %@AB@%* The conversation is assumed to be on the given app, topic and context.%@NL@%
- %@AB@%* This is useful for implementing such things as drag and drop DDE %@NL@%
- %@AB@%* protocols. hszApp and hszTopic cannot be NULL. See%@NL@%
- %@AB@%* DdeCreateServerWindow().%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HCONV EXPENTRY DdeConverseWithWindow(hwnd, hszApp, hszTopic, pCC)%@NL@%
- HWND hwnd; %@NL@%
- HSZ hszApp, hszTopic; %@NL@%
- PCONVCONTEXT pCC;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- UNUSED hwnd;%@NL@%
- UNUSED hszApp;%@NL@%
- UNUSED hszTopic;%@NL@%
- UNUSED pCC;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- if (QuerylatomLength((LATOM)hszApp) == 0 ||%@NL@%
- QuerylatomLength((LATOM)hszTopic) == 0) {%@NL@%
- pai->LastError = DMGERR_INVALIDPARAMETER;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* HWND DdeCreateServerWindow(hszApp, hszTopic, pCC)%@NL@%
- %@AB@%* HSZ hszApp, // app name to accept conversations on.%@NL@%
- %@AB@%* HSZ hszTopic; // topic name to accept conversations on.%@NL@%
- %@AB@%* PCONVCONTEXT pCC; // language information to accept or NULL for sys default.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* This creates a pre_initiated server DDE window for the caller. The %@NL@%
- %@AB@%* server window does not know what client window it will be talking to. As %@NL@%
- %@AB@%* soon as any DDE message is received by the DDE server window, its %@NL@%
- %@AB@%* companion client hwnd is remembered and the conversation is 'locked in'. %@NL@%
- %@AB@%* The hwnd of the server window is returned. hszApp and hszTopic cannot %@NL@%
- %@AB@%* be NULL. %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* Typically, the server app would call CreateServerWindow() and pass the %@NL@%
- %@AB@%* hwnd to some prospective client via some other transport mechanism. The %@NL@%
- %@AB@%* client would then call ConverseWithWindow() with the hwnd it received %@NL@%
- %@AB@%* from the server and then begin DDE transactions using the HCONV returned. %@NL@%
- %@AB@%* %@NL@%
- %@AB@%* A server may pass this hwnd to many potential clients. Only the first %@NL@%
- %@AB@%* one that responds would get 'locked in'. The rest would be out of luck %@NL@%
- %@AB@%* and their API calls would fail. The server window ignores messages that%@NL@%
- %@AB@%* to not fit the app and topic given.%@NL@%
- %@AB@%* %@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%\****************************************************************************/%@AE@%%@NL@%
- HWND EXPENTRY DdeCreateServerWindow(hszApp, hszTopic, pCC)%@NL@%
- HSZ hszApp, hszTopic;%@NL@%
- PCONVCONTEXT pCC;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- INITINFO ii;%@NL@%
- HWND hwndServer;%@NL@%
- %@NL@%
- hszApp;%@NL@%
- hszTopic;%@NL@%
- pCC;%@NL@%
- %@NL@%
- if ((pai = GetCurrentAppInfo(TRUE)) == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- if (QuerylatomLength((LATOM)hszApp) == 0 ||%@NL@%
- QuerylatomLength((LATOM)hszTopic) == 0) {%@NL@%
- pai->LastError = DMGERR_INVALIDPARAMETER;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- if ((hwndServer = CreateServerWindow(pai, hszTopic)) == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- ii.hszAppName = hszApp;%@NL@%
- ii.hszTopic = hszTopic;%@NL@%
- ii.hwndSend =%@NL@%
- ii.hwndFrame = NULL;%@NL@%
- ii.pCC = pCC;%@NL@%
- WinSendMsg(hwndServer, UMSR_INITIATE, 0L, 0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DDESPY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DDESPY\DDESPY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: ddespy%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This is a small DDE ddespyr which lets me see whats going on.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: sanfords%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@AI@%#include %@AE@%"ddespy.h" %@NL@%
- %@NL@%
- %@AB@%/*********** declares *********/%@AE@%%@NL@%
- %@NL@%
- HWND hwndExec = NULL;%@NL@%
- %@NL@%
- SWP gswp[IW_LAST - IW_FIRST + 1];%@NL@%
- PSZ apszTitles[] = {%@NL@%
- "Applications", "Topics", "System Items", "Data"%@NL@%
- };%@NL@%
- %@NL@%
- %@NL@%
- PSZ apszType[] = {%@NL@%
- "0-Type" ,%@NL@%
- "ACK" ,%@NL@%
- "ADVDATA" , %@NL@%
- "ADVREQ" , %@NL@%
- "ADVSTART" , %@NL@%
- "ADVSTOP" , %@NL@%
- "EXEC" , %@NL@%
- "INIT" ,%@NL@%
- "INITCONF" ,%@NL@%
- "MONITOR" ,%@NL@%
- "PKT" ,%@NL@%
- "POKE" ,%@NL@%
- "REGISTER" , %@NL@%
- "REQUEST" ,%@NL@%
- "RTNPKT" ,%@NL@%
- "TERM" , %@NL@%
- "UNREGISTER" ,%@NL@%
- "WILDINIT" ,%@NL@%
- "XFERCOMP" ,%@NL@%
- "19" ,%@NL@%
- "20" ,%@NL@%
- "21" ,%@NL@%
- "22" ,%@NL@%
- "23" ,%@NL@%
- "24" ,%@NL@%
- "25" ,%@NL@%
- "26" ,%@NL@%
- "27" ,%@NL@%
- "28" ,%@NL@%
- "29" ,%@NL@%
- "30" ,%@NL@%
- "31" ,%@NL@%
- };%@NL@%
- %@NL@%
- PSZ apszState[] = { %@AB@%/* corresponds to convinfo.usStatus */%@AE@%%@NL@%
- "DISCONNECTED" ,%@NL@%
- "CONNECTED" ,%@NL@%
- "NOADVISE" ,%@NL@%
- "ADVISE" ,%@NL@%
- };%@NL@%
- %@NL@%
- PSZ apszStatus[] = { %@AB@%/* corresponds to convionfi.usConvst */%@AE@%%@NL@%
- "NOACTIVITY" , %@NL@%
- "INCOMPLETE" , %@NL@%
- "TERMINATED" , %@NL@%
- "CONNECTED" ,%@NL@%
- "INITIATING" , %@NL@%
- "REQSENT" , %@NL@%
- "DATARCVD" , %@NL@%
- "POKESENT" , %@NL@%
- "POKEACKRCVD" , %@NL@%
- "EXECSENT" , %@NL@%
- "EXECACKRCVD" , %@NL@%
- "ADVSENT" , %@NL@%
- "UNADVSENT" , %@NL@%
- "ADVACKRCVD" , %@NL@%
- "UNADVACKRCVD" , %@NL@%
- "ADVDATASENT" , %@NL@%
- "ADVDATAACKRCVD",%@NL@%
- };%@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%GetLBCount(hw) (SHORT)WinSendMsg((hw), LM_QUERYITEMCOUNT, 0L, 0L) %@NL@%
- %@AI@%#define %@AE@%GetLBSelectedItem(hw) \ %@NL@%
- (SHORT)WinSendMsg((hw), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, 0L)%@NL@%
- %@AI@%#define %@AE@%GetLBItemHandle(hw, i) \ %@NL@%
- (ULONG)WinSendMsg((hw), LM_QUERYITEMHANDLE, (MPARAM)(i), 0L)%@NL@%
- %@AI@%#define %@AE@%GetLBItemText(hw, i, cch, psz) \ %@NL@%
- (ULONG)WinSendMsg((hw), LM_QUERYITEMTEXT, MPFROM2SHORT((i),(cch)), (MPARAM)(psz))%@NL@%
- %@AI@%#define %@AE@%DeleteLBItem(hw, i) WinSendMsg(hw, LM_DELETEITEM, MPFROMSHORT(i), 0L) %@NL@%
- %@AI@%#define %@AE@%NotifyOwner(hwnd, msg, mp1, mp2) \ %@NL@%
- (WinSendMsg(WinQueryWindow(hwnd, QW_OWNER, FALSE), msg, mp1, mp2))%@NL@%
- %@NL@%
- %@NL@%
- void cdecl main(int argc, char **argv);%@NL@%
- void ResizeChildren(USHORT cxNew, USHORT cyNew);%@NL@%
- HDMGDATA EXPENTRY dataxfer(HCONV hConv, HSZ hszTopic, HSZ hszItem,%@NL@%
- USHORT usFmt, USHORT usType, HDMGDATA hDmgData);%@NL@%
- MRESULT EXPENTRY ClientWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);%@NL@%
- MRESULT EXPENTRY GetTimeoutDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);%@NL@%
- MRESULT EXPENTRY EnhancedEFWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);%@NL@%
- MRESULT EXPENTRY ExecDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);%@NL@%
- void Refresh(void);%@NL@%
- SHORT InsertLBItem(HWND hwndLB, PSZ psz, ULONG ulHandle);%@NL@%
- void SetLBEntries(HCONV hConv, HSZ hszItem, USHORT iwlb);%@NL@%
- void UpdateQueue(HWND hwndCB, HCONV hConv);%@NL@%
- void ConvInfoToString(PCONVINFO pci, PSZ psz, USHORT cbMax);%@NL@%
- PSZ mylstrcat(PSZ psz1, PSZ psz2, PSZ pszLast);%@NL@%
- int lstrlen(PSZ psz);%@NL@%
- %@NL@%
- %@AB@%/************* GLOBAL VARIABLES ************/%@AE@%%@NL@%
- %@NL@%
- HAB hab;%@NL@%
- HMQ hmq;%@NL@%
- HHEAP hheap;%@NL@%
- HWND hwndFrame;%@NL@%
- HWND hwndClient;%@NL@%
- USHORT cyTitles;%@NL@%
- USHORT cxBorder;%@NL@%
- HCONVLIST hConvListMain;%@NL@%
- HSZ hszSysTopic;%@NL@%
- HSZ hszSysItemTopics;%@NL@%
- HSZ hszSysItemSysItems;%@NL@%
- ULONG gTimeout = 1000L;%@NL@%
- PFNWP lpfnSysEFWndProc;%@NL@%
- %@NL@%
- void cdecl main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- USHORT err;%@NL@%
- QMSG qmsg;%@NL@%
- %@NL@%
- argc; argv;%@NL@%
- %@NL@%
- hab = WinInitialize(0);%@NL@%
- hmq = WinCreateMsgQueue(hab, 0);%@NL@%
- hheap = WinCreateHeap(0, 0, 0, 0, 0, HM_MOVEABLE);%@NL@%
- %@NL@%
- if (!WinRegisterClass(hab, "DDESpyr Class", ClientWndProc, CS_SIZEREDRAW, 0))%@NL@%
- goto abort;%@NL@%
- %@NL@%
- cyTitles = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);%@NL@%
- cxBorder = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);%@NL@%
- %@NL@%
- hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, NULL,%@NL@%
- (PSZ)"DDESpyr Class",%@NL@%
- (PSZ)"", WS_VISIBLE, (HMODULE)NULL, IDR_MAIN,%@NL@%
- &hwndClient);%@NL@%
- %@NL@%
- WinSetWindowText(hwndFrame, "DDE Spy");%@NL@%
- if (err = DdeInitialize((PFNCALLBACK)dataxfer, 0L, 0L)) {%@NL@%
- DdePostError(err);%@NL@%
- goto abort;%@NL@%
- }%@NL@%
- %@NL@%
- hszSysTopic = DdeGetHsz((PSZ)SZDDESYS_TOPIC, 0, 0);%@NL@%
- hszSysItemTopics = DdeGetHsz((PSZ)SZDDESYS_ITEM_TOPICS, 0, 0);%@NL@%
- hszSysItemSysItems = DdeGetHsz((PSZ)SZDDESYS_ITEM_SYSITEMS, 0, 0);%@NL@%
- %@NL@%
- Refresh();%@NL@%
- %@NL@%
- while (WinGetMsg(hab, &qmsg, 0, 0, 0)) {%@NL@%
- WinDispatchMsg(hab, &qmsg);%@NL@%
- }%@NL@%
- %@NL@%
- DdeUninitialize();%@NL@%
- abort:%@NL@%
- if (hwndFrame)%@NL@%
- WinDestroyWindow(hwndFrame);%@NL@%
- if (hheap) {%@NL@%
- WinDestroyHeap(hheap);%@NL@%
- }%@NL@%
- WinTerminate(hab);%@NL@%
- DosExit(TRUE, 0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY ClientWndProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1, mp2;%@NL@%
- {%@NL@%
- USHORT i;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_CREATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * initialize globals%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndClient = hwnd;%@NL@%
- for (i = IW_APPSLBOX; i <= IW_ITEMSLBOX; i++) {%@NL@%
- gswp[i].hwnd = WinCreateWindow(hwndClient, WC_LISTBOX, "",%@NL@%
- WS_VISIBLE | LS_NOADJUSTPOS, 0, 0, 0, 0, hwndClient,%@NL@%
- HWND_TOP, i, NULL, NULL);%@NL@%
- }%@NL@%
- for (i = IW_APPSTITLE; i <= IW_DATATITLE; i++) {%@NL@%
- gswp[i].hwnd = WinCreateWindow(hwndClient, WC_STATIC,%@NL@%
- apszTitles[i - IW_APPSTITLE],%@NL@%
- WS_VISIBLE | SS_TEXT | DT_CENTER | DT_BOTTOM,%@NL@%
- 0, 0, 0, 0, hwndClient,%@NL@%
- HWND_TOP, i, NULL, NULL);%@NL@%
- }%@NL@%
- gswp[IW_DATATEXT].hwnd = WinCreateWindow(hwndClient, WC_STATIC, "",%@NL@%
- WS_VISIBLE | SS_TEXT | DT_WORDBREAK,%@NL@%
- 0, 0, 0, 0, hwndClient,%@NL@%
- HWND_TOP, i, NULL, NULL);%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (LOUSHORT(mp1)) {%@NL@%
- case IDM_REFRESH:%@NL@%
- Refresh();%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_SETTIMEOUT:%@NL@%
- gTimeout = (USHORT)WinDlgBox(hwndFrame, NULL,%@NL@%
- (PFNWP)GetTimeoutDlgProc,%@NL@%
- (HMODULE)NULL, IDD_GETTIMEOUT, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_EXEC:%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, ExecDlgProc, NULL, IDD_EXEC, NULL);%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CONTROL:%@NL@%
- switch (LOUSHORT(mp1)) {%@NL@%
- case IW_APPSLBOX:%@NL@%
- switch (HIUSHORT(mp1)) {%@NL@%
- case LN_SELECT:%@NL@%
- hwnd = gswp[IW_APPSLBOX].hwnd;%@NL@%
- SetLBEntries((HCONV)GetLBItemHandle(hwnd,%@NL@%
- GetLBSelectedItem(hwnd)),%@NL@%
- hszSysItemTopics, IW_TOPICSLBOX);%@NL@%
- SetLBEntries((HCONV)GetLBItemHandle(hwnd,%@NL@%
- GetLBSelectedItem(hwnd)),%@NL@%
- hszSysItemSysItems, IW_ITEMSLBOX);%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case IW_TOPICSLBOX:%@NL@%
- break;%@NL@%
- %@NL@%
- case IW_ITEMSLBOX:%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- goto DoDefAction;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_SIZE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * resize children%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ResizeChildren(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_ERASEBACKGROUND:%@NL@%
- return(TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- DoDefAction:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- }%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void ResizeChildren(cxNew, cyNew)%@NL@%
- USHORT cxNew, cyNew;%@NL@%
- {%@NL@%
- USHORT i;%@NL@%
- %@NL@%
- for (i = IW_FIRST; i <= IW_LAST; i++) {%@NL@%
- gswp[i].fs = SWP_SIZE | SWP_MOVE | SWP_SHOW;%@NL@%
- gswp[i].hwndInsertBehind = HWND_TOP;%@NL@%
- }%@NL@%
- %@NL@%
- for (i = IW_APPSTITLE; i <= IW_ITEMSTITLE; i++) {%@NL@%
- gswp[i].x =%@NL@%
- gswp[i - IW_APPSTITLE + IW_APPSLBOX].x = i == IW_APPSTITLE ? -cxBorder :%@NL@%
- gswp[i - 1].x + gswp[i - 1].cx - cxBorder;%@NL@%
- %@NL@%
- gswp[i].y = cyNew - cyTitles;%@NL@%
- gswp[i - IW_APPSTITLE + IW_APPSLBOX].y = cyNew / 2;%@NL@%
- %@NL@%
- gswp[i].cx =%@NL@%
- gswp[i - IW_APPSTITLE + IW_APPSLBOX].cx = cxNew / 3;%@NL@%
- %@NL@%
- gswp[i].cy = cyTitles;%@NL@%
- gswp[i - IW_APPSTITLE + IW_APPSLBOX].cy = (cyNew / 2) - cyTitles;%@NL@%
- }%@NL@%
- %@NL@%
- gswp[IW_ITEMSLBOX].cx = cxNew - gswp[IW_ITEMSLBOX].x + cxBorder;%@NL@%
- %@NL@%
- gswp[IW_DATATITLE].cy = cyTitles;%@NL@%
- gswp[IW_DATATITLE].y =%@NL@%
- gswp[IW_DATATEXT].cy = cyNew / 2 - cyTitles;%@NL@%
- %@NL@%
- gswp[IW_DATATITLE].cx =%@NL@%
- gswp[IW_DATATEXT].cx = cxNew;%@NL@%
- %@NL@%
- WinSetMultWindowPos(hab, gswp, IW_DATATEXT - IW_APPSTITLE + 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void Refresh()%@NL@%
- {%@NL@%
- HCONV hConv;%@NL@%
- register NPSZ npszAppName;%@NL@%
- CONVINFO ci;%@NL@%
- USHORT cb;%@NL@%
- %@NL@%
- WinLockWindowUpdate(HWND_DESKTOP, gswp[IW_APPSLBOX].hwnd);%@NL@%
- WinSendMsg(gswp[IW_APPSLBOX].hwnd, LM_DELETEALL, 0L, 0L);%@NL@%
- WinSendMsg(gswp[IW_TOPICSLBOX].hwnd, LM_DELETEALL, 0L, 0L);%@NL@%
- WinSendMsg(gswp[IW_ITEMSLBOX].hwnd, LM_DELETEALL, 0L, 0L);%@NL@%
- %@NL@%
- hConvListMain = DdeBeginEnumServers(0L, hszSysTopic, hConvListMain, NULL, NULL);%@NL@%
- if (hConvListMain) {%@NL@%
- hConv = 0;%@NL@%
- while (hConv = DdeGetNextServer(hConvListMain, hConv)) {%@NL@%
- DdeQueryConvInfo(hConv, &ci, QID_SYNC);%@NL@%
- if (ci.hszAppPartner != 0) {%@NL@%
- cb = DdeGetHszString(ci.hszAppPartner, NULL, 0L) + 1;%@NL@%
- npszAppName = WinAllocMem(hheap, cb);%@NL@%
- DdeGetHszString(ci.hszAppPartner, (PSZ)npszAppName, (ULONG)cb);%@NL@%
- InsertLBItem(gswp[IW_APPSLBOX].hwnd, (PSZ)npszAppName,%@NL@%
- (ULONG)hConv);%@NL@%
- WinFreeMem(hheap, npszAppName, cb);%@NL@%
- } else {%@NL@%
- InsertLBItem(gswp[IW_APPSLBOX].hwnd, SZINDETERMINATE,%@NL@%
- (ULONG)hConv);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- WinLockWindowUpdate(HWND_DESKTOP, NULL);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- SHORT InsertLBItem(hwndLB, psz, ulHandle)%@NL@%
- HWND hwndLB;%@NL@%
- PSZ psz;%@NL@%
- ULONG ulHandle;%@NL@%
- {%@NL@%
- SHORT ili;%@NL@%
- %@NL@%
- ili = (SHORT)WinSendMsg(hwndLB, LM_INSERTITEM, (MPARAM)LIT_SORTASCENDING,%@NL@%
- (MPARAM)psz);%@NL@%
- WinSendMsg(hwndLB, LM_SETITEMHANDLE, MPFROMSHORT(ili), (MPARAM)ulHandle);%@NL@%
- return(ili);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void SetLBEntries(hConv, hszItem, iwlb)%@NL@%
- HCONV hConv;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT iwlb;%@NL@%
- {%@NL@%
- NPSZ npsz, npszT1, npszT2;%@NL@%
- BOOL fDone = 0;%@NL@%
- ULONG cb;%@NL@%
- HDMGDATA hDmgData;%@NL@%
- %@NL@%
- hDmgData = DdeClientXfer(0L, 0L, hConv, hszItem, DDEFMT_TEXT,%@NL@%
- XTYP_REQUEST, gTimeout, NULL);%@NL@%
- %@NL@%
- if (hDmgData == 0) {%@NL@%
- DdePostError(DdeGetLastError());%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- cb = DdeGetData(hDmgData, NULL, 0L, 0L);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * BUG - may later want to handle the case for cb > 0xFFFF%@NL@%
- %@AB@% */%@AE@%%@NL@%
- npsz = WinAllocMem(hheap, (USHORT)cb);%@NL@%
- if (npsz == NULL) {%@NL@%
- DdePostError(DMGERR_MEMORY_ERROR);%@NL@%
- return;%@NL@%
- }%@NL@%
- if (DdeGetData(hDmgData, (PBYTE)npsz, cb, 0L) == 0) {%@NL@%
- DdePostError(DdeGetLastError());%@NL@%
- goto Exit;%@NL@%
- }%@NL@%
- npszT1 = npszT2 = npsz;%@NL@%
- WinLockWindowUpdate(HWND_DESKTOP, gswp[iwlb].hwnd);%@NL@%
- WinSendMsg(gswp[iwlb].hwnd, LM_DELETEALL, 0L, 0L);%@NL@%
- while (!fDone) {%@NL@%
- while (*npszT2 != '\t' && *npszT2 != '\0')%@NL@%
- npszT2++;%@NL@%
- if (*npszT2 == '\t') {%@NL@%
- *npszT2 = '\0';%@NL@%
- npszT2++;%@NL@%
- } else%@NL@%
- fDone = TRUE;%@NL@%
- InsertLBItem(gswp[iwlb].hwnd, (PSZ)npszT1,%@NL@%
- (ULONG)DdeGetHsz(npszT1, 0, 0));%@NL@%
- npszT1 = npszT2;%@NL@%
- }%@NL@%
- WinLockWindowUpdate(HWND_DESKTOP, NULL);%@NL@%
- %@NL@%
- Exit:%@NL@%
- WinFreeMem(hheap, (NPBYTE)npsz, (USHORT)cb);%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- HDMGDATA EXPENTRY dataxfer(hConv, hszTopic, hszItem, usFmt, usType,%@NL@%
- hDmgData)%@NL@%
- HCONV hConv;%@NL@%
- HSZ hszTopic;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT usFmt;%@NL@%
- USHORT usType;%@NL@%
- HDMGDATA hDmgData;%@NL@%
- {%@NL@%
- hConv; hszTopic; hszItem; usFmt; usType; hDmgData;%@NL@%
- %@NL@%
- switch (usType) {%@NL@%
- case XTYP_XFERCOMPLETE:%@NL@%
- if (hwndExec) {%@NL@%
- if (DdeCheckQueue(hConv, &hDmgData, (ULONG)hDmgData, 0L)) {%@NL@%
- PSZ psz;%@NL@%
- if (psz = (PSZ)DdeAccessData(hDmgData)) {%@NL@%
- WinSetDlgItemText(hwndExec, IDEF_DATA, psz);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Free this data here.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DdeFreeData(hDmgData);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY GetTimeoutDlgProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- USHORT usValue;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_INITDLG: %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * set up our entryfield to be enhanced.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSetDlgItemShort(hwnd, IDC_EF, (USHORT)gTimeout, FALSE);%@NL@%
- lpfnSysEFWndProc = WinSubclassWindow(WinWindowFromID(hwnd, IDC_EF),%@NL@%
- EnhancedEFWndProc);%@NL@%
- break;%@NL@%
- %@NL@%
- case ENHAN_ENTER:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * when the user hits the enter key, it will be passed from the%@NL@%
- %@AB@% * entryfield to here and we will use it as a signal to exit.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryDlgItemShort(hwnd, IDC_EF, &usValue, FALSE);%@NL@%
- WinDismissDlg(hwnd, usValue);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT EXPENTRY EnhancedEFWndProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch (msg) {%@NL@%
- case WM_CHAR:%@NL@%
- if (LOUSHORT(mp1) & KC_SCANCODE &&%@NL@%
- LOUSHORT(mp1) & KC_KEYUP &&%@NL@%
- %@AB@%/*---HACK ALERT!---*/%@AE@%%@NL@%
- LOBYTE(LOUSHORT(mp2)) == 0x0d) {%@NL@%
- NotifyOwner(hwnd, ENHAN_ENTER,%@NL@%
- (MPARAM)WinQueryWindowUShort(hwnd, QWS_ID), 0L);%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- return(lpfnSysEFWndProc(hwnd, msg, mp1, mp2));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY ExecDlgProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- static UCHAR szT[255];%@NL@%
- static HCONV hConv = NULL;%@NL@%
- register USHORT i;%@NL@%
- USHORT cb;%@NL@%
- register USHORT xtyp;%@NL@%
- HDMGDATA hDmgData;%@NL@%
- HSZ hszApp, hszItem, hszTopic;%@NL@%
- BOOL fAssync;%@NL@%
- ULONG xid;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_INITDLG:%@NL@%
- hwndExec = hwnd;%@NL@%
- WinSendDlgItemMsg(hwnd, IDEF_DATA, EM_SETTEXTLIMIT, (MPARAM)MAX_QSTRING, 0L);%@NL@%
- WinSendDlgItemMsg(hwnd, IDCB_QDATA, EM_SETTEXTLIMIT, (MPARAM)MAX_QSTRING, 0L);%@NL@%
- if ((i = GetLBSelectedItem(gswp[IW_APPSLBOX].hwnd)) != LIT_NONE) {%@NL@%
- GetLBItemText(gswp[IW_APPSLBOX].hwnd, i, 255, szT);%@NL@%
- WinSetDlgItemText(hwnd, IDEF_APP, szT);%@NL@%
- }%@NL@%
- if ((i = GetLBSelectedItem(gswp[IW_TOPICSLBOX].hwnd)) != LIT_NONE) {%@NL@%
- GetLBItemText(gswp[IW_TOPICSLBOX].hwnd, i, 255, szT);%@NL@%
- WinSetDlgItemText(hwnd, IDEF_TOPIC, szT);%@NL@%
- }%@NL@%
- if ((i = GetLBSelectedItem(gswp[IW_ITEMSLBOX].hwnd)) != LIT_NONE) {%@NL@%
- GetLBItemText(gswp[IW_ITEMSLBOX].hwnd, i, 255, szT);%@NL@%
- WinSetDlgItemText(hwnd, IDEF_ITEM, szT);%@NL@%
- }%@NL@%
- WinSendDlgItemMsg(hwnd, IDRB_REQUEST, BM_CLICK, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CONTROL:%@NL@%
- case WM_COMMAND:%@NL@%
- switch (LOUSHORT(mp1)) {%@NL@%
- case MBID_CANCEL:%@NL@%
- if (hConv != NULL)%@NL@%
- DdeDisconnect(hConv);%@NL@%
- hConv = NULL;%@NL@%
- WinDismissDlg(hwnd, 0);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDC_QFLUSH:%@NL@%
- DdeCheckQueue(hConv, NULL, QID_NEWEST, CQ_FLUSH);%@NL@%
- WinSetDlgItemText(hwnd, IDCB_QDATA, "");%@NL@%
- UpdateQueue(WinWindowFromID(hwnd, IDCB_QDATA), hConv);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDC_QUPDATE:%@NL@%
- UpdateQueue(WinWindowFromID(hwnd, IDCB_QDATA), hConv);%@NL@%
- WinSendDlgItemMsg(hwnd, IDCB_QDATA, CBM_SHOWLIST, (MPARAM)TRUE, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDC_DOIT:%@NL@%
- i = (USHORT)WinSendDlgItemMsg(hwnd, IDRB_ADVSTART,%@NL@%
- BM_QUERYCHECKINDEX, 0L, 0L) + IDRB_ADVSTART;%@NL@%
- WinQueryDlgItemText(hwnd, IDEF_APP, 255, szT);%@NL@%
- hszApp = DdeGetHsz(szT, 0, 0);%@NL@%
- WinQueryDlgItemText(hwnd, IDEF_TOPIC, 255, szT);%@NL@%
- hszTopic = DdeGetHsz(szT, 0, 0);%@NL@%
- WinQueryDlgItemText(hwnd, IDEF_ITEM, 255, szT);%@NL@%
- hszItem = DdeGetHsz(szT, 0, 0);%@NL@%
- if (i != IDRB_REQUEST) {%@NL@%
- WinQueryDlgItemText(hwnd, IDEF_DATA, 255, szT);%@NL@%
- cb = WinQueryDlgItemTextLength(hwnd, IDEF_DATA);%@NL@%
- }%@NL@%
- if (hConv == NULL && !(hConv = DdeConnect(hszApp, hszTopic, NULL, 0L))) {%@NL@%
- DdePostError(DdeGetLastError());%@NL@%
- if (LOUSHORT(mp1) == MBID_OK)%@NL@%
- WinDismissDlg(hwnd, 0);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- switch (i) {%@NL@%
- case IDRB_REQUEST:%@NL@%
- xtyp = XTYP_REQUEST;%@NL@%
- goto XferOut;%@NL@%
- break;%@NL@%
- case IDRB_ADVSTART:%@NL@%
- xtyp = XTYP_ADVSTART;%@NL@%
- goto XferOut;%@NL@%
- break;%@NL@%
- case IDRB_ADVSTOP:%@NL@%
- xtyp = XTYP_ADVSTOP;%@NL@%
- goto XferOut;%@NL@%
- break;%@NL@%
- case IDRB_POKE:%@NL@%
- xtyp = XTYP_POKE;%@NL@%
- goto XferOut;%@NL@%
- break;%@NL@%
- case IDRB_EXECUTE:%@NL@%
- xtyp = XTYP_EXEC;%@NL@%
- XferOut:%@NL@%
- fAssync = (BOOL)WinSendDlgItemMsg(hwnd, IDCBX_ASSYNC,%@NL@%
- BM_QUERYCHECK, 0L, 0L);%@NL@%
- if (!(hDmgData = DdeClientXfer((PBYTE)szT, (ULONG)cb + 1,%@NL@%
- hConv, hszItem, DDEFMT_TEXT, xtyp,%@NL@%
- fAssync ? TIMEOUT_ASYNC : gTimeout, &xid)))%@NL@%
- DdePostError(DdeGetLastError());%@NL@%
- %@NL@%
- if (fAssync) {%@NL@%
- UpdateQueue(WinWindowFromID(hwnd, IDCB_QDATA), hConv);%@NL@%
- } else {%@NL@%
- if (i == IDRB_REQUEST) {%@NL@%
- DdeGetData(hDmgData, szT, 255L, 0L);%@NL@%
- DdeFreeData(hDmgData);%@NL@%
- WinSetWindowText(gswp[IW_DATATEXT].hwnd, szT);%@NL@%
- WinSetDlgItemText(hwnd, IDEF_DATA, szT);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- hwndExec = NULL;%@NL@%
- default:%@NL@%
- return(WinDefDlgProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void UpdateQueue(hwndCB, hConv)%@NL@%
- HWND hwndCB;%@NL@%
- HCONV hConv;%@NL@%
- {%@NL@%
- SHORT lit;%@NL@%
- SHORT litSel = LIT_FIRST;%@NL@%
- CONVINFO ci;%@NL@%
- ULONG id, idSel;%@NL@%
- USHORT cItems;%@NL@%
- char szT[MAX_QSTRING];%@NL@%
- %@NL@%
- lit = (SHORT)WinSendMsg(hwndCB, LM_QUERYSELECTION,%@NL@%
- MPFROMSHORT(LIT_FIRST), 0L);%@NL@%
- idSel = (SHORT)WinSendMsg(hwndCB, LM_QUERYITEMHANDLE, MPFROMSHORT(lit), 0L);%@NL@%
- WinSendMsg(hwndCB, LM_DELETEALL, 0L, 0L);%@NL@%
- cItems = (USHORT)DdeCheckQueue(hConv, NULL, QID_NEWEST, CQ_COUNT);%@NL@%
- id = DdeCheckQueue(hConv, NULL, QID_NEWEST, 0L);%@NL@%
- while (cItems--) {%@NL@%
- DdeQueryConvInfo(hConv, &ci, id);%@NL@%
- ConvInfoToString(&ci, szT, MAX_QSTRING);%@NL@%
- lit = (SHORT)WinSendMsg(hwndCB, LM_INSERTITEM, MPFROMSHORT(LIT_END), szT);%@NL@%
- WinSendMsg(hwndCB, LM_SETITEMHANDLE, MPFROMSHORT(lit), (MPARAM)id);%@NL@%
- if (id == idSel) %@NL@%
- litSel = lit;%@NL@%
- id = DdeCheckQueue(hConv, NULL, id, CQ_NEXT);%@NL@%
- }%@NL@%
- WinSendMsg(hwndCB, LM_SELECTITEM, MPFROMSHORT(litSel), (MPARAM)TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void ConvInfoToString(pci, psz, cbMax)%@NL@%
- PCONVINFO pci;%@NL@%
- PSZ psz;%@NL@%
- USHORT cbMax;%@NL@%
- {%@NL@%
- PSZ pszLast;%@NL@%
- char szT[100];%@NL@%
- %@NL@%
- pszLast = psz + cbMax - 1;%@NL@%
- *psz = '\0';%@NL@%
- psz = mylstrcat(psz, apszType[(pci->usType >> 4) && 0x1F], pszLast);%@NL@%
- psz = mylstrcat(psz, ": ", pszLast);%@NL@%
- psz = mylstrcat(psz, apszState[pci->usStatus & ST_CONNECTED ? 1 : 0], pszLast);%@NL@%
- psz = mylstrcat(psz, " ", pszLast);%@NL@%
- psz = mylstrcat(psz, apszState[pci->usStatus & ST_ADVISE ? 3 : 2], pszLast);%@NL@%
- psz = mylstrcat(psz, " ", pszLast);%@NL@%
- psz = mylstrcat(psz, apszStatus[pci->usConvst], pszLast);%@NL@%
- psz = mylstrcat(psz, " ", pszLast);%@NL@%
- if (pci->usFmt == DDEFMT_TEXT) {%@NL@%
- psz = mylstrcat(psz, "TEXT", pszLast);%@NL@%
- } else { %@NL@%
- DdeGetHszString(pci->hszItem, szT, 100L);%@NL@%
- psz = mylstrcat(psz, szT, pszLast);%@NL@%
- }%@NL@%
- psz = mylstrcat(psz, " ", pszLast);%@NL@%
- DdeGetHszString(pci->hszItem, szT, 100L);%@NL@%
- psz = mylstrcat(psz, szT, pszLast);%@NL@%
- %@NL@%
- if (pci->LastError) {%@NL@%
- psz = mylstrcat(psz, " ", pszLast);%@NL@%
- DdeGetErrorString(pci->LastError, pszLast - psz, psz);%@NL@%
- }%@NL@%
- pszLast = '\0';%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* Concatonates psz1 and psz2 into psz1.%@NL@%
- %@AB@%* returns psz pointing to end of concatonated string.%@NL@%
- %@AB@%* pszLast marks point at which copying must stop. This makes this operation%@NL@%
- %@AB@%* safe for limited buffer sizes.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ mylstrcat(psz1, psz2, pszLast)%@NL@%
- PSZ psz1, psz2, pszLast;%@NL@%
- {%@NL@%
- psz1 += lstrlen(psz1);%@NL@%
- while (*psz2 != '\0' && psz1 < pszLast) {%@NL@%
- *psz1++ = *psz2++;%@NL@%
- }%@NL@%
- *psz1 = '\0';%@NL@%
- return(psz1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns string length not counting null terminator.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- int lstrlen(psz)%@NL@%
- PSZ psz;%@NL@%
- {%@NL@%
- int c = 0;%@NL@%
- %@NL@%
- while (*psz != 0) {%@NL@%
- psz++;%@NL@%
- c++;%@NL@%
- }%@NL@%
- return(c);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DEMO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DEMO\DEMO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: demo.c - Demo application%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1987 Microsoft Corporation%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"demo.h" %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- %@AB@%/************* GLOBAL VARIABLES */%@AE@%%@NL@%
- %@NL@%
- char szDemoClass[] = "Demo";%@NL@%
- %@NL@%
- HAB hab;%@NL@%
- HMQ hmqDemo;%@NL@%
- HWND hwndDemo;%@NL@%
- HWND hwndDemoFrame;%@NL@%
- HCONV hconv = NULL;%@NL@%
- HSZ hszTitle, hszTopicChase, hszItemPos;%@NL@%
- USHORT fmtSWP;%@NL@%
- SWP SWPTarget = { 0 };%@NL@%
- PFNWP RealFrameProc;%@NL@%
- BOOL flee = FALSE;%@NL@%
- USHORT cServers = 0;%@NL@%
- USHORT cxScreen, cyScreen;%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TIMEOUT 100 %@NL@%
- %@AI@%#define %@AE@%TIMERSPEED 1000 %@NL@%
- %@NL@%
- %@AB@%/**************************************/%@AE@%%@NL@%
- %@NL@%
- VOID CommandMsg(USHORT cmd)%@NL@%
- {%@NL@%
- UNUSED cmd;%@NL@%
- }%@NL@%
- %@NL@%
- BOOL DemoInit()%@NL@%
- {%@NL@%
- hab = WinInitialize(0);%@NL@%
- %@NL@%
- hmqDemo = WinCreateMsgQueue(hab, 0);%@NL@%
- %@NL@%
- cxScreen = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);%@NL@%
- cyScreen = (USHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);%@NL@%
- srand(2);%@NL@%
- %@NL@%
- if (!WinRegisterClass(hab, szDemoClass, (PFNWP)DemoWndProc,%@NL@%
- CS_SIZEREDRAW, 0))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Initialize the ddeml%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (DdeInitialize((PFNCALLBACK)callback, 0L, 0L))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Now create HSZs for each of our DDE strings.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fmtSWP = WinAddAtom(WinQuerySystemAtomTable(), "SWP FORMAT");%@NL@%
- hszTitle = DdeGetHsz("Demo", 0, 0);%@NL@%
- hszTopicChase = DdeGetHsz("Chaser", 0, 0);%@NL@%
- hszItemPos = DdeGetHsz("Position", 0, 0);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * let others know we are here - available as a server and turn on%@NL@%
- %@AB@% * filtering so we don't get bothered with any initiates for any%@NL@%
- %@AB@% * other app names.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DdeAppNameServer(hszTitle, ANS_REGISTER | ANS_FILTERON);%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- int cdecl main(int argc, char** argv)%@NL@%
- {%@NL@%
- ULONG fcf;%@NL@%
- QMSG qmsg;%@NL@%
- %@NL@%
- UNUSED argc;%@NL@%
- UNUSED argv;%@NL@%
- %@NL@%
- if (!DemoInit()) {%@NL@%
- WinAlarm(HWND_DESKTOP, WA_ERROR);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- fcf = FCF_STANDARD;%@NL@%
- %@NL@%
- hwndDemoFrame = WinCreateStdWindow(%@NL@%
- HWND_DESKTOP,%@NL@%
- WS_VISIBLE,%@NL@%
- &fcf,%@NL@%
- szDemoClass,%@NL@%
- "",%@NL@%
- WS_VISIBLE, %@NL@%
- NULL,%@NL@%
- IDR_DEMO,%@NL@%
- &hwndDemo);%@NL@%
- %@NL@%
- WinSetFocus(HWND_DESKTOP, hwndDemo);%@NL@%
- %@NL@%
- while (WinGetMsg(hab, (PQMSG)&qmsg, NULL, 0, 0)) {%@NL@%
- WinDispatchMsg(hab, (PQMSG)&qmsg);%@NL@%
- }%@NL@%
- %@NL@%
- WinDestroyWindow(hwndDemoFrame);%@NL@%
- %@NL@%
- WinDestroyMsgQueue(hmqDemo);%@NL@%
- WinTerminate(hab);%@NL@%
- %@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/********** Demo Window Procedure **************/%@AE@%%@NL@%
- %@NL@%
- MRESULT FAR PASCAL DemoWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- RECTL rclPaint;%@NL@%
- SWP swp;%@NL@%
- SHORT speed;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_CREATE:%@NL@%
- %@AB@%/* Set up this global first thing in case we need it elsewhere */%@AE@%%@NL@%
- hwndDemo = hwnd;%@NL@%
- hwndDemoFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);%@NL@%
- RealFrameProc = WinSubclassWindow(hwndDemoFrame, DemoFrameWndProc);%@NL@%
- WinSetWindowPos(hwndDemoFrame, NULL, 0, 0, 0, 0, SWP_MINIMIZE | SWP_SHOW);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * start the timer so we will keep looking for another app like ours%@NL@%
- %@AB@% * to chase.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinStartTimer(hab, hwndDemo, 1, TIMERSPEED);%@NL@%
- return(MRFROMSHORT(FALSE));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_TIMER:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We use a timer to keep us moving.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!hconv) {%@NL@%
- HDMGDATA hData;%@NL@%
- PHSZHAPP phszhapp;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * no active conversation, try to make one.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinStopTimer(hab, hwndDemo, 1);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * find out if any others like us are out there%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hData = DdeAppNameServer(hszTitle, ANS_QUERYALLBUTME);%@NL@%
- if (!hData) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * wait till others arrive.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * extract the first hApp from the hData so we can connect to it%@NL@%
- %@AB@% */%@AE@%%@NL@%
- phszhapp = (PHSZHAPP)DdeAccessData(hData);%@NL@%
- if (phszhapp->hsz == 0) {%@NL@%
- DdeFreeData(hData);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * perform directed connection to our target%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hconv = DdeConnect(hszTitle, hszTopicChase, NULL, phszhapp->hApp);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * free the hData now that we are done using it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DdeFreeData(hData);%@NL@%
- WinStartTimer(hab, hwndDemo, 1, TIMERSPEED);%@NL@%
- if (!hconv) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * cant make one, try again later.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Get the target's position into SWPTarget.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hData = DdeClientXfer(NULL, 0L, hconv, hszItemPos, fmtSWP,%@NL@%
- XTYP_REQUEST, TIMEOUT, NULL)) {%@NL@%
- DdeCopyBlock(DdeAccessData(hData), (PBYTE)&SWPTarget,%@NL@%
- sizeof(SWP));%@NL@%
- DdeFreeData(hData);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * set up an advise loop so our moving target keeps us informed%@NL@%
- %@AB@% * of where he is.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DdeClientXfer(NULL, 0L, hconv, hszItemPos, fmtSWP,%@NL@%
- XTYP_ADVSTART, TIMEOUT, NULL);%@NL@%
- }%@NL@%
- %@NL@%
- if (WinIsWindow(hab, SWPTarget.hwnd)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * target data must be valid, move toward it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- speed = 1;%@NL@%
- WinQueryWindowPos(hwndDemoFrame, &swp);%@NL@%
- if (swp.x > SWPTarget.x) %@NL@%
- swp.x -= speed;%@NL@%
- if (swp.x < SWPTarget.x)%@NL@%
- swp.x += speed;%@NL@%
- if (swp.y > SWPTarget.y) %@NL@%
- swp.y -= speed;%@NL@%
- if (swp.y < SWPTarget.y)%@NL@%
- swp.y += speed;%@NL@%
- swp.fs = SWP_MOVE | SWP_NOADJUST;%@NL@%
- WinSetMultWindowPos(hab, &swp, 1);%@NL@%
- if ((swp.x == SWPTarget.x) && (swp.y == SWPTarget.y) && (!flee)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * he's cought stop chasing him and go find another.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinAlarm(HWND_DESKTOP, WA_NOTE);%@NL@%
- DdeDisconnect(hconv);%@NL@%
- hconv = NULL;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * move to a random position%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSetWindowPos(hwndDemoFrame, HWND_TOP, rand() % cxScreen,%@NL@%
- rand() % cyScreen, 0, 0,%@NL@%
- SWP_MOVE | SWP_ZORDER | SWP_NOADJUST);%@NL@%
- }%@NL@%
- } else if (hconv) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Target is invalid, disconnect and try a reconnect later.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DdeDisconnect(hconv);%@NL@%
- hconv = NULL;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- hps = WinBeginPaint(hwnd, (HPS)NULL, &rclPaint);%@NL@%
- DemoPaint(hwnd, hps, &rclPaint);%@NL@%
- WinEndPaint(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- CommandMsg(LOUSHORT(mp1));%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- MRESULT FAR PASCAL DemoFrameWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- switch (msg) {%@NL@%
- case WM_MOVE:%@NL@%
- DdePostAdvise(hszTopicChase, hszItemPos);%@NL@%
- %@AB@%/* fall through */%@AE@%%@NL@%
- default:%@NL@%
- return(RealFrameProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- VOID DemoPaint(HWND hwnd, HPS hps, RECTL* prcl)%@NL@%
- {%@NL@%
- RECTL rcl;%@NL@%
- %@NL@%
- UNUSED prcl;%@NL@%
- %@NL@%
- %@AB@%/* get window interior rect */%@AE@%%@NL@%
- WinQueryWindowRect(hwnd, &rcl);%@NL@%
- %@NL@%
- %@AB@%/* print "Hello World" centered horizontally and vertically */%@AE@%%@NL@%
- WinDrawText(hps, -1, "Hello World", &rcl, SYSCLR_WINDOWTEXT,%@NL@%
- SYSCLR_WINDOW, DT_CENTER | DT_VCENTER | DT_ERASERECT);%@NL@%
- %@NL@%
- %@AB@%/* draw interior border */%@AE@%%@NL@%
- WinDrawBorder(hps, &rcl, 6, 6, SYSCLR_WINDOWTEXT, SYSCLR_WINDOW,%@NL@%
- DB_STANDARD);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- HDMGDATA EXPENTRY callback(%@NL@%
- HCONV hConv,%@NL@%
- HSZ hszTopic,%@NL@%
- HSZ hszItem,%@NL@%
- USHORT usFmt,%@NL@%
- USHORT usType,%@NL@%
- HDMGDATA hDmgData)%@NL@%
- {%@NL@%
- SWP swp;%@NL@%
- %@NL@%
- UNUSED hConv;%@NL@%
- %@NL@%
- if (usType == XTYP_REGISTER && hszItem == hszTitle && !hconv) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * someone else came onboard, if we are looking for a target,%@NL@%
- %@AB@% * restart our clock.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinStartTimer(hab, hwndDemo, 1, TIMERSPEED);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * we only care about stuff on our topic.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hszTopic != hszTopicChase)%@NL@%
- return(0);%@NL@%
- %@NL@%
- switch (usType) {%@NL@%
- %@NL@%
- case XTYP_ADVSTART:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Always allow advises on our item%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return(hszItem == hszItemPos);%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_ADVDATA:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Always accept advise data on our target's latest position.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hszItem == hszItemPos) %@NL@%
- DdeGetData(hDmgData, (PBYTE)&SWPTarget, sizeof(SWP), 0L);%@NL@%
- DdeFreeData(hDmgData);%@NL@%
- return(0);%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_INIT:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * always allow others to initiate with us on our topic.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return(hszItem == hszTitle && hszTopic == hszTopicChase);%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_REQUEST:%@NL@%
- case XTYP_ADVREQ:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Respond to data requests as to our whereabouts item and format are%@NL@%
- %@AB@% * ok.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hszItem != hszItemPos || usFmt != fmtSWP) %@NL@%
- return(0);%@NL@%
- WinQueryWindowPos(hwndDemoFrame, &swp);%@NL@%
- return(DdePutData((PBYTE)&swp, sizeof(SWP), 0L, hszItemPos, fmtSWP, 0));%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(0);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DIALOGS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CLOCK\DIALOGS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% dialogs.c Dialog procedures for PM Clock Application%@NL@%
- %@AB@%%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@%INCL_WINBUTTONS %@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#include %@AE@%<os2def.h> %@NL@%
- %@AI@%#include %@AE@%<pmwin.h> %@NL@%
- %@AI@%#include %@AE@%"dialogs.h" %@NL@%
- %@NL@%
- %@AB@%/* defined in paint.c */%@AE@%%@NL@%
- extern USHORT usMajorTickPref ;%@NL@%
- extern USHORT usMinorTickPref ;%@NL@%
- extern LONG clrBackground ;%@NL@%
- extern LONG clrFace ;%@NL@%
- extern LONG clrHourHand ;%@NL@%
- extern LONG clrMinuteHand ;%@NL@%
- %@NL@%
- %@AB@%/* defined in clock.c */%@AE@%%@NL@%
- extern HWND hwndFrame ;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ClkAboutDlgProc() "About..." dialog%@NL@%
- %@AB@%%@NL@%
- %@AB@% Returns: MRESULT, 0 or return value from WinDefDlgProc%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- MRESULT EXPENTRY ClkAboutDlgProc ( HWND hwnd , USHORT usMsg ,%@NL@%
- MPARAM mp1 , MPARAM mp2 )%@NL@%
- {%@NL@%
- if ( usMsg == WM_COMMAND ) {%@NL@%
- WinDismissDlg ( hwnd , TRUE ) ;%@NL@%
- return 0L ;%@NL@%
- }%@NL@%
- else return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ClkTicksDlgProc() "Ticks..." dialog%@NL@%
- %@AB@%%@NL@%
- %@AB@% Returns: MRESULT, 0 or return value from WinDefDlgProc%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- MRESULT EXPENTRY ClkTicksDlgProc ( HWND hwnd , USHORT usMsg ,%@NL@%
- MPARAM mp1 , MPARAM mp2 )%@NL@%
- {%@NL@%
- static USHORT usMajorTickSel ;%@NL@%
- static USHORT usMinorTickSel ;%@NL@%
- USHORT usButtonID ;%@NL@%
- %@NL@%
- switch ( usMsg ) {%@NL@%
- %@NL@%
- case WM_INITDLG :%@NL@%
- %@NL@%
- %@AB@%/* show the current major tick preference */%@AE@%%@NL@%
- WinSendMsg ( WinWindowFromID ( hwnd ,%@NL@%
- CLKTM_MAJOR | usMajorTickPref ) ,%@NL@%
- BM_SETCHECK , MPFROM2SHORT ( TRUE , NULL ) , NULL ) ;%@NL@%
- %@NL@%
- %@AB@%/* show the current minor tick preference */%@AE@%%@NL@%
- WinSendMsg ( WinWindowFromID ( hwnd ,%@NL@%
- CLKTM_MINOR | usMinorTickPref ) ,%@NL@%
- BM_SETCHECK , MPFROM2SHORT ( TRUE , NULL ) , NULL ) ;%@NL@%
- %@NL@%
- %@AB@%/* load the selection values from the preferences */%@AE@%%@NL@%
- usMajorTickSel = usMajorTickPref ;%@NL@%
- usMinorTickSel = usMinorTickPref ;%@NL@%
- %@NL@%
- %@AB@%/* let the default dialog procedure handle anything else */%@AE@%%@NL@%
- break ;%@NL@%
- %@NL@%
- case WM_COMMAND :%@NL@%
- %@NL@%
- switch ( LOUSHORT ( mp1 ) ) {%@NL@%
- %@NL@%
- case DID_OK :%@NL@%
- %@NL@%
- %@AB@%/* store away selections as preferences */%@AE@%%@NL@%
- usMajorTickPref = usMajorTickSel ;%@NL@%
- usMinorTickPref = usMinorTickSel ;%@NL@%
- %@NL@%
- %@AB@%/* repaint with the new preferences */%@AE@%%@NL@%
- WinInvalidateRect ( hwndFrame , NULL, TRUE ) ;%@NL@%
- %@NL@%
- case DID_CANCEL :%@NL@%
- WinDismissDlg ( hwnd , TRUE ) ;%@NL@%
- }%@NL@%
- %@NL@%
- return NULL ;%@NL@%
- %@NL@%
- case WM_CONTROL :%@NL@%
- %@NL@%
- if ( SHORT2FROMMP ( mp1 ) == BN_CLICKED ) {%@NL@%
- %@NL@%
- usButtonID = SHORT1FROMMP ( mp1 ) ;%@NL@%
- %@NL@%
- switch ( usButtonID & 0xff00 ) {%@NL@%
- %@NL@%
- case CLKTM_MAJOR :%@NL@%
- usMajorTickSel = LOBYTE ( usButtonID ) ;%@NL@%
- break ;%@NL@%
- %@NL@%
- case CLKTM_MINOR :%@NL@%
- usMinorTickSel = LOBYTE ( usButtonID ) ;%@NL@%
- break ;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* fall through to the default control processing */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% ClkColorsDlgProc() "Clock Color Preferences" Dialog%@NL@%
- %@AB@%%@NL@%
- %@AB@% Returns: MRESULT, 0 or return value from WinDefDlgProc%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- MRESULT EXPENTRY ClkColorsDlgProc ( HWND hwnd , USHORT usMsg ,%@NL@%
- MPARAM mp1 , MPARAM mp2 )%@NL@%
- {%@NL@%
- USHORT usButtonID ;%@NL@%
- static USHORT usCheckedButtonID ;%@NL@%
- HWND hwndButton ;%@NL@%
- RECTL rclButton , rclButtonInterior ;%@NL@%
- static LONG clrBackgroundNew ;%@NL@%
- static LONG clrFaceNew ;%@NL@%
- static LONG clrHourHandNew ;%@NL@%
- static LONG clrMinuteHandNew ;%@NL@%
- static LONG * pclrNew ;%@NL@%
- %@NL@%
- switch ( usMsg ) {%@NL@%
- %@NL@%
- case WM_INITDLG :%@NL@%
- %@NL@%
- %@AB@%/* load the new values from the current ones */%@AE@%%@NL@%
- clrBackgroundNew = clrBackground ;%@NL@%
- clrFaceNew = clrFace ;%@NL@%
- clrHourHandNew = clrHourHand ;%@NL@%
- clrMinuteHandNew = clrMinuteHand ;%@NL@%
- %@NL@%
- %@AB@%/* click the "Background" radio button */%@AE@%%@NL@%
- WinSendMsg ( WinWindowFromID ( hwnd , CLKCLR_BACKGROUND ) ,%@NL@%
- BM_CLICK , MPFROMSHORT ( TRUE ) , NULL ) ;%@NL@%
- %@NL@%
- %@AB@%/* let the default dialog procedure handle anything else */%@AE@%%@NL@%
- break ;%@NL@%
- %@NL@%
- case WM_COMMAND :%@NL@%
- %@NL@%
- switch ( LOUSHORT ( mp1 ) ) {%@NL@%
- case DID_OK :%@NL@%
- %@NL@%
- %@AB@%/* store the new values */%@AE@%%@NL@%
- clrBackground = clrBackgroundNew ;%@NL@%
- clrFace = clrFaceNew ;%@NL@%
- clrHourHand = clrHourHandNew ;%@NL@%
- clrMinuteHand = clrMinuteHandNew ;%@NL@%
- %@NL@%
- %@AB@%/* repaint with the new colors */%@AE@%%@NL@%
- WinInvalidateRect ( hwndFrame , NULL, TRUE ) ;%@NL@%
- %@NL@%
- case DID_CANCEL :%@NL@%
- %@NL@%
- WinDismissDlg ( hwnd , TRUE ) ;%@NL@%
- }%@NL@%
- return NULL ;%@NL@%
- %@NL@%
- case WM_CONTROL :%@NL@%
- %@NL@%
- usButtonID = SHORT1FROMMP ( mp1 ) ;%@NL@%
- %@NL@%
- %@AB@%/* selecting a new object */%@AE@%%@NL@%
- if ( usButtonID & CLKCLR_OBJECTS ) {%@NL@%
- %@NL@%
- switch ( usButtonID ) {%@NL@%
- case CLKCLR_BACKGROUND :%@NL@%
- pclrNew = & clrBackgroundNew ;%@NL@%
- break ;%@NL@%
- case CLKCLR_FACE :%@NL@%
- pclrNew = & clrFaceNew ;%@NL@%
- break ;%@NL@%
- case CLKCLR_HOURHAND :%@NL@%
- pclrNew = & clrHourHandNew ;%@NL@%
- break ;%@NL@%
- case CLKCLR_MINUTEHAND :%@NL@%
- pclrNew = & clrMinuteHandNew ;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* click the button for the new object's current color */%@AE@%%@NL@%
- WinSendMsg (%@NL@%
- WinWindowFromID ( hwnd ,%@NL@%
- CLKCLR_BUTTONSHIFT + ( USHORT ) * pclrNew ) ,%@NL@%
- BM_CLICK , MPFROMSHORT ( TRUE ) , NULL ) ;%@NL@%
- %@NL@%
- break ;%@NL@%
- }%@NL@%
- %@NL@%
- switch ( SHORT2FROMMP ( mp1 ) ) {%@NL@%
- %@NL@%
- case BN_CLICKED :%@NL@%
- %@NL@%
- * pclrNew = ( LONG ) usButtonID - CLKCLR_BUTTONSHIFT ;%@NL@%
- %@NL@%
- %@AB@%/* turn off the check state of the previously checked%@NL@%
- %@AB@% * button and turn on the check state of the button%@NL@%
- %@AB@% * just clicked */%@AE@%%@NL@%
- %@NL@%
- WinSendMsg ( WinWindowFromID ( hwnd , usCheckedButtonID ) ,%@NL@%
- BM_SETCHECK , MPFROM2SHORT ( FALSE , NULL ) ,%@NL@%
- NULL ) ;%@NL@%
- WinSendMsg ( WinWindowFromID ( hwnd , usButtonID ) ,%@NL@%
- BM_SETCHECK , MPFROM2SHORT ( TRUE , NULL ) ,%@NL@%
- NULL ) ;%@NL@%
- %@NL@%
- usCheckedButtonID = usButtonID ;%@NL@%
- %@NL@%
- break ;%@NL@%
- %@NL@%
- case BN_PAINT :%@NL@%
- %@NL@%
- %@AB@%/* fill only the interior of the button, so we don't%@NL@%
- %@AB@% * conflict with the focus indicator */%@AE@%%@NL@%
- %@NL@%
- hwndButton = ( ( PUSERBUTTON ) mp2 ) -> hwnd ;%@NL@%
- WinQueryWindowRect ( hwndButton , & rclButton ) ;%@NL@%
- rclButton . xLeft ++ ;%@NL@%
- rclButton . yBottom ++ ;%@NL@%
- rclButton . xRight -- ;%@NL@%
- rclButton . yTop -- ;%@NL@%
- WinFillRect ( ( ( PUSERBUTTON ) mp2 ) -> hps ,%@NL@%
- & rclButton ,%@NL@%
- ( LONG ) usButtonID - CLKCLR_BUTTONSHIFT ) ;%@NL@%
- %@NL@%
- %@AB@%/* hollow out those buttons which aren't checked */%@AE@%%@NL@%
- if ( ! WinSendMsg ( WinWindowFromID ( hwnd , usButtonID ) ,%@NL@%
- BM_QUERYCHECK , NULL , NULL ) ) {%@NL@%
- rclButtonInterior . xLeft = rclButton . xLeft + 4 ;%@NL@%
- rclButtonInterior . yBottom = rclButton . yBottom + 4 ;%@NL@%
- rclButtonInterior . xRight = rclButton . xRight - 4 ;%@NL@%
- rclButtonInterior . yTop = rclButton . yTop - 4 ;%@NL@%
- WinFillRect ( ( ( PUSERBUTTON ) mp2 ) -> hps ,%@NL@%
- & rclButtonInterior , SYSCLR_WINDOW ) ;%@NL@%
- }%@NL@%
- %@NL@%
- break ;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* fall through to the default control processing */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DLGPROC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\INIEDIT\DLGPROC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/******************************* Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DlgProc.c%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* System Test Application%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%LINT_ARGS // Include needed parts of PM %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT // definitions %@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINBUTTONS %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WINHEAP %@NL@%
- %@AI@%#define %@AE@%INCL_WINSHELLDATA %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINLISTBOXES %@NL@%
- %@AI@%#define %@AE@%INCL_WINENTRYFIELDS %@NL@%
- %@AI@%#define %@AE@%INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIREGIONS %@NL@%
- %@AI@%#define %@AE@%INCL_GPILCIDS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIPRIMITIVES %@NL@%
- %@AI@%#define %@AE@%INCL_DEV %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"IniEdit.h" %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************* Constants *********************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%BUF_SIZE 132 %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/******************************** Globals **********************************/%@AE@%%@NL@%
- %@NL@%
- static CHAR szSearch[BUF_SIZE] = { 0 }; // Current search string%@NL@%
- static USHORT usLastIndex = 0; // Last Searched Item%@NL@%
- %@NL@%
- %@AB@%/******************************* Externals *********************************/%@AE@%%@NL@%
- %@NL@%
- extern USHORT cAppNames; // see iniedit.c%@NL@%
- extern HWND hwndList;%@NL@%
- extern PGROUPSTRUCT pGroups;%@NL@%
- extern HAB habIniEdit;%@NL@%
- extern HWND FocusWindow;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************** Function Header ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* SearchWndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Handles the Search Dialog Box messages%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT _loadds EXPENTRY SearchWndProc(HWND hwndDialog, USHORT msg,%@NL@%
- MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HWND hwndText; // Current Text Window%@NL@%
- %@NL@%
- %@NL@%
- switch (msg)%@NL@%
- {%@NL@%
- %@NL@%
- case WM_INITDLG:%@NL@%
- hwndText = WinWindowFromID( hwndDialog, IDDI_SEARCH_TEXT );%@NL@%
- WinSetWindowText(hwndText, szSearch);%@NL@%
- WinSendMsg( hwndText, EM_SETSEL,%@NL@%
- MPFROM2SHORT(0, strlen(szSearch)), (MPARAM)0 );%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch( LOUSHORT( mp1 ) )%@NL@%
- {%@NL@%
- %@NL@%
- case IDDI_SEARCH_OK:%@NL@%
- hwndText = WinWindowFromID( hwndDialog, IDDI_SEARCH_TEXT );%@NL@%
- WinQueryWindowText( hwndText, BUF_SIZE, szSearch );%@NL@%
- WinDismissDlg( hwndDialog, 0 );%@NL@%
- %@NL@%
- if( (usLastIndex = SHORT1FROMMR(WinSendMsg( hwndList, LM_SEARCHSTRING,%@NL@%
- MPFROM2SHORT( LSS_SUBSTRING, LIT_FIRST),%@NL@%
- MPFROMP( szSearch )) ) != LIT_NONE ))%@NL@%
- {%@NL@%
- WinSendMsg( hwndList, LM_SELECTITEM,%@NL@%
- MPFROM2SHORT( (usLastIndex), NULL),%@NL@%
- MPFROM2SHORT( TRUE, NULL ) );%@NL@%
- }%@NL@%
- else %@AB@%/* not found */%@AE@%%@NL@%
- {%@NL@%
- usLastIndex = LIT_FIRST;%@NL@%
- WinAlarm( HWND_DESKTOP, 0);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case IDDI_SEARCH_NEXT:%@NL@%
- FindNext();%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return 0L;%@NL@%
- %@NL@%
- } %@AB@%/* SearchWndProc */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************** Function Header ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FindNext%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Finds the next instance of the current search string starting from the%@NL@%
- %@AB@%* Last searched position%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID FindNext()%@NL@%
- {%@NL@%
- if( (usLastIndex = SHORT1FROMMR(WinSendMsg( hwndList, LM_SEARCHSTRING,%@NL@%
- MPFROM2SHORT( LSS_SUBSTRING, usLastIndex),%@NL@%
- MPFROMP( szSearch )) ) != LIT_NONE ))%@NL@%
- {%@NL@%
- WinSendMsg( hwndList, LM_SELECTITEM,%@NL@%
- MPFROM2SHORT( (usLastIndex), NULL),%@NL@%
- MPFROM2SHORT( TRUE, NULL ) );%@NL@%
- }%@NL@%
- else %@AB@%/* alarm if not found */%@AE@%%@NL@%
- WinAlarm( HWND_DESKTOP, 0);%@NL@%
- %@NL@%
- } %@AB@%/* FindNext */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************** Function Header ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* AddKeyWndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Handles the AddKey Dialog Box messages%@NL@%
- %@AB@%* Will facilitate adding new keys for a given App Name%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT _loadds EXPENTRY AddKeyWndProc(HWND hwndDialog, USHORT msg,%@NL@%
- MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HWND hwndTextApp; // Handle for App Text Window%@NL@%
- HWND hwndTextKey;%@NL@%
- HWND hwndTextValue;%@NL@%
- CHAR szApp[BUF_SIZE]; // String Contents%@NL@%
- CHAR szKey[BUF_SIZE];%@NL@%
- CHAR szValue[BUF_SIZE];%@NL@%
- %@NL@%
- %@NL@%
- switch (msg)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_ADD_KEY_TEXT_APP, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_ADD_KEY_TEXT_KEY, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_ADD_KEY_TEXT_VAL, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- break;%@NL@%
- case WM_COMMAND:%@NL@%
- switch( LOUSHORT( mp1 ) )%@NL@%
- {%@NL@%
- %@NL@%
- case IDDI_ADD_KEY_OK:%@NL@%
- hwndTextApp = WinWindowFromID( hwndDialog, IDDI_ADD_KEY_TEXT_APP );%@NL@%
- WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );%@NL@%
- %@NL@%
- hwndTextKey = WinWindowFromID( hwndDialog, IDDI_ADD_KEY_TEXT_KEY );%@NL@%
- WinQueryWindowText( hwndTextKey, BUF_SIZE, szKey );%@NL@%
- %@NL@%
- hwndTextValue = WinWindowFromID( hwndDialog, IDDI_ADD_KEY_TEXT_VAL );%@NL@%
- WinQueryWindowText( hwndTextValue, BUF_SIZE, szValue );%@NL@%
- %@NL@%
- WinDismissDlg( hwndDialog, 0 );%@NL@%
- %@NL@%
- %@AB@%/* if the App is NULL forget it */%@AE@%%@NL@%
- if( *szApp == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* if the Key is NULL forget it */%@AE@%%@NL@%
- if( *szKey == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* if the Value is NULL forget it */%@AE@%%@NL@%
- if( *szValue == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if( !WinWriteProfileString( habIniEdit, szApp, szKey, szValue ) )%@NL@%
- ;%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return 0L;%@NL@%
- %@NL@%
- } %@AB@%/* AddKeyWndProc */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************** Function Header ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ChangeKeyWndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Handles the ChangeKey Dialog Box messages%@NL@%
- %@AB@%* Will facilitate changing a key's value given an app, key and new value%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT _loadds EXPENTRY ChangeKeyWndProc(HWND hwndDialog, USHORT msg,%@NL@%
- MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HWND hwndTextApp; // Handle for App Text Window%@NL@%
- HWND hwndTextKey;%@NL@%
- HWND hwndTextVal;%@NL@%
- CHAR szApp[BUF_SIZE]; // String Contents%@NL@%
- CHAR szKey[BUF_SIZE];%@NL@%
- CHAR szVal[BUF_SIZE];%@NL@%
- %@NL@%
- %@NL@%
- switch (msg)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- if( FocusWindow )%@NL@%
- {%@NL@%
- %@NL@%
- FocusWindow = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL );%@NL@%
- WinSetFocus( HWND_DESKTOP, FocusWindow);%@NL@%
- WinQueryWindowText( FocusWindow, BUF_SIZE, szVal );%@NL@%
- %@NL@%
- FocusWindow = (HWND)NULL;%@NL@%
- %@NL@%
- return((MRESULT) TRUE );%@NL@%
- } else {%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_CHANGE_KEY_TEXT_APP, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_CHANGE_KEY_TEXT_KEY, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch( LOUSHORT( mp1 ) )%@NL@%
- {%@NL@%
- %@NL@%
- case IDDI_CHANGE_KEY_OK:%@NL@%
- hwndTextApp = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_APP );%@NL@%
- WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );%@NL@%
- %@NL@%
- hwndTextKey = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_KEY );%@NL@%
- WinQueryWindowText( hwndTextKey, BUF_SIZE, szKey );%@NL@%
- %@NL@%
- hwndTextVal = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL );%@NL@%
- WinQueryWindowText( hwndTextVal, BUF_SIZE, szVal );%@NL@%
- %@NL@%
- %@NL@%
- WinDismissDlg( hwndDialog, IDDI_CHANGE_KEY_OK );%@NL@%
- %@NL@%
- %@AB@%/* if the App is NULL forget it */%@AE@%%@NL@%
- if( *szApp == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* if the Key is NULL forget it */%@AE@%%@NL@%
- if( *szKey == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* if the Value is NULL forget it */%@AE@%%@NL@%
- if( *szVal == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- if( !WinWriteProfileString( habIniEdit, szApp, szKey, szVal ) )%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return 0L;%@NL@%
- %@NL@%
- } %@AB@%/* ChangeKeyWndProc */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************** Function Header ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DelKeyWndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Handles the DelKey Dialog Box messages%@NL@%
- %@AB@%* Will facilitate deleting a key value given an app and the key%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT _loadds EXPENTRY DelKeyWndProc(HWND hwndDialog, USHORT msg,%@NL@%
- MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HWND hwndTextApp; // Handle for App Text Window%@NL@%
- HWND hwndTextKey;%@NL@%
- CHAR szApp[BUF_SIZE]; // String Contents%@NL@%
- CHAR szKey[BUF_SIZE];%@NL@%
- %@NL@%
- %@NL@%
- switch (msg)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_DEL_KEY_TEXT_APP, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_DEL_KEY_TEXT_KEY, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- break;%@NL@%
- case WM_COMMAND:%@NL@%
- switch( LOUSHORT( mp1 ) )%@NL@%
- {%@NL@%
- %@NL@%
- case IDDI_DEL_KEY_OK:%@NL@%
- hwndTextApp = WinWindowFromID( hwndDialog, IDDI_DEL_KEY_TEXT_APP );%@NL@%
- WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );%@NL@%
- %@NL@%
- hwndTextKey = WinWindowFromID( hwndDialog, IDDI_DEL_KEY_TEXT_KEY );%@NL@%
- WinQueryWindowText( hwndTextKey, BUF_SIZE, szKey );%@NL@%
- %@NL@%
- %@NL@%
- WinDismissDlg( hwndDialog, 0 );%@NL@%
- %@NL@%
- %@AB@%/* if the App is NULL forget it */%@AE@%%@NL@%
- if( *szApp == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* if the Key is NULL forget it */%@AE@%%@NL@%
- if( *szKey == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- if( !WinWriteProfileString( habIniEdit, szApp, szKey, (PCHAR)NULL ) )%@NL@%
- ;%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return 0L;%@NL@%
- %@NL@%
- } %@AB@%/* DelKeyProc */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************** Function Header ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DelAppWndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Handles the DelApp Dialog Box messages%@NL@%
- %@AB@%* Will facilitate deleting all keys from a given app name%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT _loadds EXPENTRY DelAppWndProc(HWND hwndDialog, USHORT msg,%@NL@%
- MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- HWND hwndTextApp; // App Name Window%@NL@%
- CHAR szApp[BUF_SIZE]; // String Contents of Window%@NL@%
- %@NL@%
- %@NL@%
- switch (msg)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- WinSendDlgItemMsg(hwndDialog, IDDI_DEL_APP_TEXT_APP, EM_SETTEXTLIMIT,%@NL@%
- MPFROMSHORT(MAX_STRING_LEN), 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch( LOUSHORT( mp1 ) )%@NL@%
- {%@NL@%
- %@NL@%
- case IDDI_DEL_APP_OK:%@NL@%
- hwndTextApp = WinWindowFromID( hwndDialog, IDDI_DEL_APP_TEXT_APP );%@NL@%
- WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );%@NL@%
- %@NL@%
- WinDismissDlg( hwndDialog, 0 );%@NL@%
- %@NL@%
- %@AB@%/* if the App is NULL forget it */%@AE@%%@NL@%
- if( *szApp == (CHAR)0 )%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if( !WinWriteProfileString( habIniEdit, szApp, (PCHAR)NULL, (PCHAR)NULL ) )%@NL@%
- ;%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- default:%@NL@%
- return WinDefDlgProc(hwndDialog, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return 0L;%@NL@%
- %@NL@%
- } %@AB@%/* DelAppWndProc */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DLGSAMP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DLGSAMP\DLGSAMP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% DLGSAMP -- Dialog Box Sample Application%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WINBUTTONS %@NL@%
- %@AI@%#define %@AE@%INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@%INCL_WINERRORS %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@%INCL_WINLISTBOXES %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINRECTANGLES %@NL@%
- %@AI@%#define %@AE@%INCL_WINSWITCHLIST %@NL@%
- %@AI@%#define %@AE@%INCL_WINSYS %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%M_I86L %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"dlgsamp.h" %@NL@%
- %@AI@%#include %@AE@%"dlgsamp1.h" %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Function Prototypes%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- VOID NEAR cdecl main(VOID);%@NL@%
- %@NL@%
- %@AB@%/* Local Routines */%@AE@%%@NL@%
- VOID cdecl CenterDlgBox(HWND);%@NL@%
- VOID cdecl CheckColor(HWND, SHORT, COLOR *);%@NL@%
- VOID cdecl EnableModality(HWND, BOOL);%@NL@%
- BOOL cdecl IsIntInRange(HWND, SHORT, SHORT, SHORT, SHORT, SHORT);%@NL@%
- VOID cdecl LoadDialog(HWND, HWND, SHORT, PFNWP, BOOL);%@NL@%
- VOID cdecl MainWndCommand(HWND, USHORT, BOOL *);%@NL@%
- VOID cdecl MainWndPaint(HWND);%@NL@%
- VOID cdecl SetModality(HWND, BOOL);%@NL@%
- VOID cdecl Trace(PSZ, PSZ);%@NL@%
- %@NL@%
- %@AB@%/* Window Procedures */%@AE@%%@NL@%
- MRESULT EXPENTRY fnwpMainWnd(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT EXPENTRY fnwpEntryFieldDlg(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT EXPENTRY fnwpAutoRadioButtonDlg(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT EXPENTRY fnwpCheckBoxDlg(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT EXPENTRY fnwpListBoxDlg(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT EXPENTRY fnwpAboutBoxDlg(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Global variables%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- COLOR colorClient = CLR_RED | CLR_BLUE; %@AB@%/* Color of client area */%@AE@%%@NL@%
- %@NL@%
- CHAR szEntryField1[10] = ""; %@AB@%/* Used to pass back info */%@AE@%%@NL@%
- CHAR szEntryField2[10] = ""; %@AB@%/* from entry fields */%@AE@%%@NL@%
- %@AB@%/* in EntryFieldDlg */%@AE@%%@NL@%
- %@NL@%
- BOOL bModality = TRUE; %@AB@%/* Does the user want modal*/%@AE@%%@NL@%
- %@AB@%/* or modeless dialogs? */%@AE@%%@NL@%
- COLOR colorSave;%@NL@%
- CHAR szSelection[LEN_LISTBOXENTRY] = ""; %@AB@%/* Used to pass back */%@AE@%%@NL@%
- %@AB@%/* list box item selected */%@AE@%%@NL@%
- %@AB@%/* in ListBoxDlg */%@AE@%%@NL@%
- %@NL@%
- HAB hab; %@AB@%/* Anchor block handle */%@AE@%%@NL@%
- HWND hwndClient; %@AB@%/* Client Window handle */%@AE@%%@NL@%
- HWND hwndFrame; %@AB@%/* Frame Window handle */%@AE@%%@NL@%
- HWND hwndModelessDlg; %@AB@%/* Modeless Dialog handle */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/**************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: main%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Typical PM main function which initializes PM, creates a message queue,%@NL@%
- %@AB@%* registers a window class, creates a window, gets and dispatches%@NL@%
- %@AB@%* messages to its winproc until its time to quit, and then tidies up%@NL@%
- %@AB@%* before terminating.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%**************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID NEAR cdecl main( )%@NL@%
- {%@NL@%
- HMQ hmq; %@AB@%/* Message Queue handle */%@AE@%%@NL@%
- QMSG qmsg; %@AB@%/* Message */%@AE@%%@NL@%
- ULONG flCreate;%@NL@%
- %@NL@%
- hab = WinInitialize( 0 ); %@AB@%/* Initialize PM */%@AE@%%@NL@%
- hmq = WinCreateMsgQueue( hab, 0 );%@AB@%/* Create application msg queue */%@AE@%%@NL@%
- %@NL@%
- WinRegisterClass( %@AB@%/* Register Window Class */%@AE@%%@NL@%
- hab, %@AB@%/* Anchor block handle */%@AE@%%@NL@%
- "DlgSamp Class", %@AB@%/* Window Class name */%@AE@%%@NL@%
- fnwpMainWnd, %@AB@%/* Address of Window Procedure */%@AE@%%@NL@%
- (ULONG) NULL, %@AB@%/* No special class style */%@AE@%%@NL@%
- 0 %@AB@%/* No extra window words */%@AE@%%@NL@%
- );%@NL@%
- %@NL@%
- flCreate = FCF_STANDARD & ~FCF_ACCELTABLE;%@NL@%
- %@NL@%
- hwndFrame = WinCreateStdWindow(%@NL@%
- HWND_DESKTOP, %@AB@%/* Desktop Window is parent */%@AE@%%@NL@%
- WS_VISIBLE, %@AB@%/* Window styles */%@AE@%%@NL@%
- (PVOID)&flCreate, %@AB@%/* Window creation parameters */%@AE@%%@NL@%
- "DlgSamp Class", %@AB@%/* Window Class name */%@AE@%%@NL@%
- "", %@AB@%/* Window Text */%@AE@%%@NL@%
- 0L, %@AB@%/* Client style */%@AE@%%@NL@%
- (HMODULE) NULL, %@AB@%/* Module handle */%@AE@%%@NL@%
- ID_MAINWND, %@AB@%/* Window ID */%@AE@%%@NL@%
- (HWND FAR *)&hwndClient %@AB@%/* Client Window handle */%@AE@%%@NL@%
- );%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Message Loop */%@AE@%%@NL@%
- while( WinGetMsg( hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )%@NL@%
- WinDispatchMsg( hab, (PQMSG)&qmsg );%@NL@%
- %@NL@%
- %@AB@%/* Cleanup code */%@AE@%%@NL@%
- WinDestroyWindow( hwndFrame );%@NL@%
- WinDestroyMsgQueue( hmq );%@NL@%
- WinTerminate( hab );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WinProc: fnwpMainWnd%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Controls the state of the menu, and loads various dialogs. The%@NL@%
- %@AB@%* dialogs will be modal or modeless depending on the setting of the%@NL@%
- %@AB@%* Modality menuitem.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***********************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT EXPENTRY fnwpMainWnd( hwnd, message, mp1, mp2 )%@NL@%
- HWND hwnd;%@NL@%
- USHORT message;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- USHORT Command; %@AB@%/* Command passed by WM_COMMAND */%@AE@%%@NL@%
- SHORT id; %@AB@%/* ID of item selected from the list box */%@AE@%%@NL@%
- %@NL@%
- switch(message)%@NL@%
- {%@NL@%
- case WM_PAINT:%@NL@%
- MainWndPaint( hwnd ); %@AB@%/* Invoke window painting routine */%@AE@%%@NL@%
- break;%@NL@%
- case WM_HELP:%@NL@%
- %@AB@%/*********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This will be received when either:-%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* 1. The user hits the F1 key%@NL@%
- %@AB@%* 2. The user clicks on the action bar item F1=Help%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*********************************************************************/%@AE@%%@NL@%
- WinMessageBox( HWND_DESKTOP,%@NL@%
- hwndFrame,%@NL@%
- (PSZ)"Dialog Sample Application: Help",%@NL@%
- (PSZ)"Try out the pulldown menus, or Alt+selection",%@NL@%
- ID_MB,%@NL@%
- MB_OK );%@NL@%
- break;%@NL@%
- case WM_COMMAND:%@NL@%
- Command = SHORT1FROMMP( mp1 );%@NL@%
- MainWndCommand( hwnd, Command, &bModality );%@NL@%
- break;%@NL@%
- case DLGSAMP_EFCOMPLETE:%@NL@%
- WinQueryWindowText( WinWindowFromID( hwndModelessDlg, EF_1 ),%@NL@%
- sizeof( szEntryField1 ), szEntryField1 );%@NL@%
- WinQueryWindowText( WinWindowFromID( hwndModelessDlg, EF_2 ),%@NL@%
- sizeof( szEntryField2 ), szEntryField2 );%@NL@%
- WinInvalidateRect( hwnd, NULL, FALSE );%@AB@%/* Request whole window repaint */%@AE@%%@NL@%
- break;%@NL@%
- case DLGSAMP_LBCOMPLETE:%@NL@%
- id = SHORT1FROMMR( WinSendDlgItemMsg( hwndModelessDlg,%@NL@%
- LB_1,%@NL@%
- LM_QUERYSELECTION,%@NL@%
- 0L,%@NL@%
- 0L ) );%@NL@%
- if( id == LIT_NONE )%@NL@%
- strcpy( szSelection, "" );%@NL@%
- else%@NL@%
- WinSendDlgItemMsg( hwndModelessDlg,%@NL@%
- LB_1,%@NL@%
- LM_QUERYITEMTEXT,%@NL@%
- MPFROM2SHORT( id, sizeof( szSelection ) ),%@NL@%
- MPFROMP( szSelection ) );%@NL@%
- break;%@NL@%
- case DLGSAMP_RBCOMPLETE:%@NL@%
- case DLGSAMP_CBCOMPLETE:%@NL@%
- break;%@NL@%
- case DLGSAMP_DESTROYDLG:%@NL@%
- WinDestroyWindow( hwndModelessDlg );%@NL@%
- EnableModality( hwndFrame, TRUE );%@NL@%
- WinInvalidateRect( hwnd, NULL, FALSE );%@AB@%/* Request whole window repaint */%@AE@%%@NL@%
- break;%@NL@%
- case WM_CLOSE:%@NL@%
- WinPostMsg( hwnd, WM_QUIT, 0L, 0L ); %@AB@%/* Cause termination */%@AE@%%@NL@%
- break;%@NL@%
- default:%@NL@%
- return WinDefWindowProc( hwnd, message, mp1, mp2 );%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DlgProc: fnwpEntryFieldDlg%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* A dialog proc which captures and validates the contents of two%@NL@%
- %@AB@%* entry fields.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***********************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT EXPENTRY fnwpEntryFieldDlg( hwndDlg, message, mp1, mp2 )%@NL@%
- HWND hwndDlg;%@NL@%
- USHORT message;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch (message)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- CenterDlgBox( hwndDlg );%@NL@%
- break;%@NL@%
- case WM_COMMAND:%@NL@%
- switch( SHORT1FROMMP( mp1 ) )%@NL@%
- {%@NL@%
- case DID_OK: %@AB@%/* Enter key or pushbutton pressed/ selected */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Validate the contents of the two entry fields%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- if( !IsIntInRange( hwndDlg, EF_1, 1, 100, ERR_EFINVALID, ID_MB ) )%@NL@%
- return FALSE;%@NL@%
- if( !IsIntInRange( hwndDlg, EF_2, 1, 100, ERR_EFINVALID, ID_MB ) )%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* A modal dialog is destroyed before control is returned to the%@NL@%
- %@AB@%* invoking winproc, so it must pass the contents of its Entry Fields etc.%@NL@%
- %@AB@%* back to the invoking window before it returns.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* When a modeless dialog box returns it still continues to exist. It%@NL@%
- %@AB@%* could pass the contents of its Entry Fields etc. back to the%@NL@%
- %@AB@%* invoking window in several ways.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Here a user message is posted to the invoking window to say that the%@NL@%
- %@AB@%* dialog has completed. The invoking window then has an opportunity%@NL@%
- %@AB@%* to extract the contents of the Entry Fields etc.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- if( bModality )%@NL@%
- {%@NL@%
- WinQueryWindowText( WinWindowFromID( hwndDlg, EF_1 ),%@NL@%
- sizeof( szEntryField1),%@NL@%
- szEntryField1 );%@NL@%
- WinQueryWindowText( WinWindowFromID( hwndDlg, EF_2 ),%@NL@%
- sizeof( szEntryField2),%@NL@%
- szEntryField2 );%@NL@%
- }%@NL@%
- else%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_EFCOMPLETE, 0L, 0L );%@NL@%
- %@NL@%
- case DID_CANCEL:%@AB@%/* Escape key or CANCEL pushbutton pressed/selected */%@AE@%%@NL@%
- if( bModality )%@NL@%
- WinDismissDlg( hwndDlg,TRUE );%@NL@%
- else%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );%@NL@%
- return FALSE;%@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- default: %@AB@%/* Pass all other messages to the default dialog proc */%@AE@%%@NL@%
- return WinDefDlgProc( hwndDlg, message, mp1, mp2 );%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DlgProc: fnwpAutoRadioButtonDlg%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* A dialog procedure which uses auto radio buttons to change the%@NL@%
- %@AB@%* color of the Client Area window.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***********************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT EXPENTRY fnwpAutoRadioButtonDlg( hwndDlg, message, mp1, mp2 )%@NL@%
- HWND hwndDlg;%@NL@%
- USHORT message;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch (message)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- colorSave = colorClient;%@NL@%
- CenterDlgBox( hwndDlg );%@NL@%
- if ( colorClient == CLR_RED )%@NL@%
- WinPostMsg( WinWindowFromID( hwndDlg, RB_RED ),%@NL@%
- BM_SETCHECK,%@NL@%
- MPFROM2SHORT( TRUE, 0 ),%@NL@%
- 0L );%@NL@%
- %@NL@%
- if ( colorClient == CLR_GREEN )%@NL@%
- WinPostMsg( WinWindowFromID( hwndDlg, RB_GREEN ),%@NL@%
- BM_SETCHECK,%@NL@%
- MPFROM2SHORT( TRUE, 0 ),%@NL@%
- 0L );%@NL@%
- %@NL@%
- if ( colorClient == CLR_BLUE )%@NL@%
- WinPostMsg( WinWindowFromID( hwndDlg, RB_BLUE ),%@NL@%
- BM_SETCHECK,%@NL@%
- MPFROM2SHORT( TRUE, 0 ),%@NL@%
- 0L );%@NL@%
- %@NL@%
- break;%@NL@%
- case WM_CONTROL:%@NL@%
- if( SHORT2FROMMP( mp1 ) == BN_CLICKED )%@NL@%
- switch( SHORT1FROMMP( mp1 ) )%@NL@%
- {%@NL@%
- case RB_RED:%@NL@%
- colorClient = CLR_RED;%@NL@%
- break;%@NL@%
- case RB_GREEN:%@NL@%
- colorClient = CLR_GREEN;%@NL@%
- break;%@NL@%
- case RB_BLUE:%@NL@%
- colorClient = CLR_BLUE;%@NL@%
- break;%@NL@%
- default:%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- WinInvalidateRect( hwndClient, NULL, FALSE );%@NL@%
- break;%@NL@%
- case WM_COMMAND:%@NL@%
- switch( SHORT1FROMMP( mp1 ) )%@NL@%
- {%@NL@%
- case DID_OK: %@AB@%/* Enter key or pushbutton pressed/ selected */%@AE@%%@NL@%
- if( !bModality )%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_RBCOMPLETE, 0L, 0L );%@NL@%
- break;%@NL@%
- case DID_CANCEL: %@AB@%/* Escape key or CANCEL pushbutton pressed/selected */%@AE@%%@NL@%
- colorClient = colorSave;%@NL@%
- break;%@NL@%
- default:%@NL@%
- return WinDefDlgProc( hwndDlg, message, mp1, mp2 );%@NL@%
- }%@NL@%
- if( bModality )%@NL@%
- WinDismissDlg( hwndDlg, TRUE );%@NL@%
- else%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );%@NL@%
- break;%@NL@%
- %@NL@%
- default: %@AB@%/* Pass all other messages to the default dialog proc */%@AE@%%@NL@%
- return WinDefDlgProc( hwndDlg, message, mp1, mp2 );%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DlgProc: fnwpCheckBoxDlg%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* A dialog procedure to which use checkboxes to change the color%@NL@%
- %@AB@%* of the Client Area Window.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***********************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT EXPENTRY fnwpCheckBoxDlg( hwndDlg, message, mp1, mp2 )%@NL@%
- HWND hwndDlg;%@NL@%
- USHORT message;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch (message)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- CenterDlgBox( hwndDlg );%@NL@%
- colorSave = colorClient;%@NL@%
- if( (colorClient & CLR_RED) == CLR_RED )%@NL@%
- WinPostMsg( WinWindowFromID( hwndDlg, CB_RED ),%@NL@%
- BM_SETCHECK,%@NL@%
- MPFROM2SHORT( TRUE,0 ),%@NL@%
- 0L );%@NL@%
- if( (colorClient & CLR_GREEN) == CLR_GREEN )%@NL@%
- WinPostMsg( WinWindowFromID( hwndDlg, CB_GREEN ),%@NL@%
- BM_SETCHECK,%@NL@%
- MPFROM2SHORT( TRUE,0 ),%@NL@%
- 0L );%@NL@%
- if( (colorClient & CLR_BLUE) == CLR_BLUE )%@NL@%
- WinPostMsg( WinWindowFromID( hwndDlg, CB_BLUE ),%@NL@%
- BM_SETCHECK,%@NL@%
- MPFROM2SHORT( TRUE,0 ),%@NL@%
- 0L );%@NL@%
- break;%@NL@%
- case WM_CONTROL: %@AB@%/* User has clicked on a checkbox */%@AE@%%@NL@%
- if( SHORT2FROMMP( mp1 ) == BN_CLICKED )%@NL@%
- CheckColor( hwndDlg, SHORT1FROMMP( mp1 ), &colorClient );%@NL@%
- WinInvalidateRect( hwndClient, NULL, FALSE );%@NL@%
- break;%@NL@%
- case WM_COMMAND:%@NL@%
- switch( SHORT1FROMMP( mp1 ) )%@NL@%
- {%@NL@%
- case DID_OK: %@AB@%/* Enter key or pushbutton pressed/ selected */%@AE@%%@NL@%
- if( !bModality )%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_CBCOMPLETE, 0L, 0L );%@NL@%
- break;%@NL@%
- case DID_CANCEL: %@AB@%/* Escape key or CANCEL pushbutton pressed/selected */%@AE@%%@NL@%
- colorClient = colorSave;%@NL@%
- break;%@NL@%
- default:%@NL@%
- return WinDefDlgProc( hwndDlg, message, mp1, mp2 );%@NL@%
- }%@NL@%
- if( bModality )%@NL@%
- WinDismissDlg( hwndDlg, TRUE );%@NL@%
- else%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- default: %@AB@%/* Pass all other messages to the default dialog proc */%@AE@%%@NL@%
- return WinDefDlgProc( hwndDlg, message, mp1, mp2 );%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DlgProc: fnwpListBoxDlg%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***********************************************************************/%@AE@%%@NL@%
- %@NL@%
- MRESULT EXPENTRY fnwpListBoxDlg( hwndDlg, message, mp1, mp2 )%@NL@%
- HWND hwndDlg;%@NL@%
- USHORT message;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- CHAR szBuffer[LEN_LISTBOXENTRY];%@NL@%
- SHORT i;%@NL@%
- SHORT id;%@NL@%
- %@NL@%
- switch (message)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- CenterDlgBox( hwndDlg );%@NL@%
- %@NL@%
- %@AB@%/*************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Initialize the listbox with a set of strings loaded from a%@NL@%
- %@AB@%* resource file.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*************************************************************************/%@AE@%%@NL@%
- %@NL@%
- for ( i = 0; i < NUM_LISTBOXENTRIES; i++ )%@NL@%
- {%@NL@%
- WinLoadString( hab,%@NL@%
- (HMODULE) NULL,%@NL@%
- LBI_1 + i,%@NL@%
- LEN_LISTBOXENTRY,%@NL@%
- (PSZ)szBuffer%@NL@%
- );%@NL@%
- WinSendDlgItemMsg( hwndDlg,%@NL@%
- LB_1,%@NL@%
- LM_INSERTITEM,%@NL@%
- MPFROM2SHORT( LIT_END, 0 ),%@NL@%
- MPFROMP( szBuffer )%@NL@%
- );%@NL@%
- }%@NL@%
- break;%@NL@%
- case WM_COMMAND:%@NL@%
- switch( SHORT1FROMMP( mp1 ) )%@NL@%
- {%@NL@%
- case DID_OK: %@AB@%/* Enter key or pushbutton pressed/ selected */%@AE@%%@NL@%
- if( bModality )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/***********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Find out which item (if any) was selected and return the selected%@NL@%
- %@AB@%* item text.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***********************************************************************/%@AE@%%@NL@%
- %@NL@%
- id = SHORT1FROMMR( WinSendDlgItemMsg( hwndDlg,%@NL@%
- LB_1,%@NL@%
- LM_QUERYSELECTION,%@NL@%
- 0L,%@NL@%
- 0L ) );%@NL@%
- if( id == LIT_NONE )%@NL@%
- strcpy( szSelection, "" );%@NL@%
- else%@NL@%
- WinSendDlgItemMsg( hwndDlg,%@NL@%
- LB_1,%@NL@%
- LM_QUERYITEMTEXT,%@NL@%
- MPFROM2SHORT( id, LEN_LISTBOXENTRY ),%@NL@%
- MPFROMP( szSelection ) );%@NL@%
- }%@NL@%
- else%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_LBCOMPLETE, 0L, 0L );%@NL@%
- case DID_CANCEL: %@AB@%/* Escape key or CANCEL pushbutton pressed/selected */%@AE@%%@NL@%
- if( bModality )%@NL@%
- WinDismissDlg( hwndDlg, TRUE );%@NL@%
- else%@NL@%
- WinPostMsg( hwndClient, DLGSAMP_DESTROYDLG, 0L, 0L );%@NL@%
- return FALSE;%@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- default: %@AB@%/* Pass all other messages to the default dialog proc */%@AE@%%@NL@%
- return WinDefDlgProc( hwndDlg, message, mp1, mp2 );%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION : CenterDlgBox%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Positions the dialog box in the center of the screen%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl CenterDlgBox( hwnd )%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- SHORT ix, iy;%@NL@%
- SHORT iwidth, idepth;%@NL@%
- SWP swp;%@NL@%
- %@NL@%
- iwidth = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );%@NL@%
- idepth = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );%@NL@%
- WinQueryWindowPos( hwnd, (PSWP)&swp );%@NL@%
- ix = ( iwidth - swp.cx ) / 2;%@NL@%
- iy = ( idepth - swp.cy ) / 2;%@NL@%
- WinSetWindowPos( hwnd, HWND_TOP, ix, iy, 0, 0, SWP_MOVE );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: CheckColor%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Toggle the Checked/UnChecked state of a checkbox and add/remove%@NL@%
- %@AB@%* the corresponding CLR color component of the Client Area Color.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl CheckColor( hwndDlg, iDlgItem, colorClient )%@NL@%
- HWND hwndDlg;%@NL@%
- SHORT iDlgItem;%@NL@%
- COLOR *colorClient;%@NL@%
- {%@NL@%
- BOOL bChecked;%@NL@%
- COLOR color;%@NL@%
- %@NL@%
- switch( iDlgItem )%@NL@%
- {%@NL@%
- case CB_RED:%@NL@%
- color = CLR_RED;%@NL@%
- break;%@NL@%
- case CB_GREEN:%@NL@%
- color = CLR_GREEN;%@NL@%
- break;%@NL@%
- case CB_BLUE:%@NL@%
- color = CLR_BLUE;%@NL@%
- break;%@NL@%
- default:%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- bChecked = SHORT1FROMMR( WinSendMsg( WinWindowFromID( hwndDlg , iDlgItem ),%@NL@%
- BM_QUERYCHECK,%@NL@%
- 0L,%@NL@%
- 0L ) );%@NL@%
- WinPostMsg( WinWindowFromID( hwndDlg, iDlgItem ),%@NL@%
- BM_SETCHECK,%@NL@%
- MPFROM2SHORT( !bChecked, 0 ),%@NL@%
- 0L );%@NL@%
- if( bChecked ) %@AB@%/* If color previously checked */%@AE@%%@NL@%
- *colorClient -= color; %@AB@%/* subtract it ... else */%@AE@%%@NL@%
- else%@NL@%
- *colorClient += color; %@AB@%/* ... add it. */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/**************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: EnableModality%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Enable or disable the Modality menuitems depending on the value%@NL@%
- %@AB@%* of modal. This is done to prevent the user from altering the%@NL@%
- %@AB@%* modality setting while a modeless dialog is active.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%**************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl EnableModality( hwnd, bModal )%@NL@%
- HWND hwnd;%@NL@%
- BOOL bModal;%@NL@%
- {%@NL@%
- if( bModal )%@NL@%
- {%@NL@%
- WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),%@NL@%
- MM_SETITEMATTR,%@NL@%
- MPFROM2SHORT( MI_MODAL, TRUE ),%@NL@%
- MPFROM2SHORT( MIA_DISABLED, ~MIA_DISABLED ) );%@NL@%
- WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),%@NL@%
- MM_SETITEMATTR,%@NL@%
- MPFROM2SHORT( MI_MODELESS, TRUE ),%@NL@%
- MPFROM2SHORT( MIA_DISABLED, ~MIA_DISABLED ) );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),%@NL@%
- MM_SETITEMATTR,%@NL@%
- MPFROM2SHORT( MI_MODAL, TRUE ),%@NL@%
- MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED ) );%@NL@%
- WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),%@NL@%
- MM_SETITEMATTR,%@NL@%
- MPFROM2SHORT( MI_MODELESS, TRUE ),%@NL@%
- MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED ) );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: IsIntInRange.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Checks whether the value of a dialog item is in an integer in%@NL@%
- %@AB@%* a given range.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL cdecl IsIntInRange( hwndDlg, idEntryField,%@NL@%
- iLoRange, iHiRange,%@NL@%
- idErrMsg, idMessageBox )%@NL@%
- HWND hwndDlg;%@NL@%
- SHORT idEntryField;%@NL@%
- SHORT iLoRange;%@NL@%
- SHORT iHiRange;%@NL@%
- SHORT idErrMsg;%@NL@%
- SHORT idMessageBox;%@NL@%
- {%@NL@%
- SHORT ivalue;%@NL@%
- CHAR szErrMsg[80];%@NL@%
- %@NL@%
- %@AB@%/****************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Validate an entry field.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If validation fails leave the dialog visible, issue an error message%@NL@%
- %@AB@%* using a messagebox, and when the user dismisses the messagebox,%@NL@%
- %@AB@%* set the input focus to the entry field containing the error. Leave%@NL@%
- %@AB@%* the contents of the entry field unchanged, and return FALSE.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* If validation is successful return the value in ivalue and return%@NL@%
- %@AB@%* TRUE.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- if( !WinQueryDlgItemShort( hwndDlg, idEntryField, &ivalue, TRUE ) ||%@NL@%
- ( ivalue < iLoRange ) ||%@NL@%
- ( ivalue > iHiRange ) )%@NL@%
- {%@NL@%
- WinLoadString( hab, (HMODULE) NULL, idErrMsg, sizeof( szErrMsg ), szErrMsg );%@NL@%
- WinMessageBox( HWND_DESKTOP,%@NL@%
- hwndFrame,%@NL@%
- (PSZ)szErrMsg,%@NL@%
- NULL,%@NL@%
- idMessageBox,%@NL@%
- MB_OK );%@NL@%
- WinSetFocus( HWND_DESKTOP, WinWindowFromID( hwndDlg, idEntryField ) );%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- else%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***********************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: LoadDialog%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Use the appropriate functions to put up a modal or modeless%@NL@%
- %@AB@%* dialog box depending on the setting of the bModality parameter.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%***********************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl LoadDialog( hwndParent, hwndOwner, idDlg, fnwpDlgProc, bModality )%@NL@%
- HWND hwndParent;%@NL@%
- HWND hwndOwner;%@NL@%
- SHORT idDlg;%@NL@%
- PFNWP fnwpDlgProc;%@NL@%
- BOOL bModality;%@NL@%
- {%@NL@%
- EnableModality( hwndOwner, FALSE ); %@AB@%/* Disable the Modality menu item */%@AE@%%@NL@%
- %@NL@%
- if( bModality )%@NL@%
- {%@NL@%
- WinDlgBox( hwndParent, %@AB@%/* Parent */%@AE@%%@NL@%
- hwndOwner, %@AB@%/* Owner */%@AE@%%@NL@%
- fnwpDlgProc, %@AB@%/* Address of dialog proc */%@AE@%%@NL@%
- (HMODULE) NULL, %@AB@%/* Module handle */%@AE@%%@NL@%
- idDlg, %@AB@%/* Id of dialog in resource */%@AE@%%@NL@%
- NULL ); %@AB@%/* Initialisation data */%@AE@%%@NL@%
- EnableModality( hwndOwner, TRUE ); %@AB@%/* Enable the Modality menu item */%@AE@%%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Check to see if a modeless dialog is already running: if%@NL@%
- %@AB@% * so destroy it before for loading the requested dialog. Save%@NL@%
- %@AB@% * the handle of the new dialog in a global variable so that in%@NL@%
- %@AB@% * can be accessed by the WinProc that issued LoadDialog.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- if( WinIsWindow( hab, hwndModelessDlg ) )%@NL@%
- WinDestroyWindow( hwndModelessDlg );%@NL@%
- hwndModelessDlg = WinLoadDlg( hwndParent,%@NL@%
- hwndOwner,%@NL@%
- fnwpDlgProc,%@NL@%
- (HMODULE) NULL,%@NL@%
- idDlg,%@NL@%
- NULL );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: MainWndCommand%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Take the appropriate action when a WM_COMMAND message is received by%@NL@%
- %@AB@%* MainWndProc. Issues calls which load dialogs in the prevailing state%@NL@%
- %@AB@%* of modality.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl MainWndCommand( hwnd, Command, bModality )%@NL@%
- HWND hwnd;%@NL@%
- USHORT Command;%@NL@%
- BOOL *bModality;%@NL@%
- {%@NL@%
- USHORT idDlg;%@NL@%
- PFNWP pfnDlgProc;%@NL@%
- %@NL@%
- switch( Command )%@NL@%
- {%@NL@%
- case MI_MODAL:%@NL@%
- case MI_MODELESS:%@NL@%
- *bModality = ( Command == MI_MODAL ) ? TRUE%@NL@%
- : FALSE;%@NL@%
- SetModality( WinQueryWindow( hwnd, QW_PARENT, FALSE ), *bModality );%@NL@%
- WinInvalidateRect( hwnd, NULL, FALSE );%@NL@%
- return;%@NL@%
- case MI_ENTRYFIELDEXAMPLE:%@NL@%
- idDlg = DLG_ENTRYFIELDEXAMPLE;%@NL@%
- pfnDlgProc = (PFNWP)fnwpEntryFieldDlg;%@NL@%
- break;%@NL@%
- case MI_AUTORADIOBUTTONEXAMPLE:%@NL@%
- idDlg = DLG_AUTORADIOBUTTONEXAMPLE;%@NL@%
- pfnDlgProc = (PFNWP)fnwpAutoRadioButtonDlg;%@NL@%
- break;%@NL@%
- case MI_CHECKBOXEXAMPLE:%@NL@%
- idDlg = DLG_CHECKBOXEXAMPLE;%@NL@%
- pfnDlgProc = (PFNWP)fnwpCheckBoxDlg;%@NL@%
- break;%@NL@%
- case MI_LISTBOXEXAMPLE:%@NL@%
- idDlg = DLG_LISTBOXEXAMPLE;%@NL@%
- pfnDlgProc = (PFNWP)fnwpListBoxDlg;%@NL@%
- break;%@NL@%
- case MI_ABOUTBOX:%@NL@%
- WinDlgBox(HWND_DESKTOP, hwnd, fnwpAboutBoxDlg, (HMODULE) NULL, DLG_ABOUT, NULL);%@NL@%
- return;%@NL@%
- default:%@NL@%
- return;%@NL@%
- }%@NL@%
- LoadDialog( HWND_DESKTOP,%@NL@%
- hwndFrame,%@NL@%
- idDlg,%@NL@%
- pfnDlgProc,%@NL@%
- *bModality );%@NL@%
- if( *bModality )%@NL@%
- WinInvalidateRect( hwnd, NULL, FALSE ); %@AB@%/* Request whole window repaint */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: MainWndPaint%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* An unsophisticated window painting routine which simply repaints the%@NL@%
- %@AB@%* entire window when a WM_PAINT message is received. In a real%@NL@%
- %@AB@%* application more sophisticated techniques could be used to determine%@NL@%
- %@AB@%* the minimum region needing repainting, and to paint only that%@NL@%
- %@AB@%* region%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl MainWndPaint( hwnd )%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- POINTL pointl;%@NL@%
- HPS hps; %@AB@%/* Presentation space handle */%@AE@%%@NL@%
- RECTL rcl; %@AB@%/* Window rectangle */%@AE@%%@NL@%
- CHAR string[50];%@NL@%
- %@NL@%
- hps = WinBeginPaint( hwnd, (HPS)NULL, (PRECTL)&rcl );%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Color in the background%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch ((int) colorClient) {%@NL@%
- case 0: %@AB@%/* (r,g,b) = (0,0,0) */%@AE@%%@NL@%
- WinFillRect( hps, (PRECTL)&rcl, CLR_BLACK );%@NL@%
- break;%@NL@%
- case 7: %@AB@%/* (r,g,b) = (1,1,1) */%@AE@%%@NL@%
- WinFillRect( hps, (PRECTL)&rcl, CLR_WHITE );%@NL@%
- break;%@NL@%
- default:%@NL@%
- WinFillRect( hps, (PRECTL)&rcl, colorClient );%@NL@%
- break;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Set the text character colors%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GpiSetColor( hps, (colorClient == 0L) ? CLR_WHITE%@NL@%
- : CLR_BLACK );%@NL@%
- pointl.x = 10L; pointl.y = 70L;%@NL@%
- strcpy( string, "Dialog modality = " );%@NL@%
- strcat( string, (bModality) ? "Modal"%@NL@%
- : "Modeless" );%@NL@%
- GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );%@NL@%
- pointl.y = 50L;%@NL@%
- strcpy( string, "Entry Field 1 = " );%@NL@%
- strcat( string, szEntryField1 );%@NL@%
- GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );%@NL@%
- pointl.y = 30L;%@NL@%
- strcpy( string, "Entry Field 2 = " );%@NL@%
- strcat( string, szEntryField2 );%@NL@%
- GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );%@NL@%
- pointl.y = 10L;%@NL@%
- strcpy( string, "List Box Selection = " );%@NL@%
- strcat( string, szSelection );%@NL@%
- GpiCharStringAt( hps, &pointl, (LONG)strlen( string ), (PSZ)string );%@NL@%
- WinEndPaint( hps );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/**************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* FUNCTION: SetModality%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Check or uncheck Modal and Modeless menu items as appropriate.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%**************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl SetModality( hwnd, bModal )%@NL@%
- HWND hwnd;%@NL@%
- BOOL bModal;%@NL@%
- {%@NL@%
- WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),%@NL@%
- MM_SETITEMATTR,%@NL@%
- MPFROM2SHORT( MI_MODAL, TRUE ),%@NL@%
- MPFROM2SHORT( MIA_CHECKED, (bModal) ? ( MIA_CHECKED)%@NL@%
- : (~MIA_CHECKED) ) );%@NL@%
- %@NL@%
- WinPostMsg( WinWindowFromID( hwnd, FID_MENU ),%@NL@%
- MM_SETITEMATTR,%@NL@%
- MPFROM2SHORT( MI_MODELESS, TRUE ),%@NL@%
- MPFROM2SHORT( MIA_CHECKED, (bModal) ? (~MIA_CHECKED)%@NL@%
- : ( MIA_CHECKED) ) );%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- MRESULT EXPENTRY fnwpAboutBoxDlg(hDlg, msg, mp1, mp2)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HWND hDlg;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hDlg, TRUE); break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGDB.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGDB.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DMGDB.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DDE manager data handling routines%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 12/14/88 Sanford Staab%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* PAPPINFO GetCurrentAppInfo()%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* This routine uses the pid of the current thread to locate the information%@NL@%
- %@AB@%* pertaining to that thread. If not found, 0 is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This call fails if the DLL is in a callback state to prevent recursion.%@NL@%
- %@AB@%* if fChkCallback is set.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 Created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PAPPINFO GetCurrentAppInfo(fChkCallback)%@NL@%
- BOOL fChkCallback;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- if (pAppInfoList == NULL || !CheckSel(SELECTOROF(pAppInfoList))) {%@NL@%
- SemLeave();%@NL@%
- return(0);%@NL@%
- }%@NL@%
- pai = pAppInfoList;%@NL@%
- while (pai) {%@NL@%
- if (pai->pid == FSRSemDmg.pid && pai->tid == FSRSemDmg.tid) {%@NL@%
- if (fChkCallback && pai->cInCallback > MAX_RECURSE) {%@NL@%
- pai->LastError = DMGERR_REENTRANCY;%@NL@%
- break;%@NL@%
- } else {%@NL@%
- SemLeave();%@NL@%
- return(pai);%@NL@%
- }%@NL@%
- }%@NL@%
- pai = pai->next;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* void UnlinkAppInfo(pai)%@NL@%
- %@AB@%* PAPPINFO pai;%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* unlinks an pai safely. Does nothing if not linked.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 Created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void UnlinkAppInfo(pai)%@NL@%
- PAPPINFO pai;%@NL@%
- {%@NL@%
- PAPPINFO paiT;%@NL@%
- %@NL@%
- AssertF(pai != NULL, "UnlinkAppInfo - NULL input");%@NL@%
- SemEnter();%@NL@%
- if (pai == pAppInfoList) {%@NL@%
- pAppInfoList = pai->next;%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- paiT = pAppInfoList;%@NL@%
- while (paiT && paiT->next != pai)%@NL@%
- paiT = paiT->next;%@NL@%
- if (paiT)%@NL@%
- paiT->next = pai->next;%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Functions ***************************\%@NL@%
- %@AB@%* General List management functions.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/15/88 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PLST CreateLst(hheap, cbItem)%@NL@%
- HHEAP hheap;%@NL@%
- USHORT cbItem;%@NL@%
- {%@NL@%
- PLST pLst;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- if (!(pLst = (PLST)FarAllocMem(hheap, sizeof(LST)))) {%@NL@%
- SemLeave();%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- pLst->hheap = hheap;%@NL@%
- pLst->cbItem = cbItem;%@NL@%
- pLst->pItemFirst = (PLITEM)NULL;%@NL@%
- SemLeave();%@NL@%
- return(pLst);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void FlushLst(pLst)%@NL@%
- PLST pLst;%@NL@%
- {%@NL@%
- if (pLst == NULL)%@NL@%
- return;%@NL@%
- SemEnter();%@NL@%
- while (pLst->pItemFirst) %@NL@%
- RemoveLstItem(pLst, pLst->pItemFirst);%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void DestroyLst(pLst)%@NL@%
- PLST pLst;%@NL@%
- {%@NL@%
- if (pLst == NULL)%@NL@%
- return;%@NL@%
- SemEnter();%@NL@%
- while (pLst->pItemFirst) %@NL@%
- RemoveLstItem(pLst, pLst->pItemFirst);%@NL@%
- FarFreeMem(pLst->hheap, pLst, sizeof(LST));%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- PLITEM FindLstItem(pLst, npfnCmp, piSearch)%@NL@%
- PLST pLst;%@NL@%
- NPFNCMP npfnCmp;%@NL@%
- PLITEM piSearch;%@NL@%
- {%@NL@%
- PLITEM pi;%@NL@%
- %@NL@%
- if (pLst == NULL)%@NL@%
- return(NULL);%@NL@%
- SemEnter();%@NL@%
- pi = pLst->pItemFirst;%@NL@%
- while (pi) {%@NL@%
- if ((*npfnCmp)%@NL@%
- ((PBYTE)pi + sizeof(LITEM), (PBYTE)piSearch + sizeof(LITEM))) {%@NL@%
- SemLeave();%@NL@%
- return(pi);%@NL@%
- }%@NL@%
- pi = pi->next;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Comparison functions for FindLstItem() and FindPileItem()%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- BOOL CmpULONG(pb1, pb2)%@NL@%
- PBYTE pb1;%@NL@%
- PBYTE pb2;%@NL@%
- {%@NL@%
- return(*(PULONG)pb1 == *(PULONG)pb2);%@NL@%
- }%@NL@%
- %@NL@%
- BOOL CmppHsz(pb1, pb2)%@NL@%
- PBYTE pb1;%@NL@%
- PBYTE pb2;%@NL@%
- {%@NL@%
- return(CmpHsz(*(PHSZ)pb1, *(PHSZ)pb2) ? FALSE : TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine creates a new list item for pLst and links it in according%@NL@%
- %@AB@%* to the ILST_ constant in afCmd. Returns a pointer to the new item%@NL@%
- %@AB@%* or NULL on failure.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Note: This MUST be in the semaphore for use since the new list item%@NL@%
- %@AB@%* is filled with garbage on return yet is linked in. %@NL@%
- %@AB@%* %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PLITEM NewLstItem(pLst, afCmd)%@NL@%
- PLST pLst;%@NL@%
- USHORT afCmd;%@NL@%
- {%@NL@%
- PLITEM pi, piT;%@NL@%
- %@NL@%
- if (pLst == NULL)%@NL@%
- return(NULL);%@NL@%
- SemCheckIn();%@NL@%
- %@NL@%
- pi = (PLITEM)FarAllocMem(pLst->hheap, pLst->cbItem + sizeof(LITEM));%@NL@%
- if (pi == NULL) {%@NL@%
- AssertF(FALSE, "NewLstItem - memory failure"); %@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- %@NL@%
- if (afCmd & ILST_NOLINK) %@NL@%
- return(pi);%@NL@%
- %@NL@%
- if (((piT = pLst->pItemFirst) == NULL) || (afCmd & ILST_FIRST)) {%@NL@%
- pi->next = piT;%@NL@%
- pLst->pItemFirst = pi;%@NL@%
- } else { %@AB@%/* ILST_LAST assumed */%@AE@%%@NL@%
- while (piT->next != NULL) %@NL@%
- piT = piT->next;%@NL@%
- piT->next = pi;%@NL@%
- pi->next = NULL;%@NL@%
- }%@NL@%
- return(pi);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine unlinks and frees pi from pLst. If pi cannot be located%@NL@%
- %@AB@%* within pLst, it is freed anyway.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL RemoveLstItem(pLst, pi)%@NL@%
- PLST pLst;%@NL@%
- PLITEM pi;%@NL@%
- {%@NL@%
- PLITEM piT;%@NL@%
- %@NL@%
- if (pLst == NULL || pi == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemCheckIn();%@NL@%
- %@NL@%
- if ((piT = pLst->pItemFirst) != NULL) {%@NL@%
- if (pi == piT) {%@NL@%
- pLst->pItemFirst = pi->next;%@NL@%
- } else {%@NL@%
- while (piT->next != pi && piT->next != NULL)%@NL@%
- piT = piT->next;%@NL@%
- if (piT->next != NULL)%@NL@%
- piT->next = pi->next; %@AB@%/* unlink */%@AE@%%@NL@%
- }%@NL@%
- } else {%@NL@%
- AssertF(pi == NULL, "Improper list item removal");%@NL@%
- }%@NL@%
- FarFreeMem(pLst->hheap, pi, pLst->cbItem + sizeof(LITEM));%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine uses ILST_ constants to insert a list item into the apropriate%@NL@%
- %@AB@%* spot of the pLst given. Only ILST_FIRST or ILST_LAST are allowed.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/11/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL InsertLstItem(pLst, pi, afCmd)%@NL@%
- PLST pLst;%@NL@%
- PLITEM pi;%@NL@%
- USHORT afCmd;%@NL@%
- {%@NL@%
- PLITEM piT;%@NL@%
- %@NL@%
- if (pLst == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- %@NL@%
- if (pLst->pItemFirst == NULL || afCmd & ILST_FIRST) {%@NL@%
- pi->next = pLst->pItemFirst;%@NL@%
- pLst->pItemFirst = pi;%@NL@%
- } else { %@AB@%/* ILST_LAST assumed */%@AE@%%@NL@%
- piT = pLst->pItemFirst;%@NL@%
- while (piT->next) %@NL@%
- piT = piT->next;%@NL@%
- piT->next = pi;%@NL@%
- pi->next = NULL;%@NL@%
- }%@NL@%
- %@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ------------- Specific list routines -------------%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This function is HIGHLY dependent on the ADVLI structure.%@NL@%
- %@AB@% * This will match an exact hsz/fmt pair with a 0 format being wild.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL CmpAdv(pb1, pb2)%@NL@%
- PBYTE pb1;%@NL@%
- PBYTE pb2;%@NL@%
- {%@NL@%
- USHORT usFmt;%@NL@%
- %@NL@%
- if (*(PHSZ)pb1 == *(PHSZ)pb2) {%@NL@%
- if ((usFmt = *(PUSHORT)(pb2 + 4)) == 0)%@NL@%
- return(TRUE);%@NL@%
- if (usFmt == *(PUSHORT)(pb1 + 4))%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- BOOL fSearchHwndList(pLst, hwnd)%@NL@%
- PLST pLst;%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- HWNDLI hwndi;%@NL@%
- %@NL@%
- hwndi.hwnd = hwnd;%@NL@%
- return((BOOL)FindLstItem(pLst, CmpHwnd, (PLITEM)&hwndi));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void AddHwndList(hwnd, pLst)%@NL@%
- HWND hwnd;%@NL@%
- PLST pLst;%@NL@%
- {%@NL@%
- HWNDLI hwndli;%@NL@%
- PHWNDLI pli;%@NL@%
- %@NL@%
- AssertF(pLst != NULL, "AddHwndList - NULL pLst");%@NL@%
- AssertF(pLst->cbItem == sizeof(HWNDLI), "AddHwndList - Bad item size");%@NL@%
- SemEnter();%@NL@%
- hwndli.hwnd = hwnd;%@NL@%
- if ((hwnd == NULL) || FindLstItem(pLst, CmpHwnd, (PLITEM)&hwndli)) {%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- pli = (PHWNDLI)NewLstItem(pLst, ILST_FIRST);%@NL@%
- pli->hwnd = hwnd;%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Insert the given data into the list if one does not already exist%@NL@%
- %@AB@% * under the given hwnd.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void AddAckHwndList(hwnd, hszApp, hszTopic, pLst)%@NL@%
- HWND hwnd;%@NL@%
- HSZ hszApp;%@NL@%
- HSZ hszTopic;%@NL@%
- PLST pLst;%@NL@%
- {%@NL@%
- HWNDLI hwndli;%@NL@%
- PACKHWNDLI pli;%@NL@%
- %@NL@%
- AssertF(pLst != NULL, "AddAckHwndList - NULL pLst");%@NL@%
- AssertF(pLst->cbItem == sizeof(ACKHWNDLI), "AddAckHwndList - Bad item size");%@NL@%
- SemEnter();%@NL@%
- hwndli.hwnd = hwnd;%@NL@%
- if ((hwnd == NULL) || FindLstItem(pLst, CmpHwnd, (PLITEM)&hwndli)) {%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- pli = (PACKHWNDLI)NewLstItem(pLst, ILST_FIRST);%@NL@%
- pli->hwnd = hwnd;%@NL@%
- pli->hszApp = hszApp;%@NL@%
- pli->hszTopic = hszTopic;%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* hwnd-hsz list functions%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/20/89 Created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void AddHwndHszList(hsz, hwnd, pLst)%@NL@%
- HSZ hsz;%@NL@%
- HWND hwnd;%@NL@%
- PLST pLst;%@NL@%
- {%@NL@%
- PHWNDHSZLI phhi;%@NL@%
- %@NL@%
- AssertF(pLst->cbItem == sizeof(HWNDHSZLI), "AddHwndHszList - Bad item size");%@NL@%
- SemEnter();%@NL@%
- if ((hsz == NULL) || (BOOL)HwndFromHsz(hsz, pLst)) {%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- phhi = (PHWNDHSZLI)NewLstItem(pLst, ILST_FIRST);%@NL@%
- phhi->hwnd = hwnd;%@NL@%
- phhi->hsz = hsz;%@NL@%
- IncHszCount(hsz);%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void DestroyHwndHszList(pLst)%@NL@%
- PLST pLst;%@NL@%
- {%@NL@%
- AssertF(pLst->cbItem == sizeof(HWNDHSZLI), "DestroyHwndHszList - Bad item size");%@NL@%
- SemEnter();%@NL@%
- while(pLst->pItemFirst) {%@NL@%
- FreeHsz(((PHWNDHSZLI)pLst->pItemFirst)->hsz);%@NL@%
- RemoveLstItem(pLst, pLst->pItemFirst);%@NL@%
- }%@NL@%
- FarFreeMem(pLst->hheap, pLst, sizeof(LST));%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- HWND HwndFromHsz(hsz, pLst)%@NL@%
- HSZ hsz;%@NL@%
- PLST pLst;%@NL@%
- {%@NL@%
- HWNDHSZLI hhli;%@NL@%
- PHWNDHSZLI phhli;%@NL@%
- %@NL@%
- hhli.hsz = hsz;%@NL@%
- if (!(phhli = (PHWNDHSZLI)FindLstItem(pLst, CmppHsz, (PLITEM)&hhli)))%@NL@%
- return(NULL);%@NL@%
- return(phhli->hwnd);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* Advise list helper functions.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/20/89 Created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL AddAdvList(pLst, hszItem, fsStatus, usFmt)%@NL@%
- PLST pLst;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT fsStatus;%@NL@%
- USHORT usFmt;%@NL@%
- {%@NL@%
- PADVLI pali;%@NL@%
- %@NL@%
- AssertF(pLst->cbItem == sizeof(ADVLI), "AddAdvList - bad item size");%@NL@%
- if (hszItem == NULL) %@NL@%
- return(TRUE);%@NL@%
- SemEnter();%@NL@%
- if (!(pali = FindAdvList(pLst, hszItem, usFmt))) {%@NL@%
- IncHszCount(hszItem);%@NL@%
- pali = (PADVLI)NewLstItem(pLst, ILST_FIRST);%@NL@%
- }%@NL@%
- AssertF((BOOL)pali, "AddAdvList - NewLstItem() failed")%@NL@%
- if (pali != NULL) {%@NL@%
- pali->hszItem = hszItem;%@NL@%
- pali->usFmt = usFmt;%@NL@%
- pali->fsStatus = fsStatus;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return((BOOL)pali); %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This will delete the matching Advise loop entry. If usFmt is 0, all%@NL@%
- %@AB@% * entries with the same hszItem are deleted. Returns fNotEmptyAfterDelete.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL DeleteAdvList(pLst, hszItem, usFmt)%@NL@%
- PLST pLst;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT usFmt;%@NL@%
- {%@NL@%
- PADVLI pali;%@NL@%
- %@NL@%
- if (hszItem == NULL) %@NL@%
- return((BOOL)pLst->pItemFirst);%@NL@%
- SemEnter();%@NL@%
- while (pali = (PADVLI)FindAdvList(pLst, hszItem, usFmt)) {%@NL@%
- FreeHsz((pali)->hszItem);%@NL@%
- RemoveLstItem(pLst, (PLITEM)pali);%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return((BOOL)pLst->pItemFirst);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine searches the advise list for and entry in hszItem. It returns%@NL@%
- %@AB@%* pAdvli only if the item is found.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PADVLI FindAdvList(pLst, hszItem, usFmt)%@NL@%
- PLST pLst;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT usFmt;%@NL@%
- {%@NL@%
- ADVLI advli;%@NL@%
- %@NL@%
- advli.hszItem = hszItem;%@NL@%
- advli.usFmt = usFmt;%@NL@%
- return((PADVLI)FindLstItem(pLst, CmpAdv, (PLITEM)&advli));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine searches for the next entry for hszItem. It returns%@NL@%
- %@AB@%* pAdvli only if the item is found.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 11/15/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PADVLI FindNextAdv(padvli, hszItem)%@NL@%
- PADVLI padvli;%@NL@%
- HSZ hszItem;%@NL@%
- {%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- while ((padvli = (PADVLI)padvli->next) != NULL) {%@NL@%
- if (padvli->hszItem == hszItem) {%@NL@%
- SemLeave();%@NL@%
- return(padvli);%@NL@%
- }%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Pile Functions ********************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* A pile is a list where each item is an array of subitems. This allows%@NL@%
- %@AB@%* a more memory efficient method of handling unordered lists.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%\*****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- PPILE CreatePile(hheap, cbItem, cItemsPerBlock)%@NL@%
- HHEAP hheap;%@NL@%
- USHORT cbItem;%@NL@%
- USHORT cItemsPerBlock;%@NL@%
- {%@NL@%
- PPILE ppile;%@NL@%
- %@NL@%
- if (!(ppile = (PPILE)FarAllocMem(hheap, sizeof(PILE)))) {%@NL@%
- SemLeave();%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- ppile->pBlockFirst = (PLITEM)NULL;%@NL@%
- ppile->hheap = hheap;%@NL@%
- ppile->cbBlock = cbItem * cItemsPerBlock + sizeof(PILEB);%@NL@%
- ppile->cSubItemsMax = cItemsPerBlock;%@NL@%
- ppile->cbSubItem = cbItem;%@NL@%
- return(ppile);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- PPILE DestroyPile(pPile)%@NL@%
- PPILE pPile;%@NL@%
- {%@NL@%
- if (pPile == NULL)%@NL@%
- return(NULL);%@NL@%
- SemEnter();%@NL@%
- while (pPile->pBlockFirst) %@NL@%
- RemoveLstItem((PLST)pPile, (PLITEM)pPile->pBlockFirst);%@NL@%
- FarFreeMem(pPile->hheap, pPile, sizeof(PILE));%@NL@%
- SemLeave();%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- %@NL@%
- void FlushPile(pPile)%@NL@%
- PPILE pPile;%@NL@%
- {%@NL@%
- if (pPile == NULL)%@NL@%
- return;%@NL@%
- SemEnter();%@NL@%
- while (pPile->pBlockFirst) %@NL@%
- RemoveLstItem((PLST)pPile, (PLITEM)pPile->pBlockFirst);%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- USHORT QPileItemCount(pPile)%@NL@%
- PPILE pPile;%@NL@%
- {%@NL@%
- register USHORT c;%@NL@%
- PPILEB pBlock;%@NL@%
- %@NL@%
- if (pPile == NULL)%@NL@%
- return(0);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- pBlock = pPile->pBlockFirst;%@NL@%
- c = 0;%@NL@%
- while (pBlock) {%@NL@%
- c += pBlock->cItems;%@NL@%
- pBlock = pBlock->next;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(c);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- BOOL CopyPileItems(pPile, pDst)%@NL@%
- PPILE pPile;%@NL@%
- PBYTE pDst;%@NL@%
- {%@NL@%
- PPILEB pBlock;%@NL@%
- %@NL@%
- AssertF(pDst != NULL, "CopyPileItems - NULL destination");%@NL@%
- if (pPile == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- pBlock = pPile->pBlockFirst;%@NL@%
- while (pBlock) {%@NL@%
- CopyBlock((PBYTE)pBlock + sizeof(PILEB), pDst,%@NL@%
- pBlock->cItems * pPile->cbSubItem);%@NL@%
- pDst += pBlock->cItems * pPile->cbSubItem;%@NL@%
- pBlock = pBlock->next;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Locate and return the pointer to the pile subitem who's key fields match%@NL@%
- %@AB@%* pbSearch using npfnCmp to compare the fields. If pbSearch == NULL, or%@NL@%
- %@AB@%* npfnCmp == NULL, the first subitem is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* afCmd may be:%@NL@%
- %@AB@%* FPI_DELETE - delete the located item%@NL@%
- %@AB@%* FPI_COUNT - count number of items that match%@NL@%
- %@AB@%* In this case, the returned pointer is not valid.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* pppb points to where to store a pointer to the block which contained%@NL@%
- %@AB@%* the located item.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* if pppb == NULL, it is ignored.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* NULL is returned if pbSearch was not found or if the list was empty.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PBYTE FindPileItem(pPile, npfnCmp, pbSearch, afCmd)%@NL@%
- PPILE pPile;%@NL@%
- NPFNCMP npfnCmp;%@NL@%
- PBYTE pbSearch;%@NL@%
- USHORT afCmd;%@NL@%
- {%@NL@%
- PBYTE pb;%@NL@%
- PPILEB ppbT;%@NL@%
- register int i;%@NL@%
- register int c;%@NL@%
- %@NL@%
- if (pPile == NULL)%@NL@%
- return(NULL);%@NL@%
- c = 0;%@NL@%
- SemEnter();%@NL@%
- ppbT = pPile->pBlockFirst;%@NL@%
- while (ppbT) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * for each block...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (pb = (PBYTE)ppbT + sizeof(PILEB), i = 0;%@NL@%
- i < ppbT->cItems; pb += pPile->cbSubItem, i++) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * and each item within that block..%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pbSearch == NULL || npfnCmp == NULL ||%@NL@%
- (*npfnCmp)(pb, pbSearch)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If it matches or we don't care...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (afCmd & FPI_DELETE) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * remove entire block if this was the last subitem in it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (--ppbT->cItems == 0) {%@NL@%
- RemoveLstItem((PLST)pPile, (PLITEM)ppbT);%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * copy last subitem in the block over the removed item.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- CopyBlock((PBYTE)ppbT + sizeof(PILEB) +%@NL@%
- pPile->cbSubItem * ppbT->cItems,%@NL@%
- pb, pPile->cbSubItem);%@NL@%
- }%@NL@%
- }%@NL@%
- if (afCmd & FPI_COUNT) {%@NL@%
- c++;%@NL@%
- } else {%@NL@%
- SemLeave();%@NL@%
- return(pb);%@NL@%
- }%@NL@%
- if (afCmd & FPI_DELETE) {%@NL@%
- pb = (PBYTE)ppbT + sizeof(PILEB);%@NL@%
- i = 0;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- ppbT = (PPILEB)ppbT->next;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return((PBYTE)(ULONG)c);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Places a copy of the subitem pointed to by pb into the first available%@NL@%
- %@AB@%* spot in the pile pPile. If npfnCmp != NULL, the pile is first searched%@NL@%
- %@AB@%* for a pb match. If found, pb replaces the located data but FALSE is%@NL@%
- %@AB@%* returned to show that no real addition took place.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL AddPileItem(pPile, pb, npfnCmp)%@NL@%
- PPILE pPile;%@NL@%
- PBYTE pb;%@NL@%
- BOOL (*npfnCmp)(PBYTE pb, PBYTE pbSearch);%@NL@%
- {%@NL@%
- PBYTE pbDst;%@NL@%
- PPILEB ppb;%@NL@%
- %@NL@%
- if (pPile == NULL)%@NL@%
- return(FALSE);%@NL@%
- SemEnter();%@NL@%
- if (npfnCmp != NULL &&%@NL@%
- (pbDst = FindPileItem(pPile, npfnCmp, pb, 0)) != NULL) {%@NL@%
- CopyBlock(pb, pbDst, pPile->cbSubItem);%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- ppb = pPile->pBlockFirst;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * locate a block with room%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while ((ppb != NULL) && ppb->cItems == pPile->cSubItemsMax) {%@NL@%
- ppb = (PPILEB)ppb->next;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If all full or no blocks, make a new one, link it on the bottom.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (ppb == NULL) {%@NL@%
- if ((ppb = (PPILEB)NewLstItem((PLST)pPile, ILST_LAST)) == NULL) {%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- ppb->cItems = 0;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * add the subitem%@NL@%
- %@AB@% */%@AE@%%@NL@%
- CopyBlock(pb, (PBYTE)ppb + sizeof(PILEB) + pPile->cbSubItem * ppb->cItems++,%@NL@%
- pPile->cbSubItem);%@NL@%
- %@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Fills pb with a copy of the top item's data and removes it from the pile.%@NL@%
- %@AB@%* returns FALSE if the pile was empty.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL PopPileSubitem(pPile, pb)%@NL@%
- PPILE pPile;%@NL@%
- PBYTE pb;%@NL@%
- {%@NL@%
- PPILEB ppb;%@NL@%
- PBYTE pSrc;%@NL@%
- %@NL@%
- %@NL@%
- if ((pPile == NULL) || ((ppb = pPile->pBlockFirst) == NULL))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- pSrc = (PBYTE)pPile->pBlockFirst + sizeof(PILEB);%@NL@%
- CopyBlock(pSrc, pb, pPile->cbSubItem);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * remove entire block if this was the last subitem in it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pPile->pBlockFirst->cItems == 1) {%@NL@%
- RemoveLstItem((PLST)pPile, (PLITEM)pPile->pBlockFirst);%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * move last item in block to replace copied subitem and decrement%@NL@%
- %@AB@% * subitem count.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- CopyBlock(pSrc + pPile->cbSubItem * --pPile->pBlockFirst->cItems,%@NL@%
- pSrc, pPile->cbSubItem);%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Semaphore Functions *************************\%@NL@%
- %@AB@%* SemEnter() and SemLeave() are macros.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 Created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void SemInit()%@NL@%
- {%@NL@%
- PBYTE pSem;%@NL@%
- SHORT c;%@NL@%
- %@NL@%
- pSem = (PBYTE)&FSRSemDmg;%@NL@%
- c = 0;%@NL@%
- while (c++ < sizeof(DOSFSRSEM)) {%@NL@%
- *pSem++ = 0;%@NL@%
- }%@NL@%
- FSRSemDmg.cb = sizeof(DOSFSRSEM);%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#ifdef %@AE@%DEBUG %@NL@%
- void SemCheckIn()%@NL@%
- { %@NL@%
- PIDINFO pi;%@NL@%
- BOOL fin;%@NL@%
- %@NL@%
- DosGetPID(&pi);%@NL@%
- fin = (FSRSemDmg.cUsage > 0) &&%@NL@%
- (FSRSemDmg.pid == pi.pid) &&%@NL@%
- ((FSRSemDmg.tid == pi.tid) || (FSRSemDmg.tid == -1));%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * !!! NOTE: during exitlists processing, semaphore TIDs are set to -1%@NL@%
- %@AB@% */%@AE@%%@NL@%
- AssertF(fin, "SemCheckIn - Out of Semaphore");%@NL@%
- if (!fin)%@NL@%
- SemEnter();%@NL@%
- }%@NL@%
- %@NL@%
- void SemCheckOut()%@NL@%
- {%@NL@%
- PIDINFO pi;%@NL@%
- BOOL fOut;%@NL@%
- %@NL@%
- DosGetPID(&pi);%@NL@%
- fOut = FSRSemDmg.cUsage == 0 || FSRSemDmg.pid != pi.pid ||%@NL@%
- FSRSemDmg.tid != pi.tid;%@NL@%
- AssertF(fOut, "SemCheckOut - In Semaphore");%@NL@%
- if (!fOut)%@NL@%
- while (FSRSemDmg.cUsage)%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- }%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- %@NL@%
- void SemEnter()%@NL@%
- {%@NL@%
- DosFSRamSemRequest(&FSRSemDmg, SEM_INDEFINITE_WAIT);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- void SemLeave()%@NL@%
- {%@NL@%
- DosFSRamSemClear(&FSRSemDmg);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void EXPENTRY ExlstAbort(usTermCode)%@NL@%
- USHORT usTermCode;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- usTermCode;%@NL@%
- %@NL@%
- SemEnter(); %@AB@%/* get any other processes out of the semaphore */%@AE@%%@NL@%
- if (pai = GetCurrentAppInfo(FALSE)) {%@NL@%
- pai->cInCallback = 0; %@AB@%/* so Unregister call will work */%@AE@%%@NL@%
- DdeUninitialize();%@NL@%
- } else {%@NL@%
- SemLeave();%@NL@%
- DosExitList(EXLST_REMOVE, (PFNEXITLIST)ExlstAbort);%@NL@%
- }%@NL@%
- DosExitList(EXLST_EXIT, 0);%@NL@%
- }%@NL@%
- %@NL@%
- BOOL CopyHugeBlock(pSrc, pDst, cb)%@NL@%
- PBYTE pSrc;%@NL@%
- PBYTE pDst;%@NL@%
- ULONG cb;%@NL@%
- {%@NL@%
- ULONG cFirst;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * |____________| |___________| |____________| |____________|%@NL@%
- %@AB@% * ^src ^%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * |____________| |___________| |____________| |____________|%@NL@%
- %@AB@% * ^dst ^%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cFirst = (ULONG)min((~(USHORT)pSrc), (~(USHORT)pDst)) + 1L;%@NL@%
- if (cb < cFirst) {%@NL@%
- CopyBlock(pSrc, pDst, (USHORT)cb);%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- goto copyit;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Now at least one of the pointers is on a segment boundry.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while (cb) {%@NL@%
- cFirst = min(0x10000 - ((USHORT)pSrc | (USHORT)pDst), cb);%@NL@%
- copyit:%@NL@%
- if (HIUSHORT(cFirst)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * special case where pSrc and pDst both are on segment%@NL@%
- %@AB@% * bounds. Copy half at a time.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * |___________| |____________| |____________|%@NL@%
- %@AB@% * ^src ^%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * |___________| |____________| |____________|%@NL@%
- %@AB@% * ^dst ^%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cFirst >>= 1;%@NL@%
- CopyBlock(pSrc, pDst, (USHORT)cFirst);%@NL@%
- pSrc += cFirst;%@NL@%
- pDst += cFirst;%@NL@%
- cb -= cFirst;%@NL@%
- }%@NL@%
- CopyBlock(pSrc, pDst, (USHORT)cFirst);%@NL@%
- pSrc = HugeOffset(pSrc, cFirst);%@NL@%
- pDst = HugeOffset(pDst, cFirst);%@NL@%
- cb -= cFirst;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * |____________| |___________| |____________| |____________|%@NL@%
- %@AB@% * ^src ^%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * |____________| |___________| |____________| |____________|%@NL@%
- %@AB@% * ^dst ^%@NL@%
- %@AB@% */%@AE@%%@NL@%
- }%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************************************************************\%@NL@%
- %@AB@%* Kills windows but avoids invalid window rips in debugger.%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL DestroyWindow(hwnd)%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- if (WinIsWindow(DMGHAB, hwnd))%@NL@%
- return(WinDestroyWindow(hwnd));%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Returns hConv of the window passed in is one of the ddeml windows.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HCONV IsDdeWindow(hwnd)%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- pai = pAppInfoList;%@NL@%
- %@NL@%
- while (pai && WinIsChild(hwnd, pai->hwndDmg)) %@NL@%
- pai = pai->next;%@NL@%
- %@NL@%
- if (pai)%@NL@%
- return((HCONV)hwnd);%@NL@%
- else%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine only frees a MYDDES segment if this process is not the owner.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void FreeData(%@NL@%
- PMYDDES pmyddes,%@NL@%
- PAPPINFO pai)%@NL@%
- {%@NL@%
- TID tid;%@NL@%
- if (!CheckSel(SELECTOROF(pmyddes)) ||%@NL@%
- ( pmyddes->offszItemName == sizeof(MYDDES) &&%@NL@%
- pmyddes->magic == MYDDESMAGIC &&%@NL@%
- pmyddes->fs & HDATA_APPOWNED &&%@NL@%
- pmyddes->pai == pai) )%@NL@%
- return;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- FindPileItem(pai->pHDataPile, CmpULONG, (PBYTE)&pmyddes, FPI_DELETE);%@NL@%
- tid = pai->tid;%@NL@%
- do {%@NL@%
- if (FindPileItem(pai->pHDataPile, CmpULONG, (PBYTE)&pmyddes, FPI_COUNT)) {%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- pai = pai->nextThread;%@NL@%
- } while (pai && pai->tid != tid);%@NL@%
- SemLeave();%@NL@%
- DosFreeSeg(SELECTOROF(pmyddes));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#ifdef %@AE@%DEBUG %@NL@%
- int APIENTRY DebugOutput(PCH);%@NL@%
- void fAssert(f, pszComment, line, szfile)%@NL@%
- BOOL f;%@NL@%
- PSZ pszComment;%@NL@%
- USHORT line;%@NL@%
- PSZ szfile;%@NL@%
- {%@NL@%
- char szT[90];%@NL@%
- PSZ psz, pszLast;%@NL@%
- %@NL@%
- if (!f) {%@NL@%
- szT[0] = '\000';%@NL@%
- psz = szT;%@NL@%
- pszLast = &szT[89];%@NL@%
- psz = lstrcat(psz, "\n\rAssertion failure: ", pszLast);%@NL@%
- psz = lstrcat(psz, szfile, pszLast);%@NL@%
- psz = lstrcat(psz, ":", pszLast);%@NL@%
- psz = dtoa(psz, line, FALSE);%@NL@%
- psz = lstrcat(psz, " ", pszLast);%@NL@%
- psz = lstrcat(psz, pszComment, pszLast);%@NL@%
- psz = lstrcat(psz, "\n\r", pszLast);%@NL@%
- DebugOutput(szT);%@NL@%
- DebugBreak(); %@NL@%
- }%@NL@%
- }%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- HDMGDATA PutData(pSrc, cb, cbOff, hszItem, usFmt, afCmd, pai)%@NL@%
- PBYTE pSrc;%@NL@%
- ULONG cb;%@NL@%
- ULONG cbOff;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT usFmt;%@NL@%
- USHORT afCmd;%@NL@%
- PAPPINFO pai;%@NL@%
- {%@NL@%
- PMYDDES pmyddes;%@NL@%
- %@NL@%
- if ((pmyddes = (PMYDDES)AllocDDESel(0, usFmt, hszItem, cb + cbOff, pai))%@NL@%
- == NULL) {%@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- pmyddes->fs = afCmd;%@NL@%
- %@NL@%
- if (afCmd & HDATA_APPFREEABLE) {%@NL@%
- if (!AddPileItem(pai->pHDataPile, (PBYTE)&pmyddes, CmpULONG)) {%@NL@%
- DosFreeSeg(SELECTOROF(pmyddes));%@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(0L);%@NL@%
- } %@NL@%
- }%@NL@%
- if (pSrc)%@NL@%
- CopyHugeBlock(pSrc, HugeOffset(DDES_PABDATA(pmyddes), cbOff), cb);%@NL@%
- return(pmyddes);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This routine adds all HSZ/HAPP pairs it finds for the given pai matching%@NL@%
- %@AB@% * hszApp to hDataAdd.%@NL@%
- %@AB@% * poffAdd is the offset into the hDataAdd to start inserting HSZ/HAPP%@NL@%
- %@AB@% * pairs. It then truncates the list with a 0 HSZ and returns the offset%@NL@%
- %@AB@% * to the terminator (ready to be called again to add more).%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * returns 0L on error.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ULONG%@NL@%
- QueryAppNames(%@NL@%
- PAPPINFO pai,%@NL@%
- HDMGDATA hDataAdd,%@NL@%
- HSZ hszApp,%@NL@%
- ULONG offAdd)%@NL@%
- {%@NL@%
- USHORT chsz;%@NL@%
- PHSZ phsz, phszPile;%@NL@%
- PPILEB pBlock;%@NL@%
- %@NL@%
- AssertF(sizeof(HSZ) == sizeof(HAPP), "Type size conflict");%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- if (chsz = (USHORT)FindPileItem(pai->pAppNamePile,%@NL@%
- hszApp ? CmpULONG : NULL, (PBYTE)&hszApp, FPI_COUNT)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * allocate for additions.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!DdeAddData(hDataAdd, NULL,%@NL@%
- (chsz + 1L) * (sizeof(HSZ) + sizeof(HDMGDATA)), offAdd)) {%@NL@%
- offAdd = 0L;%@NL@%
- GetCurrentAppInfo(FALSE)->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- goto Exit;%@NL@%
- }%@NL@%
- %@NL@%
- phsz = DDES_PABDATA((PDDESTRUCT)hDataAdd) + offAdd;%@NL@%
- if (hszApp) {%@NL@%
- *phsz++ = hszApp; %@AB@%/* only one per thread expected */%@AE@%%@NL@%
- *phsz++ = (HSZ)pai->hwndFrame;%@NL@%
- } else {%@NL@%
- pBlock = pai->pAppNamePile->pBlockFirst;%@NL@%
- while (pBlock) {%@NL@%
- phszPile = (PHSZ)(pBlock + 1);%@NL@%
- for (chsz = 0; chsz < pBlock->cItems; chsz++) {%@NL@%
- *(phsz++) = *(phszPile++);%@NL@%
- *(phsz++) = (HSZ)pai->hwndFrame;%@NL@%
- }%@NL@%
- pBlock = pBlock->next;%@NL@%
- }%@NL@%
- }%@NL@%
- *phsz = 0L;%@NL@%
- offAdd = phsz - DDES_PABDATA((PDDESTRUCT)hDataAdd);%@NL@%
- }%@NL@%
- Exit: %@NL@%
- SemLeave();%@NL@%
- return(offAdd);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGDDE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGDDE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DMGDDE.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This module contains functions used for interfacing with DDE structures%@NL@%
- %@AB@%* and such.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 12/23/88 sanfords%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* timeout()%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine creates a timer for hwndTimeout. It then runs a modal loop%@NL@%
- %@AB@%* which will exit once the WM_TIMER message is received by hwndTimeout.%@NL@%
- %@AB@%* hwndTimeout can be any window that doesn't use timers itself with TID_TIMEOUT%@NL@%
- %@AB@%* or TID_ABORT since its window proc doesn't need to do%@NL@%
- %@AB@%* anything for this to work. Only the client and server windows use these%@NL@%
- %@AB@%* so were cool.%@NL@%
- %@AB@%* Only one timeout window is allowed per thread. This is checked by the%@NL@%
- %@AB@%* pai passed in.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns fSuccess, ie TRUE if TID_TIMEOUT was received before TID_ABORT.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* Synchronous client transaction modal loops:%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* During Synchronous transactions, a client application will enter a modal%@NL@%
- %@AB@%* loop while waiting for the server to respond to the request. If an%@NL@%
- %@AB@%* application wishes to filter messages to the modal loop, it may do so%@NL@%
- %@AB@%* by setting a message filter tied to MSGF_DDE. Applications should%@NL@%
- %@AB@%* be aware however that the DDE modal loop processes private messages%@NL@%
- %@AB@%* in the WM_USER range, WM_DDE messages, and WM_TIMER messages with timer IDs%@NL@%
- %@AB@%* using the TID_ constants defined in ddeml.h.%@NL@%
- %@AB@%* These messages must not be filtered by an application!!!%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created sanfords 12/19/88%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL timeout(pai, ulTimeout, hwndTimeout)%@NL@%
- PAPPINFO pai;%@NL@%
- ULONG ulTimeout;%@NL@%
- HWND hwndTimeout;%@NL@%
- {%@NL@%
- QMSG qmsg;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- if (pai->hwndTimer) {%@NL@%
- pai->LastError = DMGERR_REENTRANCY;%@NL@%
- AssertF(FALSE, "Recursive timeout call");%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- pai->hwndTimer = hwndTimeout;%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- WinStartTimer(DMGHAB, hwndTimeout, TID_TIMEOUT, (USHORT)ulTimeout);%@NL@%
- %@NL@%
- WinGetMsg(DMGHAB, &qmsg, (HWND)NULL, 0, 0);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * stay in modal loop until a timeout happens.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while (qmsg.hwnd != hwndTimeout ||%@NL@%
- qmsg.msg != WM_TIMER ||%@NL@%
- (LOUSHORT(qmsg.mp1) != TID_TIMEOUT &&%@NL@%
- LOUSHORT(qmsg.mp1) != TID_ABORT)) {%@NL@%
- %@NL@%
- if (!WinCallMsgFilter(DMGHAB, &qmsg, MSGF_DDE))%@NL@%
- WinDispatchMsg(DMGHAB, &qmsg);%@NL@%
- %@NL@%
- WinGetMsg(DMGHAB, &qmsg, (HWND)NULL, 0, 0);%@NL@%
- }%@NL@%
- %@NL@%
- WinStopTimer(DMGHAB, hwndTimeout, TID_TIMEOUT);%@NL@%
- SemEnter();%@NL@%
- pai->hwndTimer = 0;%@NL@%
- SemLeave();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * post a callback check incase we blocked callbacks due to being%@NL@%
- %@AB@% * in a timeout.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinPostMsg(pai->hwndDmg, UM_CHECKCBQ, (MPARAM)pai, 0L);%@NL@%
- return(LOUSHORT(qmsg.mp1) == TID_TIMEOUT);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Based on pii, this sends an INITIATE message to either an exact%@NL@%
- %@AB@%* target window (hwndSend), a target frame window (hwndFrame) or to all%@NL@%
- %@AB@%* top level frames (both hwnds are NULL). It fills in pci info as apropriate.%@NL@%
- %@AB@%* Note that pii->pCC must NOT be NULL and is assumed to be properly set.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns FALSE if SendDDEInit failed.%@NL@%
- %@AB@%* On success pci->ci.xad.state is CONVST_CONNECTED.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* created 12/21/88 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL ClientInitiate(hwnd, pii, pci)%@NL@%
- HWND hwnd;%@NL@%
- PINITINFO pii;%@NL@%
- PCLIENTINFO pci;%@NL@%
- {%@NL@%
- BOOL fRet = TRUE;%@NL@%
- %@NL@%
- if (pii->pCC->cb < sizeof(CONVCONTEXT))%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * we need to set this info BEFORE we do the synchronous initiate%@NL@%
- %@AB@% * so the INITIATEACK msg is done correctly.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pci->ci.xad.state = CONVST_INIT1;%@NL@%
- pci->ci.xad.LastError = DMGERR_NO_ERROR;%@NL@%
- pci->ci.hszServerApp = pii->hszAppName;%@NL@%
- pci->ci.hszTopic = pii->hszTopic;%@NL@%
- pci->ci.cc.cb = sizeof(CONVCONTEXT);%@NL@%
- CopyBlock((PBYTE)&pii->pCC->fsContext, (PBYTE)&pci->ci.cc.fsContext,%@NL@%
- sizeof(CONVCONTEXT) - sizeof(USHORT));%@NL@%
- pci->ci.hwndFrame = pii->hwndFrame;%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- fRet = SendDDEInit(hwnd,%@NL@%
- WinIsWindow(DMGHAB, pii->hwndSend) ? pii->hwndSend : pii->hwndFrame,%@NL@%
- pci);%@NL@%
- SemEnter();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If we failed to initiate directly with the server, try the frame.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!fRet && WinIsWindow(DMGHAB, pii->hwndSend) &&%@NL@%
- WinIsWindow(DMGHAB, pii->hwndFrame)) {%@NL@%
- SemLeave();%@NL@%
- fRet = SendDDEInit(hwnd, pii->hwndFrame, pci);%@NL@%
- if (fRet) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * OK, client is locked in so he wont go away on a terminate%@NL@%
- %@AB@% * from a random window. If the new server is not the same%@NL@%
- %@AB@% * window as the origonal, send it a terminate so it can%@NL@%
- %@AB@% * go away nicely.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pii->hwndSend != pci->ci.hwndPartner) %@NL@%
- WinSendMsg(pii->hwndSend, WM_DDE_TERMINATE, 0L, 0L);%@NL@%
- }%@NL@%
- SemEnter();%@NL@%
- %@NL@%
- }%@NL@%
- if (!fRet) %@NL@%
- pci->ci.xad.state = CONVST_NULL;%@NL@%
- else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * successful initiate means we want to keep these around awhile.%@NL@%
- %@AB@% * removed at window closing time.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- IncHszCount(pci->ci.hszServerApp);%@NL@%
- IncHszCount(pci->ci.hszTopic);%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(fRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Allocates and sends a WM_DDE_INITIATE message to hwndTo. Any failures%@NL@%
- %@AB@%* cause FALSE to be returned. If hwndTo is NULL, performs equivalent of%@NL@%
- %@AB@%* WinDdeInitiate2().%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* created 12/22/88 sanfords%@NL@%
- %@AB@%* 2/2/89 sanfords added SEG_GETABLE during monitoring.%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL SendDDEInit(hwndFrom, hwndTo, pci)%@NL@%
- HWND hwndFrom;%@NL@%
- HWND hwndTo;%@NL@%
- PCLIENTINFO pci;%@NL@%
- {%@NL@%
- PID pidTo;%@NL@%
- TID tid;%@NL@%
- SEL sel;%@NL@%
- PDDEINIT pddeinit;%@NL@%
- HENUM henum;%@NL@%
- ULONG ul;%@NL@%
- USHORT cchApp, cchTopic;%@NL@%
- PSZ pszApp, pszTopic;%@NL@%
- BOOL fEnumerating; %@AB@%/* set if extra acks are ok */%@AE@%%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- %@NL@%
- if (hwndTo == NULL) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Call on self for all top level frame windows until we are connected.%@NL@%
- %@AB@% * (if enumerating, do em all anyway.)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fEnumerating = WinQueryWindow(hwndFrom, QW_PARENT, FALSE) !=%@NL@%
- pci->ci.pai->hwndDmg;%@NL@%
- if (henum = WinBeginEnumWindows(HWND_DESKTOP)) {%@NL@%
- while ((hwndTo = WinGetNextWindow(henum)) &&%@NL@%
- (fEnumerating || pci->ci.xad.state == CONVST_INIT1)) {%@NL@%
- if (hwndTo != pci->ci.pai->hwndFrame &&%@NL@%
- (ul = (ULONG)WinSendMsg(hwndTo, WM_QUERYFRAMEINFO, 0L, 0L)) &&%@NL@%
- (ul & FI_FRAME))%@NL@%
- SendDDEInit(hwndFrom, hwndTo, pci);%@NL@%
- }%@NL@%
- WinEndEnumWindows(henum);%@NL@%
- }%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- if (WinQueryWindowProcess(hwndTo, &pidTo, &tid) == NULL)%@NL@%
- return(FALSE);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- pszApp = pszFromHsz(pci->ci.hszServerApp, &cchApp);%@NL@%
- pszTopic = pszFromHsz(pci->ci.hszTopic, &cchTopic);%@NL@%
- if (DosAllocSeg(sizeof(DDEINIT) + sizeof(CONVCONTEXT) + cchApp + cchTopic,%@NL@%
- &sel, SEG_GIVEABLE) != 0) {%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- pddeinit = MAKEP(sel, 0);%@NL@%
- pddeinit->cb = sizeof(DDEINIT);%@NL@%
- pddeinit->offConvContext = sizeof(DDEINIT);%@NL@%
- pddeinit->pszAppName = (PSZ)pddeinit + sizeof(DDEINIT) + sizeof(CONVCONTEXT);%@NL@%
- pddeinit->pszTopic = pddeinit->pszAppName + cchApp;%@NL@%
- CopyBlock((PBYTE)&pci->ci.cc, (PBYTE)DDEI_PCONVCONTEXT(pddeinit), sizeof(CONVCONTEXT));%@NL@%
- CopyBlock((PBYTE)pszApp, (PBYTE)pddeinit->pszAppName, cchApp);%@NL@%
- CopyBlock((PBYTE)pszTopic, (PBYTE)pddeinit->pszTopic, cchTopic);%@NL@%
- FarFreeMem(hheapDmg, pszApp, cchApp);%@NL@%
- FarFreeMem(hheapDmg, pszTopic, cchTopic);%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- if (DosGiveSeg(sel, pidTo, &sel) != 0) {%@NL@%
- DosFreeSeg(sel);%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- WinSendMsg(hwndTo, WM_DDE_INITIATE, (MPARAM)hwndFrom, pddeinit);%@NL@%
- if (pidTo != pci->ci.pai->pid)%@NL@%
- DosFreeSeg(sel);%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Alocates and fills in a MYDDES. if pai == 0, the MYDDES is considered%@NL@%
- %@AB@%* unowned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: created 1/4/89 sanfords%@NL@%
- %@AB@%* 10/18/89 sanfords Added hack so that if usFmt==DDEFMT_TEXT and hszItem==0L,%@NL@%
- %@AB@%* the data and item strings are one.%@NL@%
- %@AB@%* (This allows for excel EXEC compatibility)%@NL@%
- %@AB@%* 2/2/89 sanfords Added GETABLE during monitoring.%@NL@%
- %@AB@%* 6/13/90 sanfords Altered to not expand hszItem at this point.%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PDDESTRUCT AllocDDESel(fsStatus, usFmt, hszItem, cbData, pai)%@NL@%
- USHORT fsStatus;%@NL@%
- USHORT usFmt;%@NL@%
- HSZ hszItem;%@NL@%
- ULONG cbData;%@NL@%
- PAPPINFO pai;%@NL@%
- {%@NL@%
- PMYDDES pmyddes = NULL;%@NL@%
- ULONG cbTotal;%@NL@%
- ULONG cchItem;%@NL@%
- SEL sel;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- cchItem = DdeGetHszString(hszItem, NULL, 0L) + 1L;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This hack makes execs conform to EXCELs way.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!hszItem && usFmt == DDEFMT_TEXT)%@NL@%
- cchItem = 0L;%@NL@%
- %@NL@%
- cbTotal = sizeof(MYDDES) + cchItem + cbData + 1;%@NL@%
- if (cbTotal <= 0xFFFF) {%@NL@%
- if (DosAllocSeg((USHORT)cbTotal, &sel, SEG_GIVEABLE) != 0)%@NL@%
- goto allocDdeExit;%@NL@%
- } else {%@NL@%
- if (DosAllocHuge((USHORT)(cbTotal >> 16), (USHORT)cbTotal, &sel,%@NL@%
- 0, SEG_GIVEABLE) != 0)%@NL@%
- goto allocDdeExit;%@NL@%
- }%@NL@%
- %@NL@%
- pmyddes = MAKEP(sel, 0);%@NL@%
- pmyddes->cbData = cbData;%@NL@%
- pmyddes->fsStatus = fsStatus;%@NL@%
- pmyddes->usFormat = usFmt;%@NL@%
- pmyddes->offszItemName = sizeof(MYDDES);%@NL@%
- pmyddes->offabData = sizeof(MYDDES) + (USHORT)cchItem;%@NL@%
- pmyddes->ulRes1 = 0L;%@NL@%
- pmyddes->magic = MYDDESMAGIC;%@NL@%
- pmyddes->hszItem = hszItem;%@NL@%
- pmyddes->pai = pai;%@NL@%
- pmyddes->fs = 0;%@NL@%
- *DDES_PABDATA((PDDESTRUCT)pmyddes) = '\0'; %@AB@%/* in case data is never placed */%@AE@%%@NL@%
- *DDES_PSZITEMNAME((PDDESTRUCT)pmyddes) = '\0'; %@AB@%/* we expand this at post time if necessary */%@AE@%%@NL@%
- %@NL@%
- allocDdeExit:%@NL@%
- SemLeave();%@NL@%
- return((PDDESTRUCT)pmyddes);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine returns the hwnd of a newly created and connected DDE%@NL@%
- %@AB@%* client or NULL if failure.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: created 1/6/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HCONV GetDDEClientWindow(hConvList, hwndFrame, hwndSend, hszApp, hszTopic, pCC)%@NL@%
- HCONVLIST hConvList;%@NL@%
- HWND hwndFrame;%@NL@%
- HWND hwndSend;%@NL@%
- HSZ hszApp;%@NL@%
- HSZ hszTopic;%@NL@%
- PCONVCONTEXT pCC;%@NL@%
- {%@NL@%
- HCONV hConv;%@NL@%
- INITINFO ii;%@NL@%
- CONVCONTEXT cc;%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- %@NL@%
- hConv = WinCreateWindow(hConvList, SZCLIENTCLASS, "", 0L,%@NL@%
- 0, 0, 0, 0, (HWND)NULL, HWND_TOP, WID_CLIENT, 0L, 0L);%@NL@%
- %@NL@%
- if (hConv == NULL)%@NL@%
- return(NULL);%@NL@%
- %@NL@%
- ii.hszTopic = hszTopic;%@NL@%
- ii.hszAppName = hszApp;%@NL@%
- ii.hwndSend = hwndSend;%@NL@%
- ii.hwndFrame = hwndFrame;%@NL@%
- if (pCC == NULL) {%@NL@%
- pCC = &cc;%@NL@%
- cc.cb = sizeof(CONVCONTEXT);%@NL@%
- cc.fsContext = 0;%@NL@%
- %@AB@%/*##LATER - may want to use process codepage instead */%@AE@%%@NL@%
- cc.usCodepage = syscc.codepage;%@NL@%
- cc.idCountry = syscc.country;%@NL@%
- }%@NL@%
- if (pCC->usCodepage == 0) %@NL@%
- pCC->usCodepage = syscc.codepage;%@NL@%
- if (pCC->idCountry == 0) %@NL@%
- pCC->idCountry = syscc.country;%@NL@%
- %@NL@%
- ii.pCC = pCC;%@NL@%
- WinSendMsg(hConv, UMCL_INITIATE, (MPARAM)&ii, 0L);%@NL@%
- %@NL@%
- if (!((USHORT)WinSendMsg(hConv, UM_QUERY, (MPARAM)Q_STATUS, 0L) &%@NL@%
- ST_CONNECTED)) {%@NL@%
- WinDestroyWindow(hConv);%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- return(hConv);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine institutes a callback directly if psi->fEnableCB is set%@NL@%
- %@AB@%* and calls QReply to complete the transaction,%@NL@%
- %@AB@%* otherwise it places the data into the queue for processing.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Since hDmgData may be freed by the app at any time once the callback is%@NL@%
- %@AB@%* issued, we cannot depend on it being there for QReply. Therefore we%@NL@%
- %@AB@%* save all the pertinant data in the queue along with it.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns fSuccess.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL MakeCallback(pai, hConv, hszTopic, hszItem, usFmt, usType, hDmgData,%@NL@%
- msg, fsStatus, hConvClient)%@NL@%
- PAPPINFO pai;%@NL@%
- HCONV hConv;%@NL@%
- HSZ hszTopic;%@NL@%
- HSZ hszItem;%@NL@%
- USHORT usFmt;%@NL@%
- USHORT usType;%@NL@%
- HDMGDATA hDmgData;%@NL@%
- USHORT msg;%@NL@%
- USHORT fsStatus;%@NL@%
- HCONV hConvClient;%@NL@%
- {%@NL@%
- PCBLI pcbli;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- %@NL@%
- if (!(pcbli = (PCBLI)NewLstItem(pai->plstCB, ILST_LAST))) {%@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- pcbli->hConv = hConv;%@NL@%
- pcbli->hszTopic = hszTopic;%@NL@%
- pcbli->hszItem = hszItem;%@NL@%
- pcbli->usFmt = usFmt;%@NL@%
- pcbli->usType = usType;%@NL@%
- pcbli->hDmgData = hDmgData;%@NL@%
- pcbli->msg = msg;%@NL@%
- pcbli->fsStatus = fsStatus;%@NL@%
- pcbli->hConvPartner = hConvClient;%@NL@%
- %@NL@%
- if (pai->fEnableCB && !pai->hwndTimer) {%@NL@%
- SemLeave();%@NL@%
- WinPostMsg(pai->hwndDmg, UM_CHECKCBQ, (MPARAM)pai, 0L);%@NL@%
- } else%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*************************************************************************\%@NL@%
- %@AB@%* Attempts to post a DDE message to hwndTo. Properly frees up pmyddes%@NL@%
- %@AB@%* if afCmd has MDPM_FREEHDATA set. We do not add pmyddes to the target%@NL@%
- %@AB@%* thread list since we assume that will be done at the receiving end%@NL@%
- %@AB@%* if necessary.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns fSuccess.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* 6/12/90 sanfords Created%@NL@%
- %@AB@%* 6/13/90 sanfords Made it convert hszItem to a string at this point%@NL@%
- %@AB@%* only if hwndTo is not a local guy.%@NL@%
- %@AB@%\*************************************************************************/%@AE@%%@NL@%
- BOOL MyDdePostMsg(%@NL@%
- HWND hwndTo,%@NL@%
- HWND hwndFrom,%@NL@%
- USHORT msg,%@NL@%
- PMYDDES pmyddes,%@NL@%
- PAPPINFO paiFrom,%@NL@%
- USHORT afCmd)%@NL@%
- {%@NL@%
- PID pid;%@NL@%
- TID tid;%@NL@%
- SEL selR;%@NL@%
- BOOL fRet;%@NL@%
- PFNWP pfnwpTo;%@NL@%
- %@NL@%
- if (!WinQueryWindowProcess(hwndTo, &pid, &tid))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- pfnwpTo = (PFNWP)WinQueryWindowPtr(hwndTo, QWP_PFNWP);%@NL@%
- if (cMonitor || (pfnwpTo != ServerWndProc && pfnwpTo != ClientWndProc)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * its not local - expand hszItem if necessary - always%@NL@%
- %@AB@% * expand if a monitor is installed.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (CheckSel(SELECTOROF(pmyddes)) >= sizeof(MYDDES) &&%@NL@%
- pmyddes->magic == MYDDESMAGIC &&%@NL@%
- pmyddes->hszItem &&%@NL@%
- !(pmyddes->fs & HDATA_PSZITEMSET)) {%@NL@%
- pmyddes->fs |= HDATA_PSZITEMSET;%@NL@%
- QueryHszName(pmyddes->hszItem, DDES_PSZITEMNAME(pmyddes),%@NL@%
- pmyddes->offabData - pmyddes->offszItemName); %@NL@%
- }%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Don't try to share seg with ourselves.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (paiFrom->pid != pid) {%@NL@%
- selR = SELECTOROF(pmyddes);%@NL@%
- if (DosGiveSeg(SELECTOROF(pmyddes), pid, &selR))%@NL@%
- return FALSE;%@NL@%
- if (afCmd & MDPM_FREEHDATA) %@NL@%
- FreeData(pmyddes, paiFrom);%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * just remove hData from our thread list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (afCmd & MDPM_FREEHDATA && !(pmyddes->fs & HDATA_APPOWNED))%@NL@%
- FindPileItem(paiFrom->pHDataPile, CmpULONG, (PBYTE)&pmyddes,%@NL@%
- FPI_DELETE);%@NL@%
- }%@NL@%
- fRet = (BOOL)WinPostMsg(hwndTo, msg, (MPARAM)hwndFrom, (MPARAM)pmyddes);%@NL@%
- if (!fRet) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * make sure this is freed if it is supposed to be - this covers%@NL@%
- %@AB@% * the case where the target is of the same process and only%@NL@%
- %@AB@% * these two threads are registered.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- tid = paiFrom->tid;%@NL@%
- do {%@NL@%
- if (FindPileItem(paiFrom->pHDataPile, CmpULONG, (PBYTE)&pmyddes,%@NL@%
- FPI_COUNT))%@NL@%
- return(FALSE); %@AB@%/* there is another thread that has this */%@AE@%%@NL@%
- paiFrom = paiFrom->nextThread;%@NL@%
- } while (paiFrom->tid != tid);%@NL@%
- DosFreeSeg(SELECTOROF(pmyddes));%@NL@%
- }%@NL@%
- return(fRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGHSZ.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGHSZ.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DMGLATOM.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This module contains functions used for HSZ control.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 8/2/88 sanfords%@NL@%
- %@AB@%* Added case preservation/insensitive 1/22/90 Sanfords%@NL@%
- %@AB@%* 6/12/90 sanfords Fixed HSZ local string allocation size errors.%@NL@%
- %@AB@%* Added latom validation checks%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * since the top 12 bits of any latom is always 0 (unless we have > 16%@NL@%
- %@AB@% * atom tables!) we can encode any ulong into only 5 bytes.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ENCODEBYTES 5 %@NL@%
- %@AI@%#define %@AE@%MAX_LATOMSTRSIZE 255 - ENCODEBYTES - 2 %@NL@%
- char szT[MAX_LATOMSTRSIZE + 1 + ENCODEBYTES]; %@AB@%/* used for HSZ expansion */%@AE@%%@NL@%
- %@NL@%
- extern BOOL APIENTRY WinSetAtomTableOwner( HATOMTBL, PID );%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*********************** LATOM management functions *************************\%@NL@%
- %@AB@%* An HSZ is a long atom which holds an encoded reference to two other long%@NL@%
- %@AB@%* atoms. One long atom is for the actual string, the other is for its%@NL@%
- %@AB@%* uppercase version. Two HSZs are ranked by their uppercase latoms.%@NL@%
- %@AB@%* This makes HSZs case insensitive, case preserving. An latom%@NL@%
- %@AB@%* is an atom with an atom table index tacked onto the HIUSHORT part of %@NL@%
- %@AB@%* of the latom. Strings too long for the atom manager are split up and%@NL@%
- %@AB@%* each piece is prepended with a coded string that represents the%@NL@%
- %@AB@%* LATOM of the rest of the string. LATOM strings thus may be of any length.%@NL@%
- %@AB@%* (up to 64K in this version)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Allocates space in the DDE manager heap for a string queried from the DDE%@NL@%
- %@AB@%* manager latomtable. The case sensitive string is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This function should be serialized. Memory allocation or latom table failure%@NL@%
- %@AB@%* results in a 0 return value.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* 0 latoms result in a NULL terminated empty string.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Note that *pcch is set to the length of the string INCLUDING the null%@NL@%
- %@AB@%* terminator. This way a wild string has a cch=1.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* created 12/22/88 sanfords%@NL@%
- %@AB@%* 11/10/89 sanfords modified to return '\0' on invalid atom.%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ pszFromHsz(hsz, pcch)%@NL@%
- HSZ hsz;%@NL@%
- USHORT FAR *pcch;%@NL@%
- {%@NL@%
- PSZ psz;%@NL@%
- LATOM latom;%@NL@%
- char sz[ENCODEBYTES + 1];%@NL@%
- register USHORT cch;%@NL@%
- %@NL@%
- SemCheckIn();%@NL@%
- %@NL@%
- if (hsz == 0)%@NL@%
- cch = 1;%@NL@%
- else {%@NL@%
- QuerylatomName((LATOM)hsz, sz, ENCODEBYTES + 1);%@NL@%
- latom = Decode(sz); %@AB@%/* take origonal case version */%@AE@%%@NL@%
- cch = QuerylatomLength(latom) + 1;%@NL@%
- }%@NL@%
- %@NL@%
- psz = (PSZ)FarAllocMem(hheapDmg, cch);%@NL@%
- if (psz == 0) {%@NL@%
- *pcch = '\000';%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- if (hsz == 0) {%@NL@%
- *pcch = 1;%@NL@%
- *psz = '\0';%@NL@%
- } else {%@NL@%
- *pcch = cch;%@NL@%
- if (QuerylatomName(latom, psz, cch) == 0) {%@NL@%
- AssertF(FALSE, "pszFromHsz - bad latom");%@NL@%
- *psz = '\0'; %@AB@%/* invalid case - never expected */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- return(psz);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* HSZ GetHsz(psz, cc, cp, fAdd)%@NL@%
- %@AB@%* PSZ psz;%@NL@%
- %@AB@%* USHORT cc;%@NL@%
- %@AB@%* USHORT cp;%@NL@%
- %@AB@%* BOOL fAdd;%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The goal of this routine is to convert a psz to an hsz. This uses the%@NL@%
- %@AB@%* atom manager for its dirty work. This call has the side effect of%@NL@%
- %@AB@%* incrementing the use count for the hsz returned and its associated latoms%@NL@%
- %@AB@%* if fAdd is set.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* if fAdd is FALSE, NULL is returned if the hsz doesn't exist.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* created 12/23/88 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- HSZ GetHsz(psz, cc, cp, fAdd)%@NL@%
- PSZ psz;%@NL@%
- USHORT cc;%@NL@%
- USHORT cp;%@NL@%
- BOOL fAdd;%@NL@%
- {%@NL@%
- LATOM latom1, latom2;%@NL@%
- USHORT cb;%@NL@%
- PSZ pszT;%@NL@%
- BOOL fNew = FALSE;%@NL@%
- HSZ hsz;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * NULL or 0 length pszs are considered wild HSZs.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (psz == NULL || *psz == '\0')%@NL@%
- return(0L);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- %@NL@%
- if (!(latom1 = FindAddlatom(psz, fAdd))) {%@NL@%
- AssertF(!fAdd, "GetHsz - Atom Add failed");%@NL@%
- SemLeave();%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- cb = lstrlen(psz) + 1;%@NL@%
- %@NL@%
- if (!(pszT = FarAllocMem(hheapDmg, max(cb, ENCODEBYTES * 2 + 1)))) {%@NL@%
- SemLeave();%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- %@NL@%
- CopyBlock((PBYTE)psz, (PBYTE)pszT, cb);%@NL@%
- WinUpper(DMGHAB, cp ? cp : syscc.codepage, cc ? cc : syscc.country, pszT);%@NL@%
- latom2 = FindAddlatom(pszT, fAdd);%@NL@%
- %@NL@%
- if (!latom2) {%@NL@%
- AssertF(!fAdd, "GetHsz - Atom Add(2) failed");%@NL@%
- hsz = 0;%@NL@%
- } else {%@NL@%
- *Encode(latom2, Encode(latom1, pszT)) = '\000';%@NL@%
- hsz = (HSZ)FindAddlatom(pszT, fAdd);%@NL@%
- }%@NL@%
- FarFreeMem(hheapDmg, pszT, max(cb, ENCODEBYTES * 2 + 1));%@NL@%
- SemLeave();%@NL@%
- return(hsz);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Note that all three associated latoms are freed.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL FreeHsz(hsz)%@NL@%
- HSZ hsz;%@NL@%
- {%@NL@%
- char sz[ENCODEBYTES * 2 + 1];%@NL@%
- %@NL@%
- SemEnter(); %@NL@%
- if (hsz && QuerylatomName((LATOM)hsz, sz, ENCODEBYTES * 2 + 1)) {%@NL@%
- Freelatom(Decode((PBYTE)sz));%@NL@%
- Freelatom(Decode((PBYTE)&sz[ENCODEBYTES]));%@NL@%
- Freelatom((LATOM)hsz);%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Note that all three associated latoms are incremented. %@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL IncHszCount(hsz)%@NL@%
- HSZ hsz;%@NL@%
- {%@NL@%
- char sz[ENCODEBYTES * 2 + 1];%@NL@%
- register BOOL fRet;%@NL@%
- %@NL@%
- if (hsz == 0)%@NL@%
- return(TRUE);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- %@NL@%
- QuerylatomName((LATOM)hsz, sz, ENCODEBYTES * 2 + 1);%@NL@%
- fRet = InclatomCount(Decode((PBYTE)sz)) &&%@NL@%
- InclatomCount(Decode((PBYTE)&sz[ENCODEBYTES])) &&%@NL@%
- InclatomCount((LATOM)hsz);%@NL@%
- SemLeave();%@NL@%
- return(fRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine adds an atom table and returns its handle. Returns fSuccess.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Effects cAtbls, aAtbls, iAtblCurrent;%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL AddAtomTable(fInit)%@NL@%
- BOOL fInit;%@NL@%
- {%@NL@%
- PHATOMTBL pat;%@NL@%
- %@NL@%
- SemEnter(); %@NL@%
- %@NL@%
- if (!(pat = (PHATOMTBL)FarAllocMem(hheapDmg,%@NL@%
- sizeof(HATOMTBL) * (cAtbls + 1)))) {%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- if (!fInit) {%@NL@%
- CopyBlock((PBYTE)aAtbls, (PBYTE)pat, sizeof(HATOMTBL) * cAtbls);%@NL@%
- FarFreeMem(hheapDmg, aAtbls, sizeof(HATOMTBL) * cAtbls);%@NL@%
- }%@NL@%
- %@NL@%
- aAtbls = pat;%@NL@%
- %@NL@%
- if (!(aAtbls[cAtbls] = WinCreateAtomTable(0, 0))) %@NL@%
- return(FALSE);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Share our atom tables with all processes...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!WinSetAtomTableOwner(aAtbls[cAtbls], NULL)) {%@NL@%
- AssertF(FALSE, "AddAtomTable - WinSetAtomTable failed");%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- iAtblCurrent = cAtbls++;%@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- USHORT QueryHszLength(hsz)%@NL@%
- HSZ hsz;%@NL@%
- {%@NL@%
- char sz[ENCODEBYTES + 1];%@NL@%
- USHORT us;%@NL@%
- %@NL@%
- if (!hsz) %@NL@%
- return(0);%@NL@%
- SemEnter();%@NL@%
- QuerylatomName((LATOM)hsz, sz, ENCODEBYTES + 1);%@NL@%
- us = QuerylatomLength(Decode(sz));%@NL@%
- SemLeave();%@NL@%
- return(us);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- USHORT QueryHszName(hsz, psz, cchMax)%@NL@%
- HSZ hsz;%@NL@%
- PSZ psz;%@NL@%
- USHORT cchMax;%@NL@%
- {%@NL@%
- char sz[ENCODEBYTES + 1];%@NL@%
- register USHORT usRet;%@NL@%
- %@NL@%
- if (hsz == 0) {%@NL@%
- if (psz)%@NL@%
- *psz = '\000';%@NL@%
- return(1);%@NL@%
- } else {%@NL@%
- usRet = 0;%@NL@%
- SemEnter();%@NL@%
- if (QuerylatomName((LATOM)hsz, sz, ENCODEBYTES + 1))%@NL@%
- usRet = QuerylatomName(Decode(sz), psz, cchMax);%@NL@%
- SemLeave();%@NL@%
- return(usRet);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * returns 0 if ==, -1 if hsz1 < hsz2, 1 if hsz1 > hsz2, 2 on error%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SHORT CmpHsz(hsz1, hsz2)%@NL@%
- HSZ hsz1, hsz2;%@NL@%
- {%@NL@%
- char sz[ENCODEBYTES * 2 + 1];%@NL@%
- LATOM latom;%@NL@%
- SHORT usRet;%@NL@%
- %@NL@%
- if (hsz1 == hsz2)%@NL@%
- return(0);%@NL@%
- if (!hsz1) %@NL@%
- return(-1);%@NL@%
- if (!hsz2)%@NL@%
- return(1);%@NL@%
- %@NL@%
- usRet = 2;%@NL@%
- SemEnter();%@NL@%
- if (QuerylatomName((LATOM)hsz1, sz, ENCODEBYTES * 2 + 1)) {%@NL@%
- latom = Decode(&sz[ENCODEBYTES]); %@AB@%/* use UPPERCASE form for comparison. */%@AE@%%@NL@%
- if (QuerylatomName((LATOM)hsz2, sz, ENCODEBYTES * 2 + 1)) {%@NL@%
- latom = latom - Decode(&sz[ENCODEBYTES]);%@NL@%
- usRet = latom == 0 ? 0 : (latom > 0 ? 1 : -1);%@NL@%
- }%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(usRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Returns the length of the latom given without NULL terminator.%@NL@%
- %@AB@%* Wild LATOMs have a length of 0.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- USHORT QuerylatomLength(latom)%@NL@%
- LATOM latom;%@NL@%
- {%@NL@%
- USHORT cb;%@NL@%
- USHORT cbT = 0;%@NL@%
- BYTE ab[ENCODEBYTES + 1];%@NL@%
- %@NL@%
- AssertF(HIUSHORT(latom) < cAtbls, "Invalid latom");%@NL@%
- if (latom == 0)%@NL@%
- return(0);%@NL@%
- SemCheckIn();%@NL@%
- while (TRUE) {%@NL@%
- if (!(cb = WinQueryAtomLength(aAtbls[HIUSHORT(latom)],%@NL@%
- LOUSHORT(latom)))) {%@NL@%
- AssertF(cbT == 0, "QuerylatomLength - failed on continued latom");%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- cbT += cb;%@NL@%
- %@NL@%
- if (cb <= MAX_LATOMSTRSIZE) {%@NL@%
- return(cbT);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * it MUST be a huge latom.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!(WinQueryAtomName(aAtbls[HIUSHORT(latom)], LOUSHORT(latom),%@NL@%
- (PSZ)ab, ENCODEBYTES + 1))) {%@NL@%
- AssertF(FALSE, "QuerylatomLength - Length but no name");%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- latom = Decode(ab);%@NL@%
- cbT -= ENCODEBYTES;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- USHORT QuerylatomName(latom, psz, cchMax)%@NL@%
- LATOM latom;%@NL@%
- PSZ psz;%@NL@%
- USHORT cchMax;%@NL@%
- {%@NL@%
- USHORT cb;%@NL@%
- extern char szT[];%@NL@%
- %@NL@%
- if (HIUSHORT(latom) >= cAtbls) {%@NL@%
- AssertF(FALSE, "Invalid latom");%@NL@%
- psz[0] = '\0';%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- AssertF(latom != 0, "QuerylatomName - 0 latom");%@NL@%
- SemCheckIn();%@NL@%
- cb = WinQueryAtomLength(aAtbls[HIUSHORT(latom)], LOUSHORT(latom));%@NL@%
- if (cb > MAX_LATOMSTRSIZE) {%@NL@%
- if (!WinQueryAtomName(aAtbls[HIUSHORT(latom)], LOUSHORT(latom), szT,%@NL@%
- MAX_LATOMSTRSIZE + ENCODEBYTES + 1)) {%@NL@%
- AssertF(FALSE, "QuerylatomName - length but no name");%@NL@%
- return(0);%@NL@%
- }%@NL@%
- CopyBlock(szT + ENCODEBYTES, psz, min(MAX_LATOMSTRSIZE, cchMax));%@NL@%
- latom = Decode((PBYTE)szT);%@NL@%
- cb = MAX_LATOMSTRSIZE + QuerylatomName(latom, psz + MAX_LATOMSTRSIZE,%@NL@%
- cchMax > MAX_LATOMSTRSIZE ? cchMax - MAX_LATOMSTRSIZE : 0);%@NL@%
- %@NL@%
- } else {%@NL@%
- WinQueryAtomName(aAtbls[HIUSHORT(latom)], LOUSHORT(latom), psz, cchMax);%@NL@%
- }%@NL@%
- psz[cchMax - 1] = '\0'; %@AB@%/* add NULL terminator */%@AE@%%@NL@%
- return(min(cb, cchMax - 1));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This uses globals szT, aAtbls, cAtbls, and iAtblCurrent to add or%@NL@%
- %@AB@%* find the latom for psz depending on fAdd.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- LATOM FindAddlatom(psz, fAdd)%@NL@%
- PSZ psz;%@NL@%
- BOOL fAdd;%@NL@%
- {%@NL@%
- LATOM latom;%@NL@%
- %@NL@%
- AssertF(psz != NULL, "FindAddlatom - NULL psz");%@NL@%
- AssertF(*psz != '\0', "FindAddlatom - NULL psz string");%@NL@%
- SemCheckIn();%@NL@%
- if (lstrlen(psz) > MAX_LATOMSTRSIZE) {%@NL@%
- latom = FindAddlatom(psz + MAX_LATOMSTRSIZE, fAdd);%@NL@%
- CopyBlock((PBYTE)psz, Encode((ULONG)latom, szT),%@NL@%
- (ULONG)MAX_LATOMSTRSIZE - ENCODEBYTES + 1);%@NL@%
- szT[MAX_LATOMSTRSIZE + ENCODEBYTES] = '\0';%@NL@%
- latom = FindAddlatomHelper(szT, fAdd);%@NL@%
- return(latom);%@NL@%
- } else {%@NL@%
- return(FindAddlatomHelper(psz, fAdd));%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- LATOM FindAddlatomHelper(psz, fAdd)%@NL@%
- PSZ psz;%@NL@%
- BOOL fAdd;%@NL@%
- {%@NL@%
- int i;%@NL@%
- ATOM atom;%@NL@%
- ATOM (APIENTRY *lpfn)(HATOMTBL, PSZ);%@NL@%
- %@NL@%
- SemCheckIn();%@NL@%
- if (fAdd) {%@NL@%
- AssertF(++cAtoms, "Possible atom count overflow");%@NL@%
- lpfn = WinAddAtom;%@NL@%
- } else %@NL@%
- lpfn = WinFindAtom;%@NL@%
- %@NL@%
- if (!(atom = (*lpfn)(aAtbls[i = iAtblCurrent], psz))) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Must be full/not found, try all the existing tables%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (i = 0; i < cAtbls; i++) {%@NL@%
- if (i != iAtblCurrent) {%@NL@%
- if (atom = (*lpfn)(aAtbls[i], psz)) {%@NL@%
- if (fAdd)%@NL@%
- iAtblCurrent = i;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if (!atom) {%@NL@%
- if (fAdd) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * they're all full, make another table.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!AddAtomTable(FALSE)) {%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- if (!(atom = (*lpfn)(aAtbls[iAtblCurrent], psz))) {%@NL@%
- return(0L); %@NL@%
- }%@NL@%
- } else {%@NL@%
- return(0L);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- return((LATOM)MAKEP(i, atom));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- BOOL InclatomCount(latom)%@NL@%
- LATOM latom;%@NL@%
- {%@NL@%
- AssertF(HIUSHORT(latom) < cAtbls, "Invalid latom");%@NL@%
- AssertF(latom != 0, "InclatomCount - 0 latom");%@NL@%
- SemCheckIn();%@NL@%
- AssertF(++cAtoms, "Possible atom count overflow");%@NL@%
- return(WinAddAtom(aAtbls[HIUSHORT(latom)], MAKEP(0XFFFF, LOUSHORT(latom))));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- BOOL Freelatom(latom)%@NL@%
- LATOM latom;%@NL@%
- {%@NL@%
- AssertF(HIUSHORT(latom) < cAtbls, "Invalid latom");%@NL@%
- AssertF(latom != 0, "Freelatom - 0 latom");%@NL@%
- AssertF(WinQueryAtomUsage(aAtbls[HIUSHORT(latom)], LOUSHORT(latom)),%@NL@%
- "Freelatom - Freeing Non-existing atom");%@NL@%
- SemCheckIn();%@NL@%
- %@NL@%
- if (WinDeleteAtom(aAtbls[HIUSHORT(latom)], LOUSHORT(latom))) {%@NL@%
- AssertF(FALSE, "Freelatom - WinDeleteAtom failed");%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- AssertF(--cAtoms >= 0, "Freelatom - negative atom count");%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#ifdef %@AE@%DEBUG %@NL@%
- BASEVAL '0' %@AB@%/* more readable for debugging */%@AE@%%@NL@%
- %@AI@%#else %@AE@%%@NL@%
- BASEVAL 1 %@AB@%/* less likely to conflict with a string */%@AE@%%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Converts an latom into a ENCODEBYTES character string apropriate for%@NL@%
- %@AB@%* atomization. (NULL terminator must be added)%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PBYTE Encode(latom, pb)%@NL@%
- ULONG latom;%@NL@%
- PBYTE pb;%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@NL@%
- AssertF(HIUSHORT(latom) < cAtbls, "Invalid latom");%@NL@%
- for (i = 0; i < ENCODEBYTES; i++) {%@NL@%
- *pb++ = ((BYTE)latom & 0x0F) + BASEVAL;%@NL@%
- latom >>= 4;%@NL@%
- }%@NL@%
- return(pb);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This takes a pointer to a buffer of 8 bytes which is a coded LATOM and%@NL@%
- %@AB@%* returns the LATOM.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- LATOM Decode(pb)%@NL@%
- PBYTE pb;%@NL@%
- {%@NL@%
- ULONG ul = 0;%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = ENCODEBYTES - 1; i >= 0; i--) {%@NL@%
- ul <<= 4;%@NL@%
- ul += (ULONG)(pb[i] - BASEVAL);%@NL@%
- }%@NL@%
- return((LATOM)ul);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This routine extracts the hszItem out of an existing hData handle.%@NL@%
- %@AB@% * local conversations can use the hsz directly out of the handle while%@NL@%
- %@AB@% * non-dll conversations will have to generate the hsz from the string.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- HSZ GetHszItem(%@NL@%
- PMYDDES pmyddes,%@NL@%
- PCONVCONTEXT pCC,%@NL@%
- BOOL fAdd)%@NL@%
- {%@NL@%
- if (CheckSel(SELECTOROF(pmyddes)) >= sizeof(MYDDES) &&%@NL@%
- pmyddes->magic == MYDDESMAGIC) {%@NL@%
- if (fAdd) %@NL@%
- IncHszCount(pmyddes->hszItem);%@NL@%
- return(pmyddes->hszItem);%@NL@%
- } else {%@NL@%
- return(GetHsz(DDES_PSZITEMNAME(pmyddes), pCC->idCountry,%@NL@%
- pCC->usCodepage, fAdd));%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGMON.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGMON.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DMGMON.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This module contains functions used for DDE monitor control.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 8/2/88 sanfords%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@AI@%#define %@AE@%MSGF_DDEPOSTMSG 3 %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%freeMonStr(psz) MyFreeMem(hheapDmg, (NPBYTE)(USHORT)psz, MAX_MONITORSTR + 1) %@NL@%
- %@NL@%
- %@NL@%
- BOOL EXPENTRY DdeSendHookProc(hab, psmh, fInterTask)%@NL@%
- HAB hab;%@NL@%
- PSMHSTRUCT psmh;%@NL@%
- BOOL fInterTask;%@NL@%
- {%@NL@%
- PSZ psz;%@NL@%
- PSZ pszSave;%@NL@%
- PSZ pszLast;%@NL@%
- %@NL@%
- UNUSED hab;%@NL@%
- UNUSED fInterTask;%@NL@%
- %@NL@%
- if (psmh->msg == WM_DDE_INITIATE || psmh->msg == WM_DDE_INITIATEACK) {%@NL@%
- if (allocMonStr(&pszSave, &pszLast)) {%@NL@%
- psz = timestamp(pszSave, pszLast);%@NL@%
- psz = lstrcat(psz, " ", pszLast);%@NL@%
- psz = ltoa((ULONG)psmh->mp1, psz, pszLast);%@NL@%
- psz = lstrcat(psz, " -> ", pszLast);%@NL@%
- psz = ltoa((ULONG)psmh->hwnd, psz, pszLast);%@NL@%
- psz = lstrcat(psz, "\n\r", pszLast);%@NL@%
- psz = ddeMsgToPsz(psmh->msg, psz, pszLast);%@NL@%
- psz = pddesToPsz(psmh->msg, (PDDESTRUCT)psmh->mp2, psz, pszLast);%@NL@%
- psz = lstrcat(psz, ")\n\r", pszLast);%@NL@%
- MonitorBroadcast(pszSave);%@NL@%
- freeMonStr(pszSave);%@NL@%
- }%@NL@%
- }%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- BOOL EXPENTRY DdePostHookProc(hab, pqmsg, fs)%@NL@%
- HAB hab;%@NL@%
- PQMSG pqmsg;%@NL@%
- USHORT fs;%@NL@%
- {%@NL@%
- PSZ psz;%@NL@%
- PSZ pszSave;%@NL@%
- PSZ pszLast;%@NL@%
- %@NL@%
- UNUSED hab;%@NL@%
- %@NL@%
- if (fs && pqmsg->msg >= WM_DDE_FIRST && pqmsg->msg <= WM_DDE_LAST) {%@NL@%
- pszLast = psz + MAX_MONITORSTR; %@NL@%
- if (allocMonStr(&pszSave, &pszLast)) {%@NL@%
- psz = timestamp(pszSave, pszLast);%@NL@%
- psz = lstrcat(psz, " ", pszLast);%@NL@%
- psz = ltoa((ULONG)pqmsg->mp1, psz, pszLast);%@NL@%
- psz = lstrcat(psz, " -> ", pszLast);%@NL@%
- psz = ltoa((ULONG)pqmsg->hwnd, psz, pszLast);%@NL@%
- psz = lstrcat(psz, "\n\r", pszLast);%@NL@%
- psz = ddeMsgToPsz(pqmsg->msg, psz, pszLast);%@NL@%
- psz = pddesToPsz(pqmsg->msg, (PDDESTRUCT)pqmsg->mp2, psz, pszLast);%@NL@%
- psz = lstrcat(psz, ")\n\r", pszLast);%@NL@%
- MonitorBroadcast(pszSave);%@NL@%
- freeMonStr(pszSave);%@NL@%
- }%@NL@%
- }%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This guy sends a UM_MONITOR to all the monitor windows (up to MAX_MONITOR)%@NL@%
- %@AB@% * The cheap restriction is due to needing to not be in the semaphore%@NL@%
- %@AB@% * while the monitor is in control yet needing to keep access to pai in%@NL@%
- %@AB@% * the semaphore.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void MonitorBroadcast(psz)%@NL@%
- PSZ psz;%@NL@%
- {%@NL@%
- HWND hwnd[MAX_MONITORS];%@NL@%
- PAPPINFO pai;%@NL@%
- register USHORT i = 0;%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- SemEnter();%@NL@%
- pai = pAppInfoList;%@NL@%
- while (pai && i < cMonitor && i < MAX_MONITORS) {%@NL@%
- if (pai->hwndMonitor) {%@NL@%
- hwnd[i] = pai->hwndMonitor;%@NL@%
- i++;%@NL@%
- }%@NL@%
- pai = pai->next;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- for (i = 0; i < cMonitor; i++)%@NL@%
- WinSendMsg(hwnd[i], UM_MONITOR, (MPARAM)psz, 0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We need to allocate the string buffer so that recursive calls will work.%@NL@%
- %@AB@% * We also need to do this because the DLL DS is shared between all potential%@NL@%
- %@AB@% * monitor processes.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * This also initializes the psz for us with a null terminator and checks%@NL@%
- %@AB@% * cMonitor for us. If this fails, no monitor action is done.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * ppsz will contain a pointer to the begining of the allocated buffer.%@NL@%
- %@AB@% * ppszLast will contain a pointer to the end of the allocated buffer.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL allocMonStr(ppsz, ppszLast)%@NL@%
- PSZ far *ppsz;%@NL@%
- PSZ far *ppszLast;%@NL@%
- {%@NL@%
- SemEnter();%@NL@%
- if (cMonitor == 0 ||%@NL@%
- ((*ppsz = FarAllocMem(hheapDmg, MAX_MONITORSTR + 1)) == NULL)) {%@NL@%
- SemLeave();%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- *ppszLast = *ppsz + MAX_MONITORSTR;%@NL@%
- **ppsz = '\0';%@NL@%
- SemLeave();%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY MonitorWndProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- register MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- HDMGDATA hDmgData;%@NL@%
- %@NL@%
- pai = GetCurrentAppInfo(FALSE);%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_CREATE:%@NL@%
- mp1 = (PSZ)"\n\rMonitor Created\n\r\n\r";%@NL@%
- goto MonOut;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- mp1 = (PSZ)"\n\r\n\rMonitor Destroyed\n\r";%@NL@%
- %@AB@%/* fall through */%@AE@%%@NL@%
- %@NL@%
- case UM_MONITOR:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * mp1 = psz to print%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MonOut:%@NL@%
- hDmgData = DdePutData((PSZ)mp1, (ULONG)(lstrlen(mp1) + 1),%@NL@%
- 0L, (HSZ)0L, DDEFMT_TEXT, 0);%@NL@%
- pai->cInCallback++;%@NL@%
- DoCallback(pai, 0, 0, 0, DDEFMT_TEXT, XTYP_MONITOR, hDmgData);%@NL@%
- if (pai->cInCallback > 0) %@AB@%/* test incase exitlist processing messed things up */%@AE@%%@NL@%
- pai->cInCallback--;%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGQ.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGQ.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DMGQ.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DDE Manager queue control functions.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 9/1/89 Sanford Staab%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This is a general queue manager - yes another one!%@NL@%
- %@AB@%* Queues are each allocated within their own segment and have a%@NL@%
- %@AB@%* QST structure associated with that heap. Each queue item%@NL@%
- %@AB@%* is allocated within the heap segment. The offset of the items%@NL@%
- %@AB@%* address combined with an instance count is used as the item ID.%@NL@%
- %@AB@%* This is both unique and allows for instant location of an item.%@NL@%
- %@AB@%* New items are added to the head of the queue which is a doubly linked%@NL@%
- %@AB@%* list. The next links point to more recent entries, the prev pointers%@NL@%
- %@AB@%* to older entries. The next of the head is the tail. The prev of the%@NL@%
- %@AB@%* tail is the head. All pointers are far.%@NL@%
- %@AB@%* Queue Data may be of any structure type that begins identical to%@NL@%
- %@AB@%* a QUEUEITEM structure. Functions that require an cbItem perameter%@NL@%
- %@AB@%* should be given the size of the specialized queue item structure.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Creates a Queue for items of cbItem.%@NL@%
- %@AB@%* Returns NULL on error.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PQST CreateQ(cbItem)%@NL@%
- USHORT cbItem;%@NL@%
- {%@NL@%
- QST cq;%@NL@%
- PQST pQ;%@NL@%
- %@NL@%
- cq.cItems = 0;%@NL@%
- cq.instLast = 0;%@NL@%
- cq.cbItem = cbItem;%@NL@%
- cq.pqiHead = NULL;%@NL@%
- if (!(cq.hheap = MyCreateHeap(0, sizeof(QST) + cbItem << 3,%@NL@%
- cbItem << 3, cbItem, cbItem, HEAPFLAGS)))%@NL@%
- return(NULL);%@NL@%
- if (!(pQ = (PQST)FarAllocMem(cq.hheap, sizeof(QST)))) {%@NL@%
- MyDestroyHeap(cq.hheap);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- *pQ = cq;%@NL@%
- return(pQ);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL DestroyQ(pQ)%@NL@%
- PQST pQ;%@NL@%
- {%@NL@%
- if (pQ)%@NL@%
- MyDestroyHeap(pQ->hheap);%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns a long pointer to the queue item data created. The new item%@NL@%
- %@AB@%* is added to the head of the queue. The queue's cbItem specified at%@NL@%
- %@AB@%* creation is used for allocation.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PQUEUEITEM Addqi(pQ)%@NL@%
- PQST pQ;%@NL@%
- {%@NL@%
- PQUEUEITEM pqi;%@NL@%
- %@NL@%
- if ((pqi = (PQUEUEITEM)FarAllocMem(pQ->hheap, pQ->cbItem)) == NULL) {%@NL@%
- if (pQ->cItems == 0)%@NL@%
- return(0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * remove the oldest item to make room for the new.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pqi = pQ->pqiHead->next;%@NL@%
- SemEnter();%@NL@%
- pqi->prev->next = pqi->next;%@NL@%
- pqi->next->prev = pqi->prev;%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- if (pQ->cItems == 0) {%@NL@%
- pQ->pqiHead = pqi->prev = pqi->next = pqi;%@NL@%
- } else {%@NL@%
- pqi->prev = pQ->pqiHead;%@NL@%
- pqi->next = pQ->pqiHead->next;%@NL@%
- pQ->pqiHead->next->prev = pqi;%@NL@%
- pQ->pqiHead->next = pqi;%@NL@%
- pQ->pqiHead = pqi;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- pQ->cItems++;%@NL@%
- pqi->inst = ++pQ->instLast;%@NL@%
- return(pqi);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The id given is an external LONG id, not an item instance number.%@NL@%
- %@AB@%* If id is QID_NEWEST, the head item is deleted.%@NL@%
- %@AB@%* If id is QID_OLDEST, the tail item is deleted.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void Deleteqi(pQ, id)%@NL@%
- PQST pQ;%@NL@%
- ULONG id;%@NL@%
- {%@NL@%
- PQUEUEITEM pqi;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- pqi = Findqi(pQ, id);%@NL@%
- if (pqi == NULL) {%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- pqi->prev->next = pqi->next;%@NL@%
- pqi->next->prev = pqi->prev;%@NL@%
- if (pqi == pQ->pqiHead)%@NL@%
- pQ->pqiHead = pqi->prev;%@NL@%
- if (!(--pQ->cItems))%@NL@%
- pQ->pqiHead = NULL;%@NL@%
- FarFreeMem(pQ->hheap, pqi, pQ->cbItem);%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* The id given is an external LONG id, not an item instance number.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* if id == QID_NEWEST, returns the head queue data item.%@NL@%
- %@AB@%* if id == QID_OLDEST, returns the tail queue data item.%@NL@%
- %@AB@%* if the id is not found or the queue is empty, NULL is returned.%@NL@%
- %@AB@%* if found, pqi is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PQUEUEITEM Findqi(pQ, id)%@NL@%
- PQST pQ;%@NL@%
- ULONG id;%@NL@%
- {%@NL@%
- PQUEUEITEM pqi;%@NL@%
- %@NL@%
- SemCheckIn();%@NL@%
- if (pQ == NULL || pQ->pqiHead == NULL)%@NL@%
- return(NULL);%@NL@%
- %@NL@%
- if (id == QID_OLDEST) %@NL@%
- return(pQ->pqiHead->next);%@NL@%
- %@NL@%
- if (id == QID_NEWEST) %@NL@%
- return(pQ->pqiHead);%@NL@%
- %@NL@%
- if (id) {%@NL@%
- pqi = PFROMID(pQ, id);%@NL@%
- if (pqi->inst == HIUSHORT(id)) {%@NL@%
- return(pqi);%@NL@%
- }%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%* Module Name: DMGSTR.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DDE manager string handling routines%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 1/31/88 Sanford Staab%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@AI@%#include %@AE@%"ctype.h" %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* returns string length not counting null terminator.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- int lstrlen(psz)%@NL@%
- PSZ psz;%@NL@%
- {%@NL@%
- int c = 0;%@NL@%
- %@NL@%
- while (*psz != 0) {%@NL@%
- psz++;%@NL@%
- c++;%@NL@%
- }%@NL@%
- return(c);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* Concatonates psz1 and psz2 into psz1.%@NL@%
- %@AB@%* returns psz pointing to end of concatonated string.%@NL@%
- %@AB@%* pszLast marks point at which copying must stop. This makes this operation%@NL@%
- %@AB@%* safe for limited buffer sizes.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: 1/1/89 created sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ lstrcat(psz1, psz2, pszLast)%@NL@%
- PSZ psz1, psz2, pszLast;%@NL@%
- {%@NL@%
- psz1 += lstrlen(psz1);%@NL@%
- while (*psz2 != '\0' && psz1 < pszLast) {%@NL@%
- *psz1++ = *psz2++;%@NL@%
- }%@NL@%
- *psz1 = '\0';%@NL@%
- return(psz1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* DESCRIPTION: ASCII dependent converter of DDE structure data to a string.%@NL@%
- %@AB@%* returns psz pointing to end of copy.%@NL@%
- %@AB@%* During monitoring we allocate segments as gettable so we can monitor them.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: Created 1/31/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ pddesToPsz(msg, pddes, psz, pszLast)%@NL@%
- USHORT msg;%@NL@%
- PDDESTRUCT pddes;%@NL@%
- PSZ psz;%@NL@%
- PSZ pszLast;%@NL@%
- {%@NL@%
- USHORT cb;%@NL@%
- PBYTE pData;%@NL@%
- %@AI@%#define %@AE@%pDdeInit ((PDDEINIT)pddes) %@NL@%
- %@NL@%
- *psz = '\0';%@NL@%
- switch (msg) {%@NL@%
- case WM_DDE_REQUEST:%@NL@%
- case WM_DDE_ACK:%@NL@%
- case WM_DDE_DATA:%@NL@%
- case WM_DDE_ADVISE:%@NL@%
- case WM_DDE_UNADVISE:%@NL@%
- case WM_DDE_POKE:%@NL@%
- case WM_DDE_EXECUTE:%@NL@%
- psz = lstrcat(psz, "S:", pszLast);%@NL@%
- psz = Status(pddes->fsStatus, psz, pszLast);%@NL@%
- psz = lstrcat(psz, " F:", pszLast);%@NL@%
- psz = Format(pddes->usFormat, psz, pszLast);%@NL@%
- psz = lstrcat(psz, " I:", pszLast);%@NL@%
- psz = lstrcat(psz, DDES_PSZITEMNAME(pddes), pszLast);%@NL@%
- if (pddes->cbData)%@NL@%
- psz = lstrcat(psz, "\n\r Data:", pszLast);%@NL@%
- pData = DDES_PABDATA(pddes);%@NL@%
- %@NL@%
- for (cb = 0; (ULONG)cb < pddes->cbData && psz < pszLast; cb++, pData++) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * new line every 64 chars%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((cb & 0x3F) == 0) {%@NL@%
- *psz = '\0';%@NL@%
- psz = lstrcat(psz, "\n\r ", pszLast);%@NL@%
- }%@NL@%
- if (*pData > 0x20)%@NL@%
- *psz = *pData;%@NL@%
- else%@NL@%
- *psz = '.';%@NL@%
- %@NL@%
- *psz++ = *psz & 0x7f;%@NL@%
- }%@NL@%
- CopyBlock("\n\r", pszLast - 3, 3L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_INITIATEACK:%@NL@%
- case WM_DDE_INITIATE:%@NL@%
- if (CheckSel(SELECTOROF(pDdeInit))) {%@NL@%
- psz = lstrcat(psz, "A:", pszLast);%@NL@%
- psz = lstrcat(psz, pDdeInit->pszAppName, pszLast);%@NL@%
- psz = lstrcat(psz, " T:", pszLast);%@NL@%
- psz = lstrcat(psz, pDdeInit->pszTopic, pszLast);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_TERMINATE:%@NL@%
- break;%@NL@%
- }%@NL@%
- *psz = '\0';%@NL@%
- return(psz);%@NL@%
- %@NL@%
- %@AI@%#undef %@AE@%pDdeInit %@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- PSZ Status(fs, psz, pszLast)%@NL@%
- USHORT fs;%@NL@%
- PSZ psz;%@NL@%
- PSZ pszLast;%@NL@%
- {%@NL@%
- if (fs & DDE_FACK) {%@NL@%
- psz = lstrcat(psz, "ACK ", pszLast);%@NL@%
- }%@NL@%
- if (fs & DDE_FBUSY) {%@NL@%
- psz = lstrcat(psz, "BUSY ", pszLast);%@NL@%
- }%@NL@%
- if (fs & DDE_FNODATA) {%@NL@%
- psz = lstrcat(psz, "NODATA ", pszLast);%@NL@%
- }%@NL@%
- if (fs & DDE_FACKREQ) {%@NL@%
- psz = lstrcat(psz, "ACKREQ ", pszLast);%@NL@%
- }%@NL@%
- if (fs & DDE_FRESPONSE) {%@NL@%
- psz = lstrcat(psz, "RESPONSE ", pszLast);%@NL@%
- }%@NL@%
- if (fs & DDE_NOTPROCESSED) {%@NL@%
- psz = lstrcat(psz, "NOTPROCESSED ", pszLast);%@NL@%
- }%@NL@%
- if (fs & DDE_FAPPSTATUS) {%@NL@%
- psz = lstrcat(psz, "APPSTAT=", pszLast);%@NL@%
- psz = itoa(fs & DDE_FAPPSTATUS, psz, pszLast);%@NL@%
- *psz++ = ' ';%@NL@%
- *psz++ = '\0';%@NL@%
- }%@NL@%
- if (fs & DDE_FRESERVED) {%@NL@%
- psz = lstrcat(psz, "RESERVED=", pszLast);%@NL@%
- psz = itoa(fs & DDE_FRESERVED, psz, pszLast);%@NL@%
- }%@NL@%
- return(psz);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- PSZ Format(fmt, psz, pszLast)%@NL@%
- USHORT fmt;%@NL@%
- PSZ psz;%@NL@%
- PSZ pszLast;%@NL@%
- {%@NL@%
- if (fmt > 0xbfff) {%@NL@%
- *psz++ = '"';%@NL@%
- psz += WinQueryAtomName(WinQuerySystemAtomTable(), fmt, psz, pszLast - psz);%@NL@%
- *psz++ = '"';%@NL@%
- *psz = '\0';%@NL@%
- } else if (fmt == DDEFMT_TEXT) {%@NL@%
- psz = lstrcat(psz, "TEXT", pszLast);%@NL@%
- } else {%@NL@%
- psz = itoa(fmt, psz, pszLast);%@NL@%
- }%@NL@%
- return(psz);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* DESCRIPTION: puts an apropriate string for a DDE message into psz. pszLast%@NL@%
- %@AB@%* specifies the last spot to copy. Returns a psz pointing to the end of%@NL@%
- %@AB@%* the copyed data.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: Created 1/31/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ ddeMsgToPsz(msg, psz, pszLast)%@NL@%
- USHORT msg;%@NL@%
- PSZ psz;%@NL@%
- PSZ pszLast;%@NL@%
- {%@NL@%
- psz = lstrcat(psz, " ", pszLast);%@NL@%
- if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST) {%@NL@%
- psz = itoa(msg, psz, pszLast);%@NL@%
- } else {%@NL@%
- WinLoadString(DMGHAB, hmodDmg, msg, pszLast - psz + 1, psz);%@NL@%
- psz += lstrlen(psz);%@NL@%
- }%@NL@%
- return(lstrcat(psz, "(", pszLast));%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* fills psz with a hex string "0xdddd" and returns psz pointing to the 0%@NL@%
- %@AB@%* terminator at the end. copying will never go beyond pszLast.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: Created 1/31/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ itoa(us, psz, pszLast)%@NL@%
- USHORT us;%@NL@%
- PSZ psz;%@NL@%
- PSZ pszLast;%@NL@%
- {%@NL@%
- if (psz > pszLast - 7)%@NL@%
- return(psz);%@NL@%
- *psz++ = '0';%@NL@%
- *psz++ = 'x';%@NL@%
- return(stoa(psz, us));%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* fills psz with a hex string "0xdddddddd" and returns psz pointing to the 0%@NL@%
- %@AB@%* terminator at the end. copying will never go beyond pszLast.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: Created 1/31/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ ltoa(ul, psz, pszLast)%@NL@%
- ULONG ul;%@NL@%
- PSZ psz;%@NL@%
- PSZ pszLast;%@NL@%
- {%@NL@%
- if (psz > pszLast - 11)%@NL@%
- return(psz);%@NL@%
- *psz++ = '0';%@NL@%
- *psz++ = 'x';%@NL@%
- psz = stoa(psz, HIUSHORT(ul));%@NL@%
- return(stoa(psz, LOUSHORT(ul)));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* fills psz with a hex string "dddd" and returns psz pointing to the 0%@NL@%
- %@AB@%* terminator at the end.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: Created 1/31/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ stoa(psz, us)%@NL@%
- PSZ psz;%@NL@%
- USHORT us;%@NL@%
- {%@NL@%
- static char dtoa[] = "0123456789abcdef";%@NL@%
- %@NL@%
- *psz++ = dtoa[(us & 0xf000) >> 12];%@NL@%
- *psz++ = dtoa[(us & 0xf00) >> 8];%@NL@%
- *psz++ = dtoa[(us & 0xf0) >> 4];%@NL@%
- *psz++ = dtoa[us & 0xf];%@NL@%
- *psz = '\0';%@NL@%
- return(psz);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Decimal to ascii%@NL@%
- %@AB@% */%@AE@%%@NL@%
- PSZ dtoa(psz, us, fRecurse)%@NL@%
- PSZ psz;%@NL@%
- USHORT us;%@NL@%
- BOOL fRecurse;%@NL@%
- {%@NL@%
- if (us > 9) {%@NL@%
- psz = dtoa(psz, us / 10, TRUE);%@NL@%
- *psz++ = (UCHAR)(us % 10) + '0';%@NL@%
- } else if (us > 0)%@NL@%
- *psz++ = (UCHAR)us + '0';%@NL@%
- else if (!fRecurse)%@NL@%
- *psz++ = '0';%@NL@%
- *psz = '\000';%@NL@%
- return(psz);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* fills psz with a hex time stamp and returns psz pointing to the 0%@NL@%
- %@AB@%* terminator at the end.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: Created 5/9/89 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- PSZ timestamp(psz, pszLast)%@NL@%
- PSZ psz;%@NL@%
- PSZ pszLast;%@NL@%
- {%@NL@%
- DATETIME dt;%@NL@%
- static USHORT prevTime = 0;%@NL@%
- USHORT Time;%@NL@%
- %@NL@%
- DosGetDateTime(&dt);%@NL@%
- Time = MAKESHORT(dt.hundredths, dt.seconds);%@NL@%
- psz = lstrcat(psz, "----------- dTime=", pszLast);%@NL@%
- psz = itoa(Time - prevTime, psz, pszLast);%@NL@%
- psz = lstrcat(psz, " ", pszLast);%@NL@%
- prevTime = Time;%@NL@%
- return(psz + lstrlen(psz));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGSTRT.ASM%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGSTRT.ASM%@AE@%%@NL@%
- %@NL@%
- %@AB@%; DDE manager library initialization routine%@AE@%%@NL@%
- %@NL@%
- .286p%@NL@%
- %@NL@%
- ?WIN=1 %@AB@%; Use Windows prolog/epilog%@AE@%%@NL@%
- ?PLM=1 %@AB@%; Use PLM calling convention%@AE@%%@NL@%
- DOS5=1%@NL@%
- .xlist%@NL@%
- include cmacros.inc%@NL@%
- .list%@NL@%
- %@NL@%
- sBegin DATA%@NL@%
- %@NL@%
- assumes DS,DATA%@NL@%
- %@NL@%
- externW hmodDmg%@NL@%
- externW usHugeShift%@NL@%
- %@NL@%
- sEnd DATA%@NL@%
- %@NL@%
- sBegin CODE%@NL@%
- assumes cs,CODE%@NL@%
- assumes ds,DATA%@NL@%
- %@NL@%
- externNP SemInit%@NL@%
- %@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; Registers set up by DosLoadModule...%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; SI = heap size%@AE@%%@NL@%
- %@AB@%; DI = module ID%@AE@%%@NL@%
- %@AB@%; DS = library's automatic data segment%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- cProc LoadProc,<FAR,PUBLIC>%@NL@%
- cBegin LoadProc%@NL@%
- %@AB@%; int 3%@AE@%%@NL@%
- mov hmodDmg, di%@NL@%
- call SemInit%@NL@%
- cEnd LoadProc%@NL@%
- %@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; FillBlock(PBYTE pDst, USHORT cb, BYTE b)%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- cProc FillBlock,<PUBLIC, NEAR>,<DI, DS>%@NL@%
- ParmD pDst%@NL@%
- ParmW cb%@NL@%
- ParmW b%@NL@%
- cBegin%@NL@%
- les di,pDst%@NL@%
- mov cx,cb%@NL@%
- mov ax,b%@NL@%
- cld%@NL@%
- rep stosb%@NL@%
- cEnd%@NL@%
- %@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; CopyBlock(pbSrc, pbDst, cb)%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- LabelNP <PUBLIC, CopyBlock>%@NL@%
- mov bx,sp%@NL@%
- push si%@NL@%
- push di%@NL@%
- mov dx,ds %@AB@%; preserve DS%@AE@%%@NL@%
- %@NL@%
- mov cx,ss:[bx+2]%@NL@%
- jcxz copydone %@AB@%; all done if crc == 0%@AE@%%@NL@%
- les di,ss:[bx+2+2]%@NL@%
- lds si,ss:[bx+2+2+4]%@NL@%
- cmp si,di%@NL@%
- jae copyok%@NL@%
- mov ax,cx%@NL@%
- dec ax%@NL@%
- add si,ax%@NL@%
- add di,ax%@NL@%
- std%@NL@%
- rep movsb%@NL@%
- cld%@NL@%
- jmp short copydone%@NL@%
- copyok:%@NL@%
- cld%@NL@%
- rep movsb%@NL@%
- copydone:%@NL@%
- %@NL@%
- mov ds,dx%@NL@%
- pop di%@NL@%
- pop si%@NL@%
- ret 10%@NL@%
- %@NL@%
- %@NL@%
- cProc HugeOffset,<NEAR, PUBLIC>%@NL@%
- parmD pSrc%@NL@%
- parmD cb%@NL@%
- cBegin%@NL@%
- mov dx, SEG_cb%@NL@%
- mov ax, OFF_pSrc%@NL@%
- add ax, OFF_cb%@NL@%
- adc dx, 0%@NL@%
- mov cx, usHugeShift%@NL@%
- shl dx, cl%@NL@%
- add dx, SEG_pSrc%@NL@%
- cEnd%@NL@%
- %@NL@%
- %@NL@%
- LabelFP <PUBLIC, DdeDebugBreak>%@NL@%
- int 3%@NL@%
- retf 0%@NL@%
- %@NL@%
- %@AB@%;%@AE@%%@NL@%
- %@AB@%; Returns segment size or 0 on error.%@AE@%%@NL@%
- %@AB@%;%@AE@%%@NL@%
- LabelNP <PUBLIC, CheckSel>%@NL@%
- %@AB@%; parmW Selector ; selector to validate%@AE@%%@NL@%
- cBegin nogen%@NL@%
- mov bx,sp %@AB@%; BX = selector to validate%@AE@%%@NL@%
- mov bx,ss:[bx].2%@NL@%
- lar ax,bx %@AB@%; See if valid selector%@AE@%%@NL@%
- jnz invalid_selector%@NL@%
- %@NL@%
- lsl ax,bx%@NL@%
- or ax,ax %@AB@%; zero sized?%@AE@%%@NL@%
- jnz valid_selector %@AB@%; nope, ok.%@AE@%%@NL@%
- %@NL@%
- invalid_selector:%@NL@%
- xor ax,ax %@AB@%; Return zero just to be nice%@AE@%%@NL@%
- %@NL@%
- valid_selector:%@NL@%
- ret 2%@NL@%
- %@NL@%
- cEnd nogen%@NL@%
- %@NL@%
- sEnd CODE%@NL@%
- end LoadProc%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DMGWNDP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\DDEML\DMGWNDP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/****************************** Module Header ******************************\%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Module Name: DMGWNDP.C%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This module contains all the window procs for the DDE manager.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created: 12/23/88 sanfords%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copyright (c) 1988, 1989 Microsoft Corporation%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"ddemlp.h" %@NL@%
- %@NL@%
- %@NL@%
- ULONG defid = QID_SYNC;%@NL@%
- XFERINFO defXferInfo = {%@NL@%
- &defid,%@NL@%
- 1L,%@NL@%
- XTYP_INIT,%@NL@%
- DDEFMT_TEXT,%@NL@%
- 0L,%@NL@%
- 0L,%@NL@%
- 0L,%@NL@%
- NULL%@NL@%
- };%@NL@%
- %@NL@%
- void InitAck(HWND hwnd, PCLIENTINFO pci, HWND hwndServer, PDDEINIT pddei);%@NL@%
- MRESULT ClientXferReq(PXFERINFO pXferInfo, PCLIENTINFO pci, HWND hwnd);%@NL@%
- USHORT SendClientReq(PXADATA pXad, HWND hwndServer, HWND hwnd, PAPPINFO pai);%@NL@%
- void DoClientDDEmsg(PCLIENTINFO pci, HWND hwnd, USHORT msg, HWND hwndFrom,%@NL@%
- PDDESTRUCT pddes);%@NL@%
- BOOL fExpectedMsg(PXADATA pXad, PDDESTRUCT pddes, USHORT msg, PCLIENTINFO pci);%@NL@%
- BOOL AdvanceXaction(HWND hwnd, PCLIENTINFO pci, PXADATA pXad,%@NL@%
- PDDESTRUCT pddes, USHORT msg, PUSHORT pErr);%@NL@%
- MRESULT ClientXferRespond(PCLIENTINFO pci, PXADATA pXad, PUSHORT pErr);%@NL@%
- void FrameInitConv(HWND hwndClient, PDDEINIT pddei);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ----------------CLIENT SECTION------------------%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Each client conversation has associated with it a window and a queue.%@NL@%
- %@AB@% * A conversation has one synchronous transaction and may have many%@NL@%
- %@AB@% * asynchronous transactions. A transaction is differientiated by its%@NL@%
- %@AB@% * state and other pertinant data. A transaction may be synchronous,%@NL@%
- %@AB@% * asynchronous, (initiated by DdeClientXfer()), or it may be external,%@NL@%
- %@AB@% * (initiated by an advise loop.)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * A transaction is active if it is in the middle of tranfer, otherwise%@NL@%
- %@AB@% * it is shutdown. A shutdown transaction is either successful or%@NL@%
- %@AB@% * failed. When an asynchronous transaction shuts down, the client%@NL@%
- %@AB@% * is notified via the callback function. (XTYP_XFERCOMPLETE)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The synchronous transaction, when active, is in a timeout loop which%@NL@%
- %@AB@% * can shut-down the transaction at the end of a predefined time period.%@NL@%
- %@AB@% * Shutdown synchronous transactions imediately transfer their information%@NL@%
- %@AB@% * to the client application by returning to DdeClientXfer().%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * asynchronous transactions remain in the client queue until removed%@NL@%
- %@AB@% * by the client application via DdeCheckQueue(). %@NL@%
- %@AB@% *%@NL@%
- %@AB@% * external transactions take place when the client is in an advise%@NL@%
- %@AB@% * data loop. These transactions pass through the callback function to%@NL@%
- %@AB@% * the client to be accepted.(XTYP_ADVDATA)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* MRESULT EXPENTRY ClientWndProc(hwnd, msg, mp1, mp2);%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This window controls a single DDE conversation from the CLIENT side.%@NL@%
- %@AB@%* If closed, it will automaticly abort any conversationn in progress.%@NL@%
- %@AB@%* It maintains an internal list of any extra WM_DDEINITIATEACK messages%@NL@%
- %@AB@%* it receives so that it can be queried later about this information.%@NL@%
- %@AB@%* Any extra WM_DDEINITIATEACK messages comming in will be immediately%@NL@%
- %@AB@%* terminated.%@NL@%
- %@AB@%* It also maintains an internal list of all items which currently are%@NL@%
- %@AB@%* in active ADVISE loops.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 12/16/88 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- MRESULT EXPENTRY ClientWndProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- register PCLIENTINFO pci;%@NL@%
- PAPPINFO pai;%@NL@%
- MRESULT mrData;%@NL@%
- PDDESTRUCT pddes;%@NL@%
- %@NL@%
- pci = (PCLIENTINFO)WinQueryWindowULong(hwnd, QWL_USER);%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_CREATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * allocate and initialize the client window info.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pai = GetCurrentAppInfo(FALSE);%@NL@%
- SemEnter();%@NL@%
- pci = (PCLIENTINFO)FarAllocMem(pai->hheapApp, sizeof(CLIENTINFO));%@NL@%
- SemLeave();%@NL@%
- if (pci == NULL) {%@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(1); %@AB@%/* aboart creation - low memory */%@AE@%%@NL@%
- }%@NL@%
- WinSetWindowULong(hwnd, QWL_USER, (ULONG)pci);%@NL@%
- pci->ci.pai = pai;%@NL@%
- pci->ci.xad.state = CONVST_NULL;%@NL@%
- pci->ci.xad.pXferInfo = &defXferInfo;%@NL@%
- pci->ci.fs = 0;%@NL@%
- pci->ci.hwndPartner = NULL;%@NL@%
- pci->ci.hszServerApp = NULL;%@NL@%
- pci->ci.hszTopic = NULL;%@NL@%
- pci->pQ = NULL; %@AB@%/* don't create until we need one */%@AE@%%@NL@%
- if (!(pci->ci.pAdviseList = CreateLst(pai->hheapApp, sizeof(ADVLI)))) {%@NL@%
- FarFreeMem(pai->hheapApp, (PBYTE)pci, sizeof(CLIENTINFO));%@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(1); %@AB@%/* aboart creation - low memory */%@AE@%%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case UMCL_INITIATE:%@NL@%
- if (pci->ci.xad.state == CONVST_NULL) {%@NL@%
- return(ClientInitiate(hwnd, (PINITINFO)mp1, pci));%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_INITIATEACK:%@NL@%
- InitAck(hwnd, pci, mp1, mp2);%@NL@%
- DosFreeSeg(SELECTOROF(mp2));%@NL@%
- return(1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- SemCheckOut();%@NL@%
- if (pci->ci.fs & ST_CONNECTED) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * stop any advises in progress%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->ci.fs & ST_ADVISE) {%@NL@%
- pddes = AllocDDESel(0, 0, 0, 0L, NULL);%@NL@%
- MyDdePostMsg(pci->ci.hwndPartner, hwnd, WM_DDE_UNADVISE,%@NL@%
- (PMYDDES)pddes, pci->ci.pai, MDPM_FREEHDATA);%@NL@%
- }%@NL@%
- WinSendMsg(hwnd, UMCL_TERMINATE, 0L, 0L);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * decrement the use counts on hszs we are done with.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- FreeHsz(pci->ci.hszServerApp);%@NL@%
- FreeHsz(pci->ci.hszTopic);%@NL@%
- }%@NL@%
- %@NL@%
- DestroyLst(pci->ci.pAdviseList);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- DestroyQ(pci->pQ);%@NL@%
- FarFreeMem(pci->ci.pai->hheapApp, (PBYTE)pci, sizeof(CLIENTINFO));%@NL@%
- SemLeave();%@NL@%
- break;%@NL@%
- %@NL@%
- case UMCL_TERMINATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * terminates any conversation in progress%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->ci.fs & ST_CONNECTED) {%@NL@%
- pci->ci.fs = pci->ci.fs & ~ST_CONNECTED;%@NL@%
- pci->ci.xad.state = CONVST_TERMINATED;%@NL@%
- if (WinIsWindow(DMGHAB, pci->ci.hwndPartner))%@NL@%
- WinDdePostMsg(pci->ci.hwndPartner, hwnd, WM_DDE_TERMINATE, 0L, FALSE);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case UMCL_XFER:%@NL@%
- if (!(pci->ci.fs & ST_CONNECTED)) {%@NL@%
- pci->ci.pai->LastError = DMGERR_NO_CONV_ESTABLISHED;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- return(ClientXferReq((PXFERINFO)mp1, pci, hwnd));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_DATA:%@NL@%
- case WM_DDE_ACK:%@NL@%
- DoClientDDEmsg(pci, hwnd, msg, (HWND)mp1, (PDDESTRUCT)mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_TERMINATE:%@NL@%
- SemCheckOut();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * only respond if this is for us.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((HWND)mp1 != pci->ci.hwndPartner) {%@NL@%
- DosFreeSeg(SELECTOROF(mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- WinSendMsg(hwnd, UMCL_TERMINATE, 0L, 0L);%@NL@%
- DosFreeSeg(SELECTOROF(mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- case UM_QUERY:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * LOUSHORT(mp1) = info index.%@NL@%
- %@AB@% * mp2 = pData. If pData==0, return data else copy into pData.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch (LOUSHORT(mp1)) {%@NL@%
- case Q_STATUS:%@NL@%
- mrData = (MRESULT)pci->ci.fs;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_CLIENT:%@NL@%
- mrData = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_APPINFO:%@NL@%
- mrData = pci->ci.pai;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_APPNAME:%@NL@%
- mrData = *(PHSZ)PTOPPILEITEM(pci->ci.pai->pAppNamePile);%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_ALL:%@NL@%
- mrData = (MRESULT)(CLIENTINFO FAR *)pci;%@NL@%
- break;%@NL@%
- }%@NL@%
- if (mp2 == 0)%@NL@%
- return(mrData);%@NL@%
- else%@NL@%
- *(MRESULT FAR *)mp2 = mrData;%@NL@%
- return(1);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Client response to a WM_DDE_INITIATEACK message when expected.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void InitAck(hwnd, pci, hwndServer, pddei)%@NL@%
- HWND hwnd;%@NL@%
- PCLIENTINFO pci;%@NL@%
- HWND hwndServer;%@NL@%
- PDDEINIT pddei;%@NL@%
- {%@NL@%
- SemCheckOut();%@NL@%
- %@NL@%
- if (pci->ci.fs & ST_CONNECTED) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * extra server - spawn another client window. (we assume we%@NL@%
- %@AB@% * will only get extras if enumerating.)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- AssertF(WinQueryWindow(hwnd, QW_PARENT, FALSE) != pci->ci.pai->hwndDmg,%@NL@%
- "Improper client spawn")%@NL@%
- if (hwndServer != pci->ci.hwndPartner) {%@NL@%
- WinSendMsg(hwndServer, WM_DDE_TERMINATE, hwnd, 0L);%@NL@%
- GetDDEClientWindow(WinQueryWindow(hwnd, QW_PARENT, FALSE),%@NL@%
- hwndServer, hwndServer, pci->ci.hszServerApp,%@NL@%
- pci->ci.hszTopic, &pci->ci.cc);%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- if (pci->ci.xad.state != CONVST_INIT1) %@NL@%
- return;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * first one back... lock in!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pci->ci.hwndPartner = hwndServer;%@NL@%
- pci->ci.xad.state = CONVST_CONNECTED;%@NL@%
- pci->ci.fs |= ST_CONNECTED;%@NL@%
- if (WinQueryWindowPtr(hwndServer, QWP_PFNWP) == ServerWndProc) %@NL@%
- pci->ci.fs |= ST_INTRADLL;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If the connection was made using a wild app name, we want to%@NL@%
- %@AB@% * hack in an apropriate name so QueryConvInfo can give the app%@NL@%
- %@AB@% * something useful to refer to this guy as.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * - the protocol is little help here.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->ci.hszServerApp == 0) {%@NL@%
- if (WinQueryWindowPtr(hwndServer, QWP_PFNWP) == ServerWndProc) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * one of ours! simple.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pci->ci.hszServerApp = (PAPPINFO)WinSendMsg(pci->ci.hwndPartner,%@NL@%
- UM_QUERY, (MPARAM)Q_APPNAME, 0L);%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Try the psz in pddei. Maybe the server set it properly%@NL@%
- %@AB@% * before returning it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!(pci->ci.hszServerApp =%@NL@%
- GetHsz(PSZAPP(pddei), pci->ci.cc.idCountry,%@NL@%
- pci->ci.cc.usCodepage, TRUE))) {%@NL@%
- %@NL@%
- PSZ pszT;%@NL@%
- USHORT cb;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * WORST CASE:%@NL@%
- %@AB@% * Until a better way is found, we set the hszServerApp to%@NL@%
- %@AB@% * the title of the frame window.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pszT = FarAllocMem(pci->ci.pai->hheapApp,%@NL@%
- cb = WinQueryWindowTextLength(pci->ci.hwndFrame) + 1)) {%@NL@%
- WinQueryWindowText(pci->ci.hwndFrame, cb, (PSZ)pszT);%@NL@%
- pci->ci.hszServerApp = GetHsz(pszT, pci->ci.cc.idCountry,%@NL@%
- pci->ci.cc.usCodepage, TRUE);%@NL@%
- FarFreeMem(pci->ci.pai->hheapApp, (PBYTE)pszT, cb);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Now what if the topic was wild?%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->ci.hszTopic == 0) {%@NL@%
- if (WinQueryWindowPtr(hwndServer, QWP_PFNWP) == ServerWndProc) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * one of ours! simple.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pci->ci.hszTopic = (PAPPINFO)WinSendMsg(pci->ci.hwndPartner,%@NL@%
- UM_QUERY, (MPARAM)Q_TOPIC, 0L);%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Try the psz in pddei. Maybe the server set it properly%@NL@%
- %@AB@% * before returning it. If this doesn't work were out of%@NL@%
- %@AB@% * luck, keep it wild.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pci->ci.hszServerApp = GetHsz(PSZAPP(pddei), pci->ci.cc.idCountry,%@NL@%
- pci->ci.cc.usCodepage, TRUE);%@NL@%
- } %@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* Processes a client transfer request issued by one of the ClientXfer%@NL@%
- %@AB@%* functions. This may be synchronous or asynchronous.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- MRESULT ClientXferReq(pXferInfo, pci, hwnd)%@NL@%
- PXFERINFO pXferInfo;%@NL@%
- PCLIENTINFO pci;%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- PCQDATA pcqd;%@NL@%
- MRESULT retVal;%@NL@%
- %@NL@%
- if (pXferInfo->ulTimeout == TIMEOUT_ASYNC) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * add a client queue item to track this transaction and return%@NL@%
- %@AB@% * the ID.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->pQ == NULL)%@NL@%
- pci->pQ = CreateQ(sizeof(CQDATA));%@NL@%
- if (pci->pQ == NULL) {%@NL@%
- pci->ci.pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- pcqd = (PCQDATA)Addqi(pci->pQ);%@NL@%
- if (pcqd == NULL) {%@NL@%
- pci->ci.pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- CopyBlock((PBYTE)pXferInfo, (PBYTE)&pcqd->XferInfo, sizeof(XFERINFO));%@NL@%
- pcqd->xad.state = CONVST_CONNECTED;%@NL@%
- pcqd->xad.pddes = 0;%@NL@%
- pcqd->xad.LastError = DMGERR_NO_ERROR;%@NL@%
- pcqd->xad.pXferInfo = &pcqd->XferInfo;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Get transaction started - if it fails, quit now.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((pcqd->xad.LastError = SendClientReq(&pcqd->xad,%@NL@%
- pci->ci.hwndPartner, hwnd, pci->ci.pai)) == DMGERR_SERVER_DIED) {%@NL@%
- pci->ci.fs = pci->ci.fs & ~ST_CONNECTED;%@NL@%
- Deleteqi(pci->pQ, MAKEID(pcqd));%@NL@%
- pci->ci.pai->LastError = DMGERR_SERVER_DIED;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- return((MRESULT)MAKEID(pcqd));%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * if not quiesent, yet synchronous, tell him were busy.%@NL@%
- %@AB@% * (this case could happen on a recursive call.)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->ci.xad.state != CONVST_CONNECTED) {%@NL@%
- pci->ci.pai->LastError = DMGERR_BUSY;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Set this so messages comming in during the conversation know whats up%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pci->ci.xad.pXferInfo = pXferInfo;%@NL@%
- %@NL@%
- if ((pci->ci.pai->LastError = SendClientReq(&pci->ci.xad,%@NL@%
- pci->ci.hwndPartner, hwnd, pci->ci.pai)) == DMGERR_SERVER_DIED) {%@NL@%
- pci->ci.fs = pci->ci.fs & ~ST_CONNECTED;%@NL@%
- }%@NL@%
- %@NL@%
- if (pci->ci.pai->LastError != DMGERR_NO_ERROR)%@NL@%
- return(0);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * reset the LastError here so we know if we had problems while%@NL@%
- %@AB@% * in the modal loop.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pci->ci.pai->LastError = DMGERR_NO_ERROR;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * timeout - modal loop.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!timeout(pci->ci.pai, pXferInfo->ulTimeout, hwnd)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * reentrency or client has unregistered%@NL@%
- %@AB@% */%@AE@%%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * check results - lasterror already set by timeout().%@NL@%
- %@AB@% * Synchronous conversation must be reset to quiesent by the time we%@NL@%
- %@AB@% * give up.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->ci.xad.state == CONVST_INCOMPLETE) {%@NL@%
- pci->ci.xad.state = CONVST_CONNECTED;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- retVal = ClientXferRespond(pci, &pci->ci.xad, &pci->ci.pai->LastError);%@NL@%
- if (pci->ci.xad.state == CONVST_INCOMPLETE) %@NL@%
- pci->ci.xad.state = CONVST_CONNECTED;%@NL@%
- %@NL@%
- return(retVal);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine sends the apropriate initiation messages for starting a%@NL@%
- %@AB@%* client request according to the transaction data given.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- USHORT SendClientReq(pXad, hwndServer, hwnd, pai) %@NL@%
- PXADATA pXad;%@NL@%
- HWND hwndServer;%@NL@%
- HWND hwnd;%@NL@%
- PAPPINFO pai;%@NL@%
- {%@NL@%
- USHORT fsStatus = 0;%@NL@%
- USHORT msg;%@NL@%
- BOOL fCopy;%@NL@%
- PDDESTRUCT pddes;%@NL@%
- %@NL@%
- switch (pXad->pXferInfo->usType) {%@NL@%
- case XTYP_REQUEST:%@NL@%
- msg = WM_DDE_REQUEST;%@NL@%
- pXad->state = CONVST_REQSENT;%@NL@%
- fCopy = FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_POKE:%@NL@%
- msg = WM_DDE_POKE;%@NL@%
- pXad->state = CONVST_POKESENT;%@NL@%
- fCopy = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_EXEC:%@NL@%
- msg = WM_DDE_EXECUTE;%@NL@%
- pXad->state = CONVST_EXECSENT;%@NL@%
- fCopy = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_ADVSTART:%@NL@%
- case XTYP_ADVSTART | XTYPF_NODATA:%@NL@%
- case XTYP_ADVSTART | XTYPF_ACKREQ:%@NL@%
- case XTYP_ADVSTART | XTYPF_NODATA | XTYPF_ACKREQ:%@NL@%
- fsStatus = pXad->pXferInfo->usType & (DDE_FACKREQ | DDE_FNODATA);%@NL@%
- msg = WM_DDE_ADVISE;%@NL@%
- pXad->state = CONVST_ADVSENT;%@NL@%
- fCopy = FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_ADVSTOP:%@NL@%
- msg = WM_DDE_UNADVISE;%@NL@%
- pXad->state = CONVST_UNADVSENT;%@NL@%
- fCopy = FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(DMGERR_INVALIDPARAMETER);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Send transfer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((pddes = AllocDDESel(fsStatus, pXad->pXferInfo->usFmt,%@NL@%
- pXad->pXferInfo->hszItem, fCopy ? pXad->pXferInfo->cb : 0, NULL))%@NL@%
- == 0) {%@NL@%
- pXad->state = CONVST_CONNECTED;%@NL@%
- return(DMGERR_MEMORY_ERROR);%@NL@%
- }%@NL@%
- %@NL@%
- if (fCopy)%@NL@%
- CopyHugeBlock((PBYTE)pXad->pXferInfo->pData, DDES_PABDATA(pddes),%@NL@%
- pXad->pXferInfo->cb);%@NL@%
- %@NL@%
- if (WinIsWindow(DMGHAB, hwndServer)) {%@NL@%
- if (!MyDdePostMsg(hwndServer, hwnd, msg, (PMYDDES)pddes, pai, MDPM_FREEHDATA)) {%@NL@%
- pXad->state = CONVST_CONNECTED;%@NL@%
- return(DMGERR_POSTMSG_FAILED);%@NL@%
- }%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We lost the server, we are TERMINATED arnold!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pXad->state = CONVST_TERMINATED;%@NL@%
- FreeData((PMYDDES)pddes, pai);%@NL@%
- return(DMGERR_SERVER_DIED);%@NL@%
- }%@NL@%
- return(DMGERR_NO_ERROR);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This handles client window processing of WM_DDE_ACK and WM_DDE_DATA msgs.%@NL@%
- %@AB@%* On exit pddes is freed.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void DoClientDDEmsg(pci, hwnd, msg, hwndFrom, pddes)%@NL@%
- PCLIENTINFO pci;%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- HWND hwndFrom;%@NL@%
- PDDESTRUCT pddes;%@NL@%
- {%@NL@%
- PCQDATA pqd;%@NL@%
- int i;%@NL@%
- HSZ hszItem;%@NL@%
- PADVLI pAdviseItem;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * make sure its for us.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hwndFrom != pci->ci.hwndPartner || !(pci->ci.fs & ST_CONNECTED)) {%@NL@%
- FreeData((PMYDDES)pddes, pci->ci.pai);%@NL@%
- return;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Check if it fits the synchronous transaction data%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (fExpectedMsg(&pci->ci.xad, pddes, msg, pci)) {%@NL@%
- if (AdvanceXaction(hwnd, pci, &pci->ci.xad, pddes, msg,%@NL@%
- &pci->ci.pai->LastError))%@NL@%
- WinPostMsg(hwnd, WM_TIMER, (MPARAM)TID_TIMEOUT, 0L);%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * See if it fits any asynchronous transaction data - if any exist%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pci->pQ != NULL && pci->pQ->pqiHead != NULL) {%@NL@%
- SemEnter();%@NL@%
- pqd = (PCQDATA)pci->pQ->pqiHead;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * cycle from oldest to newest.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (i = pci->pQ->cItems; i; i--) {%@NL@%
- pqd = (PCQDATA)pqd->next;%@NL@%
- if (!fExpectedMsg(&pqd->xad, pddes, msg, pci))%@NL@%
- continue;%@NL@%
- if (AdvanceXaction(hwnd, pci, &pqd->xad, pddes, msg,%@NL@%
- &pqd->xad.LastError)) {%@NL@%
- ClientXferRespond(pci, &pqd->xad, &pqd->xad.LastError);%@NL@%
- SemLeave();%@NL@%
- MakeCallback(pci->ci.pai, hwnd, (HSZ)0L, (HSZ)0L, 0,%@NL@%
- XTYP_XFERCOMPLETE, (HDMGDATA)MAKEID(pqd),%@NL@%
- 0, 0, hwndFrom);%@NL@%
- return;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return;%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * It doesn't fit anything, check for an advise data message.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (msg == WM_DDE_DATA) {%@NL@%
- hszItem = GetHszItem((PMYDDES)pddes, &pci->ci.cc, TRUE);%@NL@%
- if (pAdviseItem = (PADVLI)FindAdvList(pci->ci.pAdviseList, hszItem,%@NL@%
- pddes->usFormat)) {%@NL@%
- MakeCallback(pci->ci.pai, (HCONV)hwnd, pci->ci.hszTopic,%@NL@%
- hszItem, pddes->usFormat, XTYP_ADVDATA, pddes, msg,%@NL@%
- pddes->fsStatus, pci->ci.hwndPartner);%@NL@%
- } else {%@NL@%
- FreeHsz(hszItem);%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * throw it away%@NL@%
- %@AB@% */%@AE@%%@NL@%
- FreeData((PMYDDES)pddes, pci->ci.pai);%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine matches a conversation transaction with a DDE message. If%@NL@%
- %@AB@%* the state, usType, format, itemname dde structure data and the message%@NL@%
- %@AB@%* received all agree, TRUE is returned.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL fExpectedMsg(pXad, pddes, msg, pci)%@NL@%
- PXADATA pXad;%@NL@%
- PDDESTRUCT pddes;%@NL@%
- USHORT msg;%@NL@%
- PCLIENTINFO pci;%@NL@%
- {%@NL@%
- HSZ hsz = 0;%@NL@%
- BOOL fRet = FALSE;%@NL@%
- %@NL@%
- if (!(pXad->state > CONVST_INIT1 &&%@NL@%
- pddes->usFormat == pXad->pXferInfo->usFmt &&%@NL@%
- (hsz = GetHszItem((PMYDDES)pddes, &pci->ci.cc, TRUE)) ==%@NL@%
- pXad->pXferInfo->hszItem)) {%@NL@%
- goto Exit;%@NL@%
- }%@NL@%
- switch (pXad->state) {%@NL@%
- case CONVST_REQSENT:%@NL@%
- if (msg == WM_DDE_DATA && !(pddes->fsStatus & DDE_FRESPONSE))%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Not data in response to a request!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- break;%@NL@%
- fRet = (msg == WM_DDE_ACK || msg == WM_DDE_DATA);%@NL@%
- break;%@NL@%
- %@NL@%
- case CONVST_POKESENT:%@NL@%
- case CONVST_EXECSENT:%@NL@%
- case CONVST_ADVSENT:%@NL@%
- case CONVST_UNADVSENT:%@NL@%
- fRet = (msg == WM_DDE_ACK);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- Exit: %@NL@%
- FreeHsz(hsz);%@NL@%
- return(fRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This function assumes that msg is an apropriate message for the transaction%@NL@%
- %@AB@%* referenced by pXad. It acts on msg as apropriate. pddes is the DDESTRUCT%@NL@%
- %@AB@%* associated with msg.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns fSuccess ie: transaction is ready to close up.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- BOOL AdvanceXaction(hwnd, pci, pXad, pddes, msg, pErr)%@NL@%
- HWND hwnd;%@NL@%
- PCLIENTINFO pci;%@NL@%
- PXADATA pXad;%@NL@%
- PDDESTRUCT pddes;%@NL@%
- USHORT msg;%@NL@%
- PUSHORT pErr;%@NL@%
- {%@NL@%
- switch (msg) {%@NL@%
- case WM_DDE_ACK:%@NL@%
- switch (pXad->state) {%@NL@%
- case CONVST_ADVSENT:%@NL@%
- case CONVST_EXECSENT:%@NL@%
- case CONVST_POKESENT:%@NL@%
- case CONVST_REQSENT:%@NL@%
- case CONVST_UNADVSENT:%@NL@%
- if (pddes->fsStatus & DDE_FACK) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * handle successes%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch (pXad->state) {%@NL@%
- case CONVST_POKESENT:%@NL@%
- pXad->state = CONVST_POKEACKRCVD;%@NL@%
- break;%@NL@%
- %@NL@%
- case CONVST_EXECSENT:%@NL@%
- pXad->state = CONVST_EXECACKRCVD;%@NL@%
- break;%@NL@%
- %@NL@%
- case CONVST_ADVSENT:%@NL@%
- pXad->state = CONVST_ADVACKRCVD;%@NL@%
- break;%@NL@%
- %@NL@%
- case CONVST_UNADVSENT:%@NL@%
- pXad->state = CONVST_UNADVACKRCVD;%@NL@%
- break;%@NL@%
- %@NL@%
- case CONVST_REQSENT:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * requests are not expected to send a +ACK. only%@NL@%
- %@AB@% * -ACK or data. We ignore a +ACK to a request.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- FreeData((PMYDDES)pddes, pci->ci.pai);%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * handle the expected ACK failures.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- *pErr = DMGERR_NOTPROCESSED;%@NL@%
- if (pddes->fsStatus & DDE_FBUSY)%@NL@%
- *pErr = DMGERR_BUSY;%@NL@%
- pXad->state = CONVST_INCOMPLETE;%@NL@%
- }%@NL@%
- }%@NL@%
- FreeData((PMYDDES)pddes, pci->ci.pai);%@NL@%
- return(TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_DATA:%@NL@%
- switch (pXad->state) {%@NL@%
- case CONVST_REQSENT:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * send an ack if requested - we dare not return the given%@NL@%
- %@AB@% * pddes because it may be a data item sent to several%@NL@%
- %@AB@% * clients and we would mess up the fsStatus word for%@NL@%
- %@AB@% * all processes involved.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pddes->fsStatus & DDE_FACKREQ) {%@NL@%
- MyDdePostMsg(pci->ci.hwndPartner, hwnd, WM_DDE_ACK,%@NL@%
- (PMYDDES)AllocDDESel(DDE_FACK, pddes->usFormat,%@NL@%
- pXad->pXferInfo->hszItem, 0L, NULL),%@NL@%
- pci->ci.pai, MDPM_FREEHDATA);%@NL@%
- }%@NL@%
- pXad->state = CONVST_DATARCVD;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We do NOT free the selector here yet because it will be %@NL@%
- %@AB@% * given to the client via pXad->pddes.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pXad->pddes = pddes;%@NL@%
- return(TRUE);%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- return(FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This function assumes that a client transfer request has been completed -%@NL@%
- %@AB@%* or should be completed by the time this is called.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* pci contains general client info%@NL@%
- %@AB@%* pXad contains the transaction info%@NL@%
- %@AB@%* pErr points to where to place the LastError code.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns 0 on failure%@NL@%
- %@AB@%* Returns TRUE or a Data Selector on success.%@NL@%
- %@AB@%* On failure, the conversation is left in a CONVST_INCOMPLETE state.%@NL@%
- %@AB@%* On success, the conversation is left in a CONVST_CONNECTED state.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/1/89 Sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- MRESULT ClientXferRespond(pci, pXad, pErr)%@NL@%
- PCLIENTINFO pci;%@NL@%
- PXADATA pXad;%@NL@%
- PUSHORT pErr;%@NL@%
- {%@NL@%
- if (pXad->state == CONVST_INCOMPLETE) %@NL@%
- return(0);%@NL@%
- %@NL@%
- switch (pXad->pXferInfo->usType) {%@NL@%
- case XTYP_REQUEST:%@NL@%
- if (pXad->state != CONVST_DATARCVD) {%@NL@%
- if (*pErr == DMGERR_NO_ERROR)%@NL@%
- *pErr = DMGERR_DATAACKTIMEOUT;%@NL@%
- goto failexit;%@NL@%
- }%@NL@%
- pXad->state = CONVST_CONNECTED;%@NL@%
- return(pXad->pddes);%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_POKE:%@NL@%
- if (pXad->state != CONVST_POKEACKRCVD) {%@NL@%
- if (*pErr == DMGERR_NO_ERROR)%@NL@%
- *pErr = DMGERR_POKEACKTIMEOUT;%@NL@%
- goto failexit;%@NL@%
- }%@NL@%
- pXad->state = CONVST_CONNECTED;%@NL@%
- return(TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_EXEC:%@NL@%
- if (pXad->state != CONVST_EXECACKRCVD) {%@NL@%
- if (*pErr == DMGERR_NO_ERROR)%@NL@%
- *pErr = DMGERR_EXECACKTIMEOUT;%@NL@%
- goto failexit;%@NL@%
- }%@NL@%
- pXad->state = CONVST_CONNECTED;%@NL@%
- return(TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_ADVSTART:%@NL@%
- case XTYP_ADVSTART | XTYPF_NODATA:%@NL@%
- case XTYP_ADVSTART | XTYPF_ACKREQ:%@NL@%
- case XTYP_ADVSTART | XTYPF_NODATA | XTYPF_ACKREQ:%@NL@%
- if (pXad->state != CONVST_ADVACKRCVD) {%@NL@%
- if (*pErr == DMGERR_NO_ERROR)%@NL@%
- *pErr = DMGERR_ADVACKTIMEOUT;%@NL@%
- goto failexit;%@NL@%
- }%@NL@%
- if (!AddAdvList(pci->ci.pAdviseList, pXad->pXferInfo->hszItem,%@NL@%
- pXad->pXferInfo->usType & (DDE_FACKREQ | DDE_FNODATA),%@NL@%
- pXad->pXferInfo->usFmt)) {%@NL@%
- pXad->state = CONVST_INCOMPLETE;%@NL@%
- pci->ci.pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- return(FALSE);%@NL@%
- } else {%@NL@%
- pXad->state = CONVST_CONNECTED;%@NL@%
- pci->ci.fs |= ST_ADVISE;%@NL@%
- return(TRUE);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case XTYP_ADVSTOP:%@NL@%
- if (pXad->state != CONVST_UNADVACKRCVD) {%@NL@%
- if (*pErr == DMGERR_NO_ERROR)%@NL@%
- *pErr = DMGERR_UNADVACKTIMEOUT;%@NL@%
- goto failexit;%@NL@%
- }%@NL@%
- if (!DeleteAdvList(pci->ci.pAdviseList, pXad->pXferInfo->hszItem,%@NL@%
- pXad->pXferInfo->usFmt))%@NL@%
- pci->ci.fs &= ~ST_ADVISE;%@NL@%
- pXad->state = CONVST_CONNECTED;%@NL@%
- return(TRUE);%@NL@%
- break;%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- failexit:%@NL@%
- pXad->state = CONVST_INCOMPLETE;%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ----------------------------SERVER SECTION--------------------------------%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Public Function ****************************\%@NL@%
- %@AB@%* MRESULT EXPENTRY ServerWndProc(hwnd, msg, mp1, mp2)%@NL@%
- %@AB@%* HWND hwnd;%@NL@%
- %@AB@%* USHORT msg;%@NL@%
- %@AB@%* MPARAM mp1;%@NL@%
- %@AB@%* MPARAM mp2;%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DESCRIPTION:%@NL@%
- %@AB@%* This processes DDE conversations from the server end.%@NL@%
- %@AB@%* It stores internal information and acts much like a state machine.%@NL@%
- %@AB@%* If closed, it will automaticly abort any conversation in progress.%@NL@%
- %@AB@%* It also maintains an internal list of all items which currently are%@NL@%
- %@AB@%* in active ADVISE loops.%@NL@%
- %@AB@%* PUBDOC START%@NL@%
- %@AB@%* These server windows have the feature that a conversation can be%@NL@%
- %@AB@%* re-initiated with them by a client. The Client merely terminates%@NL@%
- %@AB@%* the conversation and then re-initiates by using a SendMsg to this%@NL@%
- %@AB@%* window. This allows a client to change the topic of the conversation%@NL@%
- %@AB@%* or to pass the conversation on to another client window without%@NL@%
- %@AB@%* loosing the server it initiated with. This is quite useful for%@NL@%
- %@AB@%* wild initiates.%@NL@%
- %@AB@%* PUBDOC END%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* 10/18/89 sanfords Added hack to make hszItem==0L when offszItem==offabData.%@NL@%
- %@AB@%* 1/4/89 sanfords created %@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- MRESULT EXPENTRY ServerWndProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- %@AI@%#define %@AE@%PDDES ((PDDESTRUCT)mp2) %@NL@%
- register PSERVERINFO psi;%@NL@%
- MPARAM mrData;%@NL@%
- PADVLI pAdviseItem;%@NL@%
- PSZ pszApp, pszTopic;%@NL@%
- HSZ hsz;%@NL@%
- USHORT cchApp, cchTopic;%@NL@%
- USHORT usType;%@NL@%
- HDMGDATA hDmgData = 0L;%@NL@%
- BOOL fResult;%@NL@%
- %@NL@%
- %@NL@%
- psi = (PSERVERINFO)WinQueryWindowULong(hwnd, QWL_USER);%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_DDE_REQUEST:%@NL@%
- case WM_DDE_ACK:%@NL@%
- case WM_DDE_ADVISE:%@NL@%
- case WM_DDE_UNADVISE:%@NL@%
- case WM_DDE_POKE:%@NL@%
- case WM_DDE_EXECUTE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * only respond if this is for us.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((HWND)mp1 != psi->ci.hwndPartner || !(psi->ci.fs & ST_CONNECTED)) {%@NL@%
- FreeData((PMYDDES)mp2, psi->ci.pai);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case WM_CREATE: {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * allocate and initialize the server window info.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pai = GetCurrentAppInfo(FALSE);%@NL@%
- SemEnter();%@NL@%
- %@NL@%
- if (!(psi = (PSERVERINFO)FarAllocMem(pai->hheapApp, sizeof(SERVERINFO))))%@NL@%
- goto LowMem;%@NL@%
- FillBlock((PBYTE)&psi->ci, sizeof(COMMONINFO), 0);%@NL@%
- if (!(psi->ci.pAdviseList = CreateLst(pai->hheapApp, sizeof(ADVLI)))) {%@NL@%
- FarFreeMem(pai->hheapApp, (PBYTE)psi, sizeof(SERVERINFO));%@NL@%
- LowMem: %@NL@%
- pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- SemLeave();%@NL@%
- return(1); %@AB@%/* abort creation - low memory */%@AE@%%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- psi->ci.pai = pai;%@NL@%
- psi->ci.xad.state = CONVST_NULL;%@NL@%
- WinSetWindowULong(hwnd, QWL_USER, (ULONG)psi);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case UMSR_INITIATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This was sent by the subclassed frame of the server app.%@NL@%
- %@AB@% * The frame has already queried the server for permission%@NL@%
- %@AB@% * to create this window.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * If mp2 is NULL, this is a hot server window waiting for%@NL@%
- %@AB@% * a WM_DDE_INITIATE.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%pii ((PINITINFO)mp1) %@NL@%
- IncHszCount(psi->ci.hszServerApp = pii->hszAppName);%@NL@%
- IncHszCount(psi->ci.hszTopic = pii->hszTopic);%@NL@%
- psi->ci.hwndPartner = (HWND)mp2;%@NL@%
- psi->ci.hwndFrame = FindFrame(psi->ci.hwndPartner);%@NL@%
- psi->ci.cc.fsContext = pii->pCC->fsContext;%@NL@%
- psi->ci.cc.idCountry = pii->pCC->idCountry;%@NL@%
- psi->ci.cc.usCodepage = pii->pCC->usCodepage;%@NL@%
- psi->ci.fs |= ST_CONNECTED;%@NL@%
- psi->ci.xad.state = CONVST_CONNECTED;%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- pszApp = pszFromHsz(psi->ci.hszServerApp, &cchApp);%@NL@%
- pszTopic = pszFromHsz(psi->ci.hszTopic, &cchTopic);%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- if (mp2)%@NL@%
- WinDdeRespond((HWND)mp2, hwnd, pszApp, pszTopic);%@NL@%
- %@NL@%
- SemEnter();%@NL@%
- FarFreeMem(hheapDmg, (PBYTE)pszApp, cchApp);%@NL@%
- FarFreeMem(hheapDmg, (PBYTE)pszTopic, cchTopic);%@NL@%
- SemLeave();%@NL@%
- %@NL@%
- return(1);%@NL@%
- %@AI@%#undef %@AE@%pii %@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_INITIATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This will happen when a client tries to re-initiate a conversation%@NL@%
- %@AB@% * with this server. We allow about 10 seconds after termination%@NL@%
- %@AB@% * for another client to connect specifically with this window.%@NL@%
- %@AB@% * This allows a client to swap windows on its end of the conversation.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if (psi->ci.xad.state == CONVST_TERMINATED &&%@NL@%
- (psi->ci.hszServerApp == GetHsz(PSZAPP(mp2), psi->ci.cc.idCountry,%@NL@%
- psi->ci.cc.usCodepage, FALSE))) {%@NL@%
- %@NL@%
- WinStopTimer(DMGHAB, hwnd, TID_SELFDESTRUCT);%@NL@%
- hsz = psi->ci.hszTopic;%@NL@%
- psi->ci.hszTopic = GetHsz(PSZTOPIC(mp2), psi->ci.cc.idCountry,%@NL@%
- psi->ci.cc.usCodepage, TRUE);%@NL@%
- FreeHsz(hsz);%@NL@%
- psi->ci.hwndPartner = (HWND)mp1;%@NL@%
- psi->ci.hwndFrame = FindFrame(psi->ci.hwndPartner);%@NL@%
- psi->ci.fs |= ST_CONNECTED;%@NL@%
- psi->ci.xad.state = CONVST_CONNECTED;%@NL@%
- if (WinQueryWindowPtr(psi->ci.hwndPartner, QWP_PFNWP) == ClientWndProc) %@NL@%
- psi->ci.fs |= ST_INTRADLL;%@NL@%
- WinDdeRespond((HWND)mp1, hwnd, PSZAPP(mp2), PSZTOPIC(mp2));%@NL@%
- fResult = TRUE;%@NL@%
- } else%@NL@%
- fResult = FALSE;%@NL@%
- %@NL@%
- FreeData((PMYDDES)mp2, psi->ci.pai);%@NL@%
- return(fResult);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_TERMINATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * only respond if this is for us.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((HWND)mp1 != psi->ci.hwndPartner) %@NL@%
- break;%@NL@%
- %@AB@%/* fall through */%@AE@%%@NL@%
- %@NL@%
- case UMSR_TERMINATE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * terminates any conversation in progress%@NL@%
- %@AB@% * Note that we keep around all the other conversation data so%@NL@%
- %@AB@% * a later re-connection is possible.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (psi->ci.fs & ST_CONNECTED) {%@NL@%
- psi->ci.fs &= ~ST_CONNECTED;%@NL@%
- psi->ci.xad.state = CONVST_TERMINATED;%@NL@%
- if (WinIsWindow(DMGHAB, psi->ci.hwndPartner))%@NL@%
- WinDdePostMsg(psi->ci.hwndPartner, hwnd, WM_DDE_TERMINATE, 0L, FALSE);%@NL@%
- }%@NL@%
- if (psi->ci.fs & ST_ADVISE) {%@NL@%
- FlushLst(psi->ci.pAdviseList);%@NL@%
- psi->ci.fs &= ~ST_ADVISE;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Mr. Phelps, if this window isn't reconnected within 10 odd%@NL@%
- %@AB@% * seconds, it will self-destruct. This gives the client time%@NL@%
- %@AB@% * to reconnect with another client window. This often happens%@NL@%
- %@AB@% * with wild initiates.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinStartTimer(DMGHAB, hwnd, TID_SELFDESTRUCT, 0xa000);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_TIMER:%@NL@%
- if (LOUSHORT(mp1) == TID_SELFDESTRUCT && !(psi->ci.fs & ST_CONNECTED))%@NL@%
- DestroyWindow(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DESTROY:%@NL@%
- SemCheckOut();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Send ourselves a terminate and free local data.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinSendMsg(hwnd, UMSR_TERMINATE, 0L, 0L);%@NL@%
- MakeCallback(psi->ci.pai, hwnd, psi->ci.hszTopic, (HSZ)NULL, 0, XTYP_TERM,%@NL@%
- 0L, 0, 0, psi->ci.hwndPartner);%@NL@%
- SemEnter();%@NL@%
- DestroyLst(psi->ci.pAdviseList);%@NL@%
- FreeHsz(psi->ci.hszServerApp);%@NL@%
- FreeHsz(psi->ci.hszTopic);%@NL@%
- FarFreeMem(psi->ci.pai->hheapApp, (PBYTE)psi, sizeof(SERVERINFO));%@NL@%
- SemLeave();%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_REQUEST:%@NL@%
- usType = XTYP_REQUEST;%@NL@%
- goto Callback;%@NL@%
- %@NL@%
- case WM_DDE_EXECUTE:%@NL@%
- usType = XTYP_EXEC;%@NL@%
- hDmgData = mp2;%@NL@%
- goto Callback;%@NL@%
- %@NL@%
- case WM_DDE_POKE:%@NL@%
- usType = XTYP_POKE;%@NL@%
- hDmgData = mp2;%@NL@%
- goto Callback;%@NL@%
- %@NL@%
- case WM_DDE_ADVISE:%@NL@%
- usType = XTYP_ADVSTART; %@AB@%/* set ST_ADVISE AFTER app oks advise loop */%@AE@%%@NL@%
- goto Callback;%@NL@%
- %@NL@%
- case WM_DDE_UNADVISE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Terminate the advise now, but notify the server in callback so%@NL@%
- %@AB@% * messages don't get out of order.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (!DeleteAdvList(psi->ci.pAdviseList,%@NL@%
- GetHszItem(mp2, &psi->ci.cc, FALSE),%@NL@%
- PDDES->usFormat))%@NL@%
- psi->ci.fs &= ~ST_ADVISE;%@NL@%
- usType = XTYP_ADVSTOP;%@NL@%
- goto Callback;%@NL@%
- %@NL@%
- case WM_DDE_ACK:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This is an ack in response to the FACKREQ bit being set.%@NL@%
- %@AB@% * See if this refers to one of the advise loops.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((pAdviseItem = FindAdvList(psi->ci.pAdviseList,%@NL@%
- GetHszItem(mp2, &psi->ci.cc, FALSE),%@NL@%
- PDDES->usFormat)) &&%@NL@%
- (pAdviseItem->fsStatus & DDE_FACKREQ)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Update advise loop status - no longer waiting for an ack.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pAdviseItem->fsStatus &= ~ADVST_WAITING;%@NL@%
- if (pAdviseItem->fsStatus & ADVST_CHANGED) {%@NL@%
- pAdviseItem->fsStatus |= ADVST_POSTED; %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * The client is out of date. Send the data%@NL@%
- %@AB@% * again (simulate a post advise call).%@NL@%
- %@AB@% * Don't bother the server with ACK info.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MakeCallback(psi->ci.pai, (HCONV)hwnd, psi->ci.hszTopic,%@NL@%
- pAdviseItem->hszItem, %@NL@%
- pAdviseItem->usFmt, XTYP_ADVREQ, %@NL@%
- 0L, UMSR_POSTADVISE,%@NL@%
- pAdviseItem->fsStatus & ~DDE_FRESERVED,%@NL@%
- psi->ci.hwndPartner);%@NL@%
- FreeData((PMYDDES)mp2, psi->ci.pai);%@NL@%
- return(0);%@NL@%
- }%@NL@%
- }%@NL@%
- usType = XTYP_ACK;%@NL@%
- hDmgData = PDDES->fsStatus;%@NL@%
- %@NL@%
- Callback: %@NL@%
- MakeCallback(psi->ci.pai, (HCONV)hwnd, psi->ci.hszTopic,%@NL@%
- %@AI@%#if %@AE@%0 %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * hack for EXCEL which makes its items and data equal for%@NL@%
- %@AB@% * execute acks which SHOULD use NULL as the item name.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- (PDDES->offszItemName == PDDES->offabData) ?%@NL@%
- 0L :%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- GetHszItem((PMYDDES)mp2, &psi->ci.cc, TRUE),%@NL@%
- PDDES->usFormat, usType,%@NL@%
- hDmgData, msg, PDDES->fsStatus,%@NL@%
- psi->ci.hwndPartner);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * now free the incomming selector IF it wasn't passed on to%@NL@%
- %@AB@% * MakeCallback as hDmgData.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hDmgData != mp2)%@NL@%
- FreeData((PMYDDES)mp2, psi->ci.pai);%@NL@%
- break;%@NL@%
- %@NL@%
- case UMSR_POSTADVISE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This message came from DdePostAdvise()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Advise loops are tricky because of the desireable FACKREQ feature%@NL@%
- %@AB@% * of DDE. The advise loop list holds information in its fsStatus%@NL@%
- %@AB@% * field to maintain the state of the advise loop.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * if the ADVST_POSTED bit is set, it means that the server already%@NL@%
- %@AB@% * has an ADVREQ message in its callback queue. This prevents%@NL@%
- %@AB@% * unnecessary ADVREQ messages from getting thrown into the callback%@NL@%
- %@AB@% * queue.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * if the ADVST_WAITING bit is set, the server is still waiting for%@NL@%
- %@AB@% * the client to give it the go-ahead for more data with an%@NL@%
- %@AB@% * ACK message on this item. (FACKREQ is set) Without a go-ahead,%@NL@%
- %@AB@% * the server will not send any more advise data to the client but%@NL@%
- %@AB@% * will instead set the ADVST_CHANGED bit which will cause another%@NL@%
- %@AB@% * WM_DDE_DATA message to be sent to the client as soon as the%@NL@%
- %@AB@% * go-ahead ACK is received. This keeps the client up to date%@NL@%
- %@AB@% * but never overloads it.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if (!(psi->ci.fs & ST_ADVISE) ||%@NL@%
- !(pAdviseItem = FindAdvList(psi->ci.pAdviseList, (HSZ)mp1, 0)))%@NL@%
- break;%@NL@%
- %@NL@%
- do {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * for each format for this item that has an advise loop:%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pAdviseItem->fsStatus & ADVST_POSTED)%@NL@%
- continue;%@NL@%
- %@NL@%
- if ((pAdviseItem->fsStatus & DDE_FACKREQ) &&%@NL@%
- (pAdviseItem->fsStatus & ADVST_WAITING)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * if the client has not yet finished with the last data%@NL@%
- %@AB@% * we gave him, just update the advise loop status%@NL@%
- %@AB@% * instead of sending data now.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pAdviseItem->fsStatus |= ADVST_CHANGED;%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (pAdviseItem->fsStatus & DDE_FNODATA) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * In the nodata case, we don't bother the server. Just%@NL@%
- %@AB@% * pass the client an apropriate DATA message.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MyDdePostMsg(psi->ci.hwndPartner, hwnd, WM_DDE_DATA,%@NL@%
- (PMYDDES)AllocDDESel(pAdviseItem->fsStatus & ~(DDE_FNODATA | DDE_FACKREQ),%@NL@%
- pAdviseItem->usFmt, (HSZ)mp1, 0L, 0),%@NL@%
- psi->ci.pai, MDPM_FREEHDATA);%@NL@%
- continue;%@NL@%
- }%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Otherwise, lets get the data from the server.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pAdviseItem->fsStatus |= ADVST_POSTED;%@NL@%
- MakeCallback(psi->ci.pai, (HCONV)hwnd, psi->ci.hszTopic,%@NL@%
- (HSZ)mp1, pAdviseItem->usFmt, XTYP_ADVREQ,%@NL@%
- 0, UMSR_POSTADVISE,%@NL@%
- pAdviseItem->fsStatus & (DDE_FACKREQ | DDE_FNODATA),%@NL@%
- psi->ci.hwndPartner);%@NL@%
- } while (pAdviseItem = FindNextAdv(pAdviseItem, (HSZ)mp1));%@NL@%
- break;%@NL@%
- %@NL@%
- case UM_QUERY:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * LOUSHORT(mp1) = info index.%@NL@%
- %@AB@% * mp2 = pData. If pData==0, return data else copy into pData.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch (LOUSHORT(mp1)) {%@NL@%
- case Q_STATUS:%@NL@%
- mrData = (MRESULT)psi->ci.fs;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_CLIENT:%@NL@%
- mrData = FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_APPINFO:%@NL@%
- mrData = psi->ci.pai;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_APPNAME:%@NL@%
- mrData = psi->ci.hszServerApp;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_TOPIC:%@NL@%
- mrData = psi->ci.hszTopic;%@NL@%
- break;%@NL@%
- %@NL@%
- case Q_ALL:%@NL@%
- mrData = (MRESULT)(SERVERINFO FAR *)psi;%@NL@%
- break;%@NL@%
- }%@NL@%
- if (mp2 == 0)%@NL@%
- return(mrData);%@NL@%
- else%@NL@%
- *(MRESULT FAR *)mp2 = mrData;%@NL@%
- return(1);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- return(0);%@NL@%
- %@AI@%#undef %@AE@%PDDES %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This assumes hwnd is a DDE window. It tries to locate the proper%@NL@%
- %@AB@% * top-level frame window that this window is associated with useing%@NL@%
- %@AB@% * process and thread IDs.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- HWND FindFrame(%@NL@%
- HWND hwnd)%@NL@%
- {%@NL@%
- PID pid, pidFrame;%@NL@%
- TID tid, tidFrame;%@NL@%
- HWND hwndMaybe = NULL;%@NL@%
- HWND hwndBetter = NULL;%@NL@%
- HWND hwndFrame;%@NL@%
- HENUM hEnum;%@NL@%
- ULONG ul;%@NL@%
- %@NL@%
- WinQueryWindowProcess(hwnd, &pid, &tid);%@NL@%
- hEnum = WinBeginEnumWindows(HWND_DESKTOP);%@NL@%
- while (hwndFrame = WinGetNextWindow(hEnum)) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * for all top level windows ...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ul = (ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, 0L, 0L);%@NL@%
- if (FI_FRAME & ul) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * that are frames ...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- WinQueryWindowProcess(hwndFrame, &pidFrame, &tidFrame);%@NL@%
- if (pidFrame == pid) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * in this process - maybe - ...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndMaybe = hwndFrame;%@NL@%
- if (tidFrame == tid) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * in this thread - better - ...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndBetter = hwndFrame;%@NL@%
- if (WinQueryWindowPtr(hwndFrame, QWP_PFNWP) ==%@NL@%
- subframeWndProc) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * that are subclassed by us - certainly!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hwndBetter = hwndFrame;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- WinEndEnumWindows(hEnum);%@NL@%
- return(hwndBetter ? hwndBetter : hwndMaybe);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* This routine handles server message replys. This may have been called%@NL@%
- %@AB@%* immediately in the case of enabled callbacks, or may have been called%@NL@%
- %@AB@%* via DdeEnableCallback in which case the server action has been%@NL@%
- %@AB@%* delayed. QReply is responsible for freeing the pddes given as well as%@NL@%
- %@AB@%* the pcbi->hDmgData and pcbi->hszItem.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History:%@NL@%
- %@AB@%* Created 9/12/89 Sanfords%@NL@%
- %@AB@%* 6/12/90 sanfords Added checks for HDATA ownership.%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- void QReply(pcbi, pddes)%@NL@%
- PCBLI pcbi;%@NL@%
- PDDESTRUCT pddes; %@AB@%/* hDataRet */%@AE@%%@NL@%
- {%@NL@%
- PSERVERINFO psi;%@NL@%
- PADVLI pAdviseItem;%@NL@%
- USHORT fsStatus, msg;%@NL@%
- %@NL@%
- if ((pcbi->usType & XCLASS_MASK) == XCLASS_NOTIFICATION)%@NL@%
- return;%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- psi = WinSendMsg(pcbi->hConv, UM_QUERY, (MPARAM)Q_ALL, 0L);%@NL@%
- %@NL@%
- switch (pcbi->msg) {%@NL@%
- case UMSR_POSTADVISE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * The NODATA case never gets here.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((psi) &&%@NL@%
- (pAdviseItem = FindAdvList(psi->ci.pAdviseList, pcbi->hszItem,%@NL@%
- pcbi->usFmt))) {%@NL@%
- pAdviseItem->fsStatus &= ~ADVST_POSTED;%@NL@%
- if (pddes) {%@NL@%
- pAdviseItem->fsStatus &= ~ADVST_CHANGED;%@NL@%
- MyDdePostMsg(pcbi->hConvPartner, pcbi->hConv, WM_DDE_DATA,%@NL@%
- (PMYDDES)pddes, psi->ci.pai, MDPM_FREEHDATA);%@NL@%
- if (pAdviseItem->fsStatus & DDE_FACKREQ) %@NL@%
- pAdviseItem->fsStatus |= ADVST_WAITING;%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_REQUEST:%@NL@%
- if (pddes) {%@NL@%
- pddes->fsStatus = (pcbi->fsStatus & DDE_FACKREQ) | DDE_FRESPONSE;%@NL@%
- msg = WM_DDE_DATA;%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * send a -ACK%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pddes = AllocDDESel(((USHORT)pddes & DDE_FAPPSTATUS) |%@NL@%
- ((USHORT)pddes & DDE_FBUSY ? DDE_FBUSY : DDE_NOTPROCESSED),%@NL@%
- pcbi->usFmt, pcbi->hszItem, 0L, NULL);%@NL@%
- msg = WM_DDE_ACK;%@NL@%
- }%@NL@%
- MyDdePostMsg(pcbi->hConvPartner, pcbi->hConv, msg, (PMYDDES)pddes,%@NL@%
- psi->ci.pai, MDPM_FREEHDATA);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_POKE:%@NL@%
- case WM_DDE_EXECUTE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pddes is supposed to be the proper DDE_ constants to return.%@NL@%
- %@AB@% * we just stick them in the given pddes (hDmgData) and return%@NL@%
- %@AB@% * it as an ACK. This frees pcbi->hDmgData in the process.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ((PDDESTRUCT)pcbi->hDmgData)->fsStatus = %@NL@%
- (USHORT)pddes & ~DDE_FRESERVED;%@NL@%
- MyDdePostMsg(pcbi->hConvPartner, pcbi->hConv, WM_DDE_ACK,%@NL@%
- (PMYDDES)pcbi->hDmgData, psi->ci.pai, MDPM_FREEHDATA);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_ADVISE:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pddes is fStartAdvise%@NL@%
- %@AB@% * If DDE_FACK, we add the item to the advise loop%@NL@%
- %@AB@% * list and +ACK else we -ACK.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((BOOL)pddes) {%@NL@%
- psi = (PSERVERINFO)WinQueryWindowULong(pcbi->hConv, QWL_USER);%@NL@%
- if (AddAdvList(psi->ci.pAdviseList, pcbi->hszItem,%@NL@%
- pcbi->fsStatus & (DDE_FNODATA | DDE_FACKREQ),%@NL@%
- pcbi->usFmt) == NULL) {%@NL@%
- psi->ci.pai->LastError = DMGERR_MEMORY_ERROR;%@NL@%
- fsStatus = DDE_NOTPROCESSED;%@NL@%
- } else {%@NL@%
- psi->ci.fs |= ST_ADVISE;%@NL@%
- fsStatus = DDE_FACK;%@NL@%
- }%@NL@%
- } else {%@NL@%
- fsStatus = DDE_NOTPROCESSED;%@NL@%
- }%@NL@%
- goto AckBack;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_UNADVISE:%@NL@%
- fsStatus = DDE_FACK;%@NL@%
- goto AckBack;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_DATA:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * must be an advise data item for the CLIENT or maybe some requested%@NL@%
- %@AB@% * data mistakenly sent here due to the client queue being flushed.%@NL@%
- %@AB@% * pddes is fsStatus.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * send an ack back if requested.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pcbi->fsStatus & DDE_FACKREQ) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Clean up the status incase the app is messed up.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fsStatus = (USHORT)pddes & ~DDE_FRESERVED;%@NL@%
- if (fsStatus & (DDE_NOTPROCESSED | DDE_FBUSY))%@NL@%
- fsStatus &= ~DDE_FACK;%@NL@%
- AckBack:%@NL@%
- MyDdePostMsg(pcbi->hConvPartner, pcbi->hConv, WM_DDE_ACK,%@NL@%
- (PMYDDES)AllocDDESel(fsStatus, pcbi->usFmt, pcbi->hszItem, 0L, 0),%@NL@%
- psi->ci.pai, MDPM_FREEHDATA);%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ----------------FRAME SECTION------------------%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * A frame window exists on behalf of every registered thread. It%@NL@%
- %@AB@% * handles conversation initiation and therefore issues callbacks%@NL@%
- %@AB@% * to the server app as needed to notify or query the server app.%@NL@%
- %@AB@% * The callback queue is always bypassed for these synchronous%@NL@%
- %@AB@% * events.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/***************************** Private Function ****************************\%@NL@%
- %@AB@%* MRESULT EXPENTRY subframeWndProc(hwnd, msg, mp1, mp2)%@NL@%
- %@AB@%* HWND hwnd;%@NL@%
- %@AB@%* USHORT msg;%@NL@%
- %@AB@%* MPARAM mp1;%@NL@%
- %@AB@%* MPARAM mp2;%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* This routine takes care of setting up server windows as needed to respond%@NL@%
- %@AB@%* to incomming WM_DDE_INTIIATE messages. It is subclassed from the top%@NL@%
- %@AB@%* level frame of the server application.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* History: created 12/20/88 sanfords%@NL@%
- %@AB@%\***************************************************************************/%@AE@%%@NL@%
- MRESULT EXPENTRY subframeWndProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- PAPPINFO pai;%@NL@%
- %@NL@%
- pai = GetCurrentAppInfo(FALSE);%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case UM_REGISTER:%@NL@%
- case UM_UNREGISTER:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * we pass notification messages through this proc so we can make the%@NL@%
- %@AB@% * xfer call within the correct thread's context.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MakeCallback(pai, (HCONV)0, (HSZ)0, (HSZ)mp1, 0,%@NL@%
- msg == UM_REGISTER ? XTYP_REGISTER : XTYP_UNREGISTER,%@NL@%
- (HDMGDATA)mp2, msg, 0, 0L);%@NL@%
- return(0);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_DDE_INITIATE:%@NL@%
- FrameInitConv((HWND)mp1, (PDDEINIT)mp2);%@NL@%
- FreeData((PMYDDES)mp2, pai);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return((*lpfnFrameWndProc)(hwnd, msg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- void FrameInitConv(hwndClient, pddei)%@NL@%
- HWND hwndClient;%@NL@%
- PDDEINIT pddei;%@NL@%
- {%@NL@%
- PAPPINFO pai, paiClient;%@NL@%
- INITINFO ii;%@NL@%
- HSZPAIR hp[2];%@NL@%
- PHSZPAIR php;%@NL@%
- HSZ hsz = 0;%@NL@%
- HDMGDATA hDataCC;%@NL@%
- PDDESTRUCT pddes;%@NL@%
- HWND hwndServer;%@NL@%
- CONVCONTEXT cc;%@NL@%
- BOOL fWild;%@NL@%
- %@NL@%
- if (!CheckSel(SELECTOROF(pddei))) {%@NL@%
- AssertF(FALSE, "Invalid DDEINIT selector");%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- %@NL@%
- pai = GetCurrentAppInfo(FALSE);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If we are filtering and no app names are registered, quit.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((pai->afCmd & DMGCMD_FILTERINITS) &&%@NL@%
- QPileItemCount(pai->pAppNamePile) == 0) %@NL@%
- return;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * filter out inits from ourselves and other agents (if we are an agent)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (WinQueryWindowPtr(hwndClient, QWP_PFNWP) == ClientWndProc) {%@NL@%
- paiClient = WinSendMsg(hwndClient, UM_QUERY, (MPARAM)Q_APPINFO, 0L);%@NL@%
- if (paiClient == pai)%@NL@%
- return;%@NL@%
- %@NL@%
- if ((pai->afCmd & DMGCMD_AGENT) && (paiClient->afCmd & DMGCMD_AGENT)) %@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * make sure ii.pCC is set up right.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pddei->cb >= sizeof(DDEINIT) && pddei->offConvContext) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * new dde init structure!%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ii.pCC = DDEI_PCONVCONTEXT(pddei);%@NL@%
- } else {%@NL@%
- ii.pCC = &cc;%@NL@%
- cc.cb = sizeof(CONVCONTEXT);%@NL@%
- cc.idCountry = syscc.country;%@NL@%
- cc.usCodepage = syscc.codepage;%@NL@%
- cc.fsContext = 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- hp[0].hszApp = GetHsz(PSZAPP(pddei), ii.pCC->idCountry,%@NL@%
- ii.pCC->usCodepage, TRUE);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * filter out unwanted app names.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hp[0].hszApp && (pai->afCmd & DMGCMD_FILTERINITS) &&%@NL@%
- !FindPileItem(pai->pAppNamePile, CmppHsz, (PBYTE)&hp[0].hszApp, 0)) {%@NL@%
- FreeHsz(hp[0].hszApp);%@NL@%
- return; %@NL@%
- }%@NL@%
- %@NL@%
- hp[0].hszTopic = GetHsz(PSZTOPIC(pddei), ii.pCC->idCountry,%@NL@%
- ii.pCC->usCodepage, TRUE);%@NL@%
- %@NL@%
- hp[1].hszApp = hp[1].hszTopic = 0L;%@NL@%
- %@NL@%
- fWild = (hp[0].hszApp == 0L || hp[0].hszTopic == 0);%@NL@%
- %@NL@%
- hDataCC = PutData((PBYTE)ii.pCC, (ULONG)sizeof(CONVCONTEXT), 0L, (HSZ)NULL,%@NL@%
- 0, 0, pai);%@NL@%
- %@NL@%
- if (hDataCC == NULL)%@NL@%
- goto CheckOut;%@NL@%
- %@NL@%
- pddes = (PDDESTRUCT)DoCallback(pai, NULL, hp[0].hszTopic,%@NL@%
- hp[0].hszApp, 0, (fWild ? XTYP_WILDINIT : XTYP_INIT),%@NL@%
- hDataCC);%@NL@%
- %@NL@%
- if (pddes == NULL)%@NL@%
- goto CheckOut;%@NL@%
- %@NL@%
- FindPileItem(pai->pHDataPile, CmpULONG, (PBYTE)&hDataCC, FPI_DELETE);%@NL@%
- DosFreeSeg(SELECTOROF(hDataCC));%@NL@%
- %@NL@%
- if (fWild) {%@NL@%
- php = (PHSZPAIR)DDES_PABDATA(pddes);%@NL@%
- } else {%@NL@%
- php = &hp[0];%@NL@%
- pddes = NULL;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * now php points to a 0 terminated list of hszpairs to respond to.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SemEnter();%@NL@%
- while (QuerylatomLength((LATOM)php->hszApp) &&%@NL@%
- QuerylatomLength((LATOM)php->hszTopic)) {%@NL@%
- SemLeave();%@NL@%
- if ((hwndServer = CreateServerWindow(pai, php->hszTopic)) == 0)%@NL@%
- break;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * have the server respond%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ii.hszAppName = php->hszApp;%@NL@%
- ii.hszTopic = php->hszTopic;%@NL@%
- WinSendMsg(hwndServer, UMSR_INITIATE, (MPARAM)&ii, hwndClient);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * confirm initialization to server app%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DoCallback(pai, (HCONV)hwndServer, php->hszTopic, php->hszApp,%@NL@%
- 0, XTYP_INIT_CONFIRM, 0L);%@NL@%
- %@NL@%
- php++;%@NL@%
- SemEnter();%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- SemCheckOut();%@NL@%
- CheckOut: %@NL@%
- FreeHsz(hp[0].hszApp);%@NL@%
- FreeHsz(hp[0].hszTopic);%@NL@%
- if (fWild)%@NL@%
- FreeData((PMYDDES)pddes, pai);%@NL@%
- }%@NL@%
- %@NL@%
- HWND CreateServerWindow(%@NL@%
- PAPPINFO pai,%@NL@%
- HSZ hszTopic)%@NL@%
- {%@NL@%
- HWND hwndTSvr, hwndServer;%@NL@%
- %@NL@%
- SemCheckOut();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * locate or make a Topic server window...%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((hwndTSvr =%@NL@%
- HwndFromHsz(hszTopic, pai->pSvrTopicList)) == 0) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * NO - make one.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((hwndTSvr = WinCreateWindow(pai->hwndDmg, SZDEFCLASS, "", 0L,%@NL@%
- 0, 0, 0, 0, (HWND)NULL, HWND_BOTTOM, WID_SVRTOPIC,%@NL@%
- 0L, 0L)) == 0L) {%@NL@%
- pai->LastError = DMGERR_PMWIN_ERROR;%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- AddHwndHszList(hszTopic, hwndTSvr, pai->pSvrTopicList);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Create the server window%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if ((hwndServer = WinCreateWindow(hwndTSvr, SZSERVERCLASS, "", 0L,%@NL@%
- 0, 0, 0, 0, (HWND)NULL, HWND_BOTTOM, WID_SERVER, 0L, 0L)) == 0L) {%@NL@%
- pai->LastError = DMGERR_PMWIN_ERROR;%@NL@%
- return(NULL);%@NL@%
- }%@NL@%
- return(hwndServer);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * main application window - parent of all others in app.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * 6/12/90 sanfords Fixed semaphore bug%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MRESULT EXPENTRY DmgWndProc(hwnd, msg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- %@AI@%#define %@AE@%pai ((PAPPINFO)mp1) %@NL@%
- PCBLI pli, pliNext;%@NL@%
- BOOL fException;%@NL@%
- HDMGDATA hDataRet;%@NL@%
- %@NL@%
- hwnd;%@NL@%
- mp2;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- case UM_CHECKCBQ:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * We consider everything to be blocked if we are in a client%@NL@%
- %@AB@% * transfer modal loop. This prevents recursive timeout%@NL@%
- %@AB@% * calls.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (pai->hwndTimer)%@NL@%
- return(0);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * This is where we actually do callbacks. We do them via this%@NL@%
- %@AB@% * window proc so that we can asynchronously institute callbacks%@NL@%
- %@AB@% * via a PostMsg().%@NL@%
- %@AB@% */%@AE@%%@NL@%
- SemCheckOut();%@NL@%
- SemEnter();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * process all enabled conversation callbacks.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (pli = (PCBLI)pai->plstCB->pItemFirst; pli; pli = (PCBLI)pliNext) {%@NL@%
- pliNext = (PCBLI)pli->next;%@NL@%
- fException = FindLstItem(pai->plstCBExceptions, CmpULONG, (PLITEM)pli)%@NL@%
- == NULL ? FALSE : TRUE;%@NL@%
- if (fException == pai->fEnableCB)%@NL@%
- continue; %@AB@%/* blocked */%@AE@%%@NL@%
- %@NL@%
- pai->cInCallback++;%@NL@%
- SemLeave();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * make the actual callback here.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- hDataRet = DoCallback(pai, pli->hConv, pli->hszTopic,%@NL@%
- pli->hszItem, pli->usFmt, pli->usType, pli->hDmgData);%@NL@%
- SemEnter();%@NL@%
- if (pai->cInCallback > 0) %@AB@%/* test incase exlst processing messed it up */%@AE@%%@NL@%
- pai->cInCallback--;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * If the callback resulted in a BLOCK, disable this conversation.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (hDataRet == CBR_BLOCK && !(pli->usType & XTYPF_NOBLOCK)) {%@NL@%
- SemLeave();%@NL@%
- DdeEnableCallback(pli->hConv, FALSE);%@NL@%
- SemEnter();%@NL@%
- continue;%@NL@%
- } else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * otherwise finish processing the callback.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (WinIsWindow(DMGHAB, pli->hConvPartner)) {%@NL@%
- SemLeave();%@NL@%
- QReply(pli, (PDDESTRUCT)hDataRet);%@NL@%
- SemEnter();%@NL@%
- }%@NL@%
- RemoveLstItem(pai->plstCB, (PLITEM)pli);%@NL@%
- }%@NL@%
- }%@NL@%
- SemLeave();%@NL@%
- return(0);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- WinDefWindowProc(hwnd, msg, mp1, mp2);%@NL@%
- break;%@NL@%
- }%@NL@%
- %@AI@%#undef %@AE@%pai %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- HDMGDATA DoCallback(%@NL@%
- PAPPINFO pai,%@NL@%
- HCONV hConv,%@NL@%
- HSZ hszTopic,%@NL@%
- HSZ hszItem,%@NL@%
- USHORT usFmt,%@NL@%
- USHORT usType,%@NL@%
- HDMGDATA hDmgData)%@NL@%
- {%@NL@%
- HDMGDATA hDataRet;%@NL@%
- %@NL@%
- AssertF(IncHszCount(hszTopic) && FreeHsz(hszTopic), "Bad hszTopic on callback");%@NL@%
- AssertF(IncHszCount(hszItem) && FreeHsz(hszItem), "Bad hszItem on callback");%@NL@%
- %@NL@%
- if (usType & XCLASS_DATAIN) {%@NL@%
- AssertF(CheckSel(SELECTOROF(hDmgData)), "invalid callback data handle");%@NL@%
- ((PMYDDES)hDmgData)->fs |= HDATA_READONLY;%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#ifdef %@AE@%CRUISER %@NL@%
- if (pai->afCmd & DMGCMD_32BIT)%@NL@%
- hDataRet = ThkCallback(hConv, hszTopic, hszItem, usFmt, usType, hDmgData,%@NL@%
- pai->pfnCallback);%@NL@%
- else%@NL@%
- %@AI@%#endif %@AE@% %@NL@%
- hDataRet = (*pai->pfnCallback)(hConv, hszTopic, hszItem, usFmt, usType,%@NL@%
- hDmgData);%@NL@%
- %@NL@%
- if (usType & XCLASS_DATA && CheckSel(SELECTOROF(hDataRet)) > sizeof(MYDDES) &&%@NL@%
- ((PMYDDES)hDataRet)->magic == MYDDESMAGIC) {%@NL@%
- if (((PMYDDES)hDataRet)->pai != pai) {%@NL@%
- AssertF(FALSE, "hData from callback not created by same thread");%@NL@%
- pai->LastError = DMGERR_DLL_USAGE;%@NL@%
- hDataRet = NULL;%@NL@%
- }%@NL@%
- }%@NL@%
- return(hDataRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\STOCK\EA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*** ea.c - layer for EA support%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Author:%@NL@%
- %@AB@% * Benjamin W. Slivka%@NL@%
- %@AB@% * (c) 1990%@NL@%
- %@AB@% * Microsoft Corporation%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * History:%@NL@%
- %@AB@% * 08-Feb-1990 bens Initial version (Subset from EA.EXE sources)%@NL@%
- %@AB@% * 02-May-1990 bens Added SetEAValue (copied from ea.exe)%@NL@%
- %@AB@% * 01-Jun-1990 bens Support binary EAs%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_DOSERRORS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSFILEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_NOPM %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"ea.h" %@NL@%
- %@AI@%#include %@AE@%"mem.h" %@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#ifdef %@AE@%CHECKASSERTS %@NL@%
- %@AI@%#define %@AE@%dbg(a) a %@NL@%
- %@AI@%#else %@AE@%%@NL@%
- %@AI@%#define %@AE@%dbg(a) %@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- // Buffer sizes for EA API calls%@NL@%
- %@AI@%#define %@AE@%CB_GEAL 400 // Enough for one GEA in list %@NL@%
- %@AI@%#define %@AE@%CB_FEAL 2000 // Enough for large file list %@NL@%
- %@NL@%
- %@NL@%
- char * TranslateValue(char *pbValue,USHORT cbValue,USHORT *pcbValue);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*** EAQueryValue - Get text EA value from file%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Entry%@NL@%
- %@AB@% * pszFile - File path%@NL@%
- %@AB@% * pszName - EA name%@NL@%
- %@AB@% * pcbValue - USHORT to receive value length%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Exit-Success%@NL@%
- %@AB@% * returns non-zero pointer to value; Caller must free this!%@NL@%
- %@AB@% * If value is ASCII%@NL@%
- %@AB@% * *pcbValue == 0;%@NL@%
- %@AB@% * If value is BINARY%@NL@%
- %@AB@% * *pcbValue == length of value;%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Exit-Failure%@NL@%
- %@AB@% * returns NULL%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *EAQueryValue(char *pszFile,char *pszName,USHORT *pcbValue)%@NL@%
- {%@NL@%
- USHORT cb;%@NL@%
- EAOP eaop;%@NL@%
- FEA * pfea;%@NL@%
- FEA * pfeaEnd;%@NL@%
- FEALIST * pFEAList;%@NL@%
- GEA * pgea;%@NL@%
- GEALIST * pGEAList;%@NL@%
- char * psz;%@NL@%
- char * pszValue;%@NL@%
- USHORT rc;%@NL@%
- %@NL@%
- //%@NL@%
- // Alloc GEAList and FEAList%@NL@%
- //%@NL@%
- pGEAList = MemAlloc(CB_GEAL);%@NL@%
- if (pGEAList == NULL) {%@NL@%
- return NULL;%@NL@%
- }%@NL@%
- %@NL@%
- pFEAList = MemAlloc(CB_FEAL);%@NL@%
- if (pFEAList == NULL) {%@NL@%
- MemFree(pGEAList);%@NL@%
- return NULL;%@NL@%
- }%@NL@%
- %@NL@%
- // Build GEA List with one GEA%@NL@%
- %@NL@%
- pgea = pGEAList->list; // Point at first GEA%@NL@%
- cb = strlen(pszName);%@NL@%
- pgea->cbName = (UCHAR)cb; // Set length%@NL@%
- memcpy(pgea->szName,pszName,cb+1); // Copy name and NUL%@NL@%
- pgea = (GEA *)((char *)pgea + cb + sizeof(GEA));%@NL@%
- pGEAList->cbList = (char *)pgea - (char *)pGEAList; // Set buffer size%@NL@%
- %@NL@%
- // Get attribute value%@NL@%
- %@NL@%
- pFEAList->cbList = CB_FEAL; // Set size of FEA list%@NL@%
- eaop.fpGEAList = pGEAList;%@NL@%
- eaop.fpFEAList = pFEAList;%@NL@%
- %@NL@%
- rc = DosQPathInfo(pszFile, // File path%@NL@%
- FIL_QUERYEASFROMLIST, // info level%@NL@%
- (PBYTE)&eaop, // EAOP structure%@NL@%
- sizeof(eaop), // Size of EAOP%@NL@%
- 0L); // Reserved%@NL@%
- pfea = (FEA *)pFEAList->list; // Point at FEA%@NL@%
- %@NL@%
- // NOTE: DosQPathInfo only fails if there is an inconsistency in%@NL@%
- // one of its parameters. It DOES NOT fail if the EA is%@NL@%
- // not present. Rather, on a file system that does not%@NL@%
- // support EAs, it appears to return pFEAList->cbList ==%@NL@%
- // sizeof(pFEAList->cbList), indicating no FEAs are present.%@NL@%
- // If the file system *does* support EAs, but the particular%@NL@%
- // EA is not present, pFEA->cbValue == 0.%@NL@%
- %@NL@%
- if ((rc == 0) && // Call succeeded,...%@NL@%
- ((pFEAList->cbList) > sizeof(pFEAList->cbList)) && // FEA is there,...%@NL@%
- (pfea->cbValue > 0)) { // and file has EA value!%@NL@%
- // Parse EA value%@NL@%
- cb = pfea->cbName;%@NL@%
- psz = (char *)pfea + sizeof(FEA); // Point at name%@NL@%
- pszValue = psz + cb + 1; // Point at value%@NL@%
- psz = TranslateValue(pszValue,pfea->cbValue,pcbValue);%@NL@%
- }%@NL@%
- else%@NL@%
- psz = NULL; // EA not present, or too big%@NL@%
- %@NL@%
- MemFree(pFEAList);%@NL@%
- MemFree(pGEAList);%@NL@%
- return psz;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*** TranslateValue - produce printable representation of EA value%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Entry%@NL@%
- %@AB@% * pbValue - Value buffer%@NL@%
- %@AB@% * cbValue - Length of value buffer%@NL@%
- %@AB@% * pcbValue - USHORT to receive actual value length%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Exit-Success%@NL@%
- %@AB@% * Returns non-zero pointer to value; caller MUST free!%@NL@%
- %@AB@% * If value is ASCII%@NL@%
- %@AB@% * *pcbValue == 0;%@NL@%
- %@AB@% * If value is BINARY%@NL@%
- %@AB@% * *pcbValue == length of value;%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Exit-Failure%@NL@%
- %@AB@% * Returns NULL%@NL@%
- %@AB@% *%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * EAT_MVMT - Multi-value, Multi-type%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * +------+----------+-------+------+--------+-------+---+---+---+---+%@NL@%
- %@AB@% * | Type | Codepage | Count | Type | Length | Value |...| T | L | V |%@NL@%
- %@AB@% * +------+----------+-------+------+--------+-------+---+---+---+---+%@NL@%
- %@AB@% * us us us us us ?%@NL@%
- %@AB@% * \________________________/ \_____________________/ \_________/%@NL@%
- %@AB@% * MVMT header Value 1 Value N%@NL@%
- %@AB@% *%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char * TranslateValue(char *pbValue,USHORT cbValue,USHORT *pcbValue)%@NL@%
- {%@NL@%
- USHORT cb=cbValue;%@NL@%
- USHORT codePage;%@NL@%
- USHORT cValue;%@NL@%
- char * pbDst;%@NL@%
- char * pbSrc;%@NL@%
- char * pszNew;%@NL@%
- USHORT type;%@NL@%
- %@NL@%
- // Parse MVMT header, if present%@NL@%
- %@NL@%
- pbSrc = pbValue;%@NL@%
- %@NL@%
- type = *(USHORT *)pbSrc; // Get EA value type%@NL@%
- if (type == EAT_MVMT) {%@NL@%
- pbSrc += sizeof(USHORT); // Skip type%@NL@%
- codePage = *((USHORT*)pbSrc)++; // Get code page%@NL@%
- cValue = *((USHORT*)pbSrc)++; // Get count of values%@NL@%
- if (cValue != 1) // Not exactly one value%@NL@%
- return NULL; // Fail%@NL@%
- type = *(USHORT *)pbSrc; // Get EA value type%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- // Parse value%@NL@%
- %@NL@%
- if ( (type == EAT_ASCII) || (type == EAT_BINARY) ) {%@NL@%
- pbSrc += sizeof(USHORT); // Skip type%@NL@%
- cb = *((USHORT *)pbSrc)++; // Get data length%@NL@%
- %@NL@%
- // Allocate buffer for data%@NL@%
- %@NL@%
- pszNew = MemAlloc(cb+1); // Leave room for NUL, in ASCII case%@NL@%
- if (pszNew == NULL)%@NL@%
- return NULL;%@NL@%
- pbDst = pszNew;%@NL@%
- %@NL@%
- // Copy data%@NL@%
- %@NL@%
- memcpy(pbDst,pbSrc,cb); // Copy value%@NL@%
- pbDst += cb; // Advance destination pointer%@NL@%
- %@NL@%
- if (type == EAT_ASCII) {%@NL@%
- *pbDst++ = '\0'; // Terminate ASCIIZ string%@NL@%
- *pcbValue = 0; // Indicate value is ASCIIZ%@NL@%
- }%@NL@%
- else%@NL@%
- *pcbValue = cb; // Indicate value is binary%@NL@%
- return pszNew; // Return value%@NL@%
- }%@NL@%
- else%@NL@%
- return NULL; // Fail%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*** EASetValue - Create/Change/Delete an EA%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Entry%@NL@%
- %@AB@% * pszFile - file path%@NL@%
- %@AB@% * pszName - EA name%@NL@%
- %@AB@% * cbValue - EA length; 0 => pszValue is ASCIIZ%@NL@%
- %@AB@% * pszValue - EA value; NULL to delete EA%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Exit-Success%@NL@%
- %@AB@% * returns TRUE%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Exit-Failure%@NL@%
- %@AB@% * returns FALSE%@NL@%
- %@AB@% *%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL EASetValue(char *pszFile,char *pszName,USHORT cbValue,char *pszValue)%@NL@%
- {%@NL@%
- USHORT cbName;%@NL@%
- EAOP eaop;%@NL@%
- FEA * pfea;%@NL@%
- FEALIST * pFEAList;%@NL@%
- char * psz;%@NL@%
- USHORT rc;%@NL@%
- USHORT type;%@NL@%
- %@NL@%
- // Determine operation%@NL@%
- %@NL@%
- if (pszValue == NULL) { // Delete this EA%@NL@%
- type = EAT_ASCII;%@NL@%
- cbValue = 0;%@NL@%
- }%@NL@%
- else if (cbValue == 0) { // Create/Change value%@NL@%
- type = EAT_ASCII;%@NL@%
- cbValue = strlen(pszValue); // Compute length (do not count NUL!)%@NL@%
- }%@NL@%
- else { // Create/Change Binary value%@NL@%
- type = EAT_BINARY;%@NL@%
- }%@NL@%
- %@NL@%
- //%@NL@%
- // Alloc FEA List%@NL@%
- //%@NL@%
- pFEAList = MemAlloc(CB_FEAL);%@NL@%
- if (pFEAList == NULL)%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- cbName = strlen(pszName);%@NL@%
- %@NL@%
- //%@NL@%
- // Build EA structure%@NL@%
- //%@NL@%
- pfea = (FEA *)pFEAList->list; // Point at first FEA%@NL@%
- pfea->fEA = 0; // No flag settings%@NL@%
- pfea->cbName = (UCHAR)cbName; // Set name length%@NL@%
- pfea->cbValue = cbValue; // Set value length%@NL@%
- %@NL@%
- psz = (char *)pfea + sizeof(FEA); // Point at location for name%@NL@%
- memcpy(psz,pszName,cbName+1); // Copy Name *and* NUL%@NL@%
- psz += cbName+1; // Point at location for value%@NL@%
- if (cbValue > 0) { // Edit/Create EA%@NL@%
- *((USHORT *)psz)++ = EAT_MVMT; // Set MVMT type (to record code page!)%@NL@%
- *((USHORT *)psz)++ = NULL; // Set codepage%@NL@%
- *((USHORT *)psz)++ = 1; // Only one TLV record%@NL@%
- *((USHORT *)psz)++ = type; // Set EA type%@NL@%
- *((USHORT *)psz)++ = cbValue; // Set ASCII length%@NL@%
- %@NL@%
- pfea->cbValue += 5*sizeof(USHORT); // MVMT header and type and length%@NL@%
- memcpy(psz,pszValue,cbValue); // Copy Value%@NL@%
- }%@NL@%
- pfea = (FEA *)(psz + cbValue); // Point at byte after FEA%@NL@%
- %@NL@%
- //%@NL@%
- // Set size of FEA List (only one FEA)%@NL@%
- //%@NL@%
- %@NL@%
- pFEAList->cbList = (char *)pfea - (char *)pFEAList;%@NL@%
- %@NL@%
- eaop.fpGEAList = NULL;%@NL@%
- eaop.fpFEAList = pFEAList;%@NL@%
- %@NL@%
- rc = DosSetPathInfo(pszFile, // File path%@NL@%
- FIL_QUERYEASIZE, // Set EA%@NL@%
- (PBYTE)&eaop, // EAOP structure%@NL@%
- sizeof(eaop), // Size of EAOP%@NL@%
- 0, // Options%@NL@%
- 0L); // Reserved%@NL@%
- MemFree(pFEAList);%@NL@%
- return (rc == 0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EDPLINE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\EDPLINE\EDPLINE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% edpline.c -- polyline editor, for practice in mouse handling%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_DOSMEMMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINSWITCHLIST %@NL@%
- %@AI@%#define %@AE@%INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIPRIMITIVES %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@% INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@% INCL_WINFRAMEMGR %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"edpline.h" %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% abs(x) (((x) > 0) ? (x) : -(x)) %@NL@%
- %@AI@%#define %@AE@%PRIM_POLYLINE 0x0001 %@NL@%
- %@AI@%#define %@AE@%PRIM_POLYFILLET 0x0002 %@NL@%
- %@AI@%#define %@AE@%PRIM_POLYSPLINE 0x0004 %@NL@%
- %@AI@%#define %@AE@%PRIM_POINTARC 0x0008 %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Function declarations%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Private functions */%@AE@%%@NL@%
- %@NL@%
- VOID cdecl main(VOID);%@NL@%
- BOOL InitGlobals(VOID);%@NL@%
- BOOL InitApp(VOID);%@NL@%
- VOID Close(HWND);%@NL@%
- VOID Command(HWND, USHORT);%@NL@%
- VOID Paint(HPS, BOOL);%@NL@%
- VOID MouseMove(HWND, MPARAM);%@NL@%
- VOID ButtonUp(HWND, USHORT);%@NL@%
- VOID ButtonDown(HWND, USHORT, MPARAM);%@NL@%
- USHORT IsPtInList(PPOINTL);%@NL@%
- USHORT AddPtToList(PPOINTL);%@NL@%
- BOOL IsPtCloseToLine(PPOINTL, PPOINTL, PPOINTL);%@NL@%
- VOID DrawPrimitive(HPS, USHORT);%@NL@%
- VOID DrawPolyLine(HPS);%@NL@%
- VOID DrawPolyFillet(HPS);%@NL@%
- VOID DrawPolySpline(HPS);%@NL@%
- VOID DrawPointArc(HPS);%@NL@%
- VOID DrawControlPoints(HPS, LONG, PPOINTL);%@NL@%
- VOID MyMessageBox(HWND, PSZ);%@NL@%
- VOID SwapLong(PLONG, PLONG);%@NL@%
- %@NL@%
- %@AB@%/* Exported functions */%@AE@%%@NL@%
- %@NL@%
- ULONG EXPENTRY WndProc(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT EXPENTRY AboutDlgProc(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Global Variables%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- typedef struct%@NL@%
- {%@NL@%
- HAB hab;%@NL@%
- HMQ hMsgQ;%@NL@%
- HWND hwndFrame;%@NL@%
- HWND hwnd;%@NL@%
- %@NL@%
- ULONG flPrim;%@NL@%
- BOOL fDisplayControlPoints;%@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl;%@NL@%
- %@NL@%
- USHORT usPtGrabbed;%@NL@%
- BOOL fDragging;%@NL@%
- %@NL@%
- ULONG ulHitPrecision;%@NL@%
- %@NL@%
- } GLOBALDATA;%@NL@%
- GLOBALDATA global;%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* main%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WinInitialize resizes our ring 2 stack, among other things, so%@NL@%
- %@AB@%* we won't GP fault trying to do graphics. WinCreateMsgQueue defines%@NL@%
- %@AB@%* us as a REAL PM app. (as well as the WINDOWAPI statement in the .DEF%@NL@%
- %@AB@%* file...) Call a sub to register our window class and create a window.%@NL@%
- %@AB@%* Loop over messages. Exit cleanly.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl%@NL@%
- main()%@NL@%
- {%@NL@%
- QMSG qMsg;%@NL@%
- int iRet = 0;%@NL@%
- %@NL@%
- %@NL@%
- global.hab = WinInitialize(0);%@NL@%
- global.hMsgQ = WinCreateMsgQueue(global.hab, 0);%@NL@%
- %@NL@%
- if (InitApp())%@NL@%
- while (WinGetMsg( global.hab, (PQMSG)&qMsg, (HWND)NULL, 0, 0 ))%@NL@%
- WinDispatchMsg( global.hab, (PQMSG)&qMsg );%@NL@%
- else%@NL@%
- iRet = -1;%@NL@%
- %@NL@%
- WinDestroyWindow( global.hwndFrame );%@NL@%
- WinDestroyMsgQueue( global.hMsgQ );%@NL@%
- WinTerminate( global.hab );%@NL@%
- DosExit(EXIT_PROCESS, iRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* InitGlobals%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Initialize global variables.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL%@NL@%
- InitGlobals()%@NL@%
- {%@NL@%
- global.flPrim = PRIM_POLYLINE;%@NL@%
- global.fDisplayControlPoints = TRUE;%@NL@%
- %@NL@%
- global.cptl = 0L;%@NL@%
- global.pptl = NULL;%@NL@%
- if (DosAllocSeg(CPTLMAX * sizeof(POINTL),%@NL@%
- ((PUSHORT)&global.pptl)+1, 0))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- global.usPtGrabbed = -1;%@NL@%
- global.fDragging = FALSE;%@NL@%
- global.ulHitPrecision = 0L;%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* InitApp%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Register application window class and creates standard window.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INIT_MENU_ITEM(val, var) \ %@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, (val), (var))%@NL@%
- %@NL@%
- BOOL%@NL@%
- InitApp()%@NL@%
- {%@NL@%
- char szTitle[24];%@NL@%
- ULONG ctldata;%@NL@%
- PID pid;%@NL@%
- TID tid;%@NL@%
- HSWITCH hsw;%@NL@%
- static SWCNTRL swctl = { 0, 0, 0, 0, 0, SWL_VISIBLE,%@NL@%
- SWL_JUMPABLE, "Edit Polyline", 0 };%@NL@%
- %@NL@%
- if (!InitGlobals())%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Register Application Window Class */%@AE@%%@NL@%
- %@NL@%
- WinLoadString( global.hab, (HMODULE) NULL, IDS_TITLE, sizeof(szTitle), (PCH)szTitle );%@NL@%
- if ( !WinRegisterClass( global.hab, (PCH)szTitle, (PFNWP)WndProc,%@NL@%
- CS_SIZEREDRAW, 0 ))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Create a window instance of class "PolyLine Editor" */%@AE@%%@NL@%
- %@NL@%
- ctldata = FCF_STANDARD &%@NL@%
- ~(ULONG)(FCF_ICON | FCF_ACCELTABLE | FCF_TASKLIST);%@NL@%
- %@NL@%
- if (global.hwndFrame = WinCreateStdWindow(%@NL@%
- HWND_DESKTOP, %@AB@%/* specify desktop as parent window */%@AE@%%@NL@%
- WS_VISIBLE, %@AB@%/* window styles */%@AE@%%@NL@%
- &ctldata, %@AB@%/* frame creation flags */%@AE@%%@NL@%
- (PCH)szTitle, %@AB@%/* window class name */%@AE@%%@NL@%
- (PCH)szTitle, %@AB@%/* name appearing in window caption */%@AE@%%@NL@%
- 0L, %@AB@%/* */%@AE@%%@NL@%
- (HMODULE)NULL, %@AB@%/* use current executable module id */%@AE@%%@NL@%
- IDR_EDPLINE, %@AB@%/* menu id */%@AE@%%@NL@%
- (HWND FAR *)&global.hwnd %@AB@%/* window handle */%@AE@%%@NL@%
- ))%@NL@%
- {%@NL@%
- INIT_MENU_ITEM(IDM_CTLPOINTS, global.fDisplayControlPoints);%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYLINE)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POLYLINE);%@NL@%
- if (global.flPrim & PRIM_POLYFILLET)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POLYFILLET);%@NL@%
- if (global.flPrim & PRIM_POLYSPLINE)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POLYSPLINE);%@NL@%
- if (global.flPrim & PRIM_POINTARC)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POINTARC);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Add ourselves to the switch list. */%@AE@%%@NL@%
- %@NL@%
- WinQueryWindowProcess(global.hwndFrame, &pid, &tid);%@NL@%
- swctl.hwnd = global.hwndFrame;%@NL@%
- swctl.idProcess = pid;%@NL@%
- hsw = WinAddSwitchEntry(&swctl);%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Process messages for the window class.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- ULONG EXPENTRY%@NL@%
- WndProc( hwnd, usMsg, mp1, mp2 )%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@NL@%
- switch (usMsg)%@NL@%
- {%@NL@%
- case WM_CLOSE:%@NL@%
- Close(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- Command(hwnd, LOUSHORT(mp1));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- hps = WinBeginPaint(global.hwnd, NULL, NULL);%@NL@%
- if (global.ulHitPrecision == 0L)%@NL@%
- {%@NL@%
- HDC hdc;%@NL@%
- LONG cx;%@NL@%
- %@NL@%
- if (hdc = WinQueryWindowDC(global.hwnd)) {%@NL@%
- DevQueryCaps(hdc, CAPS_MARKER_WIDTH, 1L, &cx);%@NL@%
- global.ulHitPrecision = (cx >> 17) + 1L;%@NL@%
- } else {%@NL@%
- global.ulHitPrecision = 6L;%@NL@%
- }%@NL@%
- }%@NL@%
- Paint(hps, TRUE);%@NL@%
- WinEndPaint(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1DOWN:%@NL@%
- case WM_BUTTON2DOWN:%@NL@%
- ButtonDown(hwnd, usMsg, mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1UP:%@NL@%
- case WM_BUTTON2UP:%@NL@%
- ButtonUp(hwnd, usMsg);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MOUSEMOVE:%@NL@%
- MouseMove(hwnd, mp1);%@NL@%
- return( (ULONG)WinDefWindowProc(hwnd, usMsg, mp1, mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return( (ULONG)WinDefWindowProc(hwnd, usMsg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MouseMove%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MouseMove(hwnd, mp1)%@NL@%
- HWND hwnd;%@NL@%
- MPARAM mp1;%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- if (hwnd == global.hwnd)%@NL@%
- if (global.fDragging)%@NL@%
- {%@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- if (global.usPtGrabbed != -1)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, FALSE);%@NL@%
- %@NL@%
- *(global.pptl+global.usPtGrabbed) = ptl;%@NL@%
- %@NL@%
- Paint(hps, FALSE);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ButtonUp%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- ButtonUp(hwnd, usMsg)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- {%@NL@%
- int i;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@NL@%
- if (hwnd == global.hwnd)%@NL@%
- if (global.fDragging)%@NL@%
- {%@NL@%
- global.fDragging = FALSE;%@NL@%
- if (global.usPtGrabbed != -1)%@NL@%
- {%@NL@%
- if (usMsg == WM_BUTTON2UP)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, FALSE);%@NL@%
- %@NL@%
- if ((i = global.usPtGrabbed) < (int) global.cptl-1)%@NL@%
- while (i < (int) global.cptl-1)%@NL@%
- {%@NL@%
- global.pptl[i] = global.pptl[i+1];%@NL@%
- ++i;%@NL@%
- }%@NL@%
- %@NL@%
- --global.cptl;%@NL@%
- global.usPtGrabbed = -1;%@NL@%
- %@NL@%
- Paint(hps, FALSE);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- else %@AB@%/* WM_BUTTON1UP */%@AE@%%@NL@%
- global.usPtGrabbed = -1;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ButtonDown%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- ButtonDown(hwnd, usMsg, mp1)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- HPS hps;%@NL@%
- USHORT usNewPtGrabbed;%@NL@%
- %@NL@%
- %@NL@%
- if (hwnd == global.hwnd)%@NL@%
- if (!global.fDragging)%@NL@%
- {%@NL@%
- global.fDragging = TRUE;%@NL@%
- %@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- if ((usNewPtGrabbed = IsPtInList(&ptl)) != -1)%@NL@%
- global.usPtGrabbed = usNewPtGrabbed;%@NL@%
- %@NL@%
- if (usMsg == WM_BUTTON1DOWN)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, FALSE);%@NL@%
- %@NL@%
- if (usNewPtGrabbed == -1)%@NL@%
- global.usPtGrabbed = AddPtToList(&ptl);%@NL@%
- else%@NL@%
- global.usPtGrabbed = usNewPtGrabbed;%@NL@%
- %@NL@%
- Paint(hps, FALSE);%@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- if (global.usPtGrabbed == -1)%@NL@%
- MyMessageBox(global.hwnd, "Cannot add any more points.");%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* IsPtInList%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- USHORT%@NL@%
- IsPtInList(pptl)%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* try to find pptl in the points we already have */%@AE@%%@NL@%
- for (i = 0; i < (int) global.cptl; ++i)%@NL@%
- if (((abs(pptl->x - global.pptl[i].x))%@NL@%
- <= (LONG) global.ulHitPrecision)%@NL@%
- && ((abs(pptl->y - global.pptl[i].y))%@NL@%
- <= (LONG) global.ulHitPrecision))%@NL@%
- return i;%@NL@%
- %@NL@%
- %@AB@%/* couldn't find it */%@AE@%%@NL@%
- return -1;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* AddPtToList%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- USHORT%@NL@%
- AddPtToList(pptl)%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- int i, j;%@NL@%
- %@NL@%
- if (global.cptl < CPTLMAX)%@NL@%
- {%@NL@%
- %@AB@%/* check for new points lying on a line segment */%@AE@%%@NL@%
- for (i = 0; i < (int) (global.cptl - 1L); ++i)%@NL@%
- if (IsPtCloseToLine(&global.pptl[i], &global.pptl[i+1], pptl))%@NL@%
- {%@NL@%
- for (j = (int) global.cptl; j > i+1; --j)%@NL@%
- global.pptl[j] = global.pptl[j - 1];%@NL@%
- global.pptl[i+1] = *pptl;%@NL@%
- ++global.cptl;%@NL@%
- return i+1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* append the point */%@AE@%%@NL@%
- %@NL@%
- i = (int) global.cptl;%@NL@%
- global.pptl[i] = *pptl;%@NL@%
- ++global.cptl;%@NL@%
- return i;%@NL@%
- }%@NL@%
- %@NL@%
- return -1;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* IsPtCloseToLine%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL%@NL@%
- IsPtCloseToLine(pptl1, pptl2, pptlTest)%@NL@%
- PPOINTL pptl1;%@NL@%
- PPOINTL pptl2;%@NL@%
- PPOINTL pptlTest;%@NL@%
- {%@NL@%
- POINTL ptlLL, ptlUR;%@NL@%
- LONG dx, dy, yIntercept, result;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* find the bounding box of the line segment */%@AE@%%@NL@%
- %@NL@%
- ptlLL = *pptl1; %@AB@%/* assume line goes lower left to upper right */%@AE@%%@NL@%
- ptlUR = *pptl2;%@NL@%
- if (pptl1->x > pptl2->x)%@NL@%
- SwapLong(&ptlLL.x, &ptlUR.x);%@NL@%
- if (pptl1->y > pptl2->y)%@NL@%
- SwapLong(&ptlLL.y, &ptlUR.y);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* adjust the bounding box if it's too narrow */%@AE@%%@NL@%
- %@NL@%
- dx = pptl2->x - pptl1->x;%@NL@%
- if (abs(dx) <= (LONG) (global.ulHitPrecision >> 1))%@NL@%
- {%@NL@%
- ptlLL.x -= (LONG) (global.ulHitPrecision >> 1);%@NL@%
- ptlUR.x += (LONG) (global.ulHitPrecision >> 1);%@NL@%
- }%@NL@%
- dy = pptl2->y - pptl1->y;%@NL@%
- if (abs(dy) <= (LONG) (global.ulHitPrecision >> 1))%@NL@%
- {%@NL@%
- ptlLL.y -= (LONG) (global.ulHitPrecision >> 1);%@NL@%
- ptlUR.y += (LONG) (global.ulHitPrecision >> 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* see if the test point is in the bounding box of the line segment */%@AE@%%@NL@%
- %@NL@%
- if ((pptlTest->x >= ptlLL.x) &&%@NL@%
- (pptlTest->x <= ptlUR.x) &&%@NL@%
- (pptlTest->y >= ptlLL.y) &&%@NL@%
- (pptlTest->y <= ptlUR.y))%@NL@%
- {%@NL@%
- %@AB@%/* test for special cases */%@AE@%%@NL@%
- %@NL@%
- if (dx == 0)%@NL@%
- {%@NL@%
- if (abs(pptlTest->x - pptl1->x) <= (LONG) global.ulHitPrecision)%@NL@%
- return TRUE;%@NL@%
- else%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- if (dy == 0)%@NL@%
- {%@NL@%
- if (abs(pptlTest->y - pptl1->y) <= (LONG) global.ulHitPrecision)%@NL@%
- return TRUE;%@NL@%
- else%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* test for general case */%@AE@%%@NL@%
- %@NL@%
- yIntercept = pptl1->y - (pptl1->x * dy) / dx;%@NL@%
- %@NL@%
- result = pptlTest->y - (pptlTest->x * dy / dx) - yIntercept;%@NL@%
- if (abs(result) <= (LONG) global.ulHitPrecision)%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* SwapLong%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- SwapLong(pl1, pl2)%@NL@%
- PLONG pl1, pl2;%@NL@%
- {%@NL@%
- LONG lTmp;%@NL@%
- %@NL@%
- lTmp = *pl1;%@NL@%
- *pl1 = *pl2;%@NL@%
- *pl2 = lTmp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Close%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- Close(hwnd)%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- WinPostMsg(hwnd, WM_QUIT, 0L, 0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Command%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Dispatches menu commands to the proper handlers.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%UPDATE_MENU_BOOL(var, val) \ %@NL@%
- { \%@NL@%
- TOGGLE_BOOL((var)); \%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, (val), (var)); \%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%UPDATE_MENU_LIST(var, val) \ %@NL@%
- { \%@NL@%
- UNCHECK_MENU_ITEM(global.hwndFrame, (var)); \%@NL@%
- (var) = (val); \%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, (var)); \%@NL@%
- }%@NL@%
- %@NL@%
- VOID%@NL@%
- Command(hwnd, id)%@NL@%
- HWND hwnd;%@NL@%
- USHORT id;%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- BOOL fRedraw = FALSE;%@NL@%
- int rc;%@NL@%
- %@NL@%
- switch (id)%@NL@%
- {%@NL@%
- case IDM_ABOUT:%@NL@%
- rc = WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, (HMODULE) NULL, IDD_ABOUT, NULL);%@NL@%
- fRedraw = FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_NOPRIM:%@NL@%
- global.flPrim = 0L;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, IDM_POLYLINE, 0);%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, IDM_POLYFILLET, 0);%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, IDM_POLYSPLINE, 0);%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYLINE:%@NL@%
- global.flPrim ^= PRIM_POLYLINE;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POLYLINE));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYFILLET:%@NL@%
- global.flPrim ^= PRIM_POLYFILLET;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POLYFILLET));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYSPLINE:%@NL@%
- global.flPrim ^= PRIM_POLYSPLINE;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POLYSPLINE));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POINTARC:%@NL@%
- global.flPrim ^= PRIM_POINTARC;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POINTARC));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_CTLPOINTS:%@NL@%
- UPDATE_MENU_BOOL(global.fDisplayControlPoints, IDM_CTLPOINTS);%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_CLEARALL:%@NL@%
- global.cptl = 0L;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if (fRedraw)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, TRUE);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Paint%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- Paint(hps, fClearScreen)%@NL@%
- HPS hps;%@NL@%
- BOOL fClearScreen;%@NL@%
- {%@NL@%
- LINEBUNDLE lb;%@NL@%
- RECTL rcl;%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- if (fClearScreen)%@NL@%
- {%@NL@%
- %@AB@%/* clear the screen */%@AE@%%@NL@%
- WinQueryWindowRect(global.hwnd, &rcl);%@NL@%
- GpiBitBlt(hps, NULL, 2L, (PPOINTL) &rcl, ROP_ONE, 0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- if (global.cptl > 0L)%@NL@%
- {%@NL@%
- if (global.fDisplayControlPoints)%@NL@%
- {%@NL@%
- if (fClearScreen)%@NL@%
- %@AB@%/* draw all the control points */%@AE@%%@NL@%
- DrawControlPoints(hps, global.cptl, global.pptl);%@NL@%
- else if (global.usPtGrabbed != -1)%@NL@%
- %@AB@%/* draw just the control point that moved */%@AE@%%@NL@%
- DrawControlPoints(hps, 1L, global.pptl+global.usPtGrabbed);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* set mix mode to xor */%@AE@%%@NL@%
- lb.usMixMode = FM_XOR;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_MIX_MODE, 0L, &lb);%@NL@%
- %@NL@%
- %@AB@%/* draw the current primitives */%@AE@%%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYLINE)%@NL@%
- {%@NL@%
- lb.lColor = CLR_BROWN;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POLYLINE);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYFILLET)%@NL@%
- {%@NL@%
- lb.lColor = CLR_DARKCYAN;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POLYFILLET);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYSPLINE)%@NL@%
- {%@NL@%
- lb.lColor = CLR_DARKPINK;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POLYSPLINE);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POINTARC)%@NL@%
- {%@NL@%
- lb.lColor = CLR_BACKGROUND;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POINTARC);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPrimitive%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPrimitive(hps, usPrim)%@NL@%
- HPS hps;%@NL@%
- USHORT usPrim;%@NL@%
- {%@NL@%
- switch ( usPrim )%@NL@%
- {%@NL@%
- case IDM_POLYLINE:%@NL@%
- DrawPolyLine(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYFILLET:%@NL@%
- DrawPolyFillet(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYSPLINE:%@NL@%
- DrawPolySpline(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POINTARC:%@NL@%
- DrawPointArc(hps);%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPolyLine%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPolyLine(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPolyLine( hps, global.cptl-1L, global.pptl+1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPolyFillet%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPolyFillet(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- if (global.cptl > 2)%@NL@%
- {%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPolyFillet( hps, global.cptl-1L, global.pptl+1 );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPolySpline%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPolySpline(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- USHORT cptSlack; %@AB@%/* # points in pptl not usable by PolySpline */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GpiPolySpline expects the number of points to be a%@NL@%
- %@AB@% multiple of 3. If we have a non-multiple of three,%@NL@%
- %@AB@% (excluding the first point, which we've used to set%@NL@%
- %@AB@% the current position), only pass the largest multiple%@NL@%
- %@AB@% of three, saving the rest for the next go-round. */%@AE@%%@NL@%
- %@NL@%
- cptSlack = (int)((global.cptl-1L) % 3) + 1;%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPolySpline( hps, global.cptl-cptSlack,%@NL@%
- global.pptl+1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPointArc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPointArc(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- if (global.cptl >= 3L)%@NL@%
- {%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPointArc( hps, global.pptl+1 );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawControlPoints%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawControlPoints(hps, cptl, pptl)%@NL@%
- HPS hps;%@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- MARKERBUNDLE mb;%@NL@%
- %@NL@%
- mb.lColor = CLR_TRUE;%@NL@%
- mb.usMixMode = FM_XOR;%@NL@%
- GpiSetAttrs(hps, PRIM_MARKER, MBB_COLOR | MBB_MIX_MODE, 0L, &mb);%@NL@%
- %@NL@%
- GpiPolyMarker(hps, cptl, pptl);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MyMessageBox%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Displays a message box with the given string. To simplify matters,%@NL@%
- %@AB@%* the box will always have the same title ("PolyLine Editor"), will always%@NL@%
- %@AB@%* have a single button ("Ok"), will always have an exclamation point%@NL@%
- %@AB@%* icon, and will always be application modal.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MyMessageBox(hWnd, sz)%@NL@%
- HWND hWnd;%@NL@%
- PSZ sz;%@NL@%
- {%@NL@%
- static char *szTitle = "PolyLine Editor";%@NL@%
- %@NL@%
- WinMessageBox(HWND_DESKTOP, hWnd, sz, szTitle, (HMODULE) NULL,%@NL@%
- MB_OK|MB_ICONEXCLAMATION|MB_APPLMODAL);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT EXPENTRY AboutDlgProc(hDlg, msg, mp1, mp2)%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- HWND hDlg;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hDlg, TRUE); break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EDPLINE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\CLIPVIEW\EDPLINE\EDPLINE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% edpline.c -- polyline editor, for practice in mouse handling%@NL@%
- %@AB@% Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_DOSMEMMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINSWITCHLIST %@NL@%
- %@AI@%#define %@AE@%INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIPRIMITIVES %@NL@%
- %@AI@%#define %@AE@% INCL_GPITRANSFORMS %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@% INCL_WININPUT %@NL@%
- %@AI@%#define %@AE@% INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINCLIPBOARD %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"edpline.h" %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% abs(x) (((x) > 0) ? (x) : -(x)) %@NL@%
- %@AI@%#define %@AE@%PRIM_POLYLINE 0x0001 %@NL@%
- %@AI@%#define %@AE@%PRIM_POLYFILLET 0x0002 %@NL@%
- %@AI@%#define %@AE@%PRIM_POLYSPLINE 0x0004 %@NL@%
- %@AI@%#define %@AE@%PRIM_POINTARC 0x0008 %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Function declarations%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Private functions */%@AE@%%@NL@%
- %@NL@%
- VOID cdecl main(VOID);%@NL@%
- BOOL InitGlobals(VOID);%@NL@%
- BOOL InitApp(VOID);%@NL@%
- VOID Close(HWND);%@NL@%
- VOID Command(HWND, USHORT);%@NL@%
- VOID Paint(HPS, BOOL);%@NL@%
- VOID MouseMove(HWND, MPARAM);%@NL@%
- VOID ButtonUp(HWND, USHORT);%@NL@%
- VOID ButtonDown(HWND, USHORT, MPARAM);%@NL@%
- USHORT IsPtInList(PPOINTL);%@NL@%
- USHORT AddPtToList(PPOINTL);%@NL@%
- BOOL IsPtCloseToLine(PPOINTL, PPOINTL, PPOINTL);%@NL@%
- VOID DrawPrimitive(HPS, USHORT);%@NL@%
- VOID DrawPolyLine(HPS);%@NL@%
- VOID DrawPolyFillet(HPS);%@NL@%
- VOID DrawPolySpline(HPS);%@NL@%
- VOID DrawPointArc(HPS);%@NL@%
- VOID DrawControlPoints(HPS, LONG, PPOINTL);%@NL@%
- VOID MyMessageBox(HWND, PSZ);%@NL@%
- VOID SwapLong(PLONG, PLONG);%@NL@%
- %@NL@%
- %@AB@%/* Exported functions */%@AE@%%@NL@%
- %@NL@%
- ULONG CALLBACK WndProc(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT CALLBACK AboutDlgProc(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Global Variables%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- typedef struct%@NL@%
- {%@NL@%
- HAB hab;%@NL@%
- HMQ hMsgQ;%@NL@%
- HWND hwndFrame;%@NL@%
- HWND hwnd;%@NL@%
- %@NL@%
- ULONG flPrim;%@NL@%
- BOOL fDisplayControlPoints;%@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl;%@NL@%
- %@NL@%
- USHORT usPtGrabbed;%@NL@%
- BOOL fDragging;%@NL@%
- %@NL@%
- ULONG ulHitPrecision;%@NL@%
- %@NL@%
- HPS hpsMetafile;%@NL@%
- HDC hdcMetafile;%@NL@%
- ULONG hItem;%@NL@%
- SIZEL sizlPage;%@NL@%
- DEVOPENSTRUC dop;%@NL@%
- %@NL@%
- } GLOBALDATA;%@NL@%
- GLOBALDATA global;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* main%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WinInitialize resizes our ring 2 stack, among other things, so%@NL@%
- %@AB@%* we won't GP fault trying to do graphics. WinCreateMsgQueue defines%@NL@%
- %@AB@%* us as a REAL PM app. (as well as the WINDOWAPI statement in the .DEF%@NL@%
- %@AB@%* file...) Call a sub to register our window class and create a window.%@NL@%
- %@AB@%* Loop over messages. Exit cleanly.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl%@NL@%
- main()%@NL@%
- {%@NL@%
- QMSG qMsg;%@NL@%
- int iRet = 0;%@NL@%
- %@NL@%
- %@NL@%
- global.hab = WinInitialize(0);%@NL@%
- global.hMsgQ = WinCreateMsgQueue(global.hab, 0);%@NL@%
- %@NL@%
- if (InitApp())%@NL@%
- while (WinGetMsg( global.hab, (PQMSG)&qMsg, (HWND)NULL, 0, 0 ))%@NL@%
- WinDispatchMsg( global.hab, (PQMSG)&qMsg );%@NL@%
- else%@NL@%
- iRet = -1;%@NL@%
- %@NL@%
- WinDestroyWindow( global.hwndFrame );%@NL@%
- WinDestroyMsgQueue( global.hMsgQ );%@NL@%
- WinTerminate( global.hab );%@NL@%
- DosExit(EXIT_PROCESS, iRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* InitGlobals%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Initialize global variables.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL%@NL@%
- InitGlobals()%@NL@%
- {%@NL@%
- global.flPrim = PRIM_POLYLINE;%@NL@%
- global.fDisplayControlPoints = TRUE;%@NL@%
- %@NL@%
- global.cptl = 0L;%@NL@%
- global.pptl = NULL;%@NL@%
- if (DosAllocSeg(CPTLMAX * sizeof(POINTL),%@NL@%
- ((PUSHORT)&global.pptl)+1, 0))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- global.usPtGrabbed = -1;%@NL@%
- global.fDragging = FALSE;%@NL@%
- global.ulHitPrecision = 0L;%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* InitApp%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Register application window class and creates standard window.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INIT_MENU_ITEM(val, var) \ %@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, (val), (var))%@NL@%
- %@NL@%
- BOOL%@NL@%
- InitApp()%@NL@%
- {%@NL@%
- char szTitle[24];%@NL@%
- ULONG ctldata;%@NL@%
- PID pid;%@NL@%
- TID tid;%@NL@%
- HSWITCH hsw;%@NL@%
- static SWCNTRL swctl = { 0, 0, 0, 0, 0, SWL_VISIBLE,%@NL@%
- SWL_JUMPABLE, "Edit Polyline", 0 };%@NL@%
- %@NL@%
- if (!InitGlobals())%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Register Application Window Class */%@AE@%%@NL@%
- %@NL@%
- WinLoadString( global.hab, (HMODULE) NULL, IDS_TITLE, sizeof(szTitle), (PCH)szTitle );%@NL@%
- if ( !WinRegisterClass( global.hab, (PCH)szTitle, (PFNWP)WndProc,%@NL@%
- CS_SIZEREDRAW, 0 ))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Create a window instance of class "PolyLine Editor" */%@AE@%%@NL@%
- %@NL@%
- ctldata = FCF_STANDARD &%@NL@%
- ~(ULONG)(FCF_ICON | FCF_TASKLIST);%@NL@%
- %@NL@%
- if (global.hwndFrame = WinCreateStdWindow(%@NL@%
- HWND_DESKTOP, %@AB@%/* specify desktop as parent window */%@AE@%%@NL@%
- WS_VISIBLE, %@AB@%/* window styles */%@AE@%%@NL@%
- &ctldata, %@AB@%/* frame creation flags */%@AE@%%@NL@%
- (PCH)szTitle, %@AB@%/* window class name */%@AE@%%@NL@%
- (PCH)szTitle, %@AB@%/* name appearing in window caption */%@AE@%%@NL@%
- 0L, %@AB@%/* */%@AE@%%@NL@%
- (HMODULE)NULL, %@AB@%/* use current executable module id */%@AE@%%@NL@%
- IDR_EDPLINE, %@AB@%/* menu id */%@AE@%%@NL@%
- (HWND FAR *)&global.hwnd %@AB@%/* window handle */%@AE@%%@NL@%
- ))%@NL@%
- {%@NL@%
- INIT_MENU_ITEM(IDM_CTLPOINTS, global.fDisplayControlPoints);%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYLINE)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POLYLINE);%@NL@%
- if (global.flPrim & PRIM_POLYFILLET)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POLYFILLET);%@NL@%
- if (global.flPrim & PRIM_POLYSPLINE)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POLYSPLINE);%@NL@%
- if (global.flPrim & PRIM_POINTARC)%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, IDM_POINTARC);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Add ourselves to the switch list. */%@AE@%%@NL@%
- %@NL@%
- WinQueryWindowProcess(global.hwndFrame, &pid, &tid);%@NL@%
- swctl.hwnd = global.hwndFrame;%@NL@%
- swctl.idProcess = pid;%@NL@%
- hsw = WinAddSwitchEntry(&swctl);%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Process messages for the window class.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- ULONG CALLBACK%@NL@%
- WndProc( hwnd, usMsg, mp1, mp2 )%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- switch (usMsg)%@NL@%
- {%@NL@%
- case WM_CLOSE:%@NL@%
- Close(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- Command(hwnd, LOUSHORT(mp1));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- hps = WinBeginPaint(global.hwnd, NULL, NULL);%@NL@%
- %@NL@%
- if (global.ulHitPrecision == 0L)%@NL@%
- {%@NL@%
- HDC hdc;%@NL@%
- LONG cx;%@NL@%
- %@NL@%
- if (hdc = WinQueryWindowDC(global.hwnd)) {%@NL@%
- DevQueryCaps(hdc, CAPS_MARKER_WIDTH, 1L, &cx);%@NL@%
- global.ulHitPrecision = (cx >> 17) + 1L;%@NL@%
- } else {%@NL@%
- global.ulHitPrecision = 6L;%@NL@%
- }%@NL@%
- }%@NL@%
- Paint(hps, TRUE);%@NL@%
- WinEndPaint(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1DOWN:%@NL@%
- case WM_BUTTON2DOWN:%@NL@%
- ButtonDown(hwnd, usMsg, mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1UP:%@NL@%
- case WM_BUTTON2UP:%@NL@%
- ButtonUp(hwnd, usMsg);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MOUSEMOVE:%@NL@%
- MouseMove(hwnd, mp1);%@NL@%
- return( (ULONG)WinDefWindowProc(hwnd, usMsg, mp1, mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return( (ULONG)WinDefWindowProc(hwnd, usMsg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MouseMove%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MouseMove(hwnd, mp1)%@NL@%
- HWND hwnd;%@NL@%
- MPARAM mp1;%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- if (hwnd == global.hwnd)%@NL@%
- if (global.fDragging)%@NL@%
- {%@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- if (global.usPtGrabbed != -1)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, FALSE);%@NL@%
- %@NL@%
- *(global.pptl+global.usPtGrabbed) = ptl;%@NL@%
- %@NL@%
- Paint(hps, FALSE);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ButtonUp%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- ButtonUp(hwnd, usMsg)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- {%@NL@%
- int i;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@NL@%
- if (hwnd == global.hwnd)%@NL@%
- if (global.fDragging)%@NL@%
- {%@NL@%
- global.fDragging = FALSE;%@NL@%
- if (global.usPtGrabbed != -1)%@NL@%
- {%@NL@%
- if (usMsg == WM_BUTTON2UP)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, FALSE);%@NL@%
- %@NL@%
- if ((i = global.usPtGrabbed) < (int) global.cptl-1)%@NL@%
- while (i < (int) global.cptl-1)%@NL@%
- {%@NL@%
- global.pptl[i] = global.pptl[i+1];%@NL@%
- ++i;%@NL@%
- }%@NL@%
- %@NL@%
- --global.cptl;%@NL@%
- global.usPtGrabbed = -1;%@NL@%
- %@NL@%
- Paint(hps, FALSE);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- else %@AB@%/* WM_BUTTON1UP */%@AE@%%@NL@%
- global.usPtGrabbed = -1;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ButtonDown%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- ButtonDown(hwnd, usMsg, mp1)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- HPS hps;%@NL@%
- USHORT usNewPtGrabbed;%@NL@%
- %@NL@%
- %@NL@%
- if (hwnd == global.hwnd)%@NL@%
- if (!global.fDragging)%@NL@%
- {%@NL@%
- global.fDragging = TRUE;%@NL@%
- %@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- if ((usNewPtGrabbed = IsPtInList(&ptl)) != -1)%@NL@%
- global.usPtGrabbed = usNewPtGrabbed;%@NL@%
- %@NL@%
- if (usMsg == WM_BUTTON1DOWN)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, FALSE);%@NL@%
- %@NL@%
- if (usNewPtGrabbed == -1)%@NL@%
- global.usPtGrabbed = AddPtToList(&ptl);%@NL@%
- else%@NL@%
- global.usPtGrabbed = usNewPtGrabbed;%@NL@%
- %@NL@%
- Paint(hps, FALSE);%@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- if (global.usPtGrabbed == -1)%@NL@%
- MyMessageBox(global.hwnd, "Cannot add any more points.");%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* IsPtInList%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- USHORT%@NL@%
- IsPtInList(pptl)%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* try to find pptl in the points we already have */%@AE@%%@NL@%
- for (i = 0; i < (int) global.cptl; ++i)%@NL@%
- if (((abs(pptl->x - global.pptl[i].x))%@NL@%
- <= (LONG) global.ulHitPrecision)%@NL@%
- && ((abs(pptl->y - global.pptl[i].y))%@NL@%
- <= (LONG) global.ulHitPrecision))%@NL@%
- return i;%@NL@%
- %@NL@%
- %@AB@%/* couldn't find it */%@AE@%%@NL@%
- return -1;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* AddPtToList%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- USHORT%@NL@%
- AddPtToList(pptl)%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- int i, j;%@NL@%
- %@NL@%
- if (global.cptl < CPTLMAX)%@NL@%
- {%@NL@%
- %@AB@%/* check for new points lying on a line segment */%@AE@%%@NL@%
- for (i = 0; i < (int) (global.cptl - 1L); ++i)%@NL@%
- if (IsPtCloseToLine(&global.pptl[i], &global.pptl[i+1], pptl))%@NL@%
- {%@NL@%
- for (j = (int) global.cptl; j > i+1; --j)%@NL@%
- global.pptl[j] = global.pptl[j - 1];%@NL@%
- global.pptl[i+1] = *pptl;%@NL@%
- ++global.cptl;%@NL@%
- return i+1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* append the point */%@AE@%%@NL@%
- %@NL@%
- i = (int) global.cptl;%@NL@%
- global.pptl[i] = *pptl;%@NL@%
- ++global.cptl;%@NL@%
- return i;%@NL@%
- }%@NL@%
- %@NL@%
- return -1;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* IsPtCloseToLine%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL%@NL@%
- IsPtCloseToLine(pptl1, pptl2, pptlTest)%@NL@%
- PPOINTL pptl1;%@NL@%
- PPOINTL pptl2;%@NL@%
- PPOINTL pptlTest;%@NL@%
- {%@NL@%
- POINTL ptlLL, ptlUR;%@NL@%
- LONG dx, dy, yIntercept, result;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* find the bounding box of the line segment */%@AE@%%@NL@%
- %@NL@%
- ptlLL = *pptl1; %@AB@%/* assume line goes lower left to upper right */%@AE@%%@NL@%
- ptlUR = *pptl2;%@NL@%
- if (pptl1->x > pptl2->x)%@NL@%
- SwapLong(&ptlLL.x, &ptlUR.x);%@NL@%
- if (pptl1->y > pptl2->y)%@NL@%
- SwapLong(&ptlLL.y, &ptlUR.y);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* adjust the bounding box if it's too narrow */%@AE@%%@NL@%
- %@NL@%
- dx = pptl2->x - pptl1->x;%@NL@%
- if (abs(dx) <= (LONG) (global.ulHitPrecision >> 1))%@NL@%
- {%@NL@%
- ptlLL.x -= (LONG) (global.ulHitPrecision >> 1);%@NL@%
- ptlUR.x += (LONG) (global.ulHitPrecision >> 1);%@NL@%
- }%@NL@%
- dy = pptl2->y - pptl1->y;%@NL@%
- if (abs(dy) <= (LONG) (global.ulHitPrecision >> 1))%@NL@%
- {%@NL@%
- ptlLL.y -= (LONG) (global.ulHitPrecision >> 1);%@NL@%
- ptlUR.y += (LONG) (global.ulHitPrecision >> 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* see if the test point is in the bounding box of the line segment */%@AE@%%@NL@%
- %@NL@%
- if ((pptlTest->x >= ptlLL.x) &&%@NL@%
- (pptlTest->x <= ptlUR.x) &&%@NL@%
- (pptlTest->y >= ptlLL.y) &&%@NL@%
- (pptlTest->y <= ptlUR.y))%@NL@%
- {%@NL@%
- %@AB@%/* test for special cases */%@AE@%%@NL@%
- %@NL@%
- if (dx == 0)%@NL@%
- {%@NL@%
- if (abs(pptlTest->x - pptl1->x) <= (LONG) global.ulHitPrecision)%@NL@%
- return TRUE;%@NL@%
- else%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- if (dy == 0)%@NL@%
- {%@NL@%
- if (abs(pptlTest->y - pptl1->y) <= (LONG) global.ulHitPrecision)%@NL@%
- return TRUE;%@NL@%
- else%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* test for general case */%@AE@%%@NL@%
- %@NL@%
- yIntercept = pptl1->y - (pptl1->x * dy) / dx;%@NL@%
- %@NL@%
- result = pptlTest->y - (pptlTest->x * dy / dx) - yIntercept;%@NL@%
- if (abs(result) <= (LONG) global.ulHitPrecision)%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* SwapLong%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- SwapLong(pl1, pl2)%@NL@%
- PLONG pl1, pl2;%@NL@%
- {%@NL@%
- LONG lTmp;%@NL@%
- %@NL@%
- lTmp = *pl1;%@NL@%
- *pl1 = *pl2;%@NL@%
- *pl2 = lTmp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Close%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- Close(hwnd)%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- WinPostMsg(hwnd, WM_QUIT, 0L, 0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Command%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Dispatches menu commands to the proper handlers.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%UPDATE_MENU_BOOL(var, val) \ %@NL@%
- { \%@NL@%
- TOGGLE_BOOL((var)); \%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, (val), (var)); \%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%UPDATE_MENU_LIST(var, val) \ %@NL@%
- { \%@NL@%
- UNCHECK_MENU_ITEM(global.hwndFrame, (var)); \%@NL@%
- (var) = (val); \%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, (var)); \%@NL@%
- }%@NL@%
- %@NL@%
- VOID%@NL@%
- Command(hwnd, id)%@NL@%
- HWND hwnd;%@NL@%
- USHORT id;%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- BOOL fRedraw = FALSE;%@NL@%
- int rc;%@NL@%
- %@NL@%
- switch (id)%@NL@%
- {%@NL@%
- case IDM_ABOUT:%@NL@%
- rc = WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, (HMODULE) NULL, IDD_ABOUT, NULL);%@NL@%
- fRedraw = FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_NOPRIM:%@NL@%
- global.flPrim = 0L;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, IDM_POLYLINE, 0);%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, IDM_POLYFILLET, 0);%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, IDM_POLYSPLINE, 0);%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYLINE:%@NL@%
- global.flPrim ^= PRIM_POLYLINE;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POLYLINE));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYFILLET:%@NL@%
- global.flPrim ^= PRIM_POLYFILLET;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POLYFILLET));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYSPLINE:%@NL@%
- global.flPrim ^= PRIM_POLYSPLINE;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POLYSPLINE));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POINTARC:%@NL@%
- global.flPrim ^= PRIM_POINTARC;%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, id, (global.flPrim & PRIM_POINTARC));%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_CTLPOINTS:%@NL@%
- UPDATE_MENU_BOOL(global.fDisplayControlPoints, IDM_CTLPOINTS);%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_CLEARALL:%@NL@%
- global.cptl = 0L;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_COPY:%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% To put this image on the clipboard, create a Metafile DC.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Associate a presentation space with the DC, then play the%@NL@%
- %@AB@% drawing orders into the metafile.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- global.dop.pszLogAddress = NULL;%@NL@%
- global.dop.pszDriverName = "DISPLAY";%@NL@%
- global.dop.pdriv = NULL;%@NL@%
- global.dop.pszDataType = NULL;%@NL@%
- %@NL@%
- global.hdcMetafile = DevOpenDC(global.hab, OD_METAFILE,%@NL@%
- "*", 4L, (PDEVOPENDATA) &global.dop, NULL);%@NL@%
- global.hpsMetafile = GpiCreatePS(global.hab, global.hdcMetafile,%@NL@%
- &global.sizlPage, PU_PELS | GPIA_ASSOC);%@NL@%
- %@NL@%
- Paint(global.hpsMetafile, TRUE);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Clean up. A handle to the metafile is obtained when%@NL@%
- %@AB@% calling DevCloseDC().%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GpiAssociate(global.hpsMetafile, NULL);%@NL@%
- GpiDestroyPS(global.hpsMetafile);%@NL@%
- global.hItem = (ULONG) DevCloseDC(global.hdcMetafile);%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% Be sure to empty the clipboard of other data. This will%@NL@%
- %@AB@% also empty previous data stored in other formats.%@NL@%
- %@AB@% Then, set the clipboard data with type METAFILE, passing%@NL@%
- %@AB@% the handle to our metafile.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (WinOpenClipbrd(global.hab)) {%@NL@%
- WinEmptyClipbrd(global.hab);%@NL@%
- WinSetClipbrdData(global.hab,global.hItem, CF_METAFILE, CFI_HANDLE);%@NL@%
- WinCloseClipbrd(global.hab);%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if (fRedraw)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, TRUE);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Paint%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- Paint(hps, fClearScreen)%@NL@%
- HPS hps;%@NL@%
- BOOL fClearScreen;%@NL@%
- {%@NL@%
- LINEBUNDLE lb;%@NL@%
- RECTL rcl;%@NL@%
- if (fClearScreen)%@NL@%
- {%@NL@%
- %@AB@%/* clear the screen */%@AE@%%@NL@%
- WinQueryWindowRect(global.hwnd, &rcl);%@NL@%
- GpiBitBlt(hps, NULL, 2L, (PPOINTL) &rcl, ROP_ONE, 0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- if (global.cptl > 0L)%@NL@%
- {%@NL@%
- if (global.fDisplayControlPoints)%@NL@%
- {%@NL@%
- if (fClearScreen)%@NL@%
- %@AB@%/* draw all the control points */%@AE@%%@NL@%
- DrawControlPoints(hps, global.cptl, global.pptl);%@NL@%
- else if (global.usPtGrabbed != -1)%@NL@%
- %@AB@%/* draw just the control point that moved */%@AE@%%@NL@%
- DrawControlPoints(hps, 1L, global.pptl+global.usPtGrabbed);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* set mix mode to xor */%@AE@%%@NL@%
- lb.usMixMode = FM_XOR;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_MIX_MODE, 0L, &lb);%@NL@%
- %@NL@%
- %@AB@%/* draw the current primitives */%@AE@%%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYLINE)%@NL@%
- {%@NL@%
- lb.lColor = CLR_BROWN;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POLYLINE);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYFILLET)%@NL@%
- {%@NL@%
- lb.lColor = CLR_DARKCYAN;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POLYFILLET);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POLYSPLINE)%@NL@%
- {%@NL@%
- lb.lColor = CLR_DARKPINK;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POLYSPLINE);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.flPrim & PRIM_POINTARC)%@NL@%
- {%@NL@%
- lb.lColor = CLR_BACKGROUND;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- DrawPrimitive(hps, IDM_POINTARC);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPrimitive%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPrimitive(hps, usPrim)%@NL@%
- HPS hps;%@NL@%
- USHORT usPrim;%@NL@%
- {%@NL@%
- switch ( usPrim )%@NL@%
- {%@NL@%
- case IDM_POLYLINE:%@NL@%
- DrawPolyLine(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYFILLET:%@NL@%
- DrawPolyFillet(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYSPLINE:%@NL@%
- DrawPolySpline(hps);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POINTARC:%@NL@%
- DrawPointArc(hps);%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPolyLine%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPolyLine(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPolyLine( hps, global.cptl-1L, global.pptl+1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPolyFillet%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPolyFillet(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- if (global.cptl > 2)%@NL@%
- {%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPolyFillet( hps, global.cptl-1L, global.pptl+1 );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPolySpline%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPolySpline(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- USHORT cptSlack; %@AB@%/* # points in pptl not usable by PolySpline */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GpiPolySpline expects the number of points to be a%@NL@%
- %@AB@% multiple of 3. If we have a non-multiple of three,%@NL@%
- %@AB@% (excluding the first point, which we've used to set%@NL@%
- %@AB@% the current position), only pass the largest multiple%@NL@%
- %@AB@% of three, saving the rest for the next go-round. */%@AE@%%@NL@%
- %@NL@%
- cptSlack = (int)((global.cptl-1L) % 3) + 1;%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPolySpline( hps, global.cptl-cptSlack,%@NL@%
- global.pptl+1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPointArc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPointArc(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- if (global.cptl >= 3L)%@NL@%
- {%@NL@%
- GpiSetCurrentPosition( hps, global.pptl );%@NL@%
- GpiPointArc( hps, global.pptl+1 );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawControlPoints%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawControlPoints(hps, cptl, pptl)%@NL@%
- HPS hps;%@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- MARKERBUNDLE mb;%@NL@%
- %@NL@%
- mb.lColor = CLR_TRUE;%@NL@%
- mb.usMixMode = FM_XOR;%@NL@%
- GpiSetAttrs(hps, PRIM_MARKER, MBB_COLOR | MBB_MIX_MODE, 0L, &mb);%@NL@%
- %@NL@%
- GpiPolyMarker(hps, cptl, pptl);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MyMessageBox%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Displays a message box with the given string. To simplify matters,%@NL@%
- %@AB@%* the box will always have the same title ("PolyLine Editor"), will always%@NL@%
- %@AB@%* have a single button ("Ok"), will always have an exclamation point%@NL@%
- %@AB@%* icon, and will always be application modal.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MyMessageBox(hWnd, sz)%@NL@%
- HWND hWnd;%@NL@%
- PSZ sz;%@NL@%
- {%@NL@%
- static char *szTitle = "PolyLine Editor";%@NL@%
- %@NL@%
- WinMessageBox(HWND_DESKTOP, hWnd, sz, szTitle, 0,%@NL@%
- MB_OK|MB_ICONEXCLAMATION|MB_APPLMODAL);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT CALLBACK AboutDlgProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2) {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% About... dialog procedure%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- switch(msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch(COMMANDMSG(&msg)->cmd) {%@NL@%
- case DID_OK: WinDismissDlg(hDlg, TRUE); break;%@NL@%
- default: break;%@NL@%
- }%@NL@%
- default: return WinDefDlgProc(hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EXPAND.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\EXPAND\EXPAND.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_PM %@NL@%
- %@AI@%#include %@AE@%<OS2.H> %@NL@%
- %@AI@%#include %@AE@%"Expand.H" %@NL@%
- %@NL@%
- MRESULT EXPENTRY WndProc (HWND, USHORT, MPARAM, MPARAM );%@NL@%
- MRESULT EXPENTRY AboutDlgProc (HWND, USHORT, MPARAM, MPARAM);%@NL@%
- MRESULT EXPENTRY DialogProc (HWND, USHORT, MPARAM, MPARAM);%@NL@%
- %@NL@%
- int cdecl main(void);%@NL@%
- %@NL@%
- char szAppName[] = "Expand";%@NL@%
- %@NL@%
- HAB hAB;%@NL@%
- HMQ hmqMsgQueue;%@NL@%
- HWND hWndMain,%@NL@%
- hWndFrame;%@NL@%
- %@NL@%
- int cdecl main()%@NL@%
- {%@NL@%
- QMSG qmsg;%@NL@%
- ULONG ctlData;%@NL@%
- %@NL@%
- hAB = WinInitialize (0);%@NL@%
- hmqMsgQueue = WinCreateMsgQueue (hAB, 0);%@NL@%
- %@NL@%
- if (!WinRegisterClass (hAB,%@NL@%
- szAppName,%@NL@%
- WndProc,%@NL@%
- CS_SYNCPAINT | CS_SIZEREDRAW,%@NL@%
- 0)) {%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- ctlData = FCF_STANDARD;%@NL@%
- hWndFrame = WinCreateStdWindow ( HWND_DESKTOP,%@NL@%
- WS_VISIBLE,%@NL@%
- &ctlData,%@NL@%
- szAppName,%@NL@%
- NULL,%@NL@%
- 0L,%@NL@%
- 0,%@NL@%
- ID_RESOURCE,%@NL@%
- &hWndMain);%@NL@%
- WinSetWindowText (hWndFrame, szAppName);%@NL@%
- WinShowWindow (hWndFrame, TRUE);%@NL@%
- %@NL@%
- while ( WinGetMsg (hAB, &qmsg, NULL, 0, 0)) {%@NL@%
- WinDispatchMsg (hAB, &qmsg);%@NL@%
- }%@NL@%
- %@NL@%
- WinDestroyWindow (hWndFrame);%@NL@%
- WinDestroyMsgQueue (hmqMsgQueue);%@NL@%
- WinTerminate (hAB);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT EXPENTRY WndProc (hWnd, msg, mp1, mp2)%@NL@%
- HWND hWnd;%@NL@%
- USHORT msg;%@NL@%
- MPARAM mp1, mp2;%@NL@%
- {%@NL@%
- HPS hPS;%@NL@%
- RECTL rclPaint, rclWindow;%@NL@%
- POINTL ptlPatternRef;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (COMMANDMSG(&msg)->cmd) {%@NL@%
- case IDM_ABOUT:%@NL@%
- WinDlgBox(HWND_DESKTOP, hWnd, AboutDlgProc,%@NL@%
- (HMODULE) NULL, ID_RESOURCE, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_ITEM+1:%@NL@%
- WinDlgBox(HWND_DESKTOP, hWnd, DialogProc,%@NL@%
- (HMODULE) NULL, ID_DIALOG, NULL);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_ITEM+2:%@NL@%
- case IDM_ITEM+3:%@NL@%
- case IDM_ITEM+4:%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_EXIT:%@NL@%
- WinPostMsg (hWnd, WM_CLOSE, 0L, 0L);%@NL@%
- break;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_HELP:%@NL@%
- WinMessageBox (HWND_DESKTOP, hWnd,%@NL@%
- "Help Not Implemented Yet.",%@NL@%
- " - Help - ",%@NL@%
- 0,%@NL@%
- MB_OK | MB_MOVEABLE | MB_APPLMODAL);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CLOSE:%@NL@%
- WinPostMsg (hWnd, WM_QUIT, 0L, 0L);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- hPS = WinBeginPaint (hWnd, NULL, &rclPaint);%@NL@%
- %@NL@%
- WinQueryWindowRect(hWnd, &rclWindow);%@NL@%
- ptlPatternRef.x = rclWindow.xLeft;%@NL@%
- ptlPatternRef.y = rclWindow.yTop;%@NL@%
- GpiSetPatternRefPoint(hPS, &ptlPatternRef);%@NL@%
- WinFillRect(hPS, &rclPaint, SYSCLR_APPWORKSPACE);%@NL@%
- %@NL@%
- WinEndPaint (hPS);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return (WinDefWindowProc (hWnd, msg, mp1, mp2));%@NL@%
- }%@NL@%
- return 0L;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- switch (msg) {%@NL@%
- case WM_COMMAND:%@NL@%
- switch (COMMANDMSG(&msg)->cmd) {%@NL@%
- case IDB_OK:%@NL@%
- WinDismissDlg (hwnd, TRUE);%@NL@%
- return 0;%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- return WinDefDlgProc (hwnd, msg, mp1, mp2);%@NL@%
- }%@NL@%
- %@NL@%
- MRESULT EXPENTRY DialogProc (HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2)%@NL@%
- {%@NL@%
- SWP swpDlg, swpParent, swpOwner;%@NL@%
- static HWND option, button1, button2, button3, button4;%@NL@%
- %@NL@%
- switch (msg) {%@NL@%
- %@NL@%
- case WM_INITDLG:%@NL@%
- WinSendDlgItemMsg (hDlg, 256, EM_SETTEXTLIMIT, MPFROMSHORT(8), 0L);%@NL@%
- WinQueryWindowPos (hDlg, &swpDlg);%@NL@%
- WinQueryWindowPos (WinQueryWindow(hDlg, QW_PARENT, FALSE), &swpParent);%@NL@%
- WinQueryWindowPos (WinQueryWindow(hDlg, QW_OWNER, FALSE), &swpOwner);%@NL@%
- swpDlg.x = swpOwner.x + ((swpOwner.cx / 2) - ((swpDlg.cx+120) / 2));%@NL@%
- swpDlg.y = swpOwner.y + ((swpOwner.cy / 2) - (swpDlg.cy / 2));%@NL@%
- WinSetMultWindowPos (hAB, &swpDlg, 1);%@NL@%
- option = WinWindowFromID (hDlg, IDB_OPTION);%@NL@%
- button1 = WinWindowFromID (hDlg, IDB_RADIO1);%@NL@%
- WinShowWindow (button1, FALSE);%@NL@%
- button2 = WinWindowFromID (hDlg, IDB_RADIO2);%@NL@%
- WinShowWindow (button2, FALSE);%@NL@%
- button3 = WinWindowFromID (hDlg, IDB_RADIO3);%@NL@%
- WinShowWindow (button3, FALSE);%@NL@%
- button4 = WinWindowFromID (hDlg, IDB_RADIO4);%@NL@%
- WinShowWindow (button4, FALSE);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (COMMANDMSG(&msg)->cmd) {%@NL@%
- case IDB_OPTION:%@NL@%
- WinQueryWindowPos (hDlg, &swpDlg);%@NL@%
- swpDlg.fs = SWP_SIZE;%@NL@%
- swpDlg.cx += 120;%@NL@%
- WinSetMultWindowPos (hAB, &swpDlg, 1);%@NL@%
- WinEnableWindow (option, FALSE);%@NL@%
- WinShowWindow (button1, TRUE);%@NL@%
- WinShowWindow (button2, TRUE);%@NL@%
- WinShowWindow (button3, TRUE);%@NL@%
- WinShowWindow (button4, TRUE);%@NL@%
- WinSetFocus (HWND_DESKTOP, button1);%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- case IDB_OK:%@NL@%
- case IDB_CANCEL:%@NL@%
- WinDismissDlg (hDlg, TRUE);%@NL@%
- return 0;%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- return WinDefDlgProc (hDlg, msg, mp1, mp2);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FATPEL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\FATPEL\FATPEL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* fatpel.c -- The Diamond Metric, Theory vs. Practice%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Created by Microsoft Corporation, 1989%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_WINFRAMEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINWINDOWMGR %@NL@%
- %@AI@%#define %@AE@%INCL_WINMESSAGEMGR %@NL@%
- %@AI@%#define %@AE@% INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WINSWITCHLIST %@NL@%
- %@AI@%#define %@AE@%INCL_WINTRACKRECT %@NL@%
- %@AI@%#define %@AE@%INCL_WINDIALOGS %@NL@%
- %@AI@%#define %@AE@%INCL_WINBUTTONS %@NL@%
- %@AI@%#define %@AE@%INCL_GPILOGCOLORTABLE %@NL@%
- %@AI@%#define %@AE@%INCL_GPIBITMAPS %@NL@%
- %@AI@%#define %@AE@% INCL_GPITRANSFORMS %@NL@%
- %@AI@%#define %@AE@%INCL_DOSMEMMGR %@NL@%
- %@AI@%#define %@AE@%INCL_DOSFILEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_BITMAPFILEFORMAT %@NL@%
- %@AI@%#define %@AE@%INCL_GPIPRIMITIVES %@NL@%
- %@AI@%#define %@AE@%INCL_WINMENUS %@NL@%
- %@AI@%#define %@AE@%INCL_GPIREGIONS %@NL@%
- %@AI@%#define %@AE@%INCL_WINPOINTERS %@NL@%
- %@AI@%#define %@AE@%INCL_WININPUT %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"opendlg.h" %@NL@%
- %@AI@%#include %@AE@%"fatpel.h" %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Function declarations%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Private functions */%@AE@%%@NL@%
- %@NL@%
- VOID cdecl main(VOID);%@NL@%
- BOOL FAR InitGlobals(VOID);%@NL@%
- BOOL FAR InitApp(VOID);%@NL@%
- VOID Close(HWND);%@NL@%
- VOID Command(HWND, USHORT);%@NL@%
- VOID Paint(HPS, USHORT);%@NL@%
- VOID EraseBackground(HPS);%@NL@%
- VOID DrawGrid(HPS);%@NL@%
- VOID DisplayRenderedPels(HPS, USHORT);%@NL@%
- VOID DisplayControlPoints(HPS, LONG, PPOINTL, USHORT);%@NL@%
- VOID DisplayMathematicalObject(HPS, USHORT);%@NL@%
- VOID DrawFatPels(HPS);%@NL@%
- VOID DrawOneFatPel(HPS, PPOINTL, COLOR);%@NL@%
- VOID GetFatPelFromPt(PPOINTL, PPOINTL);%@NL@%
- VOID SetFatPel(PPOINTL, COLOR);%@NL@%
- VOID RoundControlPoints(HPS, LONG, PPOINTL, PPOINTL, LONG, LONG);%@NL@%
- VOID ComputeTransform(PRECTL, PRECTL);%@NL@%
- VOID DrawPrimitive(HPS, LONG, PPOINTL);%@NL@%
- VOID UpdateSurfaceDims(VOID);%@NL@%
- VOID MySetWindowLong (HWND, USHORT, LONG);%@NL@%
- VOID MySetWindowLongHex(HWND, USHORT, LONG);%@NL@%
- LONG MyGetWindowLong (HWND, USHORT);%@NL@%
- VOID MouseMove(HWND, MPARAM);%@NL@%
- VOID ButtonUp(HWND, USHORT);%@NL@%
- VOID ButtonDown(HWND, USHORT, MPARAM);%@NL@%
- VOID DragPelSize(HWND, POINTS);%@NL@%
- VOID WriteFile(HWND, HPS);%@NL@%
- BOOL WriteBMP(HFILE, HPS, PBITMAPINFOHEADER);%@NL@%
- VOID MyMessageBox(HWND, PSZ);%@NL@%
- VOID SaveWindowToFile(HWND);%@NL@%
- SHORT IsPtInList(PPOINTL);%@NL@%
- SHORT AddPtToList(PPOINTL);%@NL@%
- BOOL IsPtCloseToLine(PPOINTL, PPOINTL, PPOINTL);%@NL@%
- VOID SwapLong(PLONG, PLONG);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Exported functions */%@AE@%%@NL@%
- %@NL@%
- ULONG CALLBACK WndProc (HWND, USHORT, MPARAM, MPARAM);%@NL@%
- ULONG CALLBACK AboutDlg (HWND, USHORT, MPARAM, MPARAM);%@NL@%
- ULONG CALLBACK ColorsDlg (HWND, USHORT, MPARAM, MPARAM);%@NL@%
- ULONG CALLBACK PelSizeDlg(HWND, USHORT, MPARAM, MPARAM);%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Global Variables%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* compute absolute value for arbitrary (in my case, LONG) number */%@AE@%%@NL@%
- %@AB@%/* this is to avoid compiler warnings about data conversion */%@AE@%%@NL@%
- %@AI@%#define %@AE@%L_ABS(x) (((x) > 0) ? (x) : (-(x))) %@NL@%
- %@NL@%
- typedef struct%@NL@%
- {%@NL@%
- HAB hab;%@NL@%
- HMQ hMsgQ;%@NL@%
- HWND hwndFrame;%@NL@%
- HWND hwnd;%@NL@%
- %@NL@%
- BOOL fFirstTime; %@AB@%/* TRUE --> first time initialization of rcl */%@AE@%%@NL@%
- RECTL rcl; %@AB@%/* dimensions of client rectangle */%@AE@%%@NL@%
- %@NL@%
- HPS hpsFat;%@NL@%
- HDC hdcFat;%@NL@%
- HBITMAP hbmFat;%@NL@%
- HPS hpsFatShadow;%@NL@%
- HDC hdcFatShadow;%@NL@%
- HBITMAP hbmFatShadow;%@NL@%
- %@NL@%
- RECTL rclFatBM; %@AB@%/* dimensions of fatbits bitmap */%@AE@%%@NL@%
- RECTL rclFat; %@AB@%/* dimensions of active fat bits grid */%@AE@%%@NL@%
- LONG cxFatPel; %@AB@%/* width of fat pel */%@AE@%%@NL@%
- LONG cyFatPel; %@AB@%/* height of fat pel */%@AE@%%@NL@%
- LONG cxHalfFatPel;%@NL@%
- LONG cyHalfFatPel;%@NL@%
- USHORT usPelShape;%@NL@%
- %@NL@%
- MATRIXLF matlf; %@AB@%/* goes from window coords to fatpel coords */%@AE@%%@NL@%
- %@NL@%
- BOOL fRGB; %@AB@%/* TRUE --> color mode is RGB */%@AE@%%@NL@%
- COLOR clrMathObj;%@NL@%
- COLOR clrRenderedObj;%@NL@%
- COLOR clrField;%@NL@%
- COLOR clrCrossHair;%@NL@%
- COLOR clrInterstice;%@NL@%
- COLOR clrControlPoints;%@NL@%
- %@NL@%
- COLOR clrBlackIndex;%@NL@%
- COLOR clrEditPel;%@NL@%
- %@NL@%
- USHORT usControlPointSymbol;%@NL@%
- %@NL@%
- BOOL fDisplayRenderedObj;%@NL@%
- BOOL fDisplayMathObj;%@NL@%
- BOOL fDisplayControlPoints;%@NL@%
- BOOL fDisplayCrossHairs;%@NL@%
- BOOL fDisplayPelBorder;%@NL@%
- BOOL fRoundControlPoints;%@NL@%
- BOOL fAutoRedraw;%@NL@%
- USHORT usCurPrim;%@NL@%
- USHORT usMix;%@NL@%
- %@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl;%@NL@%
- PPOINTL pptlTmp;%@NL@%
- %@NL@%
- BOOL fDraggingPelSize;%@NL@%
- HPOINTER hptrDragSize;%@NL@%
- %@NL@%
- BOOL fDraggingPelColor;%@NL@%
- HPOINTER hptrDragColor;%@NL@%
- %@NL@%
- SHORT sPtGrabbed;%@NL@%
- BOOL fDraggingControlPoint;%@NL@%
- LONG lHitPrecision;%@NL@%
- %@NL@%
- BOOL fEditPelColors;%@NL@%
- %@NL@%
- } GLOBALDATA;%@NL@%
- GLOBALDATA global;%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* main%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WinInitialize resizes our ring 2 stack, among other things, so%@NL@%
- %@AB@%* we won't GP fault trying to do graphics. WinCreateMsgQueue defines%@NL@%
- %@AB@%* us as a REAL PM app. (WINDOWAPI in .DEF file does also).%@NL@%
- %@AB@%* Call a sub to register our window class and create a window.%@NL@%
- %@AB@%* Loop over messages. Exit cleanly.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID cdecl%@NL@%
- main()%@NL@%
- {%@NL@%
- QMSG qMsg;%@NL@%
- int iRet = 0;%@NL@%
- %@NL@%
- %@NL@%
- global.hab = WinInitialize(0);%@NL@%
- global.hMsgQ = WinCreateMsgQueue(global.hab, 0);%@NL@%
- %@NL@%
- if (InitApp())%@NL@%
- while (WinGetMsg( global.hab, (PQMSG)&qMsg, (HWND)NULL, 0, 0 ))%@NL@%
- WinDispatchMsg( global.hab, (PQMSG)&qMsg );%@NL@%
- else%@NL@%
- iRet = -1;%@NL@%
- %@NL@%
- WinDestroyWindow( global.hwndFrame );%@NL@%
- WinDestroyMsgQueue( global.hMsgQ );%@NL@%
- WinTerminate( global.hab );%@NL@%
- DosExit(EXIT_PROCESS, iRet);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* InitGlobals%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Initialize global variables.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL FAR%@NL@%
- InitGlobals()%@NL@%
- {%@NL@%
- global.fFirstTime = TRUE;%@NL@%
- %@NL@%
- global.rcl.xLeft = 0L;%@NL@%
- global.rcl.yBottom = 0L;%@NL@%
- global.rcl.xRight = 0L;%@NL@%
- global.rcl.yTop = 0L;%@NL@%
- %@NL@%
- global.hpsFat = NULL;%@NL@%
- global.hdcFat = NULL;%@NL@%
- global.hbmFat = NULL;%@NL@%
- global.hpsFatShadow = NULL;%@NL@%
- global.hdcFatShadow = NULL;%@NL@%
- global.hbmFatShadow = NULL;%@NL@%
- global.rclFatBM.xLeft = 0L;%@NL@%
- global.rclFatBM.yBottom = 0L;%@NL@%
- global.rclFatBM.xRight = 0L;%@NL@%
- global.rclFatBM.yTop = 0L;%@NL@%
- %@NL@%
- global.cxFatPel = 32L;%@NL@%
- global.cyFatPel = 32L;%@NL@%
- global.cxHalfFatPel = global.cxFatPel / 2L;%@NL@%
- global.cyHalfFatPel = global.cyFatPel / 2L;%@NL@%
- global.usPelShape = IDD_CIRCLE;%@NL@%
- %@NL@%
- global.fRGB = FALSE;%@NL@%
- global.clrMathObj = CLR_BLUE;%@NL@%
- global.clrRenderedObj = CLR_NEUTRAL;%@NL@%
- global.clrField = CLR_CYAN;%@NL@%
- global.clrCrossHair = CLR_DARKCYAN;%@NL@%
- global.clrInterstice = CLR_BACKGROUND;%@NL@%
- global.clrControlPoints = CLR_YELLOW;%@NL@%
- %@NL@%
- global.clrBlackIndex = CLR_ERROR;%@NL@%
- global.clrEditPel = CLR_ERROR;%@NL@%
- %@NL@%
- global.usControlPointSymbol = MARKSYM_SOLIDDIAMOND;%@NL@%
- %@NL@%
- global.fDisplayRenderedObj = TRUE;%@NL@%
- global.fDisplayMathObj = TRUE;%@NL@%
- global.fDisplayControlPoints = TRUE;%@NL@%
- global.fDisplayCrossHairs = TRUE;%@NL@%
- global.fDisplayPelBorder = TRUE;%@NL@%
- global.fRoundControlPoints = FALSE;%@NL@%
- global.fAutoRedraw = TRUE;%@NL@%
- global.usCurPrim = IDM_POLYLINE;%@NL@%
- global.usMix = FM_OVERPAINT;%@NL@%
- %@NL@%
- global.fDraggingPelSize = FALSE;%@NL@%
- global.fDraggingPelColor = FALSE;%@NL@%
- global.fDraggingControlPoint = FALSE;%@NL@%
- global.sPtGrabbed = NO_POINT;%@NL@%
- global.lHitPrecision = 0L;%@NL@%
- %@NL@%
- global.fEditPelColors = FALSE;%@NL@%
- %@NL@%
- %@NL@%
- global.cptl = 0L;%@NL@%
- global.pptl = NULL;%@NL@%
- if (DosAllocSeg(CPTLMAX * sizeof(POINTL),%@NL@%
- ((PUSHORT)&global.pptl)+1, 0))%@NL@%
- return FALSE;%@NL@%
- global.pptlTmp = NULL;%@NL@%
- if (DosAllocSeg(CPTLMAX * sizeof(POINTL),%@NL@%
- ((PUSHORT)&global.pptlTmp)+1, 0))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/****************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* InitApp%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Register application window class and creates standard window.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%****************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INIT_MENU_ITEM(val, var) \ %@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, (val), (var))%@NL@%
- %@NL@%
- BOOL FAR%@NL@%
- InitApp()%@NL@%
- {%@NL@%
- char szTitle[24];%@NL@%
- ULONG ctldata;%@NL@%
- PID pid;%@NL@%
- TID tid;%@NL@%
- HSWITCH hsw;%@NL@%
- static SWCNTRL swctl = { 0, 0, 0, 0, 0, SWL_VISIBLE,%@NL@%
- SWL_JUMPABLE, "FatPels", 0 };%@NL@%
- %@NL@%
- if (!InitGlobals())%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Register Application Window Class */%@AE@%%@NL@%
- %@NL@%
- WinLoadString( global.hab, (HMODULE) NULL, IDS_TITLE, sizeof(szTitle), (PCH)szTitle );%@NL@%
- if ( !WinRegisterClass( global.hab, (PCH)szTitle, (PFNWP)WndProc,%@NL@%
- CS_SIZEREDRAW, 0 ))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Load the pointer to use when dragging pel size. */%@AE@%%@NL@%
- if (!(global.hptrDragSize = WinLoadPointer( HWND_DESKTOP, (HMODULE) NULL, IDR_DRAGSIZEPTR )))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@AB@%/* Load the pointer to use when dragging pel color. */%@AE@%%@NL@%
- if (!(global.hptrDragColor = WinLoadPointer( HWND_DESKTOP, (HMODULE) NULL, IDR_DRAGCOLORPTR )))%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Create a window instance of class "FatPel" */%@AE@%%@NL@%
- %@NL@%
- ctldata = FCF_STANDARD &%@NL@%
- ~(ULONG)(FCF_ICON | FCF_ACCELTABLE | FCF_TASKLIST);%@NL@%
- %@NL@%
- if (global.hwndFrame = WinCreateStdWindow(%@NL@%
- HWND_DESKTOP, %@AB@%/* specify desktop as parent window */%@AE@%%@NL@%
- WS_VISIBLE, %@AB@%/* window styles */%@AE@%%@NL@%
- &ctldata, %@AB@%/* frame creation flags */%@AE@%%@NL@%
- (PCH)szTitle, %@AB@%/* window class name */%@AE@%%@NL@%
- (PCH)szTitle, %@AB@%/* name appearing in window caption */%@AE@%%@NL@%
- 0L, %@AB@%/* */%@AE@%%@NL@%
- (HMODULE)NULL, %@AB@%/* use current executable module id */%@AE@%%@NL@%
- IDR_FATPEL, %@AB@%/* menu id */%@AE@%%@NL@%
- (HWND FAR *)&global.hwnd %@AB@%/* window handle */%@AE@%%@NL@%
- ))%@NL@%
- {%@NL@%
- INIT_MENU_ITEM(IDM_RENDEREDOBJ, global.fDisplayRenderedObj);%@NL@%
- INIT_MENU_ITEM(IDM_MATHOBJ, global.fDisplayMathObj);%@NL@%
- INIT_MENU_ITEM(IDM_CTLPOINTS, global.fDisplayControlPoints);%@NL@%
- INIT_MENU_ITEM(IDM_CROSSHAIRS, global.fDisplayCrossHairs);%@NL@%
- INIT_MENU_ITEM(IDM_PELBORDER, global.fDisplayPelBorder);%@NL@%
- INIT_MENU_ITEM(IDM_ROUNDPOINTS, global.fRoundControlPoints);%@NL@%
- INIT_MENU_ITEM(IDM_AUTOREDRAW, global.fAutoRedraw);%@NL@%
- INIT_MENU_ITEM(IDM_EDITPELCOLORS, global.fEditPelColors);%@NL@%
- %@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, global.usCurPrim);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Add ourselves to the switch list. */%@AE@%%@NL@%
- %@NL@%
- WinQueryWindowProcess(global.hwndFrame, &pid, &tid);%@NL@%
- swctl.hwnd = global.hwndFrame;%@NL@%
- swctl.idProcess = pid;%@NL@%
- hsw = WinAddSwitchEntry(&swctl);%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WndProc%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Process messages for the window class.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- ULONG CALLBACK%@NL@%
- WndProc( hwnd, usMsg, mp1, mp2 )%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch (usMsg)%@NL@%
- {%@NL@%
- case WM_CLOSE:%@NL@%
- Close(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- Command(hwnd, LOUSHORT(mp1));%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_PAINT:%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- if (global.fFirstTime)%@NL@%
- {%@NL@%
- SIZEF sizfx;%@NL@%
- %@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- GpiQueryMarkerBox(hps, &sizfx);%@NL@%
- global.lHitPrecision = sizfx.cx / 0x20000L + 1L;%@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- UpdateSurfaceDims();%@NL@%
- global.fFirstTime = FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* The small bitmap may have been resized since we last%@NL@%
- %@AB@% * painted, in which case it will have been initialized to%@NL@%
- %@AB@% * the field color. Therefore, we will render the mathematical%@NL@%
- %@AB@% * object to make sure the right fatpels are there.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- global.usMix = FM_OVERPAINT;%@NL@%
- hps = WinBeginPaint(global.hwnd, NULL, NULL);%@NL@%
- Paint(hps, CLEAR_BACKGROUND|RENDER_MATH_OBJ);%@NL@%
- WinEndPaint(hps);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1DOWN:%@NL@%
- case WM_BUTTON2DOWN:%@NL@%
- ButtonDown(hwnd, usMsg, mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_BUTTON1UP:%@NL@%
- case WM_BUTTON2UP:%@NL@%
- ButtonUp(hwnd, usMsg);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_MOUSEMOVE:%@NL@%
- MouseMove(hwnd, mp1);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_SIZE:%@NL@%
- UpdateSurfaceDims();%@NL@%
- return( (ULONG)WinDefWindowProc(hwnd, usMsg, mp1, mp2));%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return( (ULONG)WinDefWindowProc(hwnd, usMsg, mp1, mp2));%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MouseMove%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MouseMove(hwnd, mp1)%@NL@%
- HWND hwnd;%@NL@%
- MPARAM mp1;%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* make sure we still have our pointer */%@AE@%%@NL@%
- %@AB@%/* notice the hierarchy of pointer modes */%@AE@%%@NL@%
- %@NL@%
- if (global.fDraggingPelSize)%@NL@%
- {%@NL@%
- if (global.hptrDragSize)%@NL@%
- WinSetPointer(HWND_DESKTOP,global.hptrDragSize);%@NL@%
- }%@NL@%
- else if (global.fEditPelColors)%@NL@%
- {%@NL@%
- if (global.hptrDragColor)%@NL@%
- WinSetPointer(HWND_DESKTOP,global.hptrDragColor);%@NL@%
- }%@NL@%
- else%@NL@%
- WinSetPointer(HWND_DESKTOP,%@NL@%
- WinQuerySysPointer(HWND_DESKTOP,SPTR_ARROW,FALSE));%@NL@%
- %@NL@%
- %@NL@%
- if (global.fDraggingPelColor)%@NL@%
- {%@NL@%
- POINTL ptl, ptlFat;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- %@AB@%/* letting the point go negative causes overflow errors */%@AE@%%@NL@%
- if (ptl.x < 0)%@NL@%
- ptl.x = 0;%@NL@%
- if (ptl.y < 0)%@NL@%
- ptl.y = 0;%@NL@%
- %@NL@%
- GetFatPelFromPt(&ptl, &ptlFat);%@NL@%
- SetFatPel(&ptlFat, global.clrEditPel);%@NL@%
- %@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, OVERRIDE_RENDERED_OBJ);%@NL@%
- Paint(hps, IGNORED); %@AB@%/* this call just copies fatpels to the screen */%@AE@%%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- else if (global.fDraggingControlPoint)%@NL@%
- {%@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- %@AB@%/* letting the point go negative causes overflow errors */%@AE@%%@NL@%
- if (ptl.x < 0)%@NL@%
- ptl.x = 0;%@NL@%
- if (ptl.y < 0)%@NL@%
- ptl.y = 0;%@NL@%
- %@NL@%
- if (global.sPtGrabbed != NO_POINT)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, OVERRIDE_RENDERED_OBJ);%@NL@%
- %@NL@%
- global.pptl[global.sPtGrabbed] = ptl;%@NL@%
- %@NL@%
- Paint(hps, CLEAR_FAT_BITMAP|RENDER_MATH_OBJ);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ButtonUp%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- ButtonUp(hwnd, usMsg)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- {%@NL@%
- SHORT i;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@NL@%
- if (global.fDraggingPelColor)%@NL@%
- {%@NL@%
- global.fDraggingPelColor = FALSE;%@NL@%
- WinSetCapture(HWND_DESKTOP, NULL);%@NL@%
- }%@NL@%
- else if (global.fDraggingControlPoint)%@NL@%
- {%@NL@%
- global.fDraggingControlPoint = FALSE;%@NL@%
- WinSetCapture(HWND_DESKTOP, NULL);%@NL@%
- if (global.sPtGrabbed != NO_POINT)%@NL@%
- {%@NL@%
- if (usMsg == WM_BUTTON2UP) %@AB@%/* remove point? */%@AE@%%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, OVERRIDE_RENDERED_OBJ);%@NL@%
- %@NL@%
- %@AB@%/* squeeze out selected point */%@AE@%%@NL@%
- if ((i = global.sPtGrabbed) < (SHORT)(global.cptl-1))%@NL@%
- while (i < (SHORT)(global.cptl-1))%@NL@%
- {%@NL@%
- global.pptl[i] = global.pptl[i+1];%@NL@%
- ++i;%@NL@%
- }%@NL@%
- %@NL@%
- --global.cptl;%@NL@%
- global.sPtGrabbed = NO_POINT;%@NL@%
- %@NL@%
- Paint(hps, CLEAR_FAT_BITMAP|RENDER_MATH_OBJ);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- else %@AB@%/* WM_BUTTON1UP */%@AE@%%@NL@%
- global.sPtGrabbed = NO_POINT;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ButtonDown%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- ButtonDown(hwnd, usMsg, mp1)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- {%@NL@%
- if (global.fDraggingPelSize)%@NL@%
- {%@NL@%
- POINTS pt;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- pt.x = LOUSHORT(mp1);%@NL@%
- pt.y = HIUSHORT(mp1);%@NL@%
- DragPelSize(hwnd, pt);%@NL@%
- global.fDraggingPelSize = FALSE;%@NL@%
- %@NL@%
- WinSetPointer(HWND_DESKTOP,%@NL@%
- WinQuerySysPointer(HWND_DESKTOP,SPTR_ARROW,FALSE));%@NL@%
- %@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- global.usMix = FM_OVERPAINT;%@NL@%
- Paint(hps, CLEAR_BACKGROUND|CLEAR_FAT_BITMAP|RENDER_MATH_OBJ);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- else if (global.fEditPelColors)%@NL@%
- {%@NL@%
- POINTL ptl, ptlFat;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- global.fDraggingPelColor = TRUE;%@NL@%
- WinSetCapture(HWND_DESKTOP, hwnd);%@NL@%
- %@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- if (global.usMix != FM_XOR)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- global.usMix = FM_XOR;%@NL@%
- Paint(hps, CLEAR_BACKGROUND);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- %@NL@%
- if (usMsg == WM_BUTTON1DOWN)%@NL@%
- global.clrEditPel = global.clrRenderedObj;%@NL@%
- else%@NL@%
- global.clrEditPel = global.clrField;%@NL@%
- %@NL@%
- GetFatPelFromPt(&ptl, &ptlFat);%@NL@%
- SetFatPel(&ptlFat, global.clrEditPel);%@NL@%
- %@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- Paint(hps, OVERRIDE_RENDERED_OBJ);%@NL@%
- Paint(hps, IGNORED); %@AB@%/* this call just copies fatpels to the screen */%@AE@%%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- else if (!global.fDraggingControlPoint)%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- SHORT sNewPtGrabbed;%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- global.fDraggingControlPoint = TRUE;%@NL@%
- WinSetCapture(HWND_DESKTOP, hwnd);%@NL@%
- %@NL@%
- ptl.x = (LONG) LOUSHORT(mp1);%@NL@%
- ptl.y = (LONG) HIUSHORT(mp1);%@NL@%
- %@NL@%
- sNewPtGrabbed = IsPtInList(&ptl);%@NL@%
- %@NL@%
- if (global.usMix != FM_XOR)%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- global.usMix = FM_XOR;%@NL@%
- Paint(hps, CLEAR_BACKGROUND);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- %@NL@%
- if (usMsg == WM_BUTTON1DOWN) %@AB@%/* add/move point? */%@AE@%%@NL@%
- {%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- %@NL@%
- if (sNewPtGrabbed != NO_POINT)%@NL@%
- global.sPtGrabbed = sNewPtGrabbed;%@NL@%
- Paint(hps, OVERRIDE_RENDERED_OBJ);%@NL@%
- %@NL@%
- if (sNewPtGrabbed == NO_POINT)%@NL@%
- global.sPtGrabbed = AddPtToList(&ptl);%@NL@%
- else%@NL@%
- global.sPtGrabbed = sNewPtGrabbed;%@NL@%
- %@NL@%
- Paint(hps, CLEAR_FAT_BITMAP|RENDER_MATH_OBJ);%@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- if (global.sPtGrabbed == NO_POINT)%@NL@%
- MyMessageBox(global.hwnd, "Cannot add any more points.");%@NL@%
- }%@NL@%
- else if (sNewPtGrabbed != NO_POINT)%@NL@%
- global.sPtGrabbed = sNewPtGrabbed;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* GetFatPelFromPt%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- GetFatPelFromPt(pptl, pptlFat)%@NL@%
- PPOINTL pptl;%@NL@%
- PPOINTL pptlFat;%@NL@%
- {%@NL@%
- pptlFat->x = pptl->x / global.cxFatPel;%@NL@%
- pptlFat->y = pptl->y / global.cyFatPel;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* SetFatPel%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- SetFatPel(pptl, clr)%@NL@%
- PPOINTL pptl;%@NL@%
- COLOR clr;%@NL@%
- {%@NL@%
- LINEBUNDLE lb;%@NL@%
- %@NL@%
- if (global.hpsFat)%@NL@%
- {%@NL@%
- lb.lColor = clr;%@NL@%
- GpiSetAttrs(global.hpsFat, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- GpiSetPel(global.hpsFat, pptl);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* IsPtInList%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- SHORT%@NL@%
- IsPtInList(pptl)%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- SHORT i;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* try to find pptl in the points we already have */%@AE@%%@NL@%
- for (i = 0; i < (SHORT)global.cptl; ++i)%@NL@%
- if (((L_ABS(pptl->x - global.pptl[i].x)) <= global.lHitPrecision) &&%@NL@%
- ((L_ABS(pptl->y - global.pptl[i].y)) <= global.lHitPrecision))%@NL@%
- return i;%@NL@%
- %@NL@%
- %@AB@%/* couldn't find it */%@AE@%%@NL@%
- return NO_POINT;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* AddPtToList%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- SHORT%@NL@%
- AddPtToList(pptl)%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- SHORT i, j;%@NL@%
- %@NL@%
- if (global.cptl < CPTLMAX)%@NL@%
- {%@NL@%
- %@AB@%/* check for new points lying on a line segment */%@AE@%%@NL@%
- for (i = 0; i < (SHORT)(global.cptl-1L); ++i)%@NL@%
- if (IsPtCloseToLine(&global.pptl[i], &global.pptl[i+1], pptl))%@NL@%
- {%@NL@%
- %@AB@%/* insert point between endpoints of nearest line segment */%@AE@%%@NL@%
- for (j = (SHORT)global.cptl; j > i+1; --j)%@NL@%
- global.pptl[j] = global.pptl[j - 1];%@NL@%
- global.pptl[i+1] = *pptl;%@NL@%
- ++global.cptl;%@NL@%
- return i+1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* append the point */%@AE@%%@NL@%
- %@NL@%
- i = (SHORT) global.cptl;%@NL@%
- global.pptl[i] = *pptl;%@NL@%
- ++global.cptl;%@NL@%
- return i;%@NL@%
- }%@NL@%
- %@NL@%
- return NO_POINT;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* IsPtCloseToLine%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL%@NL@%
- IsPtCloseToLine(pptl1, pptl2, pptlTest)%@NL@%
- PPOINTL pptl1;%@NL@%
- PPOINTL pptl2;%@NL@%
- PPOINTL pptlTest;%@NL@%
- {%@NL@%
- POINTL ptlLL, ptlUR;%@NL@%
- LONG dx, dy, yIntercept, error;%@NL@%
- LONG lBoxAdjustment;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* find the bounding box of the line segment */%@AE@%%@NL@%
- %@NL@%
- ptlLL = *pptl1; %@AB@%/* assume line goes lower left to upper right */%@AE@%%@NL@%
- ptlUR = *pptl2;%@NL@%
- if (pptl1->x > pptl2->x)%@NL@%
- SwapLong(&ptlLL.x, &ptlUR.x);%@NL@%
- if (pptl1->y > pptl2->y)%@NL@%
- SwapLong(&ptlLL.y, &ptlUR.y);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* adjust the bounding box if it's too narrow */%@AE@%%@NL@%
- %@NL@%
- lBoxAdjustment = global.lHitPrecision/2L;%@NL@%
- %@NL@%
- dx = pptl2->x - pptl1->x;%@NL@%
- if (L_ABS(dx) <= global.lHitPrecision)%@NL@%
- {%@NL@%
- ptlLL.x -= lBoxAdjustment;%@NL@%
- ptlUR.x += lBoxAdjustment;%@NL@%
- }%@NL@%
- dy = pptl2->y - pptl1->y;%@NL@%
- if (L_ABS(dy) <= global.lHitPrecision)%@NL@%
- {%@NL@%
- ptlLL.y -= lBoxAdjustment;%@NL@%
- ptlUR.y += lBoxAdjustment;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* see if the test point is in the bounding box of the line segment */%@AE@%%@NL@%
- %@NL@%
- if ((pptlTest->x >= ptlLL.x) &&%@NL@%
- (pptlTest->x <= ptlUR.x) &&%@NL@%
- (pptlTest->y >= ptlLL.y) &&%@NL@%
- (pptlTest->y <= ptlUR.y))%@NL@%
- {%@NL@%
- %@AB@%/* test for special cases */%@AE@%%@NL@%
- %@NL@%
- if (dx == 0) %@AB@%/* vertical line */%@AE@%%@NL@%
- {%@NL@%
- return (L_ABS(pptlTest->x - pptl1->x) <= global.lHitPrecision);%@NL@%
- }%@NL@%
- %@NL@%
- if (dy == 0) %@AB@%/* horizontal line */%@AE@%%@NL@%
- {%@NL@%
- return (L_ABS(pptlTest->y - pptl1->y) <= global.lHitPrecision);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* test for general case */%@AE@%%@NL@%
- %@NL@%
- yIntercept = pptl1->y - (pptl1->x * dy) / dx;%@NL@%
- %@NL@%
- error = pptlTest->y - (pptlTest->x * dy / dx) - yIntercept;%@NL@%
- if (L_ABS(error) <= global.lHitPrecision)%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- %@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* SwapLong%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- SwapLong(pl1, pl2)%@NL@%
- PLONG pl1, pl2;%@NL@%
- {%@NL@%
- LONG lTmp;%@NL@%
- %@NL@%
- lTmp = *pl1;%@NL@%
- *pl1 = *pl2;%@NL@%
- *pl2 = lTmp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DragPelSize%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Set the dimensions of a fat pel by dragging a rectangle%@NL@%
- %@AB@%* on the screen.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DragPelSize(hwnd, pt)%@NL@%
- HWND hwnd;%@NL@%
- POINTS pt;%@NL@%
- {%@NL@%
- TRACKINFO ti;%@NL@%
- %@NL@%
- WinSendMsg(global.hwndFrame, WM_QUERYTRACKINFO, (MPARAM)TF_MOVE, (MPARAM)&ti);%@NL@%
- %@NL@%
- ti.cxBorder = 1;%@NL@%
- ti.cyBorder = 1;%@NL@%
- ti.rclTrack.xLeft = (LONG)pt.x;%@NL@%
- ti.rclTrack.yBottom = (LONG)pt.y;%@NL@%
- ti.rclTrack.xRight = (LONG)pt.x;%@NL@%
- ti.rclTrack.yTop = (LONG)pt.y;%@NL@%
- ti.fs = TF_RIGHT | TF_TOP;%@NL@%
- ti.ptlMinTrackSize.x = 1L;%@NL@%
- ti.ptlMinTrackSize.y = 1L;%@NL@%
- %@NL@%
- if (WinTrackRect(hwnd, NULL, &ti))%@NL@%
- {%@NL@%
- global.cxFatPel = (ti.rclTrack.xRight - ti.rclTrack.xLeft) ;%@NL@%
- global.cyFatPel = (ti.rclTrack.yTop - ti.rclTrack.yBottom);%@NL@%
- %@NL@%
- if (global.cxFatPel < 1L)%@NL@%
- global.cxFatPel = 1L;%@NL@%
- %@NL@%
- if (global.cyFatPel < 1L)%@NL@%
- global.cyFatPel = 1L;%@NL@%
- %@NL@%
- global.cxHalfFatPel = global.cxFatPel / 2L;%@NL@%
- global.cyHalfFatPel = global.cyFatPel / 2L;%@NL@%
- %@NL@%
- UpdateSurfaceDims();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Close%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- Close(hwnd)%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- if (global.hptrDragSize)%@NL@%
- WinDestroyPointer(global.hptrDragSize);%@NL@%
- WinPostMsg(hwnd, WM_QUIT, 0L, 0L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Command%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Dispatches menu commands to the proper handlers.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%UPDATE_MENU_BOOL(var, val) \ %@NL@%
- { \%@NL@%
- TOGGLE_BOOL((var)); \%@NL@%
- TOGGLE_MENU_ITEM(global.hwndFrame, (val), (var)); \%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%UPDATE_MENU_LIST(var, val) \ %@NL@%
- { \%@NL@%
- UNCHECK_MENU_ITEM(global.hwndFrame, (var)); \%@NL@%
- (var) = (val); \%@NL@%
- CHECK_MENU_ITEM(global.hwndFrame, (var)); \%@NL@%
- }%@NL@%
- %@NL@%
- VOID%@NL@%
- Command(hwnd, id)%@NL@%
- HWND hwnd;%@NL@%
- USHORT id;%@NL@%
- {%@NL@%
- BOOL fRedraw = FALSE;%@NL@%
- USHORT fsCmd = IGNORED;%@NL@%
- %@NL@%
- %@NL@%
- switch (id)%@NL@%
- {%@NL@%
- case IDM_SAVE:%@NL@%
- SaveWindowToFile(hwnd);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_ABOUT:%@NL@%
- WinDlgBox( HWND_DESKTOP, hwnd, (PFNWP)AboutDlg, (HMODULE) NULL,%@NL@%
- IDR_ABOUTDLG, NULL );%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_REDRAW:%@NL@%
- fsCmd = CLEAR_BACKGROUND|CLEAR_FAT_BITMAP|RENDER_MATH_OBJ;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_SETPELSIZE:%@NL@%
- {%@NL@%
- LONG cxFatPel, cyFatPel;%@NL@%
- %@NL@%
- cxFatPel = global.cxFatPel;%@NL@%
- cyFatPel = global.cyFatPel;%@NL@%
- %@NL@%
- if (WinDlgBox( HWND_DESKTOP, hwnd, (PFNWP)PelSizeDlg, (HMODULE) NULL,%@NL@%
- IDR_PELSIZEDLG, NULL ))%@NL@%
- {%@NL@%
- if ((cxFatPel == global.cxFatPel) &&%@NL@%
- (cyFatPel == global.cyFatPel))%@NL@%
- fsCmd = CLEAR_BACKGROUND;%@NL@%
- else%@NL@%
- fsCmd = CLEAR_BACKGROUND|CLEAR_FAT_BITMAP|RENDER_MATH_OBJ;%@NL@%
- fRedraw = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_DRAGPELSIZE:%@NL@%
- global.fDraggingPelSize = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_RENDEREDOBJ:%@NL@%
- UPDATE_MENU_BOOL(global.fDisplayRenderedObj, IDM_RENDEREDOBJ);%@NL@%
- fsCmd = CLEAR_BACKGROUND|CLEAR_FAT_BITMAP|RENDER_MATH_OBJ;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_MATHOBJ:%@NL@%
- UPDATE_MENU_BOOL(global.fDisplayMathObj, IDM_MATHOBJ);%@NL@%
- fsCmd = CLEAR_BACKGROUND;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_CTLPOINTS:%@NL@%
- UPDATE_MENU_BOOL(global.fDisplayControlPoints, IDM_CTLPOINTS);%@NL@%
- fsCmd = CLEAR_BACKGROUND;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_CROSSHAIRS:%@NL@%
- UPDATE_MENU_BOOL(global.fDisplayCrossHairs, IDM_CROSSHAIRS);%@NL@%
- fsCmd = CLEAR_BACKGROUND;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_PELBORDER:%@NL@%
- UPDATE_MENU_BOOL(global.fDisplayPelBorder, IDM_PELBORDER);%@NL@%
- fsCmd = CLEAR_BACKGROUND;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_ROUNDPOINTS:%@NL@%
- UPDATE_MENU_BOOL(global.fRoundControlPoints, IDM_ROUNDPOINTS);%@NL@%
- fsCmd = CLEAR_BACKGROUND;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_AUTOREDRAW:%@NL@%
- UPDATE_MENU_BOOL(global.fAutoRedraw, IDM_AUTOREDRAW);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_NOPRIM:%@NL@%
- case IDM_POLYLINE:%@NL@%
- case IDM_POLYFILLET:%@NL@%
- case IDM_POLYSPLINE:%@NL@%
- case IDM_POINTARC:%@NL@%
- UPDATE_MENU_LIST(global.usCurPrim, id);%@NL@%
- fsCmd = CLEAR_BACKGROUND|CLEAR_FAT_BITMAP|RENDER_MATH_OBJ;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_SETCOLORS:%@NL@%
- if (WinDlgBox( HWND_DESKTOP, hwnd, (PFNWP)ColorsDlg, (HMODULE) NULL,%@NL@%
- IDR_COLORSDLG, NULL ))%@NL@%
- {%@NL@%
- fsCmd = CLEAR_BACKGROUND|RENDER_MATH_OBJ;%@NL@%
- fRedraw = TRUE;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_EDITPELCOLORS:%@NL@%
- UPDATE_MENU_BOOL(global.fEditPelColors, IDM_EDITPELCOLORS);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_CLEARALL:%@NL@%
- global.cptl = 0L;%@NL@%
- fsCmd = CLEAR_BACKGROUND|CLEAR_FAT_BITMAP|RENDER_MATH_OBJ;%@NL@%
- fRedraw = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if ((global.fAutoRedraw && fRedraw) || (id == IDM_REDRAW))%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- global.usMix = FM_OVERPAINT;%@NL@%
- Paint(hps, fsCmd);%@NL@%
- WinReleasePS(hps);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Paint%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- Paint(hps, fsCmd)%@NL@%
- HPS hps;%@NL@%
- USHORT fsCmd;%@NL@%
- {%@NL@%
- HRGN hrgn, hrgnClipOld, hrgnT;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Clear the unused part of the client rectangle to a hatch pattern. */%@AE@%%@NL@%
- if (fsCmd & CLEAR_BACKGROUND)%@NL@%
- EraseBackground(hps);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Set up the color mode as the user has requested */%@AE@%%@NL@%
- %@NL@%
- if (global.fRGB)%@NL@%
- {%@NL@%
- GpiCreateLogColorTable(hps, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL);%@NL@%
- if (global.hpsFat)%@NL@%
- {%@NL@%
- GpiCreateLogColorTable(global.hpsFat, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL);%@NL@%
- GpiCreateLogColorTable(global.hpsFatShadow, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL);%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- if (global.hpsFat)%@NL@%
- {%@NL@%
- GpiCreateLogColorTable(global.hpsFat, LCOL_RESET, LCOLF_INDRGB, 0L, 0L, NULL);%@NL@%
- GpiCreateLogColorTable(global.hpsFatShadow, LCOL_RESET, LCOLF_INDRGB, 0L, 0L, NULL);%@NL@%
- global.clrBlackIndex = GpiQueryColorIndex(hps, 0L, 0x000000L);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- if (global.usPelShape == IDD_CIRCLE)%@NL@%
- {%@NL@%
- ARCPARAMS arcp;%@NL@%
- %@NL@%
- arcp.lP = global.cxFatPel / 2L;%@NL@%
- arcp.lQ = global.cyFatPel / 2L;%@NL@%
- arcp.lR = 0L;%@NL@%
- arcp.lS = 0L;%@NL@%
- %@NL@%
- GpiSetArcParams(hps, &arcp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* set clipping rectangle to the fatbit surface */%@AE@%%@NL@%
- %@NL@%
- if ((hrgn = GpiCreateRegion(hps, 1L, &global.rcl)) != HRGN_ERROR)%@NL@%
- GpiSetClipRegion(hps, hrgn, &hrgnClipOld);%@NL@%
- %@NL@%
- %@NL@%
- if (fsCmd & CLEAR_BACKGROUND)%@NL@%
- {%@NL@%
- DrawGrid(hps);%@NL@%
- %@NL@%
- if (global.hpsFatShadow)%@NL@%
- {%@NL@%
- AREABUNDLE ab;%@NL@%
- %@NL@%
- %@AB@%/* clear shadow fatpel surface to background color */%@AE@%%@NL@%
- ab.lColor = global.clrField;%@NL@%
- GpiSetAttrs(global.hpsFatShadow, PRIM_AREA, ABB_COLOR, 0L, &ab);%@NL@%
- GpiBitBlt(global.hpsFatShadow, NULL, 2L, (PPOINTL)&global.rclFat, ROP_PATCOPY,(ULONG) 0);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if (global.fDisplayRenderedObj && !(fsCmd & OVERRIDE_RENDERED_OBJ))%@NL@%
- DisplayRenderedPels(hps, fsCmd);%@NL@%
- %@NL@%
- if (global.fDisplayControlPoints)%@NL@%
- {%@NL@%
- %@AB@%/* when rubberbanding with the rendered obj, newly drawn fatpels%@NL@%
- %@AB@% * can wipe out stationary control point markers, so we have to%@NL@%
- %@AB@% * redraw them all each time%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if (global.fDisplayRenderedObj || (fsCmd & CLEAR_BACKGROUND))%@NL@%
- DisplayControlPoints(hps, global.cptl, global.pptl, global.usMix);%@NL@%
- else if (global.sPtGrabbed != NO_POINT)%@NL@%
- %@AB@%/* draw just the control point that moved */%@AE@%%@NL@%
- DisplayControlPoints(hps, 1L, global.pptl+global.sPtGrabbed, global.usMix);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.fDisplayMathObj)%@NL@%
- DisplayMathematicalObject(hps, global.usMix);%@NL@%
- %@NL@%
- %@AB@%/* delete the clip region we set up */%@AE@%%@NL@%
- %@NL@%
- if (hrgnClipOld != HRGN_ERROR)%@NL@%
- GpiSetClipRegion(hps, hrgnClipOld, &hrgnT);%@NL@%
- if (hrgn != HRGN_ERROR)%@NL@%
- GpiDestroyRegion(hps, hrgn);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DisplayMathematicalObject%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DisplayMathematicalObject(hps, usMix)%@NL@%
- HPS hps;%@NL@%
- USHORT usMix;%@NL@%
- {%@NL@%
- PPOINTL pptl;%@NL@%
- LINEBUNDLE lb;%@NL@%
- %@NL@%
- if (global.cptl > 0)%@NL@%
- {%@NL@%
- if (global.fRoundControlPoints)%@NL@%
- {%@NL@%
- RoundControlPoints(hps, global.cptl, global.pptl, global.pptlTmp,%@NL@%
- global.cxFatPel, global.cyFatPel);%@NL@%
- pptl = global.pptlTmp;%@NL@%
- }%@NL@%
- else%@NL@%
- pptl = global.pptl;%@NL@%
- %@NL@%
- %@AB@%/* draw line */%@AE@%%@NL@%
- lb.lColor = global.clrMathObj;%@NL@%
- lb.usMixMode = usMix;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR|LBB_MIX_MODE, 0L, &lb);%@NL@%
- DrawPrimitive(hps, global.cptl, pptl);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DisplayControlPoints%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DisplayControlPoints(hps, cptl, pptl, usMix)%@NL@%
- HPS hps;%@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl;%@NL@%
- USHORT usMix;%@NL@%
- {%@NL@%
- PPOINTL pptlT;%@NL@%
- MARKERBUNDLE mb;%@NL@%
- %@NL@%
- if (cptl > 0)%@NL@%
- {%@NL@%
- if (global.fRoundControlPoints)%@NL@%
- {%@NL@%
- RoundControlPoints(hps, cptl, pptl, global.pptlTmp,%@NL@%
- global.cxFatPel, global.cyFatPel);%@NL@%
- pptlT = global.pptlTmp;%@NL@%
- }%@NL@%
- else%@NL@%
- pptlT = pptl;%@NL@%
- %@NL@%
- %@NL@%
- mb.lColor = global.clrControlPoints;%@NL@%
- mb.usMixMode = usMix;%@NL@%
- mb.usSymbol = global.usControlPointSymbol;%@NL@%
- GpiSetAttrs(hps, PRIM_MARKER, MBB_COLOR|MBB_MIX_MODE|MBB_SYMBOL, 0L, &mb);%@NL@%
- %@NL@%
- GpiPolyMarker(hps, cptl, pptlT);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* EraseBackground%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Erase the unused part of the window to a hatch pattern.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- EraseBackground(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- RECTL rclClient, rclT;%@NL@%
- AREABUNDLE ab;%@NL@%
- %@NL@%
- %@NL@%
- WinQueryWindowRect(global.hwnd, &rclClient);%@NL@%
- %@NL@%
- ab.lColor = CLR_BLACK;%@NL@%
- ab.lBackColor = CLR_WHITE;%@NL@%
- ab.usSymbol = PATSYM_DIAG1;%@NL@%
- GpiSetAttrs(hps, PRIM_AREA, ABB_COLOR|ABB_BACK_COLOR|ABB_SYMBOL,%@NL@%
- 0L, (PBUNDLE)&ab);%@NL@%
- %@NL@%
- if (global.rcl.yTop < rclClient.yTop)%@NL@%
- {%@NL@%
- rclT.xLeft = rclClient.xLeft;%@NL@%
- rclT.yBottom = global.rcl.yBottom;%@NL@%
- rclT.xRight = rclClient.xRight;%@NL@%
- rclT.yTop = rclClient.yTop;%@NL@%
- GpiBitBlt(hps, NULL, 2L, (PPOINTL)&rclT, ROP_PATCOPY, (ULONG) 0);%@NL@%
- }%@NL@%
- %@NL@%
- if (global.rcl.xRight < rclClient.xRight)%@NL@%
- {%@NL@%
- rclT.xLeft = global.rcl.xRight;%@NL@%
- rclT.yBottom = rclClient.yBottom;%@NL@%
- rclT.xRight = rclClient.xRight;%@NL@%
- rclT.yTop = global.rcl.yTop;%@NL@%
- GpiBitBlt(hps, NULL, 2L, (PPOINTL)&rclT, ROP_PATCOPY, (ULONG) 0);%@NL@%
- }%@NL@%
- %@NL@%
- ab.usSymbol = PATSYM_SOLID;%@NL@%
- GpiSetAttrs(hps, PRIM_AREA, ABB_SYMBOL, 0L, (PBUNDLE)&ab);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawGrid%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawGrid(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- AREABUNDLE ab;%@NL@%
- POINTL ptl;%@NL@%
- POINTL aptl[3];%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* clear fatpel surface to background color */%@AE@%%@NL@%
- ab.lColor = global.clrInterstice;%@NL@%
- GpiSetAttrs(hps, PRIM_AREA, ABB_COLOR, 0L, &ab);%@NL@%
- GpiBitBlt(hps, NULL, 2L, (PPOINTL)&global.rcl, ROP_PATCOPY, (ULONG) 0);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* draw one pel in lower left corner */%@AE@%%@NL@%
- %@NL@%
- ptl.x = global.cxFatPel / 2L;%@NL@%
- ptl.y = global.cyFatPel / 2L;%@NL@%
- DrawOneFatPel(hps, &ptl, global.clrField);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* blt up first column then across -- we don't have to worry%@NL@%
- %@AB@% * about the edges because a clip region has been setup to do that.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- aptl[0].x = 0L;%@NL@%
- aptl[0].y = global.cyFatPel;%@NL@%
- aptl[1].x = global.cxFatPel;%@NL@%
- aptl[2].x = 0L;%@NL@%
- aptl[2].y = 0L;%@NL@%
- %@NL@%
- while (aptl[0].y <= global.rcl.yTop)%@NL@%
- {%@NL@%
- aptl[1].y = aptl[0].y + aptl[0].y;%@NL@%
- GpiBitBlt(hps, hps, 3L, aptl, ROP_SRCCOPY, (LONG)NULL);%@NL@%
- aptl[0].y += aptl[1].y - aptl[0].y;%@NL@%
- }%@NL@%
- %@NL@%
- aptl[0].x = global.cxFatPel;%@NL@%
- aptl[0].y = 0L;%@NL@%
- aptl[1].y = global.rcl.yTop;%@NL@%
- aptl[2].x = 0L;%@NL@%
- aptl[2].y = 0L;%@NL@%
- %@NL@%
- while (aptl[0].x <= global.rcl.xRight)%@NL@%
- {%@NL@%
- aptl[1].x = aptl[0].x + aptl[0].x;%@NL@%
- GpiBitBlt(hps, hps, 3L, aptl, ROP_SRCCOPY, (LONG)NULL);%@NL@%
- aptl[0].x += aptl[1].x - aptl[0].x;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DisplayRenderedPels%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DisplayRenderedPels(hps, fsCmd)%@NL@%
- HPS hps;%@NL@%
- USHORT fsCmd;%@NL@%
- {%@NL@%
- LINEBUNDLE lb;%@NL@%
- AREABUNDLE ab;%@NL@%
- POINTL aptl[3];%@NL@%
- %@NL@%
- %@AB@%/* Call GPI to draw the current primitive into the small bitmap,%@NL@%
- %@AB@% * then fatbit it to the display.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if (global.hbmFat)%@NL@%
- {%@NL@%
- if (fsCmd & CLEAR_FAT_BITMAP)%@NL@%
- {%@NL@%
- %@AB@%/* clear fatpel surface to background color */%@AE@%%@NL@%
- ab.lColor = global.clrField;%@NL@%
- GpiSetAttrs(global.hpsFat, PRIM_AREA, ABB_COLOR, 0L, &ab);%@NL@%
- GpiBitBlt(global.hpsFat, NULL, 2L, (PPOINTL)&global.rclFat, ROP_PATCOPY, (ULONG) 0);%@NL@%
- }%@NL@%
- %@NL@%
- if (fsCmd & RENDER_MATH_OBJ)%@NL@%
- {%@NL@%
- if (global.cptl > 0)%@NL@%
- {%@NL@%
- %@AB@%/* draw line */%@AE@%%@NL@%
- lb.lColor = global.clrRenderedObj;%@NL@%
- GpiSetAttrs(global.hpsFat, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- GpiSetModelTransformMatrix(global.hpsFat, 9L,%@NL@%
- &global.matlf, TRANSFORM_REPLACE);%@NL@%
- DrawPrimitive(global.hpsFat, global.cptl, global.pptl);%@NL@%
- GpiSetModelTransformMatrix(global.hpsFat, 0L, NULL, TRANSFORM_REPLACE);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* xor the new rendered bitmap into the shadow bitmap */%@AE@%%@NL@%
- *((PRECTL)&aptl[0]) = global.rclFat;%@NL@%
- aptl[2].x = 0L;%@NL@%
- aptl[2].y = 0L;%@NL@%
- GpiBitBlt(global.hpsFatShadow, global.hpsFat, 3L, aptl, ROP_SRCINVERT, (ULONG) 0);%@NL@%
- %@NL@%
- %@AB@%/* fatbit object to the display */%@AE@%%@NL@%
- DrawFatPels(hps);%@NL@%
- %@NL@%
- %@AB@%/* get the new shadow bitmap */%@AE@%%@NL@%
- GpiBitBlt(global.hpsFatShadow, global.hpsFat, 3L, aptl, ROP_SRCCOPY, (ULONG) 0);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawFatPels%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawFatPels(hps)%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- POINTL ptl, ptlCenter;%@NL@%
- LONG i, j;%@NL@%
- COLOR clr;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* if the pel size is 1,1, then just blt the small bitmap to the%@NL@%
- %@AB@% * display.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if ((global.cxFatPel == 1L) && (global.cyFatPel == 1L))%@NL@%
- {%@NL@%
- POINTL aptl[3];%@NL@%
- %@NL@%
- *((PRECTL)&aptl[0]) = global.rcl;%@NL@%
- aptl[2].x = 0L;%@NL@%
- aptl[2].y = 0L;%@NL@%
- GpiBitBlt(hps, global.hpsFat, 3L, aptl, ROP_SRCCOPY, 0L);%@NL@%
- %@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- for (i = 0; i < global.rclFat.xRight; ++i)%@NL@%
- for (j = 0; j < global.rclFat.yTop; ++j)%@NL@%
- {%@NL@%
- ptl.x = i;%@NL@%
- ptl.y = j;%@NL@%
- %@NL@%
- clr = GpiQueryPel(global.hpsFatShadow, &ptl);%@NL@%
- if ((global.fRGB && (clr != 0x000000L)) ||%@NL@%
- (!global.fRGB && (clr != global.clrBlackIndex)))%@NL@%
- {%@NL@%
- clr = GpiQueryPel(global.hpsFat, &ptl);%@NL@%
- ptlCenter.x = (i * global.cxFatPel) + global.cxHalfFatPel;%@NL@%
- ptlCenter.y = (j * global.cyFatPel) + global.cyHalfFatPel;%@NL@%
- DrawOneFatPel(hps, &ptlCenter, clr);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawOneFatPel%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawOneFatPel(hps, pptl, clr)%@NL@%
- HPS hps;%@NL@%
- PPOINTL pptl;%@NL@%
- COLOR clr;%@NL@%
- {%@NL@%
- POINTL ptl;%@NL@%
- LINEBUNDLE lb;%@NL@%
- AREABUNDLE ab;%@NL@%
- %@NL@%
- %@NL@%
- if (global.fDisplayPelBorder || global.fDisplayCrossHairs)%@NL@%
- {%@NL@%
- lb.lColor = global.clrCrossHair;%@NL@%
- GpiSetAttrs(hps, PRIM_LINE, LBB_COLOR, 0L, &lb);%@NL@%
- }%@NL@%
- %@NL@%
- ab.lColor = clr;%@NL@%
- GpiSetAttrs(hps, PRIM_AREA, ABB_COLOR, 0L, &ab);%@NL@%
- %@NL@%
- %@NL@%
- switch (global.usPelShape)%@NL@%
- {%@NL@%
- case IDD_SQUARE:%@NL@%
- {%@NL@%
- POINTL ptlT;%@NL@%
- ULONG flCmd;%@NL@%
- %@NL@%
- if (global.fDisplayPelBorder)%@NL@%
- flCmd = DRO_OUTLINEFILL;%@NL@%
- else%@NL@%
- flCmd = DRO_FILL;%@NL@%
- %@NL@%
- ptlT.x = pptl->x - global.cxHalfFatPel;%@NL@%
- ptlT.y = pptl->y - global.cyHalfFatPel;%@NL@%
- GpiSetCurrentPosition(hps, &ptlT);%@NL@%
- ptlT.x = pptl->x + global.cxHalfFatPel;%@NL@%
- ptlT.y = pptl->y + global.cyHalfFatPel;%@NL@%
- GpiBox(hps, flCmd, &ptlT, 0L, 0L);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case IDD_DIAMOND:%@NL@%
- {%@NL@%
- POINTL aptlT[4];%@NL@%
- ULONG flCmd;%@NL@%
- %@NL@%
- if (global.fDisplayPelBorder)%@NL@%
- flCmd = BA_BOUNDARY;%@NL@%
- else%@NL@%
- flCmd = 0L;%@NL@%
- %@NL@%
- aptlT[0].x = pptl->x;%@NL@%
- aptlT[0].y = pptl->y - global.cyHalfFatPel;%@NL@%
- aptlT[1].x = pptl->x - global.cxHalfFatPel;%@NL@%
- aptlT[1].y = pptl->y;%@NL@%
- aptlT[2].x = pptl->x;%@NL@%
- aptlT[2].y = pptl->y + global.cyHalfFatPel;%@NL@%
- aptlT[3].x = pptl->x + global.cxHalfFatPel;%@NL@%
- aptlT[3].y = pptl->y;%@NL@%
- %@NL@%
- GpiSetCurrentPosition(hps, &aptlT[3]);%@NL@%
- GpiBeginArea(hps, flCmd);%@NL@%
- GpiPolyLine(hps, 4L, aptlT);%@NL@%
- GpiEndArea(hps);%@NL@%
- }%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- case IDD_CIRCLE:%@NL@%
- {%@NL@%
- ULONG flCmd;%@NL@%
- %@NL@%
- if (global.fDisplayPelBorder)%@NL@%
- flCmd = DRO_OUTLINEFILL;%@NL@%
- else%@NL@%
- flCmd = DRO_FILL;%@NL@%
- %@NL@%
- GpiSetCurrentPosition(hps, pptl);%@NL@%
- GpiFullArc(hps, flCmd, 0x10000L);%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- if (global.fDisplayCrossHairs)%@NL@%
- {%@NL@%
- %@AB@%/* draw cross in center of pel */%@AE@%%@NL@%
- %@NL@%
- ptl.x = pptl->x - global.cxHalfFatPel;%@NL@%
- ptl.y = pptl->y;%@NL@%
- GpiSetCurrentPosition(hps, &ptl);%@NL@%
- ptl.x = pptl->x + global.cxHalfFatPel;%@NL@%
- GpiPolyLine(hps, 1L, &ptl);%@NL@%
- %@NL@%
- ptl.x = pptl->x;%@NL@%
- ptl.y = pptl->y - global.cyHalfFatPel;%@NL@%
- GpiSetCurrentPosition(hps, &ptl);%@NL@%
- ptl.y = pptl->y + global.cyHalfFatPel;%@NL@%
- GpiPolyLine(hps, 1L, &ptl);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* RoundControlPoints%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- RoundControlPoints(hps, cptl, pptl1, pptl2, cx, cy)%@NL@%
- HPS hps;%@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl1;%@NL@%
- PPOINTL pptl2;%@NL@%
- LONG cx;%@NL@%
- LONG cy;%@NL@%
- {%@NL@%
- LONG cx2, cy2;%@NL@%
- LONG i;%@NL@%
- MATRIXLF matlf;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* copy the input buffer to the output/scratch buffer */%@AE@%%@NL@%
- for (i = 0; i < cptl; ++i)%@NL@%
- pptl2[i] = pptl1[i];%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* set the transform, transform the points to device space (i.e. to%@NL@%
- %@AB@% * hpsFat dimensions), then restore the original transform%@NL@%
- %@AB@% */%@AE@%%@NL@%
- GpiQueryModelTransformMatrix(hps, 9L, &matlf);%@NL@%
- GpiSetModelTransformMatrix(hps, 9L, &global.matlf, TRANSFORM_REPLACE);%@NL@%
- GpiConvert(hps, CVTC_WORLD, CVTC_DEVICE, cptl, pptl2);%@NL@%
- GpiSetModelTransformMatrix(hps, 9L, &matlf, TRANSFORM_REPLACE);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* position each point in the center of its fatpel */%@AE@%%@NL@%
- %@NL@%
- cx2 = cx / 2L;%@NL@%
- cy2 = cy / 2L;%@NL@%
- %@NL@%
- for (i = 0; i < cptl; ++i, ++pptl2)%@NL@%
- {%@NL@%
- pptl2->x = pptl2->x * cx + cx2;%@NL@%
- pptl2->y = pptl2->y * cy + cy2;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ComputeTransform%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- ComputeTransform(prcl1, prcl2)%@NL@%
- PRECTL prcl1;%@NL@%
- PRECTL prcl2;%@NL@%
- {%@NL@%
- LONG xExt1, yExt1;%@NL@%
- LONG xExt2, yExt2;%@NL@%
- FIXED xScale, yScale;%@NL@%
- %@NL@%
- %@NL@%
- xExt1 = prcl1->xRight - prcl1->xLeft;%@NL@%
- yExt1 = prcl1->yTop - prcl1->yBottom;%@NL@%
- xExt2 = prcl2->xRight - prcl2->xLeft;%@NL@%
- yExt2 = prcl2->yTop - prcl2->yBottom;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* If the rectangles are of exactly the same dimensions, then%@NL@%
- %@AB@% * set the unity transform. If not, compute the x and y scale%@NL@%
- %@AB@% * factors. Note that in world coordinates rectangles are%@NL@%
- %@AB@% * inclusive-inclusive, whereas in device coordinates they are%@NL@%
- %@AB@% * inclusive-exclusive. The extents of the destination are%@NL@%
- %@AB@% * therefore one pel too large as computed, so we subtract one%@NL@%
- %@AB@% * in the scale factor computation.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if (xExt1 == xExt2)%@NL@%
- xScale = 0x10000L;%@NL@%
- else%@NL@%
- xScale = ((xExt2-1L) * 0x10000L) / xExt1;%@NL@%
- %@NL@%
- if (yExt1 == yExt2)%@NL@%
- yScale = 0x10000L;%@NL@%
- else%@NL@%
- yScale = ((yExt2-1L) * 0x10000L) / yExt1;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* store the transform matrix for easy access */%@AE@%%@NL@%
- %@NL@%
- global.matlf.fxM11 = xScale;%@NL@%
- global.matlf.fxM12 = 0L;%@NL@%
- global.matlf. lM13 = 0L;%@NL@%
- global.matlf.fxM21 = 0L;%@NL@%
- global.matlf.fxM22 = yScale;%@NL@%
- global.matlf. lM23 = 0L;%@NL@%
- global.matlf. lM31 = 0L;%@NL@%
- global.matlf. lM32 = 0L;%@NL@%
- global.matlf. lM33 = 1L;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* DrawPrimitive%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- DrawPrimitive(hps, cptl, pptl)%@NL@%
- HPS hps;%@NL@%
- LONG cptl;%@NL@%
- PPOINTL pptl;%@NL@%
- {%@NL@%
- switch (global.usCurPrim)%@NL@%
- {%@NL@%
- case IDM_NOPRIM:%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYLINE:%@NL@%
- GpiSetCurrentPosition(hps, pptl);%@NL@%
- GpiPolyLine(hps, cptl-1L, pptl + 1);%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYFILLET:%@NL@%
- if (cptl >= 3L)%@NL@%
- {%@NL@%
- GpiSetCurrentPosition(hps, pptl);%@NL@%
- GpiPolyFillet(hps, cptl-1L, pptl + 1);%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POLYSPLINE:%@NL@%
- if (cptl >= 4L)%@NL@%
- {%@NL@%
- LONG cptSlack; %@AB@%/* # points in pptl not usable by PolySpline */%@AE@%%@NL@%
- %@NL@%
- cptSlack = ((cptl-1L) % 3) + 1;%@NL@%
- GpiSetCurrentPosition( hps, pptl );%@NL@%
- GpiPolySpline( hps, cptl-cptSlack, pptl+1 );%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case IDM_POINTARC:%@NL@%
- if (cptl >= 3L)%@NL@%
- {%@NL@%
- GpiSetCurrentPosition( hps, pptl );%@NL@%
- GpiPointArc( hps, pptl+1 );%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* UpdateSurfaceDims%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- UpdateSurfaceDims()%@NL@%
- {%@NL@%
- SIZEL size;%@NL@%
- BITMAPINFOHEADER bminfo;%@NL@%
- AREABUNDLE ab;%@NL@%
- %@NL@%
- %@NL@%
- WinQueryWindowRect(global.hwnd, &global.rcl);%@NL@%
- %@NL@%
- %@AB@%/* compute size of small surface */%@AE@%%@NL@%
- global.rclFat.xLeft = 0L;%@NL@%
- global.rclFat.yBottom = 0L;%@NL@%
- global.rclFat.xRight = global.rcl.xRight / global.cxFatPel;%@NL@%
- global.rclFat.yTop = global.rcl.yTop / global.cyFatPel;%@NL@%
- %@NL@%
- %@AB@%/* compute size of fatpel version of small surface */%@AE@%%@NL@%
- global.rcl.xLeft = 0L;%@NL@%
- global.rcl.yBottom = 0L;%@NL@%
- global.rcl.xRight = global.rclFat.xRight * global.cxFatPel;%@NL@%
- global.rcl.yTop = global.rclFat.yTop * global.cyFatPel;%@NL@%
- %@NL@%
- ComputeTransform(&global.rcl, &global.rclFat);%@NL@%
- %@NL@%
- if ((global.rclFat.xRight <= global.rclFatBM.xRight) &&%@NL@%
- (global.rclFat.yTop <= global.rclFatBM.yTop))%@NL@%
- return;%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* The new fatbits surface doesn't fit in the bitmap, so we%@NL@%
- %@AB@% * have to make a new one. If we don't have a DC or PS, make%@NL@%
- %@AB@% * those before making the bitmap. If we do have a bitmap,%@NL@%
- %@AB@% * delete it before making the new one.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- global.rclFatBM = global.rclFat;%@NL@%
- %@NL@%
- if (global.hbmFat)%@NL@%
- {%@NL@%
- GpiSetBitmap(global.hpsFat, NULL);%@NL@%
- GpiDeleteBitmap(global.hbmFat);%@NL@%
- GpiSetBitmap(global.hpsFatShadow, NULL);%@NL@%
- GpiDeleteBitmap(global.hbmFatShadow);%@NL@%
- }%@NL@%
- %@NL@%
- if (!global.hdcFat)%@NL@%
- {%@NL@%
- global.hdcFat = DevOpenDC(global.hab, OD_MEMORY, "*", 0L, NULL, NULL);%@NL@%
- if (!global.hdcFat)%@NL@%
- goto usd_error;%@NL@%
- %@NL@%
- global.hdcFatShadow = DevOpenDC(global.hab, OD_MEMORY, "*", 0L, NULL, NULL);%@NL@%
- if (!global.hdcFatShadow)%@NL@%
- goto usd_error;%@NL@%
- }%@NL@%
- %@NL@%
- if (!global.hpsFat)%@NL@%
- {%@NL@%
- size.cx = 0L;%@NL@%
- size.cy = 0L;%@NL@%
- global.hpsFat = GpiCreatePS(global.hab, global.hdcFat, &size,%@NL@%
- PU_PELS|GPIT_MICRO|GPIA_ASSOC);%@NL@%
- if (!global.hpsFat)%@NL@%
- goto usd_error;%@NL@%
- %@NL@%
- global.hpsFatShadow = GpiCreatePS(global.hab, global.hdcFatShadow, &size,%@NL@%
- PU_PELS|GPIT_MICRO|GPIA_ASSOC);%@NL@%
- if (!global.hpsFatShadow)%@NL@%
- goto usd_error;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* create bitmap with maximum color resolution (24-bit color) */%@AE@%%@NL@%
- bminfo.cbFix = sizeof(BITMAPINFOHEADER);%@NL@%
- bminfo.cx = (USHORT) (global.rclFatBM.xRight - global.rclFatBM.xLeft);%@NL@%
- bminfo.cy = (USHORT) (global.rclFatBM.yTop - global.rclFatBM.yBottom);%@NL@%
- bminfo.cPlanes = 1L;%@NL@%
- bminfo.cBitCount = 24L;%@NL@%
- global.hbmFat = GpiCreateBitmap(global.hpsFat, &bminfo, 0L, 0L, 0L);%@NL@%
- if (!global.hbmFat)%@NL@%
- goto usd_error;%@NL@%
- GpiSetBitmap(global.hpsFat, global.hbmFat);%@NL@%
- %@NL@%
- %@AB@%/* create a shadow bitmap of the one we just created */%@AE@%%@NL@%
- bminfo.cbFix = sizeof(BITMAPINFOHEADER);%@NL@%
- bminfo.cx = (USHORT) (global.rclFatBM.xRight - global.rclFatBM.xLeft);%@NL@%
- bminfo.cy = (USHORT) (global.rclFatBM.yTop - global.rclFatBM.yBottom);%@NL@%
- bminfo.cPlanes = 1L;%@NL@%
- bminfo.cBitCount = 24L;%@NL@%
- global.hbmFatShadow = GpiCreateBitmap(global.hpsFatShadow, &bminfo, 0L, 0L, 0L);%@NL@%
- if (!global.hbmFat)%@NL@%
- goto usd_error;%@NL@%
- GpiSetBitmap(global.hpsFatShadow, global.hbmFatShadow);%@NL@%
- %@NL@%
- %@AB@%/* clear bitmap surface to field color */%@AE@%%@NL@%
- ab.lColor = global.clrField;%@NL@%
- GpiSetAttrs(global.hpsFat, PRIM_AREA, ABB_COLOR, 0L, &ab);%@NL@%
- GpiBitBlt(global.hpsFat, NULL, 2L, (PPOINTL)&global.rclFat, ROP_PATCOPY, (ULONG) 0);%@NL@%
- %@NL@%
- return;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* error exit point */%@AE@%%@NL@%
- %@NL@%
- usd_error:%@NL@%
- if (global.hpsFat)%@NL@%
- GpiDestroyPS(global.hpsFat);%@NL@%
- if (global.hpsFatShadow)%@NL@%
- GpiDestroyPS(global.hpsFatShadow);%@NL@%
- if (global.hdcFat)%@NL@%
- DevCloseDC(global.hdcFat);%@NL@%
- if (global.hdcFatShadow)%@NL@%
- DevCloseDC(global.hdcFatShadow);%@NL@%
- %@NL@%
- global.hpsFat = NULL;%@NL@%
- global.hdcFat = NULL;%@NL@%
- global.hpsFatShadow = NULL;%@NL@%
- global.hdcFatShadow = NULL;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* AboutDlg%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Process messages for the About box.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- ULONG CALLBACK%@NL@%
- AboutDlg(hwnd, usMsg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- switch (usMsg)%@NL@%
- {%@NL@%
- case WM_COMMAND:%@NL@%
- if (SHORT1FROMMP(mp1) == DID_OK)%@NL@%
- WinDismissDlg(hwnd, TRUE);%@NL@%
- else%@NL@%
- return FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return (ULONG) WinDefDlgProc(hwnd, usMsg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PelSizeDlg%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Process messages for the Pel Size dialog box.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- ULONG CALLBACK%@NL@%
- PelSizeDlg(hwnd, usMsg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- BOOL fRet = FALSE;%@NL@%
- %@NL@%
- switch (usMsg)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- MySetWindowLong(hwnd, IDD_PELWIDTH, global.cxFatPel);%@NL@%
- MySetWindowLong(hwnd, IDD_PELHEIGHT, global.cyFatPel);%@NL@%
- WinSendDlgItemMsg(hwnd, global.usPelShape,%@NL@%
- BM_SETCHECK, (MPARAM)TRUE, 0L);%@NL@%
- return FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (SHORT1FROMMP(mp1))%@NL@%
- {%@NL@%
- case IDD_OK:%@NL@%
- global.cxFatPel = MyGetWindowLong(hwnd, IDD_PELWIDTH);%@NL@%
- global.cyFatPel = MyGetWindowLong(hwnd, IDD_PELHEIGHT);%@NL@%
- %@NL@%
- if (global.cxFatPel < 1L)%@NL@%
- global.cxFatPel = 1L;%@NL@%
- %@NL@%
- if (global.cyFatPel < 1L)%@NL@%
- global.cyFatPel = 1L;%@NL@%
- %@NL@%
- global.cxHalfFatPel = global.cxFatPel / 2L;%@NL@%
- global.cyHalfFatPel = global.cyFatPel / 2L;%@NL@%
- %@NL@%
- global.usPelShape = SHORT1FROMMR( WinSendDlgItemMsg(hwnd, IDD_SQUARE,%@NL@%
- BM_QUERYCHECKINDEX, 0L, 0L) + IDD_SQUARE);%@NL@%
- %@NL@%
- %@NL@%
- UpdateSurfaceDims();%@NL@%
- %@NL@%
- fRet = TRUE;%@NL@%
- %@NL@%
- %@AB@%/* fall through to some common code */%@AE@%%@NL@%
- %@NL@%
- case IDD_CANCEL:%@NL@%
- WinDismissDlg(hwnd, fRet);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return (ULONG) WinDefDlgProc(hwnd, usMsg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* ColorsDlg%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Process messages for the Set Colors dialog box.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- ULONG CALLBACK%@NL@%
- ColorsDlg(hwnd, usMsg, mp1, mp2)%@NL@%
- HWND hwnd;%@NL@%
- USHORT usMsg;%@NL@%
- MPARAM mp1;%@NL@%
- MPARAM mp2;%@NL@%
- {%@NL@%
- BOOL fRet = FALSE;%@NL@%
- BOOL fRGB;%@NL@%
- COLOR clrMathObj;%@NL@%
- COLOR clrRenderedObj;%@NL@%
- COLOR clrField;%@NL@%
- COLOR clrCrossHair;%@NL@%
- COLOR clrInterstice;%@NL@%
- COLOR clrControlPoints;%@NL@%
- %@NL@%
- switch (usMsg)%@NL@%
- {%@NL@%
- case WM_INITDLG:%@NL@%
- if (global.fRGB)%@NL@%
- {%@NL@%
- MySetWindowLongHex(hwnd, IDD_MATHOBJ, global.clrMathObj);%@NL@%
- MySetWindowLongHex(hwnd, IDD_RENDEREDOBJ, global.clrRenderedObj);%@NL@%
- MySetWindowLongHex(hwnd, IDD_FIELD, global.clrField);%@NL@%
- MySetWindowLongHex(hwnd, IDD_CROSSHAIRS, global.clrCrossHair);%@NL@%
- MySetWindowLongHex(hwnd, IDD_INTERSTICE, global.clrInterstice);%@NL@%
- MySetWindowLongHex(hwnd, IDD_CTLPOINTS, global.clrControlPoints);%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- MySetWindowLong (hwnd, IDD_MATHOBJ, global.clrMathObj);%@NL@%
- MySetWindowLong (hwnd, IDD_RENDEREDOBJ, global.clrRenderedObj);%@NL@%
- MySetWindowLong (hwnd, IDD_FIELD, global.clrField);%@NL@%
- MySetWindowLong (hwnd, IDD_CROSSHAIRS, global.clrCrossHair);%@NL@%
- MySetWindowLong (hwnd, IDD_INTERSTICE, global.clrInterstice);%@NL@%
- MySetWindowLong (hwnd, IDD_CTLPOINTS, global.clrControlPoints);%@NL@%
- }%@NL@%
- WinSendDlgItemMsg(hwnd, IDD_RGB, BM_SETCHECK, MPFROM2SHORT(global.fRGB,0), 0L);%@NL@%
- return FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_CONTROL:%@NL@%
- if ((SHORT1FROMMP(mp1) == IDD_RGB) && (SHORT2FROMMP(mp1)== BN_CLICKED))%@NL@%
- {%@NL@%
- fRGB = !SHORT1FROMMR(WinSendDlgItemMsg(hwnd, IDD_RGB, BM_QUERYCHECK, 0L, 0L));%@NL@%
- WinSendDlgItemMsg(hwnd, IDD_RGB, BM_SETCHECK, MPFROM2SHORT(fRGB,0), 0L);%@NL@%
- %@NL@%
- clrMathObj = MyGetWindowLong(hwnd, IDD_MATHOBJ);%@NL@%
- clrRenderedObj = MyGetWindowLong(hwnd, IDD_RENDEREDOBJ);%@NL@%
- clrField = MyGetWindowLong(hwnd, IDD_FIELD);%@NL@%
- clrCrossHair = MyGetWindowLong(hwnd, IDD_CROSSHAIRS);%@NL@%
- clrInterstice = MyGetWindowLong(hwnd, IDD_INTERSTICE);%@NL@%
- clrControlPoints = MyGetWindowLong(hwnd, IDD_CTLPOINTS);%@NL@%
- %@NL@%
- if (fRGB)%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@AB@%/* for each color, get rgb value from index */%@AE@%%@NL@%
- %@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- %@NL@%
- clrMathObj = GpiQueryRGBColor(hps, 0L, clrMathObj);%@NL@%
- clrRenderedObj = GpiQueryRGBColor(hps, 0L, clrRenderedObj);%@NL@%
- clrField = GpiQueryRGBColor(hps, 0L, clrField);%@NL@%
- clrCrossHair = GpiQueryRGBColor(hps, 0L, clrCrossHair);%@NL@%
- clrInterstice = GpiQueryRGBColor(hps, 0L, clrInterstice);%@NL@%
- clrControlPoints = GpiQueryRGBColor(hps, 0L, clrControlPoints);%@NL@%
- %@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- MySetWindowLongHex(hwnd, IDD_MATHOBJ, clrMathObj);%@NL@%
- MySetWindowLongHex(hwnd, IDD_RENDEREDOBJ, clrRenderedObj);%@NL@%
- MySetWindowLongHex(hwnd, IDD_FIELD, clrField);%@NL@%
- MySetWindowLongHex(hwnd, IDD_CROSSHAIRS, clrCrossHair);%@NL@%
- MySetWindowLongHex(hwnd, IDD_INTERSTICE, clrInterstice);%@NL@%
- MySetWindowLongHex(hwnd, IDD_CTLPOINTS, clrControlPoints);%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- HPS hps;%@NL@%
- %@NL@%
- %@AB@%/* for each color, get nearest index value from rgb */%@AE@%%@NL@%
- %@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- %@NL@%
- clrMathObj = GpiQueryColorIndex(hps, 0L, clrMathObj);%@NL@%
- clrRenderedObj = GpiQueryColorIndex(hps, 0L, clrRenderedObj);%@NL@%
- clrField = GpiQueryColorIndex(hps, 0L, clrField);%@NL@%
- clrCrossHair = GpiQueryColorIndex(hps, 0L, clrCrossHair);%@NL@%
- clrInterstice = GpiQueryColorIndex(hps, 0L, clrInterstice);%@NL@%
- clrControlPoints = GpiQueryColorIndex(hps, 0L, clrControlPoints);%@NL@%
- %@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- MySetWindowLong (hwnd, IDD_MATHOBJ, clrMathObj);%@NL@%
- MySetWindowLong (hwnd, IDD_RENDEREDOBJ, clrRenderedObj);%@NL@%
- MySetWindowLong (hwnd, IDD_FIELD, clrField);%@NL@%
- MySetWindowLong (hwnd, IDD_CROSSHAIRS, clrCrossHair);%@NL@%
- MySetWindowLong (hwnd, IDD_INTERSTICE, clrInterstice);%@NL@%
- MySetWindowLong (hwnd, IDD_CTLPOINTS, clrControlPoints);%@NL@%
- }%@NL@%
- }%@NL@%
- return (ULONG) WinDefDlgProc(hwnd, usMsg, mp1, mp2);%@NL@%
- break;%@NL@%
- %@NL@%
- case WM_COMMAND:%@NL@%
- switch (SHORT1FROMMP(mp1))%@NL@%
- {%@NL@%
- case IDD_OK:%@NL@%
- global.clrMathObj = MyGetWindowLong(hwnd, IDD_MATHOBJ);%@NL@%
- global.clrRenderedObj = MyGetWindowLong(hwnd, IDD_RENDEREDOBJ);%@NL@%
- global.clrField = MyGetWindowLong(hwnd, IDD_FIELD);%@NL@%
- global.clrCrossHair = MyGetWindowLong(hwnd, IDD_CROSSHAIRS);%@NL@%
- global.clrInterstice = MyGetWindowLong(hwnd, IDD_INTERSTICE);%@NL@%
- global.clrControlPoints = MyGetWindowLong(hwnd, IDD_CTLPOINTS);%@NL@%
- %@NL@%
- global.fRGB = SHORT1FROMMR(WinSendDlgItemMsg(hwnd, IDD_RGB, BM_QUERYCHECK, 0L, 0L));%@NL@%
- %@NL@%
- fRet = TRUE;%@NL@%
- %@NL@%
- %@AB@%/* fall through to some common code */%@AE@%%@NL@%
- %@NL@%
- case IDD_CANCEL:%@NL@%
- WinDismissDlg(hwnd, fRet);%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- return (ULONG) WinDefDlgProc(hwnd, usMsg, mp1, mp2);%@NL@%
- }%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MySetWindowLong%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Sets the given control id to the value specified.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MySetWindowLong(hWnd, id, num)%@NL@%
- HWND hWnd;%@NL@%
- USHORT id;%@NL@%
- LONG num;%@NL@%
- {%@NL@%
- char szStr[CCHSTR];%@NL@%
- %@NL@%
- sprintf((NPCH)szStr, "%ld", num);%@NL@%
- WinSetWindowText(WinWindowFromID(hWnd, id), (PCH)szStr);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MySetWindowLongHex%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Sets the given control id to the value specified, in hexadecimal%@NL@%
- %@AB@%* notation.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MySetWindowLongHex(hWnd, id, num)%@NL@%
- HWND hWnd;%@NL@%
- USHORT id;%@NL@%
- LONG num;%@NL@%
- {%@NL@%
- char szStr[CCHSTR];%@NL@%
- %@NL@%
- sprintf((NPCH)szStr, "0x%06lX", num);%@NL@%
- WinSetWindowText(WinWindowFromID(hWnd, id), (PCH)szStr);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MyGetWindowLong%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Returns the value from the given control id.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- LONG%@NL@%
- MyGetWindowLong(hWnd, id)%@NL@%
- HWND hWnd;%@NL@%
- USHORT id;%@NL@%
- {%@NL@%
- char szStr[CCHSTR];%@NL@%
- LONG num;%@NL@%
- %@NL@%
- WinQueryWindowText(WinWindowFromID(hWnd, id), CCHSTR, (PCH)szStr);%@NL@%
- %@NL@%
- if (strchr(szStr, 'x'))%@NL@%
- sscanf((NPCH)szStr, "0x%lx", &num);%@NL@%
- else if (strchr(szStr, 'X'))%@NL@%
- sscanf((NPCH)szStr, "0X%lx", &num);%@NL@%
- else%@NL@%
- sscanf((NPCH)szStr, "%ld", &num);%@NL@%
- %@NL@%
- return num;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* SaveWindowToFile%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Copy the bits from the client rectangle (actually, just the fatpel%@NL@%
- %@AB@%* area) into a bitmap, then save that bitmap.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- SaveWindowToFile(hwnd)%@NL@%
- HWND hwnd;%@NL@%
- {%@NL@%
- BITMAPINFOHEADER bminfo;%@NL@%
- HBITMAP hbm;%@NL@%
- HPS hps;%@NL@%
- POINTL aptl[3];%@NL@%
- %@NL@%
- %@AB@%/* create bitmap in display's favorite format */%@AE@%%@NL@%
- bminfo.cbFix = sizeof(BITMAPINFOHEADER);%@NL@%
- bminfo.cx = (USHORT) (global.rcl.xRight - global.rcl.xLeft);%@NL@%
- bminfo.cy = (USHORT) (global.rcl.yTop - global.rcl.yBottom);%@NL@%
- bminfo.cPlanes = 0L;%@NL@%
- bminfo.cBitCount = 0L;%@NL@%
- if (hbm = GpiCreateBitmap(global.hpsFat, &bminfo, 0L, 0L, 0L))%@NL@%
- {%@NL@%
- %@AB@%/* select it into the small bitmap's PS */%@AE@%%@NL@%
- GpiSetBitmap(global.hpsFat, hbm);%@NL@%
- %@NL@%
- %@AB@%/* GpiBitBlt from the window to the bitmap */%@AE@%%@NL@%
- hps = WinGetPS(hwnd);%@NL@%
- %@NL@%
- *((PRECTL)&aptl[0]) = global.rcl;%@NL@%
- aptl[2].x = 0L;%@NL@%
- aptl[2].y = 0L;%@NL@%
- GpiBitBlt(global.hpsFat, hps, 3L, aptl, ROP_SRCCOPY, 0L);%@NL@%
- %@NL@%
- WinReleasePS(hps);%@NL@%
- %@NL@%
- %@AB@%/* save the bitmap */%@AE@%%@NL@%
- WriteFile(hwnd, global.hpsFat);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* deselect the bitmap and delete it */%@AE@%%@NL@%
- GpiSetBitmap(global.hpsFat, global.hbmFat);%@NL@%
- if (hbm)%@NL@%
- GpiDeleteBitmap(hbm);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WriteFile%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Calls the OpenDlg's DlgFile function to ask the user what file name to%@NL@%
- %@AB@%* save under.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- WriteFile(hwnd, hps)%@NL@%
- HWND hwnd;%@NL@%
- HPS hps;%@NL@%
- {%@NL@%
- HFILE hfile;%@NL@%
- DLF dlf;%@NL@%
- BITMAPINFOHEADER bmih;%@NL@%
- %@NL@%
- dlf.rgbAction = DLG_SAVEDLG;%@NL@%
- dlf.rgbFlags = 0;%@NL@%
- dlf.phFile = &hfile;%@NL@%
- dlf.pszExt = "";%@NL@%
- dlf.pszAppName = "FatPel";%@NL@%
- dlf.pszInstructions = NULL;%@NL@%
- dlf.szFileName[0] = '\0';%@NL@%
- dlf.szOpenFile[0] = '\0';%@NL@%
- dlf.pszTitle = "Save Bitmap";%@NL@%
- %@NL@%
- %@NL@%
- switch (DlgFile(hwnd,&dlf))%@NL@%
- {%@NL@%
- case TDF_ERRMEM:%@NL@%
- case TDF_INVALID:%@NL@%
- MyMessageBox(hwnd, "Error opening file.");%@NL@%
- break;%@NL@%
- %@NL@%
- case TDF_NOSAVE:%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- bmih.cbFix = sizeof(BITMAPINFOHEADER);%@NL@%
- bmih.cx = (USHORT) global.rcl.xRight;%@NL@%
- bmih.cy = (USHORT) global.rcl.yTop;%@NL@%
- bmih.cPlanes = 0L;%@NL@%
- bmih.cBitCount = 0L;%@NL@%
- %@NL@%
- if (!WriteBMP(hfile, hps, &bmih))%@NL@%
- MyMessageBox(hwnd, "Error writing file.");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* WriteBMP%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Write the bitmap out to a BMP format file. Write the file%@NL@%
- %@AB@%* header first, then the bitmap bits. Space for the header%@NL@%
- %@AB@%* and the bits is allocated. Huge bitmaps are supported.%@NL@%
- %@AB@%* Free up memory and close the file before leaving. The file%@NL@%
- %@AB@%* will have been opened by the time this function is called,%@NL@%
- %@AB@%* and the file handle will be in the *pdlf structure.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- BOOL%@NL@%
- WriteBMP(hfile, hps, pbmih)%@NL@%
- HFILE hfile;%@NL@%
- HPS hps; %@AB@%/* hps from which to get bitmap bits. */%@AE@%%@NL@%
- PBITMAPINFOHEADER pbmih; %@AB@%/* Bitmap information. */%@AE@%%@NL@%
- {%@NL@%
- ULONG cScans;%@NL@%
- ULONG ulSize; %@AB@%/* Number of bytes occupied by bitmap bits. */%@AE@%%@NL@%
- USHORT cSegs; %@AB@%/* Number of 64K segments in ulSize. */%@AE@%%@NL@%
- USHORT cbExtra; %@AB@%/* Bytes in last segment of ulSize. */%@AE@%%@NL@%
- SEL selBits; %@AB@%/* Base selector to bitmap bits. */%@AE@%%@NL@%
- USHORT hugeshift; %@AB@%/* Segment index shift value. */%@AE@%%@NL@%
- USHORT cbBMHdr; %@AB@%/* Size of bitmap header. */%@AE@%%@NL@%
- PBITMAPFILEHEADER pbfh; %@AB@%/* Pointer to private copy of bitmap info data. */%@AE@%%@NL@%
- USHORT cbWrite1; %@AB@%/* Number of bytes to write first call to DosWrite */%@AE@%%@NL@%
- USHORT cbWrite2; %@AB@%/* Number of bytes to write second call to DosWrite */%@AE@%%@NL@%
- USHORT cbWritten; %@AB@%/* Number of bytes written by DosWrite. */%@AE@%%@NL@%
- BOOL fRet = FALSE; %@AB@%/* Function return code. */%@AE@%%@NL@%
- int i; %@AB@%/* Generic loop index. */%@AE@%%@NL@%
- struct%@NL@%
- {%@NL@%
- LONG cPlanes;%@NL@%
- LONG cBitCount;%@NL@%
- } bmFmt;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * If the bitmap was created with either 0 planes or 0 bits per%@NL@%
- %@AB@% * pixel, then query the format to write with. By asking for just%@NL@%
- %@AB@% * one format (two LONGs, or one instance of structure of bmFmt),%@NL@%
- %@AB@% * we'll get the device's favored format.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- if ((pbmih->cPlanes == 0) || (pbmih->cBitCount == 0))%@NL@%
- {%@NL@%
- if (!GpiQueryDeviceBitmapFormats(hps, 2L, (PLONG)&bmFmt))%@NL@%
- goto lfwrite_error_close_file;%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- bmFmt.cPlanes = pbmih->cPlanes;%@NL@%
- bmFmt.cBitCount = pbmih->cBitCount;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * Determine size of bitmap header. The header consists of a%@NL@%
- %@AB@% * a fixed-size part and a variable-length color table. The%@NL@%
- %@AB@% * latter has 2^cBitCount entries, each of which is sizeof(RGB)%@NL@%
- %@AB@% * bytes long. The exception is when cBitCount is 24, in which%@NL@%
- %@AB@% * case the color table is omitted because the pixels are direct%@NL@%
- %@AB@% * rgb values.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- i = (int) bmFmt.cBitCount;%@NL@%
- if (i == 24)%@NL@%
- cbBMHdr = 0;%@NL@%
- else%@NL@%
- for (cbBMHdr = sizeof(RGB); i > 0; --i)%@NL@%
- cbBMHdr *= 2;%@NL@%
- cbBMHdr += sizeof(BITMAPFILEHEADER);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * Copy structure from input to work buffer. The call to%@NL@%
- %@AB@% * GpiQueryBitmapBits will have write-access to this, so we won't%@NL@%
- %@AB@% * let it have the user's data.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- pbfh = 0;%@NL@%
- if (DosAllocSeg(cbBMHdr, ((PUSHORT)&pbfh)+1, 0))%@NL@%
- goto lfwrite_error_close_file;%@NL@%
- pbfh->bmp = *pbmih;%@NL@%
- if ((pbmih->cPlanes == 0) || (pbmih->cBitCount))%@NL@%
- {%@NL@%
- pbfh->bmp.cPlanes = (USHORT) bmFmt.cPlanes;%@NL@%
- pbfh->bmp.cBitCount = (USHORT) bmFmt.cBitCount;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * Allocate space for the bitmap bits -- all of them at once.%@NL@%
- %@AB@% * The extra ULONG casts are there to force all the arithmetic%@NL@%
- %@AB@% * to be done in 32 bits.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- ulSize = (%@NL@%
- (%@NL@%
- (%@NL@%
- (ULONG)pbfh->bmp.cBitCount%@NL@%
- * (ULONG)pbfh->bmp.cx%@NL@%
- + 31L%@NL@%
- ) / 32L%@NL@%
- ) * (ULONG)pbfh->bmp.cPlanes * 4L%@NL@%
- ) * (ULONG)pbfh->bmp.cy;%@NL@%
- %@NL@%
- cSegs = (USHORT)(ulSize/0x10000L);%@NL@%
- cbExtra = (USHORT)(ulSize%0x10000L);%@NL@%
- if (DosAllocHuge(cSegs, cbExtra, (PSEL)&selBits, 0, 0))%@NL@%
- goto lfwrite_error_free_header;%@NL@%
- if (DosGetHugeShift(&hugeshift))%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * Tell GPI to give us the bits. The function returns the number%@NL@%
- %@AB@% * of scan lines of the bitmap that were copied. We want all of%@NL@%
- %@AB@% * them at once.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- cScans = GpiQueryBitmapBits( hps%@NL@%
- , 0L%@NL@%
- , (ULONG)pbfh->bmp.cy%@NL@%
- , (PBYTE)MAKEP(selBits, 0)%@NL@%
- , (PBITMAPINFO)&pbfh->bmp);%@NL@%
- if (cScans != pbfh->bmp.cy) %@AB@%/* compare with original number of scans */%@AE@%%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * Fill in the extra header fields and write the header out to%@NL@%
- %@AB@% * the file.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- pbfh->usType = 0x4D42; %@AB@%/* 'MB' */%@AE@%%@NL@%
- pbfh->cbSize = ulSize + cbBMHdr;%@NL@%
- pbfh->xHotspot = pbfh->bmp.cx / 2;%@NL@%
- pbfh->yHotspot = pbfh->bmp.cy / 2;%@NL@%
- pbfh->offBits = cbBMHdr;%@NL@%
- %@NL@%
- if (DosWrite( hfile%@NL@%
- , (PVOID)pbfh%@NL@%
- , cbBMHdr%@NL@%
- , &cbWritten))%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- if (cbWritten != cbBMHdr)%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * Write the bits out to the file. The DosWrite function allows a%@NL@%
- %@AB@% * maximum of 64K-1 bytes written at a time. We get around this%@NL@%
- %@AB@% * by writing two 32K chunks for each 64K segment, and writing the%@NL@%
- %@AB@% * last segment in one piece.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- for (i = 0; i <= (SHORT) cSegs; ++i)%@NL@%
- {%@NL@%
- if (i < (SHORT) cSegs)%@NL@%
- {%@NL@%
- %@AB@%/* This segment is 64K bytes long, so split it up. */%@AE@%%@NL@%
- cbWrite1 = 0x8000;%@NL@%
- cbWrite2 = 0x8000;%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* This segment is less than 64K bytes long, so write it all. */%@AE@%%@NL@%
- cbWrite1 = cbExtra;%@NL@%
- cbWrite2 = 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* There's a possibility that cbExtra will be 0, so check%@NL@%
- %@AB@% * to avoid an unnecessary system call.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (cbWrite1 > 0)%@NL@%
- {%@NL@%
- if (DosWrite( hfile%@NL@%
- , (PVOID)MAKEP(selBits+(i<<hugeshift), 0)%@NL@%
- , cbWrite1%@NL@%
- , &cbWritten))%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- if (cbWrite1 != cbWritten)%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* This will always be skipped on the last partial segment. */%@AE@%%@NL@%
- if (cbWrite2 > 0)%@NL@%
- {%@NL@%
- if (DosWrite( hfile%@NL@%
- , (PVOID)MAKEP(selBits+(i<<hugeshift), cbWrite1)%@NL@%
- , cbWrite2%@NL@%
- , &cbWritten))%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- if (cbWrite2 != cbWritten)%@NL@%
- goto lfwrite_error_free_bits;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- fRet = TRUE; %@AB@%/* The bits are on the disk. */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*******************************************************************%@NL@%
- %@AB@% * Close the file, free the buffer space and leave. This is a%@NL@%
- %@AB@% * common exit point from the function. Since the same cleanup%@NL@%
- %@AB@% * operations need to be performed for such a large number of%@NL@%
- %@AB@% * possible error conditions, this is concise way to do the right%@NL@%
- %@AB@% * thing.%@NL@%
- %@AB@% *******************************************************************/%@AE@%%@NL@%
- %@NL@%
- lfwrite_error_free_bits:%@NL@%
- DosFreeSeg(selBits);%@NL@%
- lfwrite_error_free_header:%@NL@%
- DosFreeSeg(*((PUSHORT)&pbfh+1));%@NL@%
- lfwrite_error_close_file:%@NL@%
- DosClose(hfile);%@NL@%
- return fRet;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/************************************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* MyMessageBox%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* Displays a message box with the given string. To simplify matters,%@NL@%
- %@AB@%* the box will always have the same title ("FatPel"), will always%@NL@%
- %@AB@%* have a single button ("Ok"), will always have an exclamation point%@NL@%
- %@AB@%* icon, and will always be application modal.%@NL@%
- %@AB@%*%@NL@%
- %@AB@%************************************************************************/%@AE@%%@NL@%
- %@NL@%
- VOID%@NL@%
- MyMessageBox(hWnd, sz)%@NL@%
- HWND hWnd;%@NL@%
- PSZ sz;%@NL@%
- {%@NL@%
- static char *szTitle = "FatPel Application";%@NL@%
- %@NL@%
- WinMessageBox(HWND_DESKTOP, hWnd, sz, szTitle, 0,%@NL@%
- MB_OK|MB_ICONEXCLAMATION|MB_APPLMODAL);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FDIR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\OS2SDK\OS2SDK12\FDIR\FDIR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*************************************************************%@NL@%
- %@AB@%%@NL@%
- %@AB@% This sample code demonstrates conversion from longnames to 8.3 and how%@NL@%
- %@AB@% to determine the longname from the EA of a FAT file.%@NL@%
- %@AB@% Should be compiled with the Large model.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Written by Jeff Johnson 6/20/89%@NL@%
- %@AB@%%@NL@%
- %@AB@% This code was written to demonstrate two new features of OS/2 V1.2:%@NL@%
- %@AB@% 1) How to convert long filenames to the appropriate 8.3 names.%@NL@%
- %@AB@% 2) How to find a file's longname on a FAT system by checking its EA.%@NL@%
- %@AB@%%@NL@%
- %@AB@% Procedures in this file:%@NL@%
- %@AB@% main() Does the main directory program calling support modules%@NL@%
- %@AB@% Convert_to_8dot3() Converts a longname to 8.3 name%@NL@%
- %@AB@% ParsePathName() Breaks a full path into its 3 components%@NL@%
- %@AB@% QueryLongname() Gets the .LONGNAME EA for a given file%@NL@%
- %@AB@% QueryIFS() Determines the IFS type of a drive%@NL@%
- %@AB@%%@NL@%
- %@AB@%**************************************************************/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INCL_DOSFILEMGR %@NL@%
- %@AI@%#define %@AE@%INCL_BASE %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%FAT 0 %@NL@%
- %@AI@%#define %@AE@%HPFS 1 %@NL@%
- %@AI@%#define %@AE@%GetInfoLevel1 0x0001 %@NL@%
- %@AI@%#define %@AE@%GetInfoLevel3 0x0003 %@NL@%
- %@NL@%
- VOID Convert_to_8dot3(CHAR *,CHAR *);%@NL@%
- VOID ParsePathName(CHAR *,CHAR *,CHAR *,CHAR *);%@NL@%
- VOID QueryLongname(CHAR *,CHAR *);%@NL@%
- VOID QueryIFS(CHAR *,PUSHORT,PUSHORT);%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Function name: main()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Parameters: argc, argv. If the user places a file spec on the command%@NL@%
- %@AB@% * line it is used to select/filter the directory listing.%@NL@%
- %@AB@% * Otherwise, the default directory is listed.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Returns: Always exits with 0.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Purpose: main() coordinates the directory process by calling the%@NL@%
- %@AB@% * appropriate setup routines, then handling the DosFindNext%@NL@%
- %@AB@% * loop for each file.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Usage/Warnings: Very little error checking is done as the code is written%@NL@%
- %@AB@% * to demonstrate longname conversion/EA reading, not as%@NL@%
- %@AB@% * a finished app.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Calls: ParsePathName(), QueryIFS(), Convert_to_8dot3(), QueryLongname()%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- main (int argc, char *argv[])%@NL@%
- {%@NL@%
- USHORT uRetval,hdir=0xffff,SearchCount=1;%@NL@%
- PFILEFINDBUF pfbuf;%@NL@%
- char szDrive[3],szPath[260],szFilename[CCHMAXPATH],szFullPath[CCHMAXPATH];%@NL@%
- USHORT ifsloc,ifsname;%@NL@%
- char *szFilePtr,szLongName[260];%@NL@%
- %@NL@%
- if(argc<2)%@NL@%
- ParsePathName("",szDrive,szPath,szFilename);%@NL@%
- else%@NL@%
- ParsePathName(argv[1],szDrive,szPath,szFilename);%@NL@%
- %@NL@%
- if(strlen(szFilename) == 0)%@NL@%
- strcpy(szFilename,"*");%@NL@%
- %@NL@%
- strcpy(szFullPath,szDrive);%@NL@%
- strcat(szFullPath,szPath);%@NL@%
- szFilePtr = szFullPath + strlen(szFullPath);%@NL@%
- strcat(szFullPath,szFilename);%@NL@%
- %@NL@%
- QueryIFS(szDrive,&ifsloc,&ifsname);%@NL@%
- %@NL@%
- if(ifsname != FAT && ifsname != HPFS)%@NL@%
- {%@NL@%
- printf("Unrecognized file system.\n");%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- if(ifsname == FAT)%@NL@%
- printf("FAT -> HPFS directory listing\n");%@NL@%
- else%@NL@%
- printf("HPFS -> FAT directory listing\n");%@NL@%
- %@NL@%
- %@NL@%
- pfbuf = (PFILEFINDBUF) malloc(sizeof(FILEFINDBUF));%@NL@%
- uRetval=DosFindFirst(szFullPath,(PHDIR) &hdir,FILE_DIRECTORY,%@NL@%
- pfbuf,sizeof(FILEFINDBUF),&SearchCount,0L);%@NL@%
- %@NL@%
- if(uRetval)%@NL@%
- {%@NL@%
- printf("No files found.\n");%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- if(ifsname == FAT)%@NL@%
- {%@NL@%
- strcpy(szFilePtr,pfbuf->achName); %@AB@%/* Drop in name after path */%@AE@%%@NL@%
- %@NL@%
- QueryLongname(szFullPath,szLongName);%@NL@%
- %@NL@%
- if(strlen(szLongName) == 0)%@NL@%
- printf("%s\n",pfbuf->achName);%@NL@%
- else%@NL@%
- printf("%s\n",szLongName);%@NL@%
- }%@NL@%
- else %@AB@%/* It's HPFS */%@AE@%%@NL@%
- {%@NL@%
- Convert_to_8dot3(pfbuf->achName,szFilename);%@NL@%
- printf("%s\n",szFilename);%@NL@%
- }%@NL@%
- } while(!(uRetval=DosFindNext(hdir,pfbuf,%@NL@%
- sizeof(FILEFINDBUF),&SearchCount)));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Function name: Convert_to_8dot3()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Parameters: szLong points to the input long file name.%@NL@%
- %@AB@% * szFat points to a return buffer for the FAT compatible name.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Returns: VOID. The converted string is placed in szFat buffer.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Purpose: Converts a HPFS longname to the standard 8.3 name. This is%@NL@%
- %@AB@% * done as follows: The extension is the first 3 characters after%@NL@%
- %@AB@% * the last dot, no extension if there are no dots. The file stem%@NL@%
- %@AB@% * is at most 8 character and is taken from the beginning of the%@NL@%
- %@AB@% * longname string, replacing all dots with underscores.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Usage/Warnings: Should be bulletproof. Exception code included to allow%@NL@%
- %@AB@% * the special file name '..' through.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Calls:%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- VOID Convert_to_8dot3(CHAR *szLong,CHAR *szFat)%@NL@%
- {%@NL@%
- USHORT usStemMaxLen; %@AB@%/* Holds the max size the 8 char base can be */%@AE@%%@NL@%
- USHORT cnt;%@NL@%
- CHAR szStem[9],szExt[4]; %@AB@%/* Holds the Stem and Extension */%@AE@%%@NL@%
- CHAR *szLastDot; %@AB@%/* Pointer to the last dot */%@AE@%%@NL@%
- %@NL@%
- if(!strcmp(szLong,"..")) %@AB@%/* Allow the predecessor file to pass thru */%@AE@%%@NL@%
- {%@NL@%
- strcpy(szFat,"..");%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- szLastDot = strrchr(szLong,'.'); %@AB@%/* Find the last period */%@AE@%%@NL@%
- %@NL@%
- if(szLastDot) %@AB@%/* There is at least one period */%@AE@%%@NL@%
- {%@NL@%
- strncpy(szExt,szLastDot+1,3); %@AB@%/* 1st 3 chars after . are ext */%@AE@%%@NL@%
- szExt[3]=0;%@NL@%
- usStemMaxLen = szLastDot - szLong; %@AB@%/* Max stem is everything b4 . */%@AE@%%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- *szExt = 0; %@AB@%/* No extension */%@AE@%%@NL@%
- usStemMaxLen = strlen(szLong); %@AB@%/* Stem can be whole string */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- if(usStemMaxLen>8) %@AB@%/* Limit stem to 8 chars */%@AE@%%@NL@%
- usStemMaxLen = 8;%@NL@%
- %@NL@%
- for(cnt=0;cnt<usStemMaxLen;cnt++) %@AB@%/* Copy in chars to form stem */%@AE@%%@NL@%
- {%@NL@%
- switch(szLong[cnt])%@NL@%
- {%@NL@%
- case '.': %@AB@%/* Convert .'s to _'s */%@AE@%%@NL@%
- szStem[cnt] = '_';%@NL@%
- break;%@NL@%
- default: %@AB@%/* Copy all other chars */%@AE@%%@NL@%
- szStem[cnt] = szLong[cnt];%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- szStem[cnt] = 0;%@NL@%
- %@NL@%
- %@AB@%/* Put it all together */%@AE@%%@NL@%
- strcpy(szFat,szStem);%@NL@%
- strcat(szFat,".");%@NL@%
- strcat(szFat,szExt);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Function name: ParsePathName()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Parameters: szFullPath points to the input full path name.%@NL@%
- %@AB@% * szDrive points to the return buffer for the drive letter.%@NL@%
- %@AB@% * szPath points to the return buffer for the path.%@NL@%
- %@AB@% * szFilename points to the return buffer for the Filename.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Returns: VOID. The converted string is placed in last 3 passed params.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Purpose: Break a full path string and break it into its three components.%@NL@%
- %@AB@% * If the passed string doesn't have a drive, the current letter is%@NL@%
- %@AB@% * fetched an placed in the return buffer. The same is true for%@NL@%
- %@AB@% * the path buffer.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Usage/Warnings: Error checking should be done on the DOS calls.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Calls:%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- VOID ParsePathName(CHAR *szFullPath,CHAR *szDrive,CHAR *szPath,CHAR *szFilename)%@NL@%
- {%@NL@%
- CHAR *szBack; %@AB@%/* Used to find last backslach */%@AE@%%@NL@%
- USHORT usPathLen; %@AB@%/* Holds the length of the path part of string */%@AE@%%@NL@%
- %@NL@%
- *szPath = *szFilename = 0;%@NL@%
- %@NL@%
- %@AB@%/* Do the Drive letter */%@AE@%%@NL@%
- if(*(szFullPath+1)==':') %@AB@%/* If there is a drive letter */%@AE@%%@NL@%
- {%@NL@%
- szDrive[0] = *szFullPath;%@NL@%
- %@NL@%
- szFullPath += 2;%@NL@%
- }%@NL@%
- else %@AB@%/* We take the default */%@AE@%%@NL@%
- {%@NL@%
- USHORT dno; %@AB@%/* Drive number */%@AE@%%@NL@%
- ULONG dmap; %@AB@%/* Map of available drives */%@AE@%%@NL@%
- %@NL@%
- DosQCurDisk((PUSHORT) &dno,(PULONG) &dmap);%@NL@%
- *szDrive = (CHAR)( dno + 'A'-1);%@NL@%
- }%@NL@%
- szDrive[1] = ':'; %@AB@%/* Add the colon */%@AE@%%@NL@%
- szDrive[2] = (CHAR) 0;%@NL@%
- %@NL@%
- %@AB@%/* Now do the path */%@AE@%%@NL@%
- szBack = strrchr(szFullPath,'\\');%@NL@%
- if(szBack) %@AB@%/* There is at least 1 backslash */%@AE@%%@NL@%
- {%@NL@%
- usPathLen = szBack - szFullPath + 1;%@NL@%
- strncpy(szPath,szFullPath,usPathLen); %@AB@%/* Copy path */%@AE@%%@NL@%
- szPath[usPathLen] = (CHAR) 0;%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- *szPath = (CHAR) 0;%@NL@%
- szBack = szFullPath-1; %@AB@%/* Points 1 char before the file name */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Finally do the file name */%@AE@%%@NL@%
- strcpy(szFilename,szBack+1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Function name: QueryLongname()%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Parameters: szfile points to the file to be queried.%@NL@%
- %@AB@% * szLong points to the return buffer for the long filename.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Returns: VOID. The converted string is placed in last 3 passed params.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Purpose: Looks for an EA named .LONGNAME attached to szfile. If found,%@NL@%
- %@AB@% * it places the EA value in the return buffer.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Usage/Warnings: Routine assumes that the EA format is LP ASCII which%@NL@%
- %@AB@% * is what the specs required, but probably the exception%@NL@%
- %@AB@% * handling should be a bit tighter. Return buf should be%@NL@%
- %@AB@% * at least CCHMAXPATH long to accomodate max length names.%@NL@%
- %@AB@% * Note also that no check is made to prevent overwriting%@NL@%
- %@AB@% * the end of the return buffer.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Calls:%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- VOID QueryL