--- mstools/samples/mfedit/mfedit.c 2018/08/09 18:20:54 1.1.1.1 +++ mstools/samples/mfedit/mfedit.c 2018/08/09 18:21:57 1.1.1.2 @@ -7,7 +7,7 @@ * Created: 28-May-1992 14:24:00 * Author: Petrus Wong * -* Copyright (c) 1990 Microsoft Corporation +* Copyright (c) 1992 Microsoft Corporation * * The Enhanced Metafile Editor serves to demonstrate the enhanced metafile * APIs in Windows NT. @@ -36,16 +36,16 @@ #include #include + // // Forward declarations. // BOOL InitializeApp (void); -LONG MainWndProc (HWND, UINT, DWORD, LONG); -LONG DrawSurfWndProc (HWND, UINT, DWORD, LONG); -LONG MDIWndProc (HWND, UINT, DWORD, LONG); -LONG About (HWND, UINT, DWORD, LONG); -LONG TextWndProc (HWND, UINT, DWORD, LONG); -LONG CtrlPanelDlgProc(HWND, UINT, DWORD, LONG); +LONG APIENTRY MainWndProc (HWND, UINT, DWORD, LONG); +LONG APIENTRY DrawSurfWndProc (HWND, UINT, DWORD, LONG); +LONG APIENTRY About (HWND, UINT, DWORD, LONG); +LONG APIENTRY TextWndProc (HWND, UINT, DWORD, LONG); +LONG APIENTRY CtrlPanelDlgProc(HWND, UINT, DWORD, LONG); BOOL bDrawStuff (HDC, INT, INT, INT, INT, BOOL, BOOL, BOOL, LPSTR); HENHMETAFILE hemfLoadMetafile(HWND); HDC hDCRecordMetafileAs(HWND, LPSTR); @@ -57,6 +57,7 @@ BOOL bGetBMP(HWND, BOOL); BOOL bChooseNewFont(HWND, PLOGFONT, COLORREF * ); BOOL bChooseNewColor(HWND, LPDWORD); HBRUSH hBrCreateBrush(HDC, DWORD); +extern int FAR PASCAL ShellAbout(HWND, LPCSTR, LPCSTR, HICON); /***************************************************************************\ * WinMain @@ -64,11 +65,11 @@ HBRUSH hBrCreateBrush(HDC, DWORD); * History: * 11-Feb-1992 Petrus Wong \***************************************************************************/ -int WinMain( - HANDLE hInstance, - HANDLE hPrevInstance, - LPSTR lpCmdLine, - int nShowCmd) +int APIENTRY WinMain( + HANDLE hInstance, + HANDLE hPrevInstance, + LPSTR lpCmdLine, + int nShowCmd) { MSG msg; HANDLE hAccel; @@ -174,6 +175,7 @@ BOOL InitializeApp(void) return FALSE; SetWindowLong(ghwndMain, GWL_USERDATA, 0L); + ghwndNext = SetClipboardViewer(ghwndMain); SetFocus(ghwndMain); /* set initial focus */ @@ -190,7 +192,7 @@ BOOL InitializeApp(void) * 09-09-91 Petrus Wong Created. \***************************************************************************/ -long MainWndProc( +long APIENTRY MainWndProc( HWND hwnd, UINT message, DWORD wParam, @@ -231,6 +233,16 @@ long MainWndProc( ghpnWide = CreatePen(PS_SOLID, 5, RGB(0, 0, 0)); return 0L; } + case WM_DRAWCLIPBOARD: + if ((IsClipboardFormatAvailable(CF_METAFILEPICT)) || + (IsClipboardFormatAvailable(CF_ENHMETAFILE)) ) + EnableMenuItem(hMenu, MM_PASTE, MF_ENABLED); + else + EnableMenuItem(hMenu, MM_PASTE, MF_GRAYED); + + if (ghwndNext) + SendMessage(ghwndNext, message, wParam, lParam); + return 0L; case WM_SIZE: { RECT rc; @@ -260,7 +272,8 @@ long MainWndProc( 0, lcyCtrlPanel, LOWORD(lParam), // cx of hwnd lcyDrawSurf, TRUE); - break; + //break; + return DefWindowProc(hwnd, message, wParam, lParam); } case WM_DESTROY: { @@ -272,6 +285,7 @@ long MainWndProc( DeleteObject(ghpnCur); DeleteObject(ghbrAppBkgd); DeleteObject(ghpnWide); + ChangeClipboardChain(ghwndMain, ghwndNext); PostQuitMessage(0); return 0L; } @@ -311,12 +325,13 @@ long MainWndProc( //!!!GetClientRect(ghwndDrawSurf, &rcClientDS); hDCDrawSurf = GetDC(ghwndDrawSurf); //!!!EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, &rcClientDS); - EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds); + EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds); // // Enabling the user to record a metafile record selectively // - if ((gbRecording) && (ghDCMetaf != NULL)) - EnumEnhMetaFile(ghDCMetaf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds); + if ((gbRecording) && (ghDCMetaf != NULL)) { + EnumEnhMetaFile(ghDCMetaf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds); + } ReleaseDC(ghwndDrawSurf, hDCDrawSurf); } return 0L; @@ -333,10 +348,56 @@ long MainWndProc( case MM_PAGESETUP: case MM_PRINTSETUP: case MM_CUT: - case MM_COPY: - case MM_PASTE: - case MM_DEL: return 0L; + + case MM_COPY: { + HENHMETAFILE hEmfTmp; + if (ghMetaf == 0) { + SetWindowText(ghTextWnd, "No Metafile for copying"); + return 0L; + } + + OpenClipboard(ghwndMain); + EmptyClipboard(); + hEmfTmp = CopyEnhMetaFile(ghMetaf, NULL); + + if (hEmfTmp) { + SetClipboardData(CF_ENHMETAFILE, hEmfTmp); + DeleteEnhMetaFile(hEmfTmp); + } + + CloseClipboard(); + return 0L; + } + + case MM_PASTE: { + HENHMETAFILE hEmfTmp; + ENHMETAHEADER EnhMetaHdr; + + OpenClipboard(ghwndMain); + + hEmfTmp = GetClipboardData(CF_ENHMETAFILE); + if (hEmfTmp) { + DeleteEnhMetaFile(ghMetaf); + ghMetaf = CopyEnhMetaFile(hEmfTmp, NULL); + DeleteEnhMetaFile(hEmfTmp); + GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr); + SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, EnhMetaHdr.nRecords, FALSE); + bReset = TRUE; + } + + CloseClipboard(); + EnableMenuItem(hMenu, MM_COPY, MF_ENABLED); + return 0L; + } + + case MM_DEL: { + OpenClipboard(ghwndMain); + EmptyClipboard(); + CloseClipboard(); + return 0L; + } + case MM_PEN: { HDC hDC; DWORD dwRGB; @@ -403,9 +464,15 @@ long MainWndProc( } return 0L; } - case MM_ABOUT: + + case MM_LEABOUT: if (DialogBox(ghModule, (LPCSTR)"AboutBox", ghwndMain, (DLGPROC)About) == -1) MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK); + return 0L; + + case MM_ABOUT: + ShellAbout(ghwndMain, "Metafile Editor", "", + LoadIcon(ghModule, MAKEINTRESOURCE(APPICON))); return 0L; case MM_LOAD_MASKBMP: @@ -425,15 +492,24 @@ long MainWndProc( case MM_LOAD: case DID_OPEN: { ENHMETAHEADER EnhMetaHdr; + HENHMETAFILE hEmfTmp; SetWindowText(ghTextWnd, "Load Metafile"); - DeleteEnhMetaFile(ghMetaf); - ghMetaf = hemfLoadMetafile(hwnd); - if (ghMetaf != 0) { + // + // If user hit cancel, we still have the original metafile + // + //DeleteEnhMetaFile(ghMetaf); + //ghMetaf = hemfLoadMetafile(hwnd); + hEmfTmp = hemfLoadMetafile(hwnd); + if (hEmfTmp != 0) { + DeleteEnhMetaFile(ghMetaf); + ghMetaf = CopyEnhMetaFile(hEmfTmp, NULL); GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr); SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, EnhMetaHdr.nRecords, FALSE); - } else { - SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, 0, FALSE); + DeleteEnhMetaFile(hEmfTmp); + EnableMenuItem(hMenu, MM_COPY, MF_ENABLED); + //} else { + // SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, 0, FALSE); } bReset = TRUE; return 0L; @@ -507,6 +583,7 @@ long MainWndProc( gbRecording = FALSE; } return 0L; + case DID_PLAY: { HDC hDCDrawSurf; ENHMETAHEADER EnhMetaHdr; @@ -523,11 +600,15 @@ long MainWndProc( // // Enabling the user to embed another metafile // - if ((gbRecording) && (ghDCMetaf != NULL)) + if ((gbRecording) && (ghDCMetaf != NULL)) { PlayEnhMetaFile( ghDCMetaf, ghMetaf, (LPRECT) &EnhMetaHdr.rclBounds); + } ReleaseDC(ghwndDrawSurf, hDCDrawSurf); + } else { + SetWindowText(ghTextWnd, "No Metafile for Playing"); } + return 0L; } case DID_FF: { @@ -549,13 +630,14 @@ long MainWndProc( //!!!GetClientRect(ghwndDrawSurf, &rcClientDS); hDCDrawSurf = GetDC(ghwndDrawSurf); //!!!EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT) &rcClientDS); - EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT) &EnhMetaHdr.rclBounds); + EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT) &EnhMetaHdr.rclBounds); // // Enabling the user to record a metafile records selectively // - if ((gbRecording) && (ghDCMetaf != NULL)) - EnumEnhMetaFile(ghDCMetaf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds); + if ((gbRecording) && (ghDCMetaf != NULL)) { + EnumEnhMetaFile(ghDCMetaf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds); + } ReleaseDC(ghwndDrawSurf, hDCDrawSurf); } @@ -642,7 +724,7 @@ long MainWndProc( * Wrote it. \**************************************************************************/ -long DrawSurfWndProc( +long APIENTRY DrawSurfWndProc( HWND hwnd, UINT message, DWORD wParam, @@ -838,7 +920,7 @@ long DrawSurfWndProc( * 04-13-91 ???? Created. \***************************************************************************/ -long About( +long APIENTRY About( HWND hDlg, UINT message, DWORD wParam, @@ -872,7 +954,7 @@ long About( * \***************************************************************************/ -LONG TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam) +LONG APIENTRY TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam) { static HFONT hFont = (HFONT) NULL; @@ -983,7 +1065,7 @@ LONG TextWndProc (HWND hwnd, UINT messag * Wrote it. \**************************************************************************/ -LONG CtrlPanelDlgProc(HWND hwnd, UINT msg, DWORD dwParam, LONG lParam) +LONG APIENTRY CtrlPanelDlgProc(HWND hwnd, UINT msg, DWORD dwParam, LONG lParam) { switch (msg) { case WM_INITDIALOG: { @@ -1141,18 +1223,24 @@ LONG CtrlPanelDlgProc(HWND hwnd, UINT ms //case WM_CTLCOLOR: case WM_CTLCOLORDLG: //case WM_CTLCOLORLISTBOX: - //case WM_CTLCOLORSTATIC: + case WM_CTLCOLORSTATIC: switch (GET_WM_CTLCOLOR_TYPE(dwParam, lParam, msg)) { case CTLCOLOR_DLG: //case CTLCOLOR_LISTBOX: return (BOOL)GetStockObject(LTGRAY_BRUSH); - //case CTLCOLOR_STATIC: + case CTLCOLOR_STATIC: + SetBkMode(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg), + TRANSPARENT); + // SetTextColor(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg), + // RGB(255,0,0)); // SetBkColor(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg), // LIGHTGRAY); - // return (BOOL)GetStockObject(LTGRAY_BRUSH); + // RGB(255, 255,0)); + return (BOOL)GetStockObject(DKGRAY_BRUSH); } - return (BOOL)NULL; + //return (BOOL)NULL; + return (BOOL)GetStockObject(LTGRAY_BRUSH); default: return FALSE; @@ -1233,14 +1321,31 @@ BOOL bDrawStuff(HDC hDC, INT OrgX, INT O break; } - SetTextAlign(hDC, TA_UPDATECP); + SetTextAlign(hDC, TA_BASELINE | TA_LEFT | TA_UPDATECP); hObjOld = SelectObject(hDC, ghCurFont); SetTextColor(hDC, gCrText); SetBkMode(hDC, TRANSPARENT); - TextOut(hDC, 0, 0, lpstr, 1); - SelectObject(hDC, hObjOld); + + + { + LONG lHeight; + LONG lWidth; + TEXTMETRIC tm; + + if (GetTextMetrics(hDC, &tm)) { + lHeight = tm.tmHeight; + lWidth = tm.tmMaxCharWidth; + } + + TextOut(hDC, NextX, NextY, lpstr, 1); GetCurrentPositionEx(hDC, (LPPOINT) &Pt); - SetCaretPos(Pt.x, Pt.y+2); + SetCaretPos(Pt.x+lWidth, Pt.y); + + } + + SelectObject(hDC, hObjOld); + //GetCurrentPositionEx(hDC, (LPPOINT) &Pt); + //SetCaretPos(Pt.x, Pt.y+2); ShowCaret(ghwndDrawSurf); bCaretShown = TRUE; @@ -1445,6 +1550,7 @@ BOOL bDrawStuff(HDC hDC, INT OrgX, INT O * History: * 08-May-1992 -by- Petrus Wong * Wrote it. +* 28-Aug-1992 -by- Petrus Wong supports aldus placable mf, wmf and emf \**************************************************************************/ HENHMETAFILE hemfLoadMetafile(HWND hwnd) { @@ -1452,8 +1558,23 @@ HENHMETAFILE hemfLoadMetafile(HWND hwnd) char szFile[256], szFileTitle[256]; static char *szFilter; + HMETAFILE hmf; + UINT uiSize; + LPVOID pvData; + HDC hDCDrawSurf; + HENHMETAFILE hemf; + + HANDLE hFile, hMapFile; + LPVOID pMapFile; + LPENHMETAHEADER pemh; + + BOOL bSuccess; + + + bSuccess = TRUE; + szFilter = - "EnhMeta files (*.emf)\0*.emf\0\0"; + "EnhMeta files (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0"; strcpy(szFile, "*.emf\0"); ofn.lStructSize = sizeof(OPENFILENAME); @@ -1476,7 +1597,112 @@ HENHMETAFILE hemfLoadMetafile(HWND hwnd) if (!GetOpenFileName(&ofn)) return 0L; - return GetEnhMetaFile(szFile); + if ((hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == (HANDLE)-1) { + MessageBox(ghwndMain, "Fail in file open!", "Error", MB_OK); + return 0L; + } + + // + // Create a map file of the opened file + // + if ((hMapFile = CreateFileMapping(hFile, NULL, + PAGE_READONLY, 0, 0, "MapF")) == (HANDLE)-1) { + MessageBox(ghwndMain, "Fail in creating map file!", "Error", MB_OK); + bSuccess = FALSE; + goto ErrorExit1; + } + + // + // Map a view of the whole file + // + if ((pMapFile = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0)) == NULL) { + MessageBox(ghwndMain, "Fail in mapping view of the Map File object!", "Error", MB_OK); + bSuccess = FALSE; + goto ErrorExit2; + } + + // + // First check that if it is an enhanced metafile + // + pemh = (LPENHMETAHEADER) pMapFile; + if (pemh->dSignature == META32_SIGNATURE) { + hemf = GetEnhMetaFile(szFile); + goto HLM_EXIT; + } + + // + // If it has an ALDUS header skip it + // Notice: APMSIZE is used because the HANDLE and RECT of the structure + // depends on the environment + // + if (*((LPDWORD)pemh) == ALDUS_ID) { + MessageBox(ghwndMain, "This is an ALDUS metafile!", "Hey!", MB_OK); + uiSize = *((LPDWORD) ((PBYTE)pMapFile + APMSIZE + 6)); + hDCDrawSurf = GetDC(ghwndDrawSurf); + hemf = SetWinMetaFileBits(uiSize*2L, (PBYTE)pMapFile + APMSIZE, hDCDrawSurf, NULL); + ReleaseDC(ghwndDrawSurf, hDCDrawSurf); + if (!hemf) { + char text[256]; + + wsprintf(text, "SetWinMetaFileBits failed, %x", GetLastError()); + MessageBox(ghwndMain, text, "Error!", MB_OK); + } + goto HLM_EXIT; + } + + + // + // It is a Windows 3x format metafile (hopefully) + // + if (!(hmf = GetMetaFile((LPCSTR)szFile))) { + char text[256]; + + wsprintf(text, "GetMetaFile failed, %x", GetLastError()); + MessageBox(ghwndMain, text, "Error!", MB_OK); + bSuccess = FALSE; + goto ErrorExit3; + } + + if (!(uiSize = GetMetaFileBitsEx(hmf, 0, NULL))) { + MessageBox(ghwndMain, "Fail in 1st GetMetaFileBitsEx!", "Error", MB_OK); + return NULL; + } + + if ((pvData = (LPVOID) LocalAlloc(LMEM_FIXED, uiSize)) == NULL) { + MessageBox(ghwndMain, "Fail in Memory Allocation!", "Error", MB_OK); + bSuccess = FALSE; + goto ErrorExit3; + } + + if (!(uiSize = GetMetaFileBitsEx(hmf, uiSize, pvData))) { + MessageBox(ghwndMain, "Fail in 2nd GetMetaFileBitsEx!", "Error", MB_OK); + bSuccess = FALSE; + goto ErrorExit3; + } + + DeleteMetaFile(hmf); + + hDCDrawSurf = GetDC(ghwndDrawSurf); + hemf = SetWinMetaFileBits(uiSize, (LPBYTE)pvData, hDCDrawSurf, NULL); + + LocalFree(pvData); + + ReleaseDC(ghwndDrawSurf ,hDCDrawSurf); + +HLM_EXIT: +ErrorExit3: + UnmapViewOfFile(pMapFile); + +ErrorExit2: + CloseHandle(hMapFile); +ErrorExit1: + CloseHandle(hFile); + + if (bSuccess) + return hemf; + else + return 0L; } /******************************Public*Routine******************************\ @@ -1503,6 +1729,11 @@ HDC hDCRecordMetafileAs(HWND hwnd, LPSTR char *szTmp, szTmp2[256]; HDC hDCMeta; + int iWidthMM, iHeightMM, iWidthPels, iHeightPels, iMMPerPelX, iMMPerPelY; + RECT rc; + HDC hDC; + + szFilter = "EnhMeta files (*.emf)\0\0"; strcpy(szFile, "*.emf\0"); ofn.lStructSize = sizeof(OPENFILENAME); @@ -1526,7 +1757,25 @@ HDC hDCRecordMetafileAs(HWND hwnd, LPSTR return 0L; } - hDCMeta = CreateEnhMetaFile((HDC)NULL, szFile, (LPRECT)NULL, (LPSTR)NULL); + + hDC = GetDC(hwnd); + iWidthMM = GetDeviceCaps(hDC, HORZSIZE); + iHeightMM = GetDeviceCaps(hDC, VERTSIZE); + iWidthPels = GetDeviceCaps(hDC, HORZRES); + iHeightPels = GetDeviceCaps(hDC, VERTRES); + ReleaseDC(hwnd, hDC); + iMMPerPelX = (iWidthMM * 100)/iWidthPels; + iMMPerPelY = (iHeightMM * 100)/iHeightPels; + GetClientRect(ghwndDrawSurf, &rc); + rc.left = rc.left * iMMPerPelX; + rc.top = rc.top * iMMPerPelY; + rc.right = rc.right * iMMPerPelX; + rc.bottom = rc.bottom * iMMPerPelY; + + + + //hDCMeta = CreateEnhMetaFile((HDC)NULL, szFile, (LPRECT)NULL, (LPSTR)NULL); + hDCMeta = CreateEnhMetaFile((HDC)NULL, szFile, (LPRECT)&rc, (LPSTR)NULL); // // parses the new filename, removes the extension and copy it into @@ -1696,6 +1945,7 @@ HBITMAP hBmpLoadBitmapFile(HDC hDC, PSTR PBYTE pjTmp; ULONG sizBMI; HBITMAP hBitmap; + INT iNumClr; hBitmap = NULL; @@ -1731,21 +1981,54 @@ HBITMAP hBmpLoadBitmapFile(HDC hDC, PSTR goto ErrExit3; } - pbmh = (LPBITMAPINFOHEADER)((PBYTE)pMapFile + sizeof(BITMAPFILEHEADER)); - // - // Use the size to determine if it is a BitmapCoreHeader or - // BitmapInfoHeader + // The file header doesn't end on DWORD boundary... // - if (pbmh->biSize == sizeof(BITMAPCOREHEADER)) - { - sizBMI = sizeof(BITMAPCOREHEADER)+sizeof(RGBTRIPLE)* - ((((LPBITMAPCOREHEADER)pbmh)->bcBitCount == 24) ? 0 : (1 << ((LPBITMAPCOREHEADER)pbmh)->bcBitCount)); - } - else // BITMAPINFOHEADER + pbmh = (LPBITMAPINFOHEADER)((PBYTE)pMapFile + sizeof(BITMAPFILEHEADER)); + { - sizBMI = sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)* - ((pbmh->biBitCount == 24) ? 0 : (1 << pbmh->biBitCount)); + BITMAPCOREHEADER bmch, *pbmch; + BITMAPINFOHEADER bmih, *pbmih; + PBYTE pjTmp; + ULONG ulSiz; + + pbmch = &bmch; + pbmih = &bmih; + + pjTmp = (PBYTE)pbmh; + ulSiz = sizeof(BITMAPCOREHEADER); + while (ulSiz--) { + *(((PBYTE)pbmch)++) = *(((PBYTE)pjTmp)++); + } + + pjTmp = (PBYTE)pbmh; + ulSiz = sizeof(BITMAPINFOHEADER); + while (ulSiz--) { + *(((PBYTE)pbmih)++) = *(((PBYTE)pjTmp)++); + } + + // + // Use the size to determine if it is a BitmapCoreHeader or + // BitmapInfoHeader + // + if (bmch.bcSize == sizeof(BITMAPCOREHEADER)) + { + WORD wBitCount; + + wBitCount = bmch.bcBitCount; + iNumClr = ((wBitCount == 24) ? 0 : (1 << wBitCount)); + sizBMI = sizeof(BITMAPCOREHEADER)+sizeof(RGBTRIPLE)*iNumClr; + } + else // BITMAPINFOHEADER + { + WORD wBitCount; + + wBitCount = bmih.biBitCount; + iNumClr = ((wBitCount == 24) ? 0 : (1 << wBitCount)); + sizBMI = sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*iNumClr; + } + + } if ((pbmi = (LPBITMAPINFO) LocalAlloc(LMEM_FIXED,sizBMI)) == NULL) { @@ -1870,19 +2153,26 @@ BOOL bHitTest(HDC hDC, INT x, INT y) { //POINT point; //!!!RECT rcClientDS; HTDATA htData; + static HCURSOR hCurHT, hCurWait; bSuccess = TRUE; if (ghMetaf == 0) return 0L; + hCurHT = LoadCursor(NULL, IDC_CROSS); + hCurWait = LoadCursor(NULL, IDC_WAIT); + GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr); //!!!GetClientRect(ghwndDrawSurf, &rcClientDS); htData.point.x = x; htData.point.y = y; htData.iRecord = EnhMetaHdr.nRecords; - EnumEnhMetaFile(hDC, ghMetaf, (PROC)bDoHitTest, (LPVOID) &htData, (LPRECT)&EnhMetaHdr.rclBounds); + + SetCursor(hCurWait); + EnumEnhMetaFile(hDC, ghMetaf, (ENHMFENUMPROC)bDoHitTest, (LPVOID) &htData, (LPRECT)&EnhMetaHdr.rclBounds); //!!!EnumEnhMetaFile(hDC, ghMetaf, (PROC)bDoHitTest, (LPVOID) &point, (LPRECT)&rcClientDS); + SetCursor(hCurHT); return bSuccess; } @@ -1959,7 +2249,7 @@ BOOL APIENTRY bDoHitTest(HDC hDC, LPHAND case MR_SETWORLDTRANSFORM: case MR_MODIFYWORLDTRANSFORM: { // - // play all records related to transformation + // play all records related to transformation & font // PlayEnhMetaFileRecord(hDC, lpHandleTable, lpEnhMetaRecord, nHandles); @@ -2025,6 +2315,8 @@ BOOL APIENTRY bDoHitTest(HDC hDC, LPHAND break; } default: + wsprintf((LPSTR) ach, "NO HIT: I don't Hit-Test %s", rgMetaName[lpEnhMetaRecord->iType]); + SetWindowText(ghTextWnd, ach); return TRUE; } //switch @@ -2068,7 +2360,7 @@ BOOL APIENTRY bDoHitTest(HDC hDC, LPHAND // bSuccess = PtInRegion(hRgn, PtOrg.x, PtOrg.y); //Temporily comment this out to avoid a bug in 265 - //FillRgn(hDC, hRgn, ghbrRed); + FillRgn(hDC, hRgn, ghbrRed); DeleteObject(hRgn); // // Set transform back. @@ -2148,7 +2440,7 @@ BOOL bChooseNewFont(HWND hwnd, PLOGFONT chf.nSizeMin = 0; chf.nSizeMax = 0; chf.Flags = CF_SCREENFONTS | CF_EFFECTS; - chf.lpfnHook = (FARPROC)NULL; + chf.lpfnHook = (LPCFHOOKPROC)NULL; chf.lpTemplateName = (LPSTR)NULL; if (ChooseFont( &chf ) == FALSE ) {