/****************************************************************** * PlayMetaFile (GDI.123) * */ BOOL16 WINAPI PlayMetaFile16( HDC16 hdc, HMETAFILE16 hmf16 ) { HMETAFILE hmf = create_metafile32( hmf16 ); BOOL ret = PlayMetaFile( HDC_32(hdc), hmf ); DeleteMetaFile( hmf ); return ret; }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HMETAFILE hmf ; static int cxClient, cyClient ; HBRUSH hBrush ; HDC hdc, hdcMeta ; int x, y ; PAINTSTRUCT ps ; switch (message) { case WM_CREATE: hdcMeta = CreateMetaFile (NULL) ; hBrush = CreateSolidBrush (RGB (0, 0, 255)) ; Rectangle (hdcMeta, 0, 0, 100, 100) ; MoveToEx (hdcMeta, 0, 0, NULL) ; LineTo (hdcMeta, 100, 100) ; MoveToEx (hdcMeta, 0, 100, NULL) ; LineTo (hdcMeta, 100, 0) ; SelectObject (hdcMeta, hBrush) ; Ellipse (hdcMeta, 20, 20, 80, 80) ; hmf = CloseMetaFile (hdcMeta) ; DeleteObject (hBrush) ; return 0 ; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SetMapMode (hdc, MM_ANISOTROPIC) ; SetWindowExtEx (hdc, 1000, 1000, NULL) ; SetViewportExtEx (hdc, cxClient, cyClient, NULL) ; for (x = 0 ; x < 10 ; x++) for (y = 0 ; y < 10 ; y++) { SetWindowOrgEx (hdc, -100 * x, -100 * y, NULL) ; PlayMetaFile (hdc, hmf) ; } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: DeleteMetaFile (hmf) ; PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
void IT_PLAYMETAFILE(ENV *envp,LONGPROC f) { HDC hDC; WORD wSel; HGLOBAL hGlobal; hDC = GETWORD(SP+6); wSel = GETWORD(SP+4); hGlobal = GetSelectorHandle(wSel); envp->reg.ax = PlayMetaFile(hDC, hGlobal); envp->reg.sp += 2 * HANDLE_86 + RET_86; }
long UPSF::hMetaFile_To_UBit( HGLOBAL& hUniv, long& univSize, HMETAFILE hMetaFile, long natvLen) { if(natvLen != (long)sizeof(HMETAFILE)) return AUPSF_SIZEERROR; HDC hDC = CreateIC("DISPLAY", NULL, NULL, NULL); HDC hDCMem = CreateCompatibleDC(hDC); HBITMAP hBitmap = CreateCompatibleBitmap(hDC, GetDeviceCaps(hDC, HORZRES), GetDeviceCaps(hDC, VERTRES)); SelectBitmap(hDCMem, hBitmap); // play the metafile PlayMetaFile(hDCMem, hMetaFile); DeleteDC(hDCMem); DeleteDC(hDC); // we are left with the bitmap with the meta file BITMAP bitmap; GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bitmap); long bitmapSize = (long)bitmap.bmHeight * (long)bitmap.bmWidthBytes * (long)bitmap.bmPlanes; HGLOBAL hBits = GlobalAlloc(MEMFLAGS, bitmapSize); if(!hBits) { DeleteObject(hBitmap); return AUPSF_MEMORYERROR; } bitmap.bmBits = GlobalLock(hBits); if(!bitmap.bmBits) { DeleteObject(hBitmap); return AUPSF_MEMORYERROR; } long ret = BITMAP_To_UBit(hUniv, univSize, bitmap, hBitmap); // clean up and exit DeleteObject(hBitmap); GlobalUnlock(hBits); GlobalFree(hBits); return ret; }
long FAR PASCAL _export ProcVentApp (HWND hwnd, WORD message, WORD wParam, LONG lParam) { static HANDLE hInstance; PAINTSTRUCT ps; switch (message) { case WM_CREATE: { /* Obtenemos el handle a la ocurrencia del m�dulo, que se guarda forever */ hInstance = ((LPCREATESTRUCT) lParam)->hInstance; return (0); } case WM_PAINT: { /* Obtenemos el contexto de la ventana */ hdc = BeginPaint (hwnd, &ps); /* Redibujamos el MetaFile */ PlayMetaFile (hdc, hMF); /* Liberamos el contexto */ EndPaint (hwnd, &ps); return (0); } case WM_DESTROY: { PostQuitMessage (0); return (0); } } return (DefFrameProc (hwnd, hwndCliente, message, wParam, lParam)); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) { switch (uMessage) { case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(hwnd, &ps); SetMapMode(ps.hdc, MM_ANISOTROPIC); /* Set the window extent to a sane value in case the metafile doesn't */ SetWindowExtEx(ps.hdc, width, height, NULL); SetViewportExtEx(ps.hdc, width, height, NULL); SetViewportOrgEx(ps.hdc, deltax, deltay, NULL); if(hmf) PlayMetaFile(ps.hdc, hmf); EndPaint(hwnd, &ps); } break; case WM_COMMAND: /* message: command from application menu */ switch (GET_WM_COMMAND_ID(wparam,lparam)) { case IDM_OPEN: { char filename[MAX_PATH]; if (FileOpen(hwnd, filename, sizeof(filename))) { isAldus = FileIsPlaceable(filename); if (isAldus) { hmf = GetPlaceableMetaFile(hwnd, filename); } else { RECT r; hmf = GetMetaFile(filename); GetClientRect(hwnd, &r); width = r.right - r.left; height = r.bottom - r.top; } InvalidateRect( hwnd, NULL, TRUE ); } } break; case IDM_SET_EXT_TO_WIN: { RECT r; GetClientRect(hwnd, &r); width = r.right - r.left; height = r.bottom - r.top; deltax = deltay = 0; InvalidateRect( hwnd, NULL, TRUE ); } break; case IDM_LEFT: deltax += 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_RIGHT: deltax -= 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_UP: deltay += 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_DOWN: deltay -= 100; InvalidateRect( hwnd, NULL, TRUE ); break; case IDM_EXIT: DestroyWindow(hwnd); break; default: return DefWindowProc(hwnd, uMessage, wparam, lparam); } break; case WM_DESTROY: /* message: window being destroyed */ PostQuitMessage(0); break; default: /* Passes it on if unprocessed */ return DefWindowProc(hwnd, uMessage, wparam, lparam); } return 0; }