// // Draw the frame identified by cur_frame_fullpath // void draw_cur_frame() { HDC hdc, hdcScreen, hdcCompatible; HBITMAP hBmpFile, hBmpWindow, old_bitmap1, old_bitmap2; BITMAP bmp; FILE *fp; char c, title[512], text[2048], szHtmFile[MAX_PATH], szBmpFile[MAX_PATH]; int i, width, height; RECT text_rect; // Draw white background and instructions if (cur_frame == -1 || cur_working_path[0] == '\0') { SetWindowPos(g_hWnd, NULL, 0, 0, 320, 240, SWP_NOMOVE | SWP_NOZORDER); hdc = GetDC(g_hWnd); SetTextColor(hdc, RGB(220,0,0)); sprintf_s(text, 2048, "OHReplay 11.0.1\n"); strcat_s(text, 2048, "----------------------------------\n"); strcat_s(text, 2048, "Open a frame: SysMenu/Open, Ctrl-O, F2\n\n"); strcat_s(text, 2048, "Next frame: Tab\n"); strcat_s(text, 2048, "Previous frame: Shift-Tab\n"); strcat_s(text, 2048, "Reset: Esc\n"); memset(&text_rect, 0, sizeof(RECT)); DrawText(hdc, text, (int) strlen(text), &text_rect, DT_CALCRECT); DrawText(hdc, text, (int) strlen(text), &text_rect, NULL); ReleaseDC(g_hWnd, hdc); SetWindowText(g_hWnd, "OHReplay"); } // Draw current frame else { // Filenames sprintf_s(szHtmFile, MAX_PATH, "%sframe%06d.htm", cur_working_path, cur_frame); sprintf_s(szBmpFile, MAX_PATH, "%sframe%06d.bmp", cur_working_path, cur_frame); // Open bitmap file hBmpFile = (HBITMAP) LoadImage(0, szBmpFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!hBmpFile) return; // Get bitmap size information if (!GetObject(hBmpFile, sizeof(bmp), &bmp)) return; width = bmp.bmWidth; height = bmp.bmHeight; // Resize window SetWindowPos(g_hWnd, NULL, 0, 0, width + GetSystemMetrics(SM_CXDLGFRAME)*2, height + GetSystemMetrics(SM_CYDLGFRAME)*2 + GetSystemMetrics(SM_CYSIZE) + 1, SWP_NOMOVE | SWP_NOZORDER); // Select file bitmap into a DC hdc = GetDC(g_hWnd); hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); hdcCompatible = CreateCompatibleDC(hdcScreen); old_bitmap1 = (HBITMAP) SelectObject(hdcCompatible, hBmpFile); // Create bitmap for window and select it to window's DC hBmpWindow = CreateCompatibleBitmap(hdcScreen, width, height); old_bitmap2 = (HBITMAP) SelectObject(hdc, hBmpWindow); // Copy bitmap to window BitBlt(hdc, 0, 0, width, height, hdcCompatible, 0, 0, SRCCOPY); SelectObject(hdc, old_bitmap2); SelectObject(hdcCompatible, old_bitmap1); // Clean up DeleteObject(hBmpWindow); DeleteObject(hBmpFile); DeleteDC(hdcCompatible); DeleteDC(hdcScreen); ReleaseDC(g_hWnd, hdc); // Set title text i=0; if (fopen_s(&fp, szHtmFile, "r")==0) { c = fgetc(fp); while (c!=EOF && c!='\r' && c!='\n') { title[i++]=c; c = fgetc(fp); } fclose(fp); } title[i] = '\0'; sprintf_s(text, 2048, "%s [%06d]", title, cur_frame); SetWindowText(g_hWnd, text); } }
DWORD vboxDispIfResizeModesWDDM(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes) { UINT cbVidPnInfo = VBOXWDDM_RECOMMENDVIDPN_SIZE(cDevModes); PVBOXWDDM_RECOMMENDVIDPN pVidPnInfo = (PVBOXWDDM_RECOMMENDVIDPN)alloca(cbVidPnInfo); pVidPnInfo->cScreenInfos = cDevModes; D3DKMT_HANDLE hAdapter = NULL; NTSTATUS Status; DWORD winEr = NO_ERROR; UINT i = 0; for (; i < cDevModes; i++) { PVBOXWDDM_RECOMMENDVIDPN_SCREEN_INFO pInfo = &pVidPnInfo->aScreenInfos[i]; D3DKMT_OPENADAPTERFROMHDC OpenAdapterData = {0}; OpenAdapterData.hDc = CreateDC(NULL, paDisplayDevices[i].DeviceName, NULL, NULL); if (!OpenAdapterData.hDc) { winEr = GetLastError(); Assert(0); break; } Status = pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc(&OpenAdapterData); Assert(!Status); if (Status) { winEr = ERROR_GEN_FAILURE; Assert(0); break; } pInfo->Id = OpenAdapterData.VidPnSourceId; pInfo->Width = paDeviceModes[i].dmPelsWidth; pInfo->Height = paDeviceModes[i].dmPelsHeight; pInfo->BitsPerPixel = paDeviceModes[i].dmBitsPerPel; if (!hAdapter) { hAdapter = OpenAdapterData.hAdapter; } else { D3DKMT_CLOSEADAPTER ClosaAdapterData = {0}; ClosaAdapterData.hAdapter = OpenAdapterData.hAdapter; Status = pIf->modeData.wddm.pfnD3DKMTCloseAdapter(&ClosaAdapterData); Assert(!Status); } } if (winEr == NO_ERROR) { Assert(hAdapter); D3DKMT_INVALIDATEACTIVEVIDPN IAVidPnData = {0}; IAVidPnData.hAdapter = hAdapter; IAVidPnData.pPrivateDriverData = pVidPnInfo; IAVidPnData.PrivateDriverDataSize = cbVidPnInfo; DWORD winEr = NO_ERROR; Status = pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn(&IAVidPnData); Assert(!Status); if (Status) { Log((__FUNCTION__": pfnD3DKMTInvalidateActiveVidPn failed, Status (0x%x)\n", Status)); winEr = ERROR_GEN_FAILURE; } } if (hAdapter) { D3DKMT_CLOSEADAPTER ClosaAdapterData = {0}; ClosaAdapterData.hAdapter = hAdapter; Status = pIf->modeData.wddm.pfnD3DKMTCloseAdapter(&ClosaAdapterData); Assert(!Status); } /* ignore any prev errors and just check if resize is OK */ if (!vboxDispIfValidateResize(paDisplayDevices, paDeviceModes, cDevModes)) { /* now try to resize in a "regular" way */ /* Assign the new rectangles to displays. */ for (i = 0; i < cDevModes; i++) { /* On Vista one must specify DM_BITSPERPEL. * Note that the current mode dmBitsPerPel is already in the DEVMODE structure. */ paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH | DM_BITSPERPEL; Log(("VBoxTray: ResizeDisplayDevice: pfnChangeDisplaySettingsEx %x: %dx%dx%d at %d,%d\n", pIf->modeData.wddm.pfnChangeDisplaySettingsEx, paDeviceModes[i].dmPelsWidth, paDeviceModes[i].dmPelsHeight, paDeviceModes[i].dmBitsPerPel, paDeviceModes[i].dmPosition.x, paDeviceModes[i].dmPosition.y)); LONG status = pIf->modeData.wddm.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName, &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL); Log(("VBoxTray: ResizeDisplayDevice: ChangeDisplaySettingsEx position status %d, err %d\n", status, GetLastError ())); } /* A second call to ChangeDisplaySettings updates the monitor. */ LONG status = pIf->modeData.wddm.pfnChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL); Log(("VBoxTray: ResizeDisplayDevice: ChangeDisplaySettings update status %d\n", status)); if (status == DISP_CHANGE_SUCCESSFUL) { winEr = NO_ERROR; } else if (status == DISP_CHANGE_BADMODE) { /* Successfully set new video mode or our driver can not set the requested mode. Stop trying. */ winEr = ERROR_RETRY; } else { winEr = ERROR_GEN_FAILURE; } } else { winEr = NO_ERROR; } return winEr; }
/* =================== GLimp_Init This is the platform specific OpenGL initialization function. It is responsible for loading OpenGL, initializing it, creating a window of the appropriate size, doing fullscreen manipulations, etc. Its overall responsibility is to make sure that a functional OpenGL subsystem is operating when it returns to the ref. If there is any failure, the renderer will revert back to safe parameters and try again. =================== */ bool GLimp_Init( glimpParms_t parms ) { const char* driverName; HDC hDC; cmdSystem->AddCommand( "testSwapBuffers", GLimp_TestSwapBuffers, CMD_FL_SYSTEM, "Times swapbuffer options" ); common->Printf( "Initializing OpenGL subsystem with multisamples:%i stereo:%i fullscreen:%i\n", parms.multiSamples, parms.stereo, parms.fullScreen ); // check our desktop attributes hDC = GetDC( GetDesktopWindow() ); win32.desktopBitsPixel = GetDeviceCaps( hDC, BITSPIXEL ); win32.desktopWidth = GetDeviceCaps( hDC, HORZRES ); win32.desktopHeight = GetDeviceCaps( hDC, VERTRES ); ReleaseDC( GetDesktopWindow(), hDC ); // we can't run in a window unless it is 32 bpp if( win32.desktopBitsPixel < 32 && parms.fullScreen <= 0 ) { common->Printf( "^3Windowed mode requires 32 bit desktop depth^0\n" ); return false; } // save the hardware gamma so it can be // restored on exit GLimp_SaveGamma(); // create our window classes if we haven't already GLW_CreateWindowClasses(); // this will load the dll and set all our qgl* function pointers, // but doesn't create a window // r_glDriver is only intended for using instrumented OpenGL // dlls. Normal users should never have to use it, and it is // not archived. driverName = r_glDriver.GetString()[0] ? r_glDriver.GetString() : "opengl32"; if( !QGL_Init( driverName ) ) { common->Printf( "^3GLimp_Init() could not load r_glDriver \"%s\"^0\n", driverName ); return false; } // getting the wgl extensions involves creating a fake window to get a context, // which is pretty disgusting, and seems to mess with the AGP VAR allocation GLW_GetWGLExtensionsWithFakeWindow(); // Optionally ChangeDisplaySettings to get a different fullscreen resolution. if( !GLW_ChangeDislaySettingsIfNeeded( parms ) ) { GLimp_Shutdown(); return false; } // try to create a window with the correct pixel format // and init the renderer context if( !GLW_CreateWindow( parms ) ) { GLimp_Shutdown(); return false; } glConfig.isFullscreen = parms.fullScreen; glConfig.isStereoPixelFormat = parms.stereo; glConfig.nativeScreenWidth = parms.width; glConfig.nativeScreenHeight = parms.height; glConfig.multisamples = parms.multiSamples; glConfig.pixelAspect = 1.0f; // FIXME: some monitor modes may be distorted // should side-by-side stereo modes be consider aspect 0.5? // get the screen size, which may not be reliable... // If we use the windowDC, I get my 30" monitor, even though the window is // on a 27" monitor, so get a dedicated DC for the full screen device name. const idStr deviceName = GetDeviceName( Max( 0, parms.fullScreen - 1 ) ); HDC deviceDC = CreateDC( deviceName.c_str(), deviceName.c_str(), NULL, NULL ); const int mmWide = GetDeviceCaps( win32.hDC, HORZSIZE ); DeleteDC( deviceDC ); if( mmWide == 0 ) { glConfig.physicalScreenWidthInCentimeters = 100.0f; } else { glConfig.physicalScreenWidthInCentimeters = 0.1f * mmWide; } // wglSwapinterval, etc GLW_CheckWGLExtensions( win32.hDC ); // check logging GLimp_EnableLogging( ( r_logFile.GetInteger() != 0 ) ); return true; }
static bool PrintToDevice(PrintData& pd, ProgressUpdateUI *progressUI=NULL, AbortCookieManager *abortCookie=NULL) { AssertCrash(pd.engine); if (!pd.engine) return false; AssertCrash(pd.printerName); if (!pd.printerName) return false; BaseEngine& engine = *pd.engine; ScopedMem<WCHAR> fileName; DOCINFO di = { 0 }; di.cbSize = sizeof (DOCINFO); if (gPluginMode) { fileName.Set(ExtractFilenameFromURL(gPluginURL)); // fall back to a generic "filename" instead of the more confusing temporary filename di.lpszDocName = fileName ? fileName : L"filename"; } else di.lpszDocName = engine.FileName(); int current = 1, total = 0; if (pd.sel.Count() == 0) { for (size_t i = 0; i < pd.ranges.Count(); i++) { if (pd.ranges.At(i).nToPage < pd.ranges.At(i).nFromPage) total += pd.ranges.At(i).nFromPage - pd.ranges.At(i).nToPage + 1; else total += pd.ranges.At(i).nToPage - pd.ranges.At(i).nFromPage + 1; } } else { for (int pageNo = 1; pageNo <= engine.PageCount(); pageNo++) { if (!BoundSelectionOnPage(pd.sel, pageNo).IsEmpty()) total++; } } AssertCrash(total > 0); if (0 == total) return false; if (progressUI) progressUI->UpdateProgress(current, total); // cf. http://code.google.com/p/sumatrapdf/issues/detail?id=1882 // According to our crash dumps, Cannon printer drivers (caprenn.dll etc.) // are buggy and like to crash during printing with DEP violation // We disable dep during printing to hopefully not crash // TODO: even better would be to print in a separate process so that // crashes during printing wouldn't affect the main process. It's also // much more complicated to implement ScopeDisableDEP scopeNoDEP; // cf. http://blogs.msdn.com/b/oldnewthing/archive/2012/11/09/10367057.aspx ScopeHDC hdc(CreateDC(pd.driverName, pd.printerName, pd.portName, pd.devMode)); if (!hdc) return false; if (StartDoc(hdc, &di) <= 0) return false; // MM_TEXT: Each logical unit is mapped to one device pixel. // Positive x is to the right; positive y is down. SetMapMode(hdc, MM_TEXT); const SizeI paperSize(GetDeviceCaps(hdc, PHYSICALWIDTH), GetDeviceCaps(hdc, PHYSICALHEIGHT)); const RectI printable(GetDeviceCaps(hdc, PHYSICALOFFSETX), GetDeviceCaps(hdc, PHYSICALOFFSETY), GetDeviceCaps(hdc, HORZRES), GetDeviceCaps(hdc, VERTRES)); const float dpiFactor = min(GetDeviceCaps(hdc, LOGPIXELSX) / engine.GetFileDPI(), GetDeviceCaps(hdc, LOGPIXELSY) / engine.GetFileDPI()); bool bPrintPortrait = paperSize.dx < paperSize.dy; if (pd.devMode && (pd.devMode.Get()->dmFields & DM_ORIENTATION)) bPrintPortrait = DMORIENT_PORTRAIT == pd.devMode.Get()->dmOrientation; if (pd.sel.Count() > 0) { for (int pageNo = 1; pageNo <= engine.PageCount(); pageNo++) { RectD bounds = BoundSelectionOnPage(pd.sel, pageNo); if (bounds.IsEmpty()) continue; if (progressUI) progressUI->UpdateProgress(current, total); StartPage(hdc); SizeT<float> bSize = bounds.Size().Convert<float>(); float zoom = min((float)printable.dx / bSize.dx, (float)printable.dy / bSize.dy); // use the correct zoom values, if the page fits otherwise // and the user didn't ask for anything else (default setting) if (PrintScaleShrink == pd.advData.scale) zoom = min(dpiFactor, zoom); else if (PrintScaleNone == pd.advData.scale) zoom = dpiFactor; for (size_t i = 0; i < pd.sel.Count(); i++) { if (pd.sel.At(i).pageNo != pageNo) continue; RectD *clipRegion = &pd.sel.At(i).rect; PointI offset((int)((clipRegion->x - bounds.x) * zoom), (int)((clipRegion->y - bounds.y) * zoom)); if (!pd.advData.asImage) { RectI rc((int)(printable.dx - bSize.dx * zoom) / 2 + offset.x, (int)(printable.dy - bSize.dy * zoom) / 2 + offset.y, (int)(clipRegion->dx * zoom), (int)(clipRegion->dy * zoom)); engine.RenderPage(hdc, rc, pd.sel.At(i).pageNo, zoom, pd.rotation, clipRegion, Target_Print, abortCookie ? &abortCookie->cookie : NULL); if (abortCookie) abortCookie->Clear(); } else { RenderedBitmap *bmp = NULL; short shrink = 1; do { bmp = engine.RenderBitmap(pd.sel.At(i).pageNo, zoom / shrink, pd.rotation, clipRegion, Target_Print, abortCookie ? &abortCookie->cookie : NULL); if (abortCookie) abortCookie->Clear(); if (!bmp || !bmp->GetBitmap()) { shrink *= 2; delete bmp; bmp = NULL; } } while (!bmp && shrink < 32 && !(progressUI && progressUI->WasCanceled())); if (bmp) { RectI rc((int)(paperSize.dx - bSize.dx * zoom) / 2 + offset.x, (int)(paperSize.dy - bSize.dy * zoom) / 2 + offset.y, bmp->Size().dx * shrink, bmp->Size().dy * shrink); bmp->StretchDIBits(hdc, rc); delete bmp; } } } if (EndPage(hdc) <= 0 || progressUI && progressUI->WasCanceled()) { AbortDoc(hdc); return false; } current++; } EndDoc(hdc); return false; } // print all the pages the user requested for (size_t i = 0; i < pd.ranges.Count(); i++) { int dir = pd.ranges.At(i).nFromPage > pd.ranges.At(i).nToPage ? -1 : 1; for (DWORD pageNo = pd.ranges.At(i).nFromPage; pageNo != pd.ranges.At(i).nToPage + dir; pageNo += dir) { if ((PrintRangeEven == pd.advData.range && pageNo % 2 != 0) || (PrintRangeOdd == pd.advData.range && pageNo % 2 == 0)) continue; if (progressUI) progressUI->UpdateProgress(current, total); StartPage(hdc); SizeT<float> pSize = engine.PageMediabox(pageNo).Size().Convert<float>(); int rotation = 0; // Turn the document by 90 deg if it isn't in portrait mode if (pSize.dx > pSize.dy) { rotation += 90; swap(pSize.dx, pSize.dy); } // make sure not to print upside-down rotation = (rotation % 180) == 0 ? 0 : 270; // finally turn the page by (another) 90 deg in landscape mode if (!bPrintPortrait) { rotation = (rotation + 90) % 360; swap(pSize.dx, pSize.dy); } // dpiFactor means no physical zoom float zoom = dpiFactor; // offset of the top-left corner of the page from the printable area // (negative values move the page into the left/top margins, etc.); // offset adjustments are needed because the GDI coordinate system // starts at the corner of the printable area and we rather want to // center the page on the physical paper (default behavior) PointI offset(-printable.x, -printable.y); if (pd.advData.scale != PrintScaleNone) { // make sure to fit all content into the printable area when scaling // and the whole document page on the physical paper RectD rect = engine.PageContentBox(pageNo, Target_Print); RectT<float> cbox = engine.Transform(rect, pageNo, 1.0, rotation).Convert<float>(); zoom = min((float)printable.dx / cbox.dx, min((float)printable.dy / cbox.dy, min((float)paperSize.dx / pSize.dx, (float)paperSize.dy / pSize.dy))); // use the correct zoom values, if the page fits otherwise // and the user didn't ask for anything else (default setting) if (PrintScaleShrink == pd.advData.scale && dpiFactor < zoom) zoom = dpiFactor; // make sure that no content lies in the non-printable paper margins RectT<float> onPaper((paperSize.dx - pSize.dx * zoom) / 2 + cbox.x * zoom, (paperSize.dy - pSize.dy * zoom) / 2 + cbox.y * zoom, cbox.dx * zoom, cbox.dy * zoom); if (onPaper.x < printable.x) offset.x += (int)(printable.x - onPaper.x); else if (onPaper.BR().x > printable.BR().x) offset.x -= (int)(onPaper.BR().x - printable.BR().x); if (onPaper.y < printable.y) offset.y += (int)(printable.y - onPaper.y); else if (onPaper.BR().y > printable.BR().y) offset.y -= (int)(onPaper.BR().y - printable.BR().y); } if (!pd.advData.asImage) { RectI rc = RectI::FromXY((int)(paperSize.dx - pSize.dx * zoom) / 2 + offset.x, (int)(paperSize.dy - pSize.dy * zoom) / 2 + offset.y, paperSize.dx, paperSize.dy); engine.RenderPage(hdc, rc, pageNo, zoom, rotation, NULL, Target_Print, abortCookie ? &abortCookie->cookie : NULL); if (abortCookie) abortCookie->Clear(); } else { RenderedBitmap *bmp = NULL; short shrink = 1; do { bmp = engine.RenderBitmap(pageNo, zoom / shrink, rotation, NULL, Target_Print, abortCookie ? &abortCookie->cookie : NULL); if (abortCookie) abortCookie->Clear(); if (!bmp || !bmp->GetBitmap()) { shrink *= 2; delete bmp; bmp = NULL; } } while (!bmp && shrink < 32 && !(progressUI && progressUI->WasCanceled())); if (bmp) { RectI rc((paperSize.dx - bmp->Size().dx * shrink) / 2 + offset.x, (paperSize.dy - bmp->Size().dy * shrink) / 2 + offset.y, bmp->Size().dx * shrink, bmp->Size().dy * shrink); bmp->StretchDIBits(hdc, rc); delete bmp; } } if (EndPage(hdc) <= 0 || progressUI && progressUI->WasCanceled()) { AbortDoc(hdc); return false; } current++; } } EndDoc(hdc); return true; }
void main(int argc, char *argv[]) { // create dib section (32x32, 16bpp) LPBYTE lpBuf = (LPBYTE)GlobalAlloc(GPTR, sizeof(BITMAPINFO)); LPBITMAPINFO lpDib = (LPBITMAPINFO)lpBuf; lpDib->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpDib->bmiHeader.biWidth = 32; lpDib->bmiHeader.biHeight = 32; lpDib->bmiHeader.biPlanes = 1; lpDib->bmiHeader.biBitCount = 16; lpDib->bmiHeader.biCompression = BI_RGB; lpDib->bmiHeader.biSizeImage = 0; lpDib->bmiHeader.biXPelsPerMeter = 0; lpDib->bmiHeader.biYPelsPerMeter = 0; lpDib->bmiHeader.biClrUsed = 0; lpDib->bmiHeader.biClrImportant = 0; HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL); HBITMAP hBmp = CreateDIBSection(hdc, lpDib, DIB_RGB_COLORS, (PVOID*)&lpBmp, NULL, 0); hdcDib = CreateCompatibleDC(hdc); SelectObject(hdcDib, hBmp); // create font (ms gothic, 16pt) LOGFONT logfont; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = FW_NORMAL; logfont.lfItalic = FALSE; logfont.lfUnderline = FALSE; logfont.lfStrikeOut = FALSE; logfont.lfCharSet = DEFAULT_CHARSET; // EASTEUROPE_CHARSET logfont.lfOutPrecision = OUT_TT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; strcpy(logfont.lfFaceName, argv[1]); logfont.lfHeight = 18; for(int i = 7; i <= 14; i++) { logfont.lfWidth = i; hFont[i] = CreateFontIndirect(&logfont); } SetBkMode(hdcDib, TRANSPARENT); SetTextColor(hdcDib, RGB(255, 255, 255)); FILE *fo; fo = fopen("out.bin", "wb"); for(int i = 0x20; i <= 0x7f; i++) draw(i, i, 0, fo); for(int i = 0; i < 32; i++) { int c1 = table[i][0]; int c2 = table[i][1]; int mir = table[i][2]; draw(c1, c2, mir, fo); } for(int i = 32; i < 64; i++) { int c1 = table[i][0]; int c2 = table[i][1]; int mir = table[i][2]; draw(c1, c2, mir, fo); } fclose(fo); // release for(int i = 7; i <= 14; i++) DeleteObject(hFont[i]); DeleteDC(hdcDib); DeleteObject(hBmp); GlobalFree(lpBuf); }
INT_PTR CALLBACK PrintSizeDlgProc(HWND hdlg, UINT wmsg, WPARAM wparam, LPARAM lparam) { TCHAR buf[8]; HWND hPropSheetDlg = GetParent(hdlg); GP_LPPRINT lpr = (GP_LPPRINT) GetWindowLongPtr(hdlg, GWLP_USERDATA); switch (wmsg) { case WM_INITDIALOG: lpr = (GP_LPPRINT) ((PROPSHEETPAGE *) lparam)->lParam; SetWindowLongPtr(hdlg, GWLP_USERDATA, (LONG_PTR) lpr); wsprintf(buf, TEXT("%d"), lpr->pdef.x); SetDlgItemText(hdlg, PSIZE_DEFX, buf); wsprintf(buf, TEXT("%d"), lpr->pdef.y); SetDlgItemText(hdlg, PSIZE_DEFY, buf); wsprintf(buf, TEXT("%d"), lpr->poff.x); SetDlgItemText(hdlg, PSIZE_OFFX, buf); wsprintf(buf, TEXT("%d"), lpr->poff.y); SetDlgItemText(hdlg, PSIZE_OFFY, buf); wsprintf(buf, TEXT("%d"), lpr->psize.x); SetDlgItemText(hdlg, PSIZE_X, buf); wsprintf(buf, TEXT("%d"), lpr->psize.y); SetDlgItemText(hdlg, PSIZE_Y, buf); CheckDlgButton(hdlg, PSIZE_DEF, TRUE); EnableWindow(GetDlgItem(hdlg, PSIZE_X), FALSE); EnableWindow(GetDlgItem(hdlg, PSIZE_Y), FALSE); return TRUE; case WM_COMMAND: switch (LOWORD(wparam)) { case PSIZE_DEF: if (HIWORD(wparam) == BN_CLICKED) { EnableWindow(GetDlgItem(hdlg, PSIZE_X), FALSE); EnableWindow(GetDlgItem(hdlg, PSIZE_Y), FALSE); PropSheet_Changed(hPropSheetDlg, hdlg); } return FALSE; case PSIZE_OTHER: if (HIWORD(wparam) == BN_CLICKED) { EnableWindow(GetDlgItem(hdlg, PSIZE_X), TRUE); EnableWindow(GetDlgItem(hdlg, PSIZE_Y), TRUE); PropSheet_Changed(hPropSheetDlg, hdlg); } return FALSE; case PSIZE_X: case PSIZE_Y: case PSIZE_OFFX: case PSIZE_OFFY: if (HIWORD(wparam) == EN_UPDATE) PropSheet_Changed(hPropSheetDlg, hdlg); return FALSE; } /* switch (wparam) */ break; case WM_NOTIFY: switch (((LPNMHDR) lparam)->code) { case PSN_APPLY: /* apply changes */ /* FIXME: Need to check for valid input. */ if (SendDlgItemMessage(hdlg, PSIZE_OTHER, BM_GETCHECK, 0, 0L)) { SendDlgItemMessage(hdlg, PSIZE_X, WM_GETTEXT, 7, (LPARAM) buf); GetInt(buf, (LPINT)&lpr->psize.x); SendDlgItemMessage(hdlg, PSIZE_Y, WM_GETTEXT, 7, (LPARAM) buf); GetInt(buf, (LPINT)&lpr->psize.y); } else { lpr->psize.x = lpr->pdef.x; lpr->psize.y = lpr->pdef.y; } SendDlgItemMessage(hdlg, PSIZE_OFFX, WM_GETTEXT, 7, (LPARAM) buf); GetInt(buf, (LPINT)&lpr->poff.x); SendDlgItemMessage(hdlg, PSIZE_OFFY, WM_GETTEXT, 7, (LPARAM) buf); GetInt(buf, (LPINT)&lpr->poff.y); if (lpr->psize.x <= 0) lpr->psize.x = lpr->pdef.x; if (lpr->psize.y <= 0) lpr->psize.y = lpr->pdef.y; PropSheet_UnChanged(hPropSheetDlg, hdlg); SetWindowLongPtr(hdlg, DWLP_MSGRESULT, PSNRET_NOERROR); return TRUE; } case PSN_SETACTIVE: /* display: intialize according to printer */ if (lpr->psize.x < 0 || lpr->bDriverChanged) { /* FIXME: also if settings changed (paper size, orientation) */ IPrintDialogServices * services = (IPrintDialogServices *) lpr->services; /* Set size to full paper size of current printer */ if (services) { LPTSTR lpPrinterName = NULL; LPTSTR lpPortName = NULL; LPDEVMODE lpDevMode = NULL; UINT size; HRESULT hr; /* Note: The Windows 8.1 SDK says that these functions expect LPWSTR arguments, in contrast to the MSDN documentation, MinGW, and what was actually seen in a debugger on Windows 10. So warnings about type mismatch can be safely ignored. */ size = 0; hr = services->lpVtbl->GetCurrentPrinterName(services, NULL, &size); if (SUCCEEDED(hr) && size > 0) { lpPrinterName = (LPTSTR) malloc(size * sizeof(TCHAR)); hr = services->lpVtbl->GetCurrentPrinterName(services, lpPrinterName, &size); } size = 0; hr = services->lpVtbl->GetCurrentPortName(services, NULL, &size); if (SUCCEEDED(hr) && size > 0) { lpPortName = (LPTSTR) malloc(size * sizeof(TCHAR)); hr = services->lpVtbl->GetCurrentPortName(services, lpPortName, &size); } size = 0; hr = services->lpVtbl->GetCurrentDevMode(services, NULL, &size); if (SUCCEEDED(hr) && size > 0) { lpDevMode = (LPDEVMODE) malloc(size * sizeof(TCHAR)); hr = services->lpVtbl->GetCurrentDevMode(services, lpDevMode, &size); } if (SUCCEEDED(hr) && size > 0 && lpPortName != NULL && lpPrinterName != NULL) { HDC printer = CreateDC(TEXT("WINSPOOL"), lpPrinterName, lpPortName, lpDevMode); lpr->psize.x = GetDeviceCaps(printer, HORZSIZE); lpr->psize.y = GetDeviceCaps(printer, VERTSIZE); DeleteDC(printer); } free(lpPrinterName); free(lpPortName); free(lpDevMode); } } if (lpr->psize.x < 0) { /* something went wrong */ lpr->psize.x = lpr->pdef.x; lpr->psize.y = lpr->pdef.y; } /* apply changes */ wsprintf(buf, TEXT("%d"), lpr->psize.x); SetDlgItemText(hdlg, PSIZE_X, buf); wsprintf(buf, TEXT("%d"), lpr->psize.y); SetDlgItemText(hdlg, PSIZE_Y, buf); lpr->bDriverChanged = FALSE; SetWindowLongPtr(hdlg, DWLP_MSGRESULT, 0); /* accept activation */ return TRUE; break; } /* switch (msg) */ return FALSE; }
static SDL_bool WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode) { SDL_DisplayModeData *data; DEVMODE devmode; #ifndef _WIN32_WCE HDC hdc; #endif devmode.dmSize = sizeof(devmode); devmode.dmDriverExtra = 0; if (!EnumDisplaySettings(deviceName, index, &devmode)) { return SDL_FALSE; } data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data)); if (!data) { return SDL_FALSE; } data->DeviceMode = devmode; data->DeviceMode.dmFields = (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS); /* Fill in the mode information */ mode->format = SDL_PIXELFORMAT_UNKNOWN; mode->w = devmode.dmPelsWidth; mode->h = devmode.dmPelsHeight; mode->refresh_rate = devmode.dmDisplayFrequency; mode->driverdata = data; #ifdef _WIN32_WCE /* In WinCE EnumDisplaySettings(ENUM_CURRENT_SETTINGS) doesn't take the user defined orientation into account but GetSystemMetrics does. */ if (index == ENUM_CURRENT_SETTINGS) { mode->w = GetSystemMetrics(SM_CXSCREEN); mode->h = GetSystemMetrics(SM_CYSCREEN); } #endif /* WinCE has no GetDIBits, therefore we can't use it to get the display format */ #ifndef _WIN32_WCE if (index == ENUM_CURRENT_SETTINGS && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) { char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)]; LPBITMAPINFO bmi; HBITMAP hbm; SDL_zero(bmi_data); bmi = (LPBITMAPINFO) bmi_data; bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); hbm = CreateCompatibleBitmap(hdc, 1, 1); GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS); GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS); DeleteObject(hbm); DeleteDC(hdc); if (bmi->bmiHeader.biCompression == BI_BITFIELDS) { switch (*(Uint32 *) bmi->bmiColors) { case 0x00FF0000: mode->format = SDL_PIXELFORMAT_RGB888; break; case 0x000000FF: mode->format = SDL_PIXELFORMAT_BGR888; break; case 0xF800: mode->format = SDL_PIXELFORMAT_RGB565; break; case 0x7C00: mode->format = SDL_PIXELFORMAT_RGB555; break; } } else if (bmi->bmiHeader.biBitCount == 8) { mode->format = SDL_PIXELFORMAT_INDEX8; } else if (bmi->bmiHeader.biBitCount == 4) { mode->format = SDL_PIXELFORMAT_INDEX4LSB; } } else #endif /* _WIN32_WCE */ { /* FIXME: Can we tell what this will be? */ if ((devmode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) { switch (devmode.dmBitsPerPel) { case 32: mode->format = SDL_PIXELFORMAT_RGB888; break; case 24: mode->format = SDL_PIXELFORMAT_RGB24; break; case 16: mode->format = SDL_PIXELFORMAT_RGB565; break; case 15: mode->format = SDL_PIXELFORMAT_RGB555; break; case 8: mode->format = SDL_PIXELFORMAT_INDEX8; break; case 4: mode->format = SDL_PIXELFORMAT_INDEX4LSB; break; } } } return SDL_TRUE; }