--- pmsdk/samples/snap/snap.c 2018/08/09 12:28:13 1.1.1.1 +++ pmsdk/samples/snap/snap.c 2018/08/09 12:28:29 1.1.1.2 @@ -1,13 +1,14 @@ /* - Source file for SNAPshot utility - Created by Microsoft Corp., 1988 + snap.c -- PM snapshot utility + Created by Microsoft Corporation, 1989 */ -#define INCL_WIN -#define INCL_GPI -#define INCL_DEV -#include -#include "snap.h" +#define INCL_WIN +#define INCL_GPI +#define INCL_DEV +#include +#include "snap.h" +/* Global variables */ char szSnap[5]; HAB habSnap; @@ -35,36 +36,40 @@ BOOL fNCArea = FALSE; /* exclude noncl BOOL fHide = TRUE; /* hide snap's window while snapping */ -MRESULT FAR PASCAL SnapWndProc(HWND, USHORT, MPARAM, MPARAM); -MRESULT FAR PASCAL AboutWndProc(HWND, USHORT, MPARAM, MPARAM); +/* Function prototypes */ +MRESULT CALLBACK SnapWndProc(HWND, USHORT, MPARAM, MPARAM); +MRESULT CALLBACK AboutWndProc(HWND, USHORT, MPARAM, MPARAM); +MRESULT CALLBACK SaveFileDlgProc(HWND, USHORT, MPARAM, MPARAM); +HFILE OpenSaveFile(HWND); void SnapWindow(ULONG); -BOOL SnapInit(); -void SnapPaint(); -void SnapRegion(); -void DrawRgn(); -void SortRect(); -void SaveBitmap(); +BOOL SnapInit(void); +void SnapPaint(HPS); +void SnapRegion(HPS); +void DrawRgn(HPS); +void SortRect(PRECTL, PRECTL); +void SaveBitmap(void); void SaveBitmap2(HFILE hFile, HBITMAP hbm); void convert(NPBYTE pbuf, USHORT cch, USHORT cch2); -void Copy(); +HDC CreateDC(PSZ, HDC); +void Copy(NPBYTE, NPBYTE, USHORT); +int cdecl main(void); -int cdecl main(argc, argv) -int argc; -char *argv[]; + +/* Routines */ +int cdecl main(void) { QMSG msg; - SHORT rgWords[20]; ULONG ctlData; if (!SnapInit()) return(FALSE); ctlData = FCF_TITLEBAR | FCF_MINMAX | FCF_SIZEBORDER | - FCF_SYSMENU | FCF_MENU; + FCF_SYSMENU | FCF_MENU | FCF_ICON; hwndSnapFrame = WinCreateStdWindow(HWND_DESKTOP, FS_ICON, &ctlData, (PCH)szSnap, (PCH)szSnap, - 0L, + 0L, NULL, 1, (HWND far *)&hwndSnap); @@ -95,33 +100,30 @@ char *argv[]; WinDestroyHeap(hHeap); WinDestroyMsgQueue(hmqSnap); - WinTerminate(NULL); - - DosExit(EXIT_PROCESS, 0); + WinTerminate(habSnap); + return 0; } /* end winmain */ HDC CreateDC(lpszDriver, hdcCompat) -PSZ lpszDriver; +PSZ lpszDriver; HDC hdcCompat; { - HDC hdc; struct { ULONG FAR *lpLogAddr; - PSZ lpszDriver; + PSZ lpszDriver; } opendc; opendc.lpLogAddr = NULL; opendc.lpszDriver = lpszDriver; - return((HDC)DevOpenDC(habSnap, OD_MEMORY, (PSZ)"*", 2L, + return((HDC)DevOpenDC(habSnap, OD_MEMORY, (PSZ)"*", 2L, (PDEVOPENDATA)&opendc, hdcCompat)); } -BOOL SnapInit() +BOOL SnapInit(void) { - /* * Initialize the HAB */ @@ -140,11 +142,16 @@ BOOL SnapInit() if ((hHeap = WinCreateHeap(0, 0, 0, 0, 0, 0)) == NULL) return(FALSE); - + /* + * We assume an empty clipboard when we start. + */ + WinOpenClipbrd(habSnap); + WinEmptyClipbrd(habSnap); + WinCloseClipbrd(habSnap); } /* end snapinit */ -MRESULT FAR PASCAL SnapWndProc(hwnd, message, mp1, mp2) +MRESULT CALLBACK SnapWndProc(hwnd, message, mp1, mp2) HWND hwnd; USHORT message; MPARAM mp1; @@ -165,7 +172,7 @@ MPARAM mp2; } else if (fSnapRgn) { wptTemp.x = SHORT1FROMMP(mp1); wptTemp.y = SHORT2FROMMP(mp1); - WinMapWindowPoints(hwndSnap, (HWND)HWND_DESKTOP, + WinMapWindowPoints(hwndSnap, (HWND)HWND_DESKTOP, (PPOINTL)&wptTemp, 1); wrcRgn.yTop = wrcRgn.yBottom = wptTemp.y; wrcRgn.xRight = wrcRgn.xLeft = wptTemp.x; @@ -185,7 +192,7 @@ MPARAM mp2; DrawRgn(hpsScr); wptTemp.x = LOUSHORT(mp1); wptTemp.y = HIUSHORT(mp1); - WinMapWindowPoints(hwndSnap, (HWND)HWND_DESKTOP, + WinMapWindowPoints(hwndSnap, (HWND)HWND_DESKTOP, (PPOINTL)&wptTemp, 1); wrcRgn.yTop = wptTemp.y; wrcRgn.xRight = wptTemp.x; @@ -269,19 +276,9 @@ MPARAM mp2; fHide = !fHide; break; - case IDM_EXIT: - WinPostMsg(WinQueryWindow(hwnd, QW_PARENT, FALSE), - WM_SYSCOMMAND, MPFROMSHORT(SC_CLOSE), 0L); - break; - case IDM_ABOUT: - if (AboutCount == 4) { - AboutCount = 0; - WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutWndProc, NULL, 2, (PCH)NULL); - } else { - AboutCount++; - WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutWndProc, NULL, 1, (PCH)NULL); - } + WinDlgBox(HWND_DESKTOP, hwnd, + (PFNWP)AboutWndProc, NULL, IDD_INFO, (PCH)NULL); break; } break; @@ -324,14 +321,13 @@ ULONG loc; { BITMAPINFOHEADER bminfo; POINTL pt; - char szCaption[80]; HWND hwnd; HWND hwndT; RECTL rc, rcTmp; HPS hpsWnd, hpsMem; HDC hdc; HBITMAP hbm, hbmOld; - int cx, cy, dx, dy; + int cx, cy; POINTL rgpt[3]; SIZEL size; @@ -362,7 +358,7 @@ ULONG loc; /* create a memory PS */ size.cx = cx; size.cy = cy; - hpsMem = GpiCreatePS( habSnap, hdc, &size, + hpsMem = GpiCreatePS( habSnap, hdc, &size, PU_ARBITRARY | GPIT_NORMAL | GPIA_ASSOC ); /* Create a bitmap */ @@ -382,9 +378,9 @@ ULONG loc; /* copy the window to the memory PS */ rgpt[0].x = 0; rgpt[0].y = 0; - rgpt[1].x = cx; + rgpt[1].x = cx; rgpt[1].y = cy; - rgpt[2].x = rc.xLeft; + rgpt[2].x = rc.xLeft; rgpt[2].y = rc.yBottom; GpiBitBlt(hpsMem, hpsWnd, 3L, (PPOINTL)&rgpt[0], ROP_SRCCOPY, 0L); @@ -400,7 +396,7 @@ ULONG loc; /* destroy the memory DC */ GpiAssociate( hpsMem, NULL ); - DevCloseDC(hdc); + DevCloseDC(hdc); /* get rid of the PSs */ GpiDestroyPS(hpsMem); @@ -435,7 +431,7 @@ HPS hpsScr; /* create a memory PS */ size.cx = cx; size.cy = cy; - hpsMem = GpiCreatePS( habSnap, hdc, &size, + hpsMem = GpiCreatePS( habSnap, hdc, &size, PU_ARBITRARY | GPIT_NORMAL | GPIA_ASSOC ); /* Create a bitmap */ @@ -455,9 +451,9 @@ HPS hpsScr; /* copy the window to the memory PS */ rgpt[0].x = 0; rgpt[0].y = 0; - rgpt[1].x = cx; + rgpt[1].x = cx; rgpt[1].y = cy; - rgpt[2].x = rcTmp.xLeft; + rgpt[2].x = rcTmp.xLeft; rgpt[2].y = rcTmp.yBottom; GpiBitBlt(hpsMem, hpsScr, 3L, (PPOINTL)&rgpt[0], ROP_SRCCOPY, 0L); @@ -472,7 +468,7 @@ HPS hpsScr; } /* destroy the memory DC */ GpiAssociate( hpsMem, NULL ); - DevCloseDC(hdc); + DevCloseDC(hdc); /* get rid of the PS */ GpiDestroyPS(hpsMem); @@ -487,11 +483,9 @@ HPS hps; { RECTL rc; - POINTL rgpt[3]; - SortRect((PRECTL)&wrcRgn, (PRECTL)&rc); - WinDrawBorder(hps, (PRECTL)&rc, 1, 1, SYSCLR_WINDOW, SYSCLR_WINDOW, + WinDrawBorder(hps, (PRECTL)&rc, 1, 1, SYSCLR_WINDOW, SYSCLR_WINDOW, DB_DESTINVERT | DB_STANDARD); } @@ -514,7 +508,7 @@ PRECTL pwrcIn, pwrcSorted; } } -MRESULT FAR PASCAL AboutWndProc(hwnd, message, mp1, mp2) +MRESULT CALLBACK AboutWndProc(hwnd, message, mp1, mp2) HWND hwnd; USHORT message; MPARAM mp1; @@ -532,14 +526,12 @@ MPARAM mp2; } /* end aboutwndproc */ -void SaveBitmap() +void SaveBitmap(void) { HFILE hFile; HBITMAP hbm; HPOINTER hptr, hptrWait; - extern HFILE OpenSaveFile(HWND hwnd); - WinOpenClipbrd(habSnap); if ((hbm = WinQueryClipbrdData(habSnap, CF_BITMAP)) == NULL) { WinCloseClipbrd(habSnap); @@ -553,7 +545,7 @@ void SaveBitmap() SaveBitmap2(hFile, hbm); WinSetPointer(HWND_DESKTOP, hptr); WinDestroyPointer(hptrWait); - } else + } else WinAlarm(HWND_DESKTOP, WA_ERROR); WinCloseClipbrd(habSnap); @@ -566,7 +558,7 @@ void SaveBitmap2(hFile, hbm) HFILE hFile; HBITMAP hbm; { - /* + /* * Currently, this puts stuff out in Win386 paint format. */ typedef struct _WIN386PAINT { @@ -595,7 +587,7 @@ HBITMAP hbm; NPBYTE pScanLine, pBits, pBitsT; USHORT *phdr; USHORT cbIndexTable, cbScanLine, cbScanLineExp, cbBmpLine; - HDC hdc, hdcOld; + HDC hdc; HBITMAP hbmOld; BITMAPINFOHEADER bminfo; HPS hpsMem; @@ -605,8 +597,6 @@ HBITMAP hbm; * write header */ GpiQueryBitmapParameters(hbm, &bminfo); - - /* I hardcoded what I found in an existing file. */ hdr.key1 = 0x694C; hdr.key2 = 0x536E; hdr.dxFile = bminfo.cx; @@ -628,7 +618,7 @@ HBITMAP hbm; hdr.res1 = 0; hdr.res2 = 0; hdr.res3 = 0; - + DosWrite(hFile, (PSZ)&hdr, sizeof(FHDR), (PUSHORT)&cBytesWritten); /* calculate sizes */ @@ -646,7 +636,7 @@ HBITMAP hbm; goto Exit; } pIndexT = pIndex; - for (i=0; i < bminfo.cy; i++) + for (i=0; i < bminfo.cy; i++) *pIndexT++ = cbScanLineExp; DosWrite(hFile, (PSZ)pIndex, cbIndexTable, &cBytesWritten); @@ -678,11 +668,11 @@ HBITMAP hbm; /* create a memory PS */ size.cx = bminfo.cx; size.cy = bminfo.cy; - hpsMem = GpiCreatePS( habSnap, hdc, &size, + hpsMem = GpiCreatePS( habSnap, hdc, &size, PU_ARBITRARY | GPIT_NORMAL | GPIA_ASSOC); hbmOld = GpiSetBitmap(hpsMem, hbm); - GpiQueryBitmapBits(hpsMem, (LONG)0, (LONG)bminfo.cy, (PBYTE)pBits, + GpiQueryBitmapBits(hpsMem, (LONG)0, (LONG)bminfo.cy, (PBYTE)pBits, (PBITMAPINFO)&bminfo); pBitsT = pBits + cbBmpLine * bminfo.cy; @@ -701,13 +691,13 @@ HBITMAP hbm; DevCloseDC(hdc); GpiDestroyPS(hpsMem); -Exit: +Exit: DosClose(hFile); } /***************************************************************************\ -* Insert appropriate repeat count bytes into the scanline given. +* Insert apropriate repeat count bytes into the scanline given. \***************************************************************************/ void convert(pbuf, cch, cch2) NPBYTE pbuf; @@ -721,7 +711,7 @@ USHORT cch2; /* AFTER conversion size */ while (pWrite > pbuf) { *pWrite-- = *pRead--; if (((pWrite - pbuf) & 0x00ff) == 0) { - *pWrite-- = (BYTE)((pbuf + cch2 - pWrite) < 0x100 ? + *pWrite-- = (BYTE)((pbuf + cch2 - pWrite) < 0x100 ? (pbuf + cch2 - pWrite) : 0xff); } } @@ -734,7 +724,7 @@ USHORT cb; { USHORT i; - for (i = 0; i < cb; i++) + for (i = 0; i < cb; i++) *dest++ = *src++; } @@ -746,19 +736,16 @@ HWND hwnd; char fName[32]; USHORT action; - extern MRESULT FAR PASCAL SaveFileDlgProc(HWND hwnd, USHORT msg, - MPARAM mp1, MPARAM mp2); - dlgp.cch = 32; dlgp.psz = fName; - if (WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)SaveFileDlgProc, NULL, + if (WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)SaveFileDlgProc, NULL, IDD_SAVEFILE, (PVOID)&dlgp) != 0) { DosOpen(fName, &hFile, &action, 0L, 0, 0x0011, 0x0011, 0L); } return(hFile); } -MRESULT FAR PASCAL SaveFileDlgProc(hwnd, msg, mp1, mp2) +MRESULT CALLBACK SaveFileDlgProc(hwnd, msg, mp1, mp2) HWND hwnd; USHORT msg; MPARAM mp1; @@ -774,11 +761,11 @@ MPARAM mp2; break; case WM_CHAR: - if ( ((USHORT)mp1 & KC_VIRTUALKEY) && + if ( ((USHORT)mp1 & KC_VIRTUALKEY) && ((SHORT2FROMMP(mp2) == VK_NEWLINE) || (SHORT2FROMMP(mp2) == VK_ENTER)) ) { if (pdlgp = (DLGP FAR *)WinQueryWindowULong(hwnd, QWL_USER)) { - cch = WinQueryWindowText(WinWindowFromID(hwnd, ID_FILEENTRY), + cch = WinQueryWindowText(WinWindowFromID(hwnd, ID_FILEENTRY), pdlgp->cch, pdlgp->psz); WinDismissDlg(hwnd, cch); } else { @@ -787,7 +774,7 @@ MPARAM mp2; return(0); } break; - } - + } + return(WinDefDlgProc(hwnd, msg, mp1, mp2)); }