LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static CHOOSEFONT cf ; static int iPage ; static LOGFONT lf ; HDC hdc ; int cxChar, cyChar, x, y, i, cxLabels ; PAINTSTRUCT ps ; SIZE size ; TCHAR szBuffer [8] ; TEXTMETRIC tm ; WCHAR ch ; switch (message) { case WM_CREATE: hdc = GetDC (hwnd) ; lf.lfHeight = - GetDeviceCaps (hdc, LOGPIXELSY) / 6 ; // 12 points lstrcpy (lf.lfFaceName, TEXT ("Lucida Sans Unicode")) ; ReleaseDC (hwnd, hdc) ; cf.lStructSize = sizeof (CHOOSEFONT) ; cf.hwndOwner = hwnd ; cf.lpLogFont = &lf ; cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS ; SetScrollRange (hwnd, SB_VERT, 0, 255, FALSE) ; SetScrollPos (hwnd, SB_VERT, iPage, TRUE ) ; return 0 ; case WM_COMMAND: switch (LOWORD (wParam)) { case IDM_FONT: if (ChooseFont (&cf)) InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; } return 0 ; case WM_VSCROLL: switch (LOWORD (wParam)) { case SB_LINEUP: iPage -= 1 ; break ; case SB_LINEDOWN: iPage += 1 ; break ; case SB_PAGEUP: iPage -= 16 ; break ; case SB_PAGEDOWN: iPage += 16 ; break ; case SB_THUMBPOSITION: iPage = HIWORD (wParam) ; break ; default: return 0 ; } iPage = max (0, min (iPage, 255)) ; SetScrollPos (hwnd, SB_VERT, iPage, TRUE) ; InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SelectObject (hdc, CreateFontIndirect (&lf)) ; GetTextMetrics (hdc, &tm) ; cxChar = tm.tmMaxCharWidth ; cyChar = tm.tmHeight + tm.tmExternalLeading ; cxLabels = 0 ; for (i = 0 ; i < 16 ; i++) { wsprintf (szBuffer, TEXT (" 000%1X: "), i) ; GetTextExtentPoint (hdc, szBuffer, 7, &size) ; cxLabels = max (cxLabels, size.cx) ; } for (y = 0 ; y < 16 ; y++) { wsprintf (szBuffer, TEXT (" %03X_: "), 16 * iPage + y) ; TextOut (hdc, 0, y * cyChar, szBuffer, 7) ; for (x = 0 ; x < 16 ; x++) { ch = (WCHAR) (256 * iPage + 16 * y + x) ; TextOutW (hdc, x * cxChar + cxLabels, y * cyChar, &ch, 1); } } DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))); EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
DisplayInfo MythDisplay::GetDisplayInfo(int video_rate) { DisplayInfo ret; #if defined(Q_WS_MAC) CGDirectDisplayID disp = GetOSXDisplay(GetWindowID()); if (!disp) return ret; CFDictionaryRef ref = CGDisplayCurrentMode(disp); float rate = 0.0f; if (ref) rate = get_float_CF(ref, kCGDisplayRefreshRate); if (VALID_RATE(rate)) ret.rate = 1000000.0f / rate; else ret.rate = fix_rate(video_rate); CGSize size_in_mm = CGDisplayScreenSize(disp); ret.size = QSize((uint) size_in_mm.width, (uint) size_in_mm.height); uint width = (uint)CGDisplayPixelsWide(disp); uint height = (uint)CGDisplayPixelsHigh(disp); ret.res = QSize(width, height); #elif defined(Q_WS_WIN) HDC hdc = GetDC(GetWindowID()); int rate = 0; if (hdc) { rate = GetDeviceCaps(hdc, VREFRESH); int width = GetDeviceCaps(hdc, HORZSIZE); int height = GetDeviceCaps(hdc, VERTSIZE); ret.size = QSize((uint)width, (uint)height); width = GetDeviceCaps(hdc, HORZRES); height = GetDeviceCaps(hdc, VERTRES); ret.res = QSize((uint)width, (uint)height); } if (VALID_RATE(rate)) { // see http://support.microsoft.com/kb/2006076 switch (rate) { case 23: ret.rate = 41708; break; // 23.976Hz case 29: ret.rate = 33367; break; // 29.970Hz case 47: ret.rate = 20854; break; // 47.952Hz case 59: ret.rate = 16683; break; // 59.940Hz case 71: ret.rate = 13903; break; // 71.928Hz case 119: ret.rate = 8342; break; // 119.880Hz default: ret.rate = 1000000.0f / (float)rate; } } else ret.rate = fix_rate(video_rate); #elif USING_X11 MythXDisplay *disp = OpenMythXDisplay(); if (!disp) return ret; float rate = disp->GetRefreshRate(); if (VALID_RATE(rate)) ret.rate = 1000000.0f / rate; else ret.rate = fix_rate(video_rate); ret.res = disp->GetDisplaySize(); ret.size = disp->GetDisplayDimensions(); delete disp; #endif return ret; }
void GLUTAPIENTRY glutGameModeString(const char *string) { Criterion *criteria; int ncriteria[4], requestedMask, queries = 1; #if _WIN32 int bpp, width, height, hertz, n; #endif initGameModeSupport(); #if _WIN32 XHDC = GetDC(GetDesktopWindow()); bpp = GetDeviceCaps(XHDC, BITSPIXEL); /* Note that Windows 95 and 98 systems always return zero for VREFRESH so be prepared to ignore values of hertz that are too low. */ hertz = GetDeviceCaps(XHDC, VREFRESH); width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); #endif criteria = parseGameModeString(string, &ncriteria[0], &requestedMask); #if _WIN32 /* Build an extra set of default queries. If no pixel depth is explicitly specified, prefer a display mode that doesn't change the display mode. Likewise for the width and height. Likewise for the display frequency. */ n = ncriteria[0]; if (!(requestedMask & (1 << DM_PIXEL_DEPTH))) { criteria[n].capability = DM_PIXEL_DEPTH; criteria[n].comparison = EQ; criteria[n].value = bpp; n += 1; ncriteria[queries] = n; queries++; } if (!(requestedMask & ((1<<DM_WIDTH) | (1<<DM_HEIGHT)) )) { criteria[n].capability = DM_WIDTH; criteria[n].comparison = EQ; criteria[n].value = width; criteria[n].capability = DM_HEIGHT; criteria[n].comparison = EQ; criteria[n].value = height; n += 2; ncriteria[queries] = n; queries++; } /* Assume a display frequency of less than 50 is to be ignored. */ if (hertz >= 50) { if (!(requestedMask & (1 << DM_HERTZ))) { criteria[n].capability = DM_HERTZ; criteria[n].comparison = EQ; criteria[n].value = hertz; n += 1; ncriteria[queries] = n; queries++; } } #endif /* Perform multiple queries until one succeeds or no more queries. */ do { queries--; currentDm = findMatch(dmodes, ndmodes, criteria, ncriteria[queries]); } while((currentDm == NULL) && (queries > 0)); free(criteria); }
void PropSheet::Show(HINSTANCE hInstance, HWND hParent, std::string title, int startpage, bool floating, bool wizard) { HPROPSHEETPAGE *pages = new HPROPSHEETPAGE[list.size()]; PROPSHEETPAGE page; //common settings memset((void*)&page,0,sizeof(PROPSHEETPAGE)); page.dwSize = sizeof(PROPSHEETPAGE); page.hInstance = hInstance; int i=0; for (DlgList::iterator iter = list.begin(); iter != list.end(); iter++, i++) { if (wizard) { if (i == 0 || i == list.size()-1) page.dwFlags = PSP_HIDEHEADER; else page.dwFlags = PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE; } else { page.dwFlags = PSP_USETITLE; } page.pszTemplate = iter->resource; page.pfnDlgProc = Tab::TabDlgProc; page.pszTitle = iter->title; page.pszHeaderTitle = wizard?iter->title:0; page.pszHeaderSubTitle = wizard?iter->hdrSubTitle:0; page.lParam = (LPARAM)iter->tab; pages[i] = CreatePropertySheetPage(&page); } PROPSHEETHEADER sheet; memset(&sheet,0,sizeof(sheet)); sheet.dwSize = sizeof(PROPSHEETHEADER); sheet.hInstance = hInstance; sheet.hwndParent = hParent; sheet.pszbmWatermark = watermark; sheet.pszbmHeader = header; if (icon) sheet.hIcon = icon; if (wizard) sheet.dwFlags = PSH_USECALLBACK | PSH_WIZARD97 | (watermark?PSH_WATERMARK:0) | (header?PSH_HEADER:0); else sheet.dwFlags = PSH_USECALLBACK | PSH_PROPTITLE; if (floating) sheet.dwFlags |= PSH_MODELESS; //else // sheet.dwFlags |= PSH_NOAPPLYNOW; if (icon) sheet.dwFlags |= PSH_USEHICON; sheet.pszCaption = ConvertUTF8ToWString(title).c_str(); sheet.nPages = (UINT)list.size(); sheet.phpage = pages; sheet.nStartPage = startpage; sheet.pfnCallback = (PFNPROPSHEETCALLBACK)Callback; if (wizard) { NONCLIENTMETRICS ncm = {0}; ncm.cbSize = sizeof(ncm); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); //Create the intro/end title font LOGFONT TitleLogFont = ncm.lfMessageFont; TitleLogFont.lfWeight = FW_BOLD; lstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold")); //StringCchCopy(TitleLogFont.lfFaceName, 32, TEXT("Verdana Bold")); HDC hdc = GetDC(NULL); //gets the screen DC INT FontSize = 12; TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72; hTitleFont = CreateFontIndirect(&TitleLogFont); ReleaseDC(NULL, hdc); } else hTitleFont = 0; centered=false; PropertySheet(&sheet); if (!floating) { for (DlgList::iterator iter = list.begin(); iter != list.end(); iter++) { delete iter->tab; } DeleteObject(hTitleFont); } delete [] pages; }
static Bool winQueryRGBBitsAndMasks (ScreenPtr pScreen) { winScreenPriv(pScreen); BITMAPINFOHEADER *pbmih = NULL; Bool fReturn = TRUE; LPDWORD pdw = NULL; DWORD dwRedBits, dwGreenBits, dwBlueBits; /* Color masks for 8 bpp are standardized */ if (GetDeviceCaps (pScreenPriv->hdcScreen, RASTERCAPS) & RC_PALETTE) { /* * RGB BPP for 8 bit palletes is always 8 * and the color masks are always 0. */ pScreenPriv->dwBitsPerRGB = 8; pScreenPriv->dwRedMask = 0x0L; pScreenPriv->dwGreenMask = 0x0L; pScreenPriv->dwBlueMask = 0x0L; return TRUE; } /* Color masks for 24 bpp are standardized */ if (GetDeviceCaps (pScreenPriv->hdcScreen, PLANES) * GetDeviceCaps (pScreenPriv->hdcScreen, BITSPIXEL) == 24) { ErrorF ("winQueryRGBBitsAndMasks - GetDeviceCaps (BITSPIXEL) " "returned 24 for the screen. Using default 24bpp masks.\n"); /* 8 bits per primary color */ pScreenPriv->dwBitsPerRGB = 8; /* Set screen privates masks */ pScreenPriv->dwRedMask = WIN_24BPP_MASK_RED; pScreenPriv->dwGreenMask = WIN_24BPP_MASK_GREEN; pScreenPriv->dwBlueMask = WIN_24BPP_MASK_BLUE; return TRUE; } /* Allocate a bitmap header and color table */ pbmih = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD)); if (pbmih == NULL) { ErrorF ("winQueryRGBBitsAndMasks - malloc failed\n"); return FALSE; } /* Get screen description */ if (winQueryScreenDIBFormat (pScreen, pbmih)) { /* Get a pointer to bitfields */ pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); #if CYGDEBUG winDebug ("%s - Masks: %08x %08x %08x\n", __FUNCTION__, pdw[0], pdw[1], pdw[2]); winDebug ("%s - Bitmap: %dx%d %d bpp %d planes\n", __FUNCTION__, pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount, pbmih->biPlanes); winDebug ("%s - Compression: %d %s\n", __FUNCTION__, pbmih->biCompression, (pbmih->biCompression == BI_RGB?"(BI_RGB)": (pbmih->biCompression == BI_RLE8?"(BI_RLE8)": (pbmih->biCompression == BI_RLE4?"(BI_RLE4)": (pbmih->biCompression == BI_BITFIELDS?"(BI_BITFIELDS)":"" ))))); #endif /* Handle BI_RGB case, which is returned by Wine */ if (pbmih->biCompression == BI_RGB) { dwRedBits = 5; dwGreenBits = 5; dwBlueBits = 5; pScreenPriv->dwBitsPerRGB = 5; /* Set screen privates masks */ pScreenPriv->dwRedMask = 0x7c00; pScreenPriv->dwGreenMask = 0x03e0; pScreenPriv->dwBlueMask = 0x001f; } else { /* Count the number of bits in each mask */ dwRedBits = winCountBits (pdw[0]); dwGreenBits = winCountBits (pdw[1]); dwBlueBits = winCountBits (pdw[2]); /* Find maximum bits per red, green, blue */ if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits) pScreenPriv->dwBitsPerRGB = dwRedBits; else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits) pScreenPriv->dwBitsPerRGB = dwGreenBits; else pScreenPriv->dwBitsPerRGB = dwBlueBits; /* Set screen privates masks */ pScreenPriv->dwRedMask = pdw[0]; pScreenPriv->dwGreenMask = pdw[1]; pScreenPriv->dwBlueMask = pdw[2]; } } else { ErrorF ("winQueryRGBBitsAndMasks - winQueryScreenDIBFormat failed\n"); free (pbmih); fReturn = FALSE; } /* Free memory */ free (pbmih); return fReturn; }
LRESULT CALLBACK LConProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HWND view; HDC hdc; HBRUSH hbr; HGDIOBJ oldfont; RECT rect; int titlelen; SIZE size; LOGFONT lf; TEXTMETRIC tm; HINSTANCE inst = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); DRAWITEMSTRUCT *drawitem; CHARFORMAT2W format; switch (msg) { case WM_CREATE: // Create game title static control memset (&lf, 0, sizeof(lf)); hdc = GetDC (hWnd); lf.lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); lf.lfCharSet = ANSI_CHARSET; lf.lfWeight = FW_BOLD; lf.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN; strcpy (lf.lfFaceName, "Trebuchet MS"); GameTitleFont = CreateFontIndirect (&lf); oldfont = SelectObject (hdc, GetStockObject (DEFAULT_GUI_FONT)); GetTextMetrics (hdc, &tm); DefaultGUIFontHeight = tm.tmHeight; if (GameTitleFont == NULL) { GameTitleFontHeight = DefaultGUIFontHeight; } else { SelectObject (hdc, GameTitleFont); GetTextMetrics (hdc, &tm); GameTitleFontHeight = tm.tmHeight; } SelectObject (hdc, oldfont); // Create log read-only edit control view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "RichEdit20W", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | WS_CLIPSIBLINGS, 0, 0, 0, 0, hWnd, NULL, inst, NULL); HRESULT hr; hr = GetLastError(); if (view == NULL) { ReleaseDC (hWnd, hdc); return -1; } SendMessage (view, EM_SETREADONLY, TRUE, 0); SendMessage (view, EM_EXLIMITTEXT, 0, 0x7FFFFFFE); SendMessage (view, EM_SETBKGNDCOLOR, 0, RGB(70,70,70)); // Setup default font for the log. //SendMessage (view, WM_SETFONT, (WPARAM)GetStockObject (DEFAULT_GUI_FONT), FALSE); format.cbSize = sizeof(format); format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET; format.dwEffects = 0; format.yHeight = 200; format.crTextColor = RGB(223,223,223); format.bCharSet = ANSI_CHARSET; format.bPitchAndFamily = FF_SWISS | VARIABLE_PITCH; wcscpy(format.szFaceName, L"DejaVu Sans"); // At least I have it. :p SendMessageW(view, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format); ConWindow = view; ReleaseDC (hWnd, hdc); view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW, 0, 0, 0, 0, hWnd, NULL, inst, NULL); if (view == NULL) { return -1; } SetWindowLong (view, GWL_ID, IDC_STATIC_TITLE); GameTitleWindow = view; return 0; case WM_SIZE: if (wParam != SIZE_MAXHIDE && wParam != SIZE_MAXSHOW) { LayoutMainWindow (hWnd, ErrorPane); } return 0; case WM_DRAWITEM: // Draw title banner. if (wParam == IDC_STATIC_TITLE && DoomStartupInfo.Name.IsNotEmpty()) { const PalEntry *c; // Draw the game title strip at the top of the window. drawitem = (LPDRAWITEMSTRUCT)lParam; // Draw the background. rect = drawitem->rcItem; rect.bottom -= 1; c = (const PalEntry *)&DoomStartupInfo.BkColor; hbr = CreateSolidBrush (RGB(c->r,c->g,c->b)); FillRect (drawitem->hDC, &drawitem->rcItem, hbr); DeleteObject (hbr); // Calculate width of the title string. SetTextAlign (drawitem->hDC, TA_TOP); oldfont = SelectObject (drawitem->hDC, GameTitleFont != NULL ? GameTitleFont : (HFONT)GetStockObject (DEFAULT_GUI_FONT)); titlelen = (int)DoomStartupInfo.Name.Len(); GetTextExtentPoint32 (drawitem->hDC, DoomStartupInfo.Name, titlelen, &size); // Draw the title. c = (const PalEntry *)&DoomStartupInfo.FgColor; SetTextColor (drawitem->hDC, RGB(c->r,c->g,c->b)); SetBkMode (drawitem->hDC, TRANSPARENT); TextOut (drawitem->hDC, rect.left + (rect.right - rect.left - size.cx) / 2, 2, DoomStartupInfo.Name, titlelen); SelectObject (drawitem->hDC, oldfont); return TRUE; } // Draw startup screen else if (wParam == IDC_STATIC_STARTUP) { if (StartupScreen != NULL) { drawitem = (LPDRAWITEMSTRUCT)lParam; rect = drawitem->rcItem; // Windows expects DIBs to be bottom-up but ours is top-down, // so flip it vertically while drawing it. StretchDIBits (drawitem->hDC, rect.left, rect.bottom - 1, rect.right - rect.left, rect.top - rect.bottom, 0, 0, StartupBitmap->bmiHeader.biWidth, StartupBitmap->bmiHeader.biHeight, ST_Util_BitsForBitmap(StartupBitmap), StartupBitmap, DIB_RGB_COLORS, SRCCOPY); // If the title banner is gone, then this is an ENDOOM screen, so draw a short prompt // where the command prompt would have been in DOS. if (GameTitleWindow == NULL) { static const char QuitText[] = "Press any key or click anywhere in the window to quit."; SetTextColor (drawitem->hDC, RGB(240,240,240)); SetBkMode (drawitem->hDC, TRANSPARENT); oldfont = SelectObject (drawitem->hDC, (HFONT)GetStockObject (DEFAULT_GUI_FONT)); TextOut (drawitem->hDC, 3, drawitem->rcItem.bottom - DefaultGUIFontHeight - 3, QuitText, countof(QuitText)-1); SelectObject (drawitem->hDC, oldfont); } return TRUE; } } // Draw stop icon. else if (wParam == IDC_ICONPIC) { HICON icon; POINTL char_pos; drawitem = (LPDRAWITEMSTRUCT)lParam; // This background color should match the edit control's. hbr = CreateSolidBrush (RGB(70,70,70)); FillRect (drawitem->hDC, &drawitem->rcItem, hbr); DeleteObject (hbr); // Draw the icon aligned with the first line of error text. SendMessage (ConWindow, EM_POSFROMCHAR, (WPARAM)&char_pos, ErrorIconChar); icon = (HICON)LoadImage (0, IDI_ERROR, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED); DrawIcon (drawitem->hDC, 6, char_pos.y, icon); return TRUE; } return FALSE; case WM_COMMAND: if (ErrorIcon != NULL && (HWND)lParam == ConWindow && HIWORD(wParam) == EN_UPDATE) { // Be sure to redraw the error icon if the edit control changes. InvalidateRect (ErrorIcon, NULL, TRUE); return 0; } break; case WM_CLOSE: PostQuitMessage (0); break; case WM_DESTROY: if (GameTitleFont != NULL) { DeleteObject (GameTitleFont); } break; } return DefWindowProc (hWnd, msg, wParam, lParam); }
static void readscreen(void) { HDC hScrDC; /* screen DC */ HDC hMemDC; /* memory DC */ HBITMAP hBitmap; /* handle for our bitmap */ HBITMAP hOldBitmap; /* handle for previous bitmap */ BITMAP bm; /* bitmap properties */ unsigned int size; /* size of bitmap */ char *bmbits; /* contents of bitmap */ int w; /* screen width */ int h; /* screen height */ int y; /* y-coordinate of screen lines to grab */ int n = 16; /* number of screen lines to grab at a time */ /* Create a screen DC and a memory DC compatible to screen DC */ hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); hMemDC = CreateCompatibleDC(hScrDC); /* Get screen resolution */ w = GetDeviceCaps(hScrDC, HORZRES); h = GetDeviceCaps(hScrDC, VERTRES); /* Create a bitmap compatible with the screen DC */ hBitmap = CreateCompatibleBitmap(hScrDC, w, n); /* Select new bitmap into memory DC */ hOldBitmap = SelectObject(hMemDC, hBitmap); /* Get bitmap properties */ GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes; bmbits = OPENSSL_malloc(size); if (bmbits) { /* Now go through the whole screen, repeatedly grabbing n lines */ for (y = 0; y < h-n; y += n) { unsigned char md[MD_DIGEST_LENGTH]; /* Bitblt screen DC to memory DC */ BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY); /* Copy bitmap bits from memory DC to bmbits */ GetBitmapBits(hBitmap, size, bmbits); /* Get the hash of the bitmap */ MD(bmbits,size,md); /* Seed the random generator with the hash value */ RAND_add(md, MD_DIGEST_LENGTH, 0); } OPENSSL_free(bmbits); } /* Select old bitmap back into memory DC */ hBitmap = SelectObject(hMemDC, hOldBitmap); /* Clean up */ DeleteObject(hBitmap); DeleteDC(hMemDC); DeleteDC(hScrDC); }
bool GLimp_SetMode(unsigned *pwidth, unsigned *pheight, int mode, bool fullscreen) { int width, height, colorBits; if (!Vid_GetModeInfo(&width, &height, mode)) { appWPrintf("Invalid mode: %d\n", mode); return false; } appPrintf("Mode %d: %dx%d (%s)\n", mode, width, height, fullscreen ? "fullscreen" : "windowed"); // destroy the existing window if (gl_hWnd) GLimp_Shutdown(false); colorBits = gl_bitdepth->integer; gl_bitdepth->modified = false; // do a CDS if needed if (fullscreen) { DEVMODE dm; memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); dm.dmPelsWidth = width; dm.dmPelsHeight = height; dm.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT; if (colorBits) { dm.dmBitsPerPel = colorBits; dm.dmFields |= DM_BITSPERPEL; appPrintf("...using color depth of %d\n", colorBits); } else { HDC hdc = GetDC(NULL); int bitspixel = GetDeviceCaps(hdc, BITSPIXEL); ReleaseDC(0, hdc); appPrintf("...using desktop color depth of %d\n", bitspixel); } MSGLOG(("CDS(%dx%d, FS)\n", dm.dmPelsWidth, dm.dmPelsHeight)); if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { appWPrintf("...fullscreen unavailable in this mode\n"); appPrintf("...setting windowed mode\n"); fullscreen = false; MSGLOG(("CDS(NULL)\n")); ChangeDisplaySettings(NULL, 0); } } else // not fullscreen { appPrintf("...setting windowed mode\n"); MSGLOG(("CDS(NULL)\n")); ChangeDisplaySettings(NULL, 0); } *pwidth = width; *pheight = height; gl_config.fullscreen = fullscreen; gl_hWnd = (HWND) Vid_CreateWindow(width, height, fullscreen); if (!gl_hWnd) return false; if (!GLimp_InitGL()) return false; //?? may try to DestroyWindow(force) + CreateWindow() again // init gamma ReadGamma(); appPrintf("Gamma: %s\n", gammaStored ? "hardware" : "software"); return true; }
/* ** Sys_CreateConsole */ void Sys_CreateConsole( void ) { HDC hDC; WNDCLASS wc; RECT rect; const char *DEDCLASS = "JK2MP WinConsole"; int nHeight; int swidth, sheight; int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX; memset( &wc, 0, sizeof( wc ) ); wc.style = 0; wc.lpfnWndProc = (WNDPROC) ConWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_wv.hInstance; wc.hIcon = LoadIcon( g_wv.hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor (NULL,IDC_ARROW); wc.hbrBackground = (HBRUSH__ *)COLOR_INACTIVEBORDER;//(HBRUSH__ *)COLOR_WINDOW; wc.lpszMenuName = 0; wc.lpszClassName = DEDCLASS; if ( !RegisterClass (&wc) ) { return; } rect.left = 0; rect.right = 600; rect.top = 0; rect.bottom = 450; AdjustWindowRect( &rect, DEDSTYLE, FALSE ); hDC = GetDC( GetDesktopWindow() ); swidth = GetDeviceCaps( hDC, HORZRES ); sheight = GetDeviceCaps( hDC, VERTRES ); ReleaseDC( GetDesktopWindow(), hDC ); s_wcd.windowWidth = rect.right - rect.left + 1; s_wcd.windowHeight = rect.bottom - rect.top + 1; s_wcd.hWnd = CreateWindowEx( 0, DEDCLASS, "OpenJK Singleplayer Console", DEDSTYLE, ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1, NULL, NULL, g_wv.hInstance, NULL ); if ( s_wcd.hWnd == NULL ) { return; } // // create fonts // hDC = GetDC( s_wcd.hWnd ); nHeight = -MulDiv( 8, GetDeviceCaps( hDC, LOGPIXELSY), 72); s_wcd.hfBufferFont = CreateFont( nHeight, 0, 0, 0, FW_LIGHT, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN | FIXED_PITCH, "Consolas" ); ReleaseDC( s_wcd.hWnd, hDC ); // // create the input line // s_wcd.hwndInputLine = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, 6, 400, s_wcd.windowWidth-20, 20, s_wcd.hWnd, ( HMENU ) INPUT_ID, // child window ID g_wv.hInstance, NULL ); // // create the buttons // s_wcd.hwndButtonCopy = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 5, 425, 72, 24, s_wcd.hWnd, ( HMENU ) COPY_ID, // child window ID g_wv.hInstance, NULL ); SendMessage( s_wcd.hwndButtonCopy, WM_SETTEXT, 0, ( LPARAM ) "copy" ); s_wcd.hwndButtonClear = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 82, 425, 72, 24, s_wcd.hWnd, ( HMENU ) CLEAR_ID, // child window ID g_wv.hInstance, NULL ); SendMessage( s_wcd.hwndButtonClear, WM_SETTEXT, 0, ( LPARAM ) "clear" ); s_wcd.hwndButtonQuit = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, s_wcd.windowWidth-92, 425, 72, 24, s_wcd.hWnd, ( HMENU ) QUIT_ID, // child window ID g_wv.hInstance, NULL ); SendMessage( s_wcd.hwndButtonQuit, WM_SETTEXT, 0, ( LPARAM ) "quit" ); // // create the scrollbuffer // s_wcd.hwndBuffer = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_TABSTOP, 6, 40, s_wcd.windowWidth-20, 354, s_wcd.hWnd, ( HMENU ) EDIT_ID, // child window ID g_wv.hInstance, NULL ); SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 ); s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLongPtr( s_wcd.hwndInputLine, GWLP_WNDPROC, ( LONG_PTR ) InputLineWndProc ); SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 ); SendMessage( s_wcd.hwndBuffer, EM_LIMITTEXT, ( WPARAM ) 0x7fff, 0 ); ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT); UpdateWindow( s_wcd.hWnd ); SetForegroundWindow( s_wcd.hWnd ); SetFocus( s_wcd.hwndInputLine ); Field_Clear( &s_wcd.g_consoleField ); s_wcd.g_consoleField.widthInChars = g_console_field_width; for ( int i = 0 ; i < COMMAND_HISTORY ; i++ ) { Field_Clear( &s_wcd.historyEditLines[i] ); s_wcd.historyEditLines[i].widthInChars = g_console_field_width; } s_wcd.visLevel = 1; }
LRESULT CALLBACK VersionProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { HWND h = GetDlgItem(hDlg,IDC_DEVICEINFO); std::string buf; buf += "* * * * * * * *\r\n"; buf += "* ディスプレイ情報\r\n"; buf += "* * * * * * * *\r\n"; buf += GetMaxMinDisplayColors(NULL,NULL); buf += "---\r\n"; if(gdiplus_useable){ HMODULE hmd = GetModuleHandle("gdiplus.dll"); char b[MAX_PATH] = ""; GetModuleFileName(hmd,b,sizeof(b)-1); buf += "GDI+: 使用可->\""; buf += b; buf += "\"\r\n"; }else{ buf += "GDI+: 使用不可->gdiplus.dllが見つからない\r\n"; } buf += "---\r\n"; DWORD r; const int dcnum1[] = { RASTERCAPS , CURVECAPS , LINECAPS , POLYGONALCAPS , TEXTCAPS }; const char * dcname1[] = {"RASTERCAPS","CURVECAPS","LINECAPS","POLYGONALCAPS","TEXTCAPS"}; const int dcnum2[] = { NUMBRUSHES , NUMPENS , NUMFONTS , NUMCOLORS , HORZSIZE , VERTSIZE , HORZRES , VERTRES , LOGPIXELSX , LOGPIXELSY , BITSPIXEL , PLANES , ASPECTX , ASPECTY , ASPECTXY , CLIPCAPS , PHYSICALWIDTH , PHYSICALHEIGHT , PHYSICALOFFSETX , PHYSICALOFFSETY , SCALINGFACTORX , SCALINGFACTORY }; const char * dcname2[] = { "NUMBRUSHES","NUMPENS","NUMFONTS","NUMCOLORS", "HORZSIZE","VERTSIZE","HORZRES","VERTRES","LOGPIXELSX","LOGPIXELSY", "BITSPIXEL","PLANES","ASPECTX","ASPECTY","ASPECTXY","CLIPCAPS", "PHYSICALWIDTH","PHYSICALHEIGHT","PHYSICALOFFSETX","PHYSICALOFFSETY","SCALINGFACTORX","SCALINGFACTORY"}; HDC hdc = CreateDC("DISPLAY",NULL,NULL,NULL); for(int i = 0; i < sizeof(dcnum1)/sizeof(*dcnum1); i++){ char b[16]; r = GetDeviceCaps(hdc,dcnum1[i]); wsprintf(b,"%08X",r); buf += dcname1[i]; buf += ": "; buf += b; buf += "\r\n"; } DeleteDC(hdc); buf += "* * * * * * * *\r\n"; buf += "* プリンタ情報 \r\n"; buf += "* * * * * * * *\r\n"; if(hPrintDC == NULL){ buf += "プリンタDCを取得できません\r\n"; }else{ if(hDevNames == NULL){ buf += "DEVNAMES が NULL です\r\n"; }else{ DEVNAMES * pdn = (DEVNAMES *)GlobalLock(hDevNames); buf += "デバイスドライバ: "; buf += (char *)pdn + pdn->wDriverOffset; buf += "\r\n"; buf += "デバイス名: "; buf += (char *)pdn + pdn->wDeviceOffset; buf += "\r\n"; buf += "出力メディア: "; buf += (char *)pdn + pdn->wOutputOffset; buf += "\r\n"; GlobalUnlock(hDevNames); } buf += "---\r\n"; if(hDevMode == NULL){ buf += "DEVMODE が NULL です\r\n"; }else{ DEVMODE * pdv = (DEVMODE *)GlobalLock(hDevMode); char bb[16]; if(pdv->dmFields & DM_ORIENTATION){wsprintf(bb,"%d",pdv->dmOrientation );buf += "ORIENTATION: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_PAPERSIZE){wsprintf(bb,"%d",pdv->dmPaperSize );buf += "PAPERSIZE: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_PAPERLENGTH){wsprintf(bb,"%d",pdv->dmPaperLength );buf += "PAPERLENGTH: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_PAPERWIDTH){wsprintf(bb,"%d",pdv->dmPaperWidth );buf += "PAPERWIDTH: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_POSITION){wsprintf(bb,"%d",pdv->dmPosition );buf += "POSITION: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_SCALE){wsprintf(bb,"%d",pdv->dmScale );buf += "SCALE: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_COPIES){wsprintf(bb,"%d",pdv->dmCopies );buf += "COPIES: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_DEFAULTSOURCE){wsprintf(bb,"%d",pdv->dmDefaultSource );buf += "DEFAULTSOURCE: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_PRINTQUALITY){wsprintf(bb,"%d",pdv->dmPrintQuality );buf += "PRINTQUALITY: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_COLOR){ buf += "COLOR: "; if(pdv->dmColor == DMCOLOR_COLOR){ buf += "COLOR"; }else if(pdv->dmColor == DMCOLOR_MONOCHROME){ buf += "MONOCHROME"; }else{ wsprintf(bb,"%d",pdv->dmColor); buf += bb; } buf+="\r\n"; } if(pdv->dmFields & DM_DUPLEX){wsprintf(bb,"%d",pdv->dmDuplex );buf += "DUPLEX: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_YRESOLUTION){wsprintf(bb,"%d",pdv->dmYResolution );buf += "YRESOLUTION: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_TTOPTION){ buf += "TTOPTION: "; if(pdv->dmTTOption == DMTT_BITMAP){ buf += "BITMAP"; }else if(pdv->dmTTOption == DMTT_DOWNLOAD){ buf += "DOWNLOAD"; }else if(pdv->dmTTOption == DMTT_DOWNLOAD_OUTLINE){ buf += "DOWNLOAD_OUTLINE"; }else if(pdv->dmTTOption == DMTT_SUBDEV){ buf += "SUBDEV"; }else{ wsprintf(bb,"%d",pdv->dmTTOption); buf += bb; } buf+="\r\n"; } if(pdv->dmFields & DM_COLLATE){wsprintf(bb,"%d",pdv->dmCollate );buf += "COLLATE: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_FORMNAME){ buf += "FORMNAME: "; buf += (char *)(pdv->dmFormName); buf+="\r\n"; } if(pdv->dmFields & DM_LOGPIXELS){wsprintf(bb,"%d",pdv->dmLogPixels );buf += "LOGPIXELS: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_BITSPERPEL){wsprintf(bb,"%d",pdv->dmBitsPerPel );buf += "BITSPERPEL: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_PELSWIDTH){wsprintf(bb,"%d",pdv->dmPelsWidth );buf += "PELSWIDTH: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_PELSHEIGHT){wsprintf(bb,"%d",pdv->dmPelsHeight );buf += "PELSHEIGHT: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_DISPLAYFLAGS){wsprintf(bb,"%d",pdv->dmDisplayFlags );buf += "DISPLAYFLAGS: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_NUP){wsprintf(bb,"%d",pdv->dmNup );buf += "NUP: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_DISPLAYFREQUENCY){wsprintf(bb,"%d",pdv->dmDisplayFrequency );buf += "DISPLAYFREQUENCY: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_ICMMETHOD){wsprintf(bb,"%d",pdv->dmICMMethod );buf += "ICMMETHOD: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_ICMINTENT){wsprintf(bb,"%d",pdv->dmICMIntent );buf += "ICMINTENT: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_MEDIATYPE){wsprintf(bb,"%d",pdv->dmMediaType );buf += "MEDIATYPE: "; buf += bb; buf+="\r\n";} if(pdv->dmFields & DM_DITHERTYPE){wsprintf(bb,"%d",pdv->dmDitherType );buf += "DITHERTYPE: "; buf += bb; buf+="\r\n";} GlobalUnlock(hDevMode); } buf += "---\r\n"; for(int i = 0; i < sizeof(dcnum2)/sizeof(*dcnum2); i++){ char b[16]; r = GetDeviceCaps(hPrintDC,dcnum2[i]); wsprintf(b,"%d",r); buf += dcname2[i]; buf += ": "; buf += b; buf += "\r\n"; } for(int i = 0; i < sizeof(dcnum1)/sizeof(*dcnum1); i++){ char b[16]; r = GetDeviceCaps(hPrintDC,dcnum1[i]); wsprintf(b,"%08X",r); buf += dcname1[i]; buf += ": "; buf += b; buf += "\r\n"; } } buf += "-- 以上 --\r\n"; SetWindowText(h,buf.c_str()); } return TRUE; break; case WM_COMMAND: { int iEvent = HIWORD(wParam); int iId = LOWORD(wParam); switch(iId){ case IDOK: case IDCANCEL: { EndDialog(hDlg,0); } break; } } return FALSE; break; } return FALSE; }
// the default child constructor... CPushPinDesktop::CPushPinDesktop(HRESULT *phr, CPushSourceDesktop *pFilter) : CSourceStream(NAME("Push Source CPushPinDesktop child/pin"), phr, pFilter, L"Capture"), m_bReReadRegistry(0), m_bDeDupe(0), m_iFrameNumber(0), pOldData(NULL), m_bConvertToI420(false), m_pParent(pFilter), m_bFormatAlreadySet(false), hRawBitmap(NULL), m_bUseCaptureBlt(false), previousFrameEndTime(0) { // Get the device context of the main display, just to get some metrics for it... globalStart = GetTickCount(); m_iHwndToTrack = (HWND) read_config_setting(TEXT("hwnd_to_track"), NULL); hScrDc = GetDC(m_iHwndToTrack); //m_iScreenBitDepth = GetTrueScreenDepth(hScrDc); ASSERT(hScrDc != 0); // failure... // Get the dimensions of the main desktop window as the default m_rScreen.left = m_rScreen.top = 0; m_rScreen.right = GetDeviceCaps(hScrDc, HORZRES); // NB this *fails* for dual monitor support currently... but we just get the wrong width by default, at least with aero windows 7 both can capture both monitors m_rScreen.bottom = GetDeviceCaps(hScrDc, VERTRES); // now read some custom settings... WarmupCounter(); reReadCurrentPosition(0); int config_width = read_config_setting(TEXT("capture_width"), 0); ASSERT(config_width >= 0); // negatives not allowed... int config_height = read_config_setting(TEXT("capture_height"), 0); ASSERT(config_height >= 0); // negatives not allowed, if it's set :) if(config_width > 0) { int desired = m_rScreen.left + config_width; //int max_possible = m_rScreen.right; // disabled check until I get dual monitor working. or should I allow off screen captures anyway? //if(desired < max_possible) m_rScreen.right = desired; //else // m_rScreen.right = max_possible; } else { // leave full screen } m_iCaptureConfigWidth = m_rScreen.right - m_rScreen.left; ASSERT(m_iCaptureConfigWidth > 0); if(config_height > 0) { int desired = m_rScreen.top + config_height; //int max_possible = m_rScreen.bottom; // disabled, see above. //if(desired < max_possible) m_rScreen.bottom = desired; //else // m_rScreen.bottom = max_possible; } else { // leave full screen } m_iCaptureConfigHeight = m_rScreen.bottom - m_rScreen.top; ASSERT(m_iCaptureConfigHeight > 0); m_iStretchToThisConfigWidth = read_config_setting(TEXT("stretch_to_width"), 0); m_iStretchToThisConfigHeight = read_config_setting(TEXT("stretch_to_height"), 0); m_iStretchMode = read_config_setting(TEXT("stretch_mode_high_quality_if_1"), 0); ASSERT(m_iStretchToThisConfigWidth >= 0 && m_iStretchToThisConfigHeight >= 0 && m_iStretchMode >= 0); // sanity checks m_bUseCaptureBlt = read_config_setting(TEXT("capture_transparent_windows_with_mouse_blink_only_non_aero_if_1"), 0) == 1; // default 30 fps...hmm... int config_max_fps = read_config_setting(TEXT("default_max_fps"), 30); // TODO allow floats [?] when ever requested ASSERT(config_max_fps >= 0); // m_rtFrameLength is also re-negotiated later... m_rtFrameLength = UNITS / config_max_fps; if(is_config_set_to_1(TEXT("track_new_x_y_coords_each_frame_if_1"))) { m_bReReadRegistry = 1; // takes 0.416880ms, but I thought it took more when I made it off by default :P } if(is_config_set_to_1(TEXT("dedup_if_1"))) { m_bDeDupe = 1; // takes 10 or 20ms...but useful to me! :) } m_millisToSleepBeforePollForChanges = read_config_setting(TEXT("millis_to_sleep_between_poll_for_dedupe_changes"), 10); wchar_t out[1000]; swprintf(out, 1000, L"default/from reg read config as: %dx%d -> %dx%d (%dtop %db %dl %dr) %dfps, dedupe? %d, millis between dedupe polling %d, m_bReReadRegistry? %d \n", m_iCaptureConfigHeight, m_iCaptureConfigWidth, getCaptureDesiredFinalHeight(), getCaptureDesiredFinalWidth(), m_rScreen.top, m_rScreen.bottom, m_rScreen.left, m_rScreen.right, config_max_fps, m_bDeDupe, m_millisToSleepBeforePollForChanges, m_bReReadRegistry); LocalOutput(L"warmup the debugging message system"); __int64 measureDebugOutputSpeed = StartCounter(); LocalOutput(out); LocalOutput("writing a large-ish debug itself took: %.02Lf ms", GetCounterSinceStartMillis(measureDebugOutputSpeed)); set_config_string_setting(L"last_init_config_was", out); }
void plDynSurfaceWriter::plWinSurface::SetFont( const plString &face, uint16_t size, uint8_t flags, bool aaRGB ) { fFontFace = face; fFontSize = size; fFontFlags = flags; fFontAntiAliasRGB = aaRGB; bool hadAFont = false; if( fFont != nil ) { hadAFont = true; plWinFontCache::GetInstance().FreeFont( fFont ); fFont = nil; } if (face.IsEmpty()) return; bool bold = ( fFontFlags & plDynSurfaceWriter::kFontBold ) ? true : false; bool italic = ( fFontFlags & plDynSurfaceWriter::kFontItalic ) ? true : false; int nHeight = -MulDiv( size, GetDeviceCaps( fDC, LOGPIXELSY ), 72 ); fFont = plWinFontCache::GetInstance().GetMeAFont( face, nHeight, bold ? FW_BOLD : FW_NORMAL, italic, fFontAntiAliasRGB ? ANTIALIASED_QUALITY : DEFAULT_QUALITY ); if( fFont == nil && fFontAntiAliasRGB ) { static bool warnedCantAntiAlias = false; // Creation of font failed; could be that we can't do anti-aliasing? Try not doing it... if( !warnedCantAntiAlias ) { plStatusLog::AddLineS( "pipeline.log", "WARNING: Cannot allocate anti-aliased font. Falling back to non-anti-aliased. This will be the only warning" ); warnedCantAntiAlias = true; } fFont = plWinFontCache::GetInstance().GetMeAFont( face, nHeight, bold ? FW_BOLD : FW_NORMAL, italic, fFontAntiAliasRGB ? ANTIALIASED_QUALITY : DEFAULT_QUALITY ); } if( fFont == nil ) { hsAssert( false, "Cannot create Windows font for plDynSurfaceWriter" ); plStatusLog::AddLineS( "pipeline.log", "ERROR: Cannot allocate font for RGB surface! (face: %s, size: %d %s %s)", face.c_str(), nHeight, bold ? "bold" : "", italic ? "italic" : "" ); fFontFace = plString::Null; fFontSize = 0; return; } if( SelectObject( fDC, fFont ) == nil && hadAFont ) { char msg[ 256 ]; FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nil, GetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), msg, sizeof( msg ), nil ); char *ret = strrchr( msg, '\n' ); if( ret != nil ) *ret = 0; plStatusLog::AddLineS( "pipeline.log", 0xffff0000, "SelectObject() FAILED (%s)", msg ); } }
INT_PTR CALLBACK DlgProcOptsConnections(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA); CMStringW szBuff; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hWndDlg); SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam); ppro = (CMraProto*)lParam; if (ppro->mraGetStringW(NULL, "Server", szBuff)) SetDlgItemText(hWndDlg, IDC_SERVER, szBuff.c_str()); else SetDlgItemTextA(hWndDlg, IDC_SERVER, MRA_DEFAULT_SERVER); SetDlgItemInt(hWndDlg, IDC_SERVERPORT, ppro->getWord("ServerPort", MRA_DEFAULT_SERVER_PORT), FALSE); // if set SSL proxy, setting will ignored //CheckDlgButton(hWndDlg, IDC_KEEPALIVE, getByte("keepalive", 0)); CheckDlgButton(hWndDlg, IDC_AUTO_ADD_CONTACTS_TO_SERVER, ppro->getByte("AutoAddContactsToServer", MRA_DEFAULT_AUTO_ADD_CONTACTS_TO_SERVER)); CheckDlgButton(hWndDlg, IDC_AUTO_AUTH_REQ_ON_LOGON, ppro->getByte("AutoAuthRequestOnLogon", MRA_DEFAULT_AUTO_AUTH_REQ_ON_LOGON)); CheckDlgButton(hWndDlg, IDC_AUTO_AUTH_GRAND_IN_CLIST, ppro->getByte("AutoAuthGrandUsersInCList", MRA_DEFAULT_AUTO_AUTH_GRAND_IN_CLIST)); CheckDlgButton(hWndDlg, IDC_AUTO_AUTH_GRAND_NEW_USERS, ppro->getByte("AutoAuthGrandNewUsers", MRA_DEFAULT_AUTO_AUTH_GRAND_NEW_USERS)); CheckDlgButton(hWndDlg, IDC_SLOWSEND, ppro->getByte("SlowSend", MRA_DEFAULT_SLOW_SEND)); CheckDlgButton(hWndDlg, IDC_INCREMENTAL_NEW_MAIL_NOTIFY, ppro->getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY)); CheckDlgButton(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY, ppro->getByte("TrayIconNewMailNotify", MRA_DEFAULT_TRAYICON_NEW_MAIL_NOTIFY)); CheckDlgButton(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX, ppro->getByte("TrayIconNewMailClkToInbox", MRA_DEFAULT_TRAYICON_NEW_MAIL_CLK_TO_INBOX)); EnableWindow(GetDlgItem(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX), ppro->getByte("TrayIconNewMailNotify", MRA_DEFAULT_TRAYICON_NEW_MAIL_NOTIFY)); CheckDlgButton(hWndDlg, IDC_RTF_RECEIVE_ENABLE, ppro->getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE)); CheckDlgButton(hWndDlg, IDC_RTF_SEND_ENABLE, ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE)); EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_SEND_SMART), ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE)); EnableWindow(GetDlgItem(hWndDlg, IDC_BUTTON_FONT), ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE)); EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_BGCOLOUR), ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE)); SendDlgItemMessage(hWndDlg, IDC_RTF_BGCOLOUR, CPM_SETCOLOUR, 0, ppro->getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR)); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BUTTON_DEFAULT: SetDlgItemTextA(hWndDlg, IDC_SERVER, MRA_DEFAULT_SERVER); SetDlgItemInt(hWndDlg, IDC_SERVERPORT, MRA_DEFAULT_SERVER_PORT, FALSE); break; case IDC_TRAYICON_NEW_MAIL_NOTIFY: EnableWindow(GetDlgItem(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX), IsDlgButtonChecked(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY)); break; case IDC_RTF_SEND_ENABLE: EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_SEND_SMART), IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE)); EnableWindow(GetDlgItem(hWndDlg, IDC_BUTTON_FONT), IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE)); EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_BGCOLOUR), IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE)); break; case IDC_BUTTON_FONT: LOGFONT lf = { 0 }; CHOOSEFONT cf = { 0 }; cf.lStructSize = sizeof(cf); cf.lpLogFont = &lf; cf.rgbColors = ppro->getDword("RTFFontColour", MRA_DEFAULT_RTF_FONT_COLOUR); cf.Flags = (CF_SCREENFONTS | CF_EFFECTS | CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT); if (ppro->mraGetContactSettingBlob(NULL, "RTFFont", &lf, sizeof(LOGFONT), NULL) == FALSE) { HDC hDC = GetDC(NULL);// kegl lf.lfCharSet = MRA_DEFAULT_RTF_FONT_CHARSET; lf.lfHeight = -MulDiv(MRA_DEFAULT_RTF_FONT_SIZE, GetDeviceCaps(hDC, LOGPIXELSY), 72); lstrcpyn(lf.lfFaceName, MRA_DEFAULT_RTF_FONT_NAME, LF_FACESIZE); ReleaseDC(NULL, hDC); } if (ChooseFont(&cf)) { ppro->mraWriteContactSettingBlob(NULL, "RTFFont", &lf, sizeof(LOGFONT)); ppro->setDword("RTFFontColour", cf.rgbColors); } break; } if ((LOWORD(wParam) == IDC_SERVER || LOWORD(wParam) == IDC_SERVERPORT) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return FALSE; SendMessage(GetParent(hWndDlg), PSM_CHANGED, 0, 0); break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: TCHAR szBuff[MAX_PATH]; GetDlgItemText(hWndDlg, IDC_SERVER, szBuff, SIZEOF(szBuff)); ppro->mraSetStringW(NULL, "Server", szBuff); ppro->setWord("ServerPort", (WORD)GetDlgItemInt(hWndDlg, IDC_SERVERPORT, NULL, FALSE)); ppro->setByte("AutoAddContactsToServer", IsDlgButtonChecked(hWndDlg, IDC_AUTO_ADD_CONTACTS_TO_SERVER)); ppro->setByte("AutoAuthRequestOnLogon", IsDlgButtonChecked(hWndDlg, IDC_AUTO_AUTH_REQ_ON_LOGON)); ppro->setByte("AutoAuthGrandUsersInCList", IsDlgButtonChecked(hWndDlg, IDC_AUTO_AUTH_GRAND_IN_CLIST)); ppro->setByte("AutoAuthGrandNewUsers", IsDlgButtonChecked(hWndDlg, IDC_AUTO_AUTH_GRAND_NEW_USERS)); ppro->setByte("SlowSend", IsDlgButtonChecked(hWndDlg, IDC_SLOWSEND)); ppro->setByte("IncrementalNewMailNotify", IsDlgButtonChecked(hWndDlg, IDC_INCREMENTAL_NEW_MAIL_NOTIFY)); ppro->setByte("TrayIconNewMailNotify", IsDlgButtonChecked(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY)); ppro->setByte("TrayIconNewMailClkToInbox", IsDlgButtonChecked(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX)); ppro->setByte("RTFReceiveEnable", IsDlgButtonChecked(hWndDlg, IDC_RTF_RECEIVE_ENABLE)); ppro->setByte("RTFSendEnable", IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE)); ppro->setDword("RTFBackgroundColour", SendDlgItemMessage(hWndDlg, IDC_RTF_BGCOLOUR, CPM_GETCOLOUR, 0, 0)); return TRUE; } break; } return FALSE; }
//VC下把HBITMAP保存为bmp图片 BOOL SaveBmp(HBITMAP hBitmap, CString FileName) { HDC hDC; //当前分辨率下每象素所占字节数 int iBits; //位图中每象素所占字节数 WORD wBitCount; //定义调色板大小, 位图中像素字节大小 ,位图文件大小 , 写入文件字节数 DWORD dwPaletteSize = 0, dwBmBitsSize = 0, dwDIBSize = 0, dwWritten = 0; //位图属性结构 BITMAP Bitmap; //位图文件头结构 BITMAPFILEHEADER bmfHdr; //位图信息头结构 BITMAPINFOHEADER bi; //指向位图信息头结构 LPBITMAPINFOHEADER lpbi; //定义文件,分配内存句柄,调色板句柄 HANDLE fh, hDib, hPal, hOldPal = NULL; //计算位图文件每个像素所占字节数 hDC = CreateDC(L"DISPLAY", NULL, NULL, NULL); iBits = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES); DeleteDC(hDC); if (iBits <= 1) wBitCount = 1; else if (iBits <= 4) wBitCount = 4; else if (iBits <= 8) wBitCount = 8; else wBitCount = 24; GetObject(hBitmap, sizeof(Bitmap), (LPSTR)&Bitmap); bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = Bitmap.bmWidth; bi.biHeight = Bitmap.bmHeight; bi.biPlanes = 1; bi.biBitCount = wBitCount; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrImportant = 0; bi.biClrUsed = 0; dwBmBitsSize = ((Bitmap.bmWidth *wBitCount + 31) / 32) * 4 * Bitmap.bmHeight; //为位图内容分配内存 hDib = GlobalAlloc(GHND, dwBmBitsSize + dwPaletteSize + sizeof(BITMAPINFOHEADER)); lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib); *lpbi = bi; // 处理调色板 hPal = GetStockObject(DEFAULT_PALETTE); if (hPal) { hDC = ::GetDC(NULL); hOldPal = ::SelectPalette(hDC, (HPALETTE)hPal, FALSE); RealizePalette(hDC); } // 获取该调色板下新的像素值 GetDIBits(hDC, hBitmap, 0, (UINT)Bitmap.bmHeight, (LPSTR)lpbi + sizeof(BITMAPINFOHEADER) + dwPaletteSize, (BITMAPINFO *)lpbi, DIB_RGB_COLORS); //恢复调色板 if (hOldPal) { ::SelectPalette(hDC, (HPALETTE)hOldPal, TRUE); RealizePalette(hDC); ::ReleaseDC(NULL, hDC); } //创建位图文件 fh = CreateFile(FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (fh == INVALID_HANDLE_VALUE) return FALSE; // 设置位图文件头 bmfHdr.bfType = 0x4D42; // "BM" dwDIBSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwPaletteSize + dwBmBitsSize; bmfHdr.bfSize = dwDIBSize; bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + dwPaletteSize; // 写入位图文件头 WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL); // 写入位图文件其余内容 WriteFile(fh, (LPSTR)lpbi, dwDIBSize, &dwWritten, NULL); //清除 GlobalUnlock(hDib); GlobalFree(hDib); CloseHandle(fh); return TRUE; }
int GetFontSettingFromDB(char *settings_group, char *prefix, LOGFONT* lf, COLORREF * colour, DWORD flags) { DBVARIANT dbv; char idstr[256]; BYTE style; int retval = 0; GetDefaultFontSetting(lf, colour); if (flags & FIDF_APPENDNAME) mir_snprintf(idstr, SIZEOF(idstr), "%sName", prefix); else mir_snprintf(idstr, SIZEOF(idstr), "%s", prefix); if (!db_get_ts(NULL, settings_group, idstr, &dbv)) { _tcscpy(lf->lfFaceName, dbv.ptszVal); db_free(&dbv); } else retval = 1; if (colour) { mir_snprintf(idstr, SIZEOF(idstr), "%sCol", prefix); *colour = db_get_dw(NULL, settings_group, idstr, *colour); } mir_snprintf(idstr, SIZEOF(idstr), "%sSize", prefix); lf->lfHeight = (char)db_get_b(NULL, settings_group, idstr, lf->lfHeight); //wsprintf(idstr, "%sFlags", prefix); //if (db_get_dw(NULL, settings_group, idstr, 0) & FIDF_SAVEACTUALHEIGHT) { // HDC hdc = GetDC(0); // lf->lfHeight = -lf->lfHeight; // ReleaseDC(0, hdc); //} mir_snprintf(idstr, SIZEOF(idstr), "%sSty", prefix); style = (BYTE) db_get_b(NULL, settings_group, idstr, (lf->lfWeight == FW_NORMAL ? 0 : DBFONTF_BOLD) | (lf->lfItalic ? DBFONTF_ITALIC : 0) | (lf->lfUnderline ? DBFONTF_UNDERLINE : 0) | lf->lfStrikeOut ? DBFONTF_STRIKEOUT : 0); lf->lfWidth = lf->lfEscapement = lf->lfOrientation = 0; lf->lfWeight = style & DBFONTF_BOLD ? FW_BOLD : FW_NORMAL; lf->lfItalic = (style & DBFONTF_ITALIC) != 0; lf->lfUnderline = (style & DBFONTF_UNDERLINE) != 0; lf->lfStrikeOut = (style & DBFONTF_STRIKEOUT) != 0; mir_snprintf(idstr, SIZEOF(idstr), "%sSet", prefix); lf->lfCharSet = db_get_b(NULL, settings_group, idstr, lf->lfCharSet); lf->lfOutPrecision = OUT_DEFAULT_PRECIS; lf->lfClipPrecision = CLIP_DEFAULT_PRECIS; lf->lfQuality = DEFAULT_QUALITY; lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; if (lf->lfHeight > 0) { HDC hdc = GetDC(0); if (flags & FIDF_SAVEPOINTSIZE) { lf->lfHeight = -MulDiv(lf->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72); } else { // assume SAVEACTUALHEIGHT TEXTMETRIC tm; HFONT hFont = CreateFontIndirect(lf); HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); GetTextMetrics(hdc, &tm); lf->lfHeight = -(lf->lfHeight - tm.tmInternalLeading); SelectObject(hdc, hOldFont); DeleteObject(hFont); } //lf->lfHeight = -MulDiv(lf->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72); ReleaseDC(0, hdc); } return retval; }
/* ** Sys_CreateConsole */ void Sys_CreateConsole( void ) { HDC hDC; WNDCLASS wc; RECT rect; const char *DEDCLASS = WIN32_CONSOLE_CLASS; int nHeight; int swidth, sheight; int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX; int i; memset( &wc, 0, sizeof( wc ) ); wc.style = 0; wc.lpfnWndProc = (WNDPROC) ConWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = win32.hInstance; wc.hIcon = LoadIcon( win32.hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor (NULL,IDC_ARROW); wc.hbrBackground = (struct HBRUSH__ *)COLOR_WINDOW; wc.lpszMenuName = 0; wc.lpszClassName = DEDCLASS; if ( !RegisterClass (&wc) ) { return; } rect.left = 0; rect.right = 540; rect.top = 0; rect.bottom = 450; AdjustWindowRect( &rect, DEDSTYLE, FALSE ); hDC = GetDC( GetDesktopWindow() ); swidth = GetDeviceCaps( hDC, HORZRES ); sheight = GetDeviceCaps( hDC, VERTRES ); ReleaseDC( GetDesktopWindow(), hDC ); s_wcd.windowWidth = rect.right - rect.left + 1; s_wcd.windowHeight = rect.bottom - rect.top + 1; //s_wcd.hbmLogo = LoadBitmap( win32.hInstance, MAKEINTRESOURCE( IDB_BITMAP_LOGO) ); s_wcd.hWnd = CreateWindowEx( 0, DEDCLASS, GAME_NAME, DEDSTYLE, ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1, NULL, NULL, win32.hInstance, NULL ); if ( s_wcd.hWnd == NULL ) { return; } // // create fonts // hDC = GetDC( s_wcd.hWnd ); nHeight = -MulDiv( 8, GetDeviceCaps( hDC, LOGPIXELSY ), 72 ); s_wcd.hfBufferFont = CreateFont( nHeight, 0, 0, 0, FW_LIGHT, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN | FIXED_PITCH, "Courier New" ); ReleaseDC( s_wcd.hWnd, hDC ); // // create the input line // s_wcd.hwndInputLine = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL, 6, 400, 528, 20, s_wcd.hWnd, ( HMENU ) INPUT_ID, // child window ID win32.hInstance, NULL ); // // create the buttons // s_wcd.hwndButtonCopy = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 5, 425, 72, 24, s_wcd.hWnd, ( HMENU ) COPY_ID, // child window ID win32.hInstance, NULL ); SendMessage( s_wcd.hwndButtonCopy, WM_SETTEXT, 0, ( LPARAM ) "copy" ); s_wcd.hwndButtonClear = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 82, 425, 72, 24, s_wcd.hWnd, ( HMENU ) CLEAR_ID, // child window ID win32.hInstance, NULL ); SendMessage( s_wcd.hwndButtonClear, WM_SETTEXT, 0, ( LPARAM ) "clear" ); s_wcd.hwndButtonQuit = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 462, 425, 72, 24, s_wcd.hWnd, ( HMENU ) QUIT_ID, // child window ID win32.hInstance, NULL ); SendMessage( s_wcd.hwndButtonQuit, WM_SETTEXT, 0, ( LPARAM ) "quit" ); // // create the scrollbuffer // s_wcd.hwndBuffer = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY, 6, 40, 526, 354, s_wcd.hWnd, ( HMENU ) EDIT_ID, // child window ID win32.hInstance, NULL ); SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 ); s_wcd.SysInputLineWndProc = ( LONG_PTR ) SetWindowLongPtr( s_wcd.hwndInputLine, GWLP_WNDPROC, ( LONG_PTR ) InputLineWndProc ); SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 ); // don't show it now that we have a splash screen up if ( win32.win_viewlog.GetBool() ) { ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT); UpdateWindow( s_wcd.hWnd ); SetForegroundWindow( s_wcd.hWnd ); SetFocus( s_wcd.hwndInputLine ); } s_wcd.consoleField.Clear(); for ( i = 0 ; i < COMMAND_HISTORY ; i++ ) { s_wcd.historyEditLines[i].Clear(); } }
/* * A call to this function should initialize all the display stuff... */ static void fghInitialize( const char* displayName ) { #if TARGET_HOST_POSIX_X11 fgDisplay.Display = XOpenDisplay( displayName ); if( fgDisplay.Display == NULL ) fgError( "failed to open display '%s'", XDisplayName( displayName ) ); if( !glXQueryExtension( fgDisplay.Display, NULL, NULL ) ) fgError( "OpenGL GLX extension not supported by display '%s'", XDisplayName( displayName ) ); fgDisplay.Screen = DefaultScreen( fgDisplay.Display ); fgDisplay.RootWindow = RootWindow( fgDisplay.Display, fgDisplay.Screen ); fgDisplay.ScreenWidth = DisplayWidth( fgDisplay.Display, fgDisplay.Screen ); fgDisplay.ScreenHeight = DisplayHeight( fgDisplay.Display, fgDisplay.Screen ); fgDisplay.ScreenWidthMM = DisplayWidthMM( fgDisplay.Display, fgDisplay.Screen ); fgDisplay.ScreenHeightMM = DisplayHeightMM( fgDisplay.Display, fgDisplay.Screen ); fgDisplay.Connection = ConnectionNumber( fgDisplay.Display ); /* Create the window deletion atom */ fgDisplay.DeleteWindow = fghGetAtom("WM_DELETE_WINDOW"); /* Create the state and full screen atoms */ fgDisplay.State = None; fgDisplay.StateFullScreen = None; if (fghNetWMSupported()) { const Atom supported = fghGetAtom("_NET_SUPPORTED"); const Atom state = fghGetAtom("_NET_WM_STATE"); /* Check if the state hint is supported. */ if (fgHintPresent(fgDisplay.RootWindow, supported, state)) { const Atom full_screen = fghGetAtom("_NET_WM_STATE_FULLSCREEN"); fgDisplay.State = state; /* Check if the window manager supports full screen. */ /** Check "_NET_WM_ALLOWED_ACTIONS" on our window instead? **/ if (fgHintPresent(fgDisplay.RootWindow, supported, full_screen)) { fgDisplay.StateFullScreen = full_screen; } } } #elif TARGET_HOST_MS_WINDOWS WNDCLASS wc; ATOM atom; /* What we need to do is to initialize the fgDisplay global structure here. */ fgDisplay.Instance = GetModuleHandle( NULL ); fgDisplay.DisplayName= displayName ? strdup(displayName) : 0 ; atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc ); if( atom == 0 ) { ZeroMemory( &wc, sizeof(WNDCLASS) ); /* * Each of the windows should have its own device context, and we * want redraw events during Vertical and Horizontal Resizes by * the user. * * XXX Old code had "| CS_DBCLCKS" commented out. Plans for the * XXX future? Dead-end idea? */ wc.lpfnWndProc = fgWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = fgDisplay.Instance; wc.hIcon = LoadIcon( fgDisplay.Instance, _T("GLUT_ICON") ); #if defined(_WIN32_WCE) wc.style = CS_HREDRAW | CS_VREDRAW; #else wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; if (!wc.hIcon) wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); #endif wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = _T("FREEGLUT"); /* Register the window class */ atom = RegisterClass( &wc ); FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Not Registered", "fghInitialize" ); } /* The screen dimensions can be obtained via GetSystemMetrics() calls */ fgDisplay.ScreenWidth = GetSystemMetrics( SM_CXSCREEN ); fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); { HWND desktop = GetDesktopWindow( ); HDC context = GetDC( desktop ); fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE ); fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE ); ReleaseDC( desktop, context ); } /* If we have a DisplayName try to use it for metrics */ if( fgDisplay.DisplayName ) { HDC context = CreateDC(fgDisplay.DisplayName,0,0,0); if( context ) { fgDisplay.ScreenWidth = GetDeviceCaps( context, HORZRES ); fgDisplay.ScreenHeight = GetDeviceCaps( context, VERTRES ); fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE ); fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE ); DeleteDC(context); } else fgWarning("fghInitialize: " "CreateDC failed, Screen size info may be incorrect\n" "This is quite likely caused by a bad '-display' parameter"); } /* Set the timer granularity to 1 ms */ timeBeginPeriod ( 1 ); #endif fgState.Initialised = GL_TRUE; /* Avoid registering atexit callback on Win32 as it results in an access * violation due to calling into a module which has been unloaded. */ #if ( TARGET_HOST_MS_WINDOWS == 0 ) atexit(fgDeinitialize); #endif /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */ fgInitialiseInputDevices(); }
void *PackDialogU( DWORD style, DWORD exstyle, int x, int y, int cx, int cy, WCHAR const *titlestr, int titleid, LOGFONTW *fnt, int itemcount, struct DLG_Item *items ) { size_t dmenu_size; size_t dclass_size; size_t dtitle_size; size_t dfont_size; int title_id_len; size_t title_str_len; size_t title_space_len; WCHAR *titlespace=L" - "; WCHAR *dmenu; WCHAR *dclass; WCHAR *dtitle; WCHAR *dfont; size_t dlg_size; size_t items_size; DLGTEMPLATEEX *dlg; DLGTEMPLATEEXFONT *dfparam; size_t item_offset; char *buf; int i; /* Get size of strings */ dmenu_size=sizeof(WCHAR); dclass_size=sizeof(WCHAR); /* Calculate size of title */ dtitle_size=1; title_id_len=LoadStringU(NULL, titleid, NULL, 0, 0); dtitle_size+=title_id_len; title_str_len= titlestr ? lstrlenW(titlestr) : 0; dtitle_size+=title_str_len; title_space_len=lstrlenW(titlespace); if(title_id_len>0 && title_str_len>0) dtitle_size+=title_space_len; dtitle_size*=sizeof(WCHAR); /* Get size of face name string, if font present */ if(fnt!=NULL) dfont_size=StringBytesU(fnt->lfFaceName); else dfont_size=0; /* Calculate size of template */ dlg_size=sizeof(*dlg)+dmenu_size+dclass_size+dtitle_size; /* Add font parameters size, if present */ if(dfont_size!=0) dlg_size+=sizeof(DLGTEMPLATEEXFONT)+dfont_size; /* Adjust to DWORD boundary */ dlg_size=AdjustToDWORD(dlg_size); /* Calculate dialog items size */ items_size=0; for(i=0; i<itemcount; i++) items_size+=DlgMeasureItemU(items+i); /* Allocate buffer for template */ buf=malloc(dlg_size+items_size+sizeof(DWORD)); if(buf==NULL) return NULL; /* Set pointers in buffer */ dlg=(DLGTEMPLATEEX *)AdjustToDWORD((size_t)buf); dmenu=(WCHAR *)((char *)(dlg)+sizeof(DLGTEMPLATEEX)); dclass=(WCHAR *)((char *)(dmenu)+dmenu_size); dtitle=(WCHAR *)((char *)(dclass)+dclass_size); /* Fill template with data */ dlg->dlgVer=1; dlg->signature=0xFFFF; dlg->helpID=0; dlg->exStyle=exstyle; dlg->style=style; dlg->cDlgItems=itemcount; dlg->x=x; dlg->y=y; dlg->cx=cx; dlg->cy=cy; *dmenu=0; *dclass=0; if(title_str_len>0) { strcpyU(dtitle, titlestr); if(title_str_len>0 && title_id_len>0) { strcpyU(dtitle+title_str_len, titlespace); title_str_len+=title_space_len; } } ResLoadStringU(titleid, dtitle+title_str_len, title_id_len+1); /* Set font parameters */ if(fnt!=NULL) { HDC dc; int pointsize; dc=GetDC(NULL); pointsize=-MulDiv(fnt->lfHeight, 72, GetDeviceCaps(dc, LOGPIXELSY)); ReleaseDC(NULL, dc); dlg->style|=DS_SETFONT; dfparam=(DLGTEMPLATEEXFONT *)((char *)(dtitle)+dtitle_size); dfont=(WCHAR *)((char *)(dfparam)+sizeof(*dfparam)); dfparam->pointsize=pointsize; dfparam->weight=(WORD)fnt->lfWeight; dfparam->bItalic=fnt->lfItalic; dfparam->charset=fnt->lfCharSet; StringCopyU(dfont, fnt->lfFaceName); } else dlg->style&=~DS_SETFONT; /* Fill items data */ item_offset=dlg_size; for(i=0; i<itemcount; i++) { item_offset+=DlgPackItemU((char *)(dlg)+item_offset, items+i); if(items[i].Control->PreInit!=NULL) items[i].Control->PreInit(); } return buf; }
void DoMain (HINSTANCE hInstance) { LONG WinWidth, WinHeight; int height, width, x, y; RECT cRect; TIMECAPS tc; DEVMODE displaysettings; try { #ifdef _MSC_VER _set_new_handler (NewFailure); #endif Args = new FArgs(__argc, __argv); // Load Win32 modules Kernel32Module.Load({"kernel32.dll"}); Shell32Module.Load({"shell32.dll"}); User32Module.Load({"user32.dll"}); // Under XP, get our session ID so we can know when the user changes/locks sessions. // Since we need to remain binary compatible with older versions of Windows, we // need to extract the ProcessIdToSessionId function from kernel32.dll manually. HMODULE kernel = GetModuleHandle ("kernel32.dll"); if (Args->CheckParm("-stdout")) { // As a GUI application, we don't normally get a console when we start. // If we were run from the shell and are on XP+, we can attach to its // console. Otherwise, we can create a new one. If we already have a // stdout handle, then we have been redirected and should just use that // handle instead of creating a console window. StdOut = GetStdHandle(STD_OUTPUT_HANDLE); if (StdOut != NULL) { // It seems that running from a shell always creates a std output // for us, even if it doesn't go anywhere. (Running from Explorer // does not.) If we can get file information for this handle, it's // a file or pipe, so use it. Otherwise, pretend it wasn't there // and find a console to use instead. BY_HANDLE_FILE_INFORMATION info; if (!GetFileInformationByHandle(StdOut, &info)) { StdOut = NULL; } } if (StdOut == NULL) { // AttachConsole was introduced with Windows XP. (OTOH, since we // have to share the console with the shell, I'm not sure if it's // a good idea to actually attach to it.) typedef BOOL (WINAPI *ac)(DWORD); ac attach_console = kernel != NULL ? (ac)GetProcAddress(kernel, "AttachConsole") : NULL; if (attach_console != NULL && attach_console(ATTACH_PARENT_PROCESS)) { StdOut = GetStdHandle(STD_OUTPUT_HANDLE); DWORD foo; WriteFile(StdOut, "\n", 1, &foo, NULL); AttachedStdOut = true; } if (StdOut == NULL && AllocConsole()) { StdOut = GetStdHandle(STD_OUTPUT_HANDLE); } FancyStdOut = true; } } // Set the timer to be as accurate as possible if (timeGetDevCaps (&tc, sizeof(tc)) != TIMERR_NOERROR) TimerPeriod = 1; // Assume minimum resolution of 1 ms else TimerPeriod = tc.wPeriodMin; timeBeginPeriod (TimerPeriod); /* killough 1/98: This fixes some problems with exit handling during abnormal situations. The old code called I_Quit() to end program, while now I_Quit() is installed as an exit handler and exit() is called to exit, either normally or abnormally. */ atexit (call_terms); atterm (I_Quit); // Figure out what directory the program resides in. char *program; #ifdef _MSC_VER if (_get_pgmptr(&program) != 0) { I_FatalError("Could not determine program location."); } #else char progbuff[1024]; GetModuleFileName(0, progbuff, sizeof(progbuff)); progbuff[1023] = '\0'; program = progbuff; #endif progdir = program; program = progdir.LockBuffer(); *(strrchr(program, '\\') + 1) = '\0'; FixPathSeperator(program); progdir.Truncate((long)strlen(program)); progdir.UnlockBuffer(); HDC screenDC = GetDC(0); int dpi = GetDeviceCaps(screenDC, LOGPIXELSX); ReleaseDC(0, screenDC); width = (512 * dpi + 96 / 2) / 96; height = (384 * dpi + 96 / 2) / 96; // Many Windows structures that specify their size do so with the first // element. DEVMODE is not one of those structures. memset (&displaysettings, 0, sizeof(displaysettings)); displaysettings.dmSize = sizeof(displaysettings); EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &displaysettings); x = (displaysettings.dmPelsWidth - width) / 2; y = (displaysettings.dmPelsHeight - height) / 2; if (Args->CheckParm ("-0")) { x = y = 0; } WNDCLASS WndClass; WndClass.style = 0; WndClass.lpfnWndProc = LConProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = hInstance; WndClass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)); WndClass.hCursor = LoadCursor (NULL, IDC_ARROW); WndClass.hbrBackground = NULL; WndClass.lpszMenuName = NULL; WndClass.lpszClassName = (LPCTSTR)WinClassName; /* register this new class with Windows */ if (!RegisterClass((LPWNDCLASS)&WndClass)) I_FatalError ("Could not register window class"); /* create window */ char caption[100]; mysnprintf(caption, countof(caption), "" GAMESIG " %s " X64 " (%s)", GetVersionString(), GetGitTime()); Window = CreateWindowEx( WS_EX_APPWINDOW, (LPCTSTR)WinClassName, (LPCTSTR)caption, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN, x, y, width, height, (HWND) NULL, (HMENU) NULL, hInstance, NULL); if (!Window) I_FatalError ("Could not open window"); if (kernel != NULL) { typedef BOOL (WINAPI *pts)(DWORD, DWORD *); pts pidsid = (pts)GetProcAddress (kernel, "ProcessIdToSessionId"); if (pidsid != 0) { if (!pidsid (GetCurrentProcessId(), &SessionID)) { SessionID = 0; } hwtsapi32 = LoadLibraryA ("wtsapi32.dll"); if (hwtsapi32 != 0) { FARPROC reg = GetProcAddress (hwtsapi32, "WTSRegisterSessionNotification"); if (reg == 0 || !((BOOL(WINAPI *)(HWND, DWORD))reg) (Window, NOTIFY_FOR_THIS_SESSION)) { FreeLibrary (hwtsapi32); hwtsapi32 = 0; } else { atterm (UnWTS); } } } } GetClientRect (Window, &cRect); WinWidth = cRect.right; WinHeight = cRect.bottom; CoInitialize (NULL); atterm (UnCOM); C_InitConsole (((WinWidth / 8) + 2) * 8, (WinHeight / 12) * 8, false); I_DetectOS (); D_DoomMain (); } catch (class CNoRunExit &) { I_ShutdownGraphics(); if (!batchrun) { if (FancyStdOut && !AttachedStdOut) { // Outputting to a new console window: Wait for a keypress before quitting. DWORD bytes; HANDLE stdinput = GetStdHandle(STD_INPUT_HANDLE); ShowWindow(Window, SW_HIDE); WriteFile(StdOut, "Press any key to exit...", 24, &bytes, NULL); FlushConsoleInputBuffer(stdinput); SetConsoleMode(stdinput, 0); ReadConsole(stdinput, &bytes, 1, &bytes, NULL); } else if (StdOut == NULL) { ShowErrorPane(NULL); } } exit(0); } catch (class CDoomError &error) { I_ShutdownGraphics (); RestoreConView (); S_StopMusic(true); I_FlushBufferedConsoleStuff(); if (error.GetMessage ()) { if (!batchrun) { ShowErrorPane(error.GetMessage()); } else { Printf("%s\n", error.GetMessage()); } } exit (-1); } }
int GPrintDC::GetBits() { return GetDeviceCaps(hDC, BITSPIXEL); }
void __fastcall TfrmMain::GetMinMaxInfo(TWMGetMinMaxInfo &Msg) { Msg.MinMaxInfo->ptMaxTrackSize.x = GetDeviceCaps(Canvas->Handle, HORZRES) + (Width - ClientWidth); Msg.MinMaxInfo->ptMaxTrackSize.y = GetDeviceCaps(Canvas->Handle, VERTRES) + (Height - ClientHeight); }
int GPrintDC::DpiY() { return GetDeviceCaps(hDC, LOGPIXELSY); }
static int config(uint32_t width, uint32_t height, uint32_t d_width,uint32_t d_height, uint32_t flags, char *title, uint32_t format){ title = "MPlayer VIDIX WIN32 Overlay"; panscan_init(); image_height = height; image_width = width; image_format = format; vo_screenwidth = GetSystemMetrics(SM_CXSCREEN); vo_screenheight = GetSystemMetrics(SM_CYSCREEN); vo_depthonscreen = GetDeviceCaps(GetDC(GetDesktopWindow()),BITSPIXEL); aspect_save_orig(width, height); aspect_save_prescale(d_width, d_height); aspect_save_screenres(vo_screenwidth, vo_screenheight); vo_dx = 0; vo_dy = 0; vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2; geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); vo_fs = flags&VOFLAG_FULLSCREEN; aspect(&d_width, &d_height, A_NOZOOM); vo_dwidth=d_width; vo_dheight=d_height; window_aspect = (float)d_width / (float)d_height; if(!vo_config_count){ HINSTANCE hInstance = GetModuleHandle(NULL); WNDCLASS wc; RECT rd; rd.left = vo_dx; rd.top = vo_dy; rd.right = rd.left + vo_dwidth; rd.bottom = rd.top + vo_dheight; AdjustWindowRect(&rd,WS_OVERLAPPEDWINDOW| WS_SIZEBOX,0); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hIcon =ExtractIcon(hInstance,"mplayer.exe",0); //LoadIcon(NULL,IDI_APPLICATION); wc.hbrBackground = CreateSolidBrush(RGB(255,0,255)); wc.lpszClassName = "MPlayer - The Movie Player"; wc.lpszMenuName = NULL; RegisterClass(&wc); hWnd = CreateWindow("MPlayer - The Movie Player", title, WS_OVERLAPPEDWINDOW| WS_SIZEBOX, rd.left, rd.top, rd.right - rd.left, rd.bottom - rd.top, NULL, NULL, hInstance, NULL); wc.hbrBackground = CreateSolidBrush(RGB(0,0,0)); wc.lpszClassName = "MPlayer - Fullscreen"; RegisterClass(&wc); hWndFS = CreateWindow("MPlayer - Fullscreen","MPlayer VIDIX Fullscreen",WS_POPUP,0,0,vo_screenwidth,vo_screenheight,hWnd,NULL,hInstance,NULL); } ShowWindow(hWnd,SW_SHOW); if(vo_fs)ShowWindow(hWndFS,SW_SHOW); return(0); }
int GPrintDC::X() { return GetDeviceCaps(hDC, HORZRES); }
void screen_get(char* filename) { // This function only works for 24-bit (truecolor) display mode // prepare DCs, bitmaps,.. HDC hScreenDC = GetWindowDC(0); HDC hmemDC = CreateCompatibleDC(hScreenDC); int ScreenWidth = GetDeviceCaps(hScreenDC, HORZRES); int ScreenHeight = GetDeviceCaps(hScreenDC, VERTRES); HBITMAP hmemBM = CreateCompatibleBitmap(hScreenDC, ScreenWidth, ScreenHeight); SelectObject(hmemDC, hmemBM); // copy screen to memory DC BitBlt(hmemDC, 0, 0, ScreenWidth, ScreenHeight, hScreenDC, 0, 0, SRCCOPY); // allocate and lock memory for the bitmap data HGLOBAL hpxldata = GlobalAlloc(GMEM_FIXED, ScreenWidth * ScreenHeight * 3); void FAR* lpvpxldata = GlobalLock(hpxldata); // fill .bmp - structures BITMAPINFO bmInfo; bmInfo.bmiHeader.biSize = 40; bmInfo.bmiHeader.biWidth = ScreenWidth; bmInfo.bmiHeader.biHeight = ScreenHeight; bmInfo.bmiHeader.biPlanes = 1; bmInfo.bmiHeader.biBitCount = 24; bmInfo.bmiHeader.biCompression = 0; bmInfo.bmiHeader.biSizeImage = 0; bmInfo.bmiHeader.biXPelsPerMeter = 0; bmInfo.bmiHeader.biYPelsPerMeter = 0; bmInfo.bmiHeader.biClrUsed = 0; bmInfo.bmiHeader.biClrImportant = 0; BITMAPFILEHEADER bmFileHeader; bmFileHeader.bfType = 19778; bmFileHeader.bfSize = (ScreenWidth * ScreenHeight * 3) + 40 + 14; bmFileHeader.bfReserved1 = 0; bmFileHeader.bfReserved2 = 0; bmFileHeader.bfOffBits = 54; // copy bitmap data into global memory GetDIBits(hmemDC, hmemBM, 0, ScreenHeight, lpvpxldata, &bmInfo,DIB_RGB_COLORS); // SetDIBits(hmemDC, hmemBM, 0, ScreenHeight, lpvpxldata, &bmInfo,DIB_RGB_COLORS); SetDIBitsToDevice(hmemDC, 0, 0, ScreenWidth, ScreenHeight, 0, 0, 0,ScreenHeight, lpvpxldata, &bmInfo, DIB_RGB_COLORS); // StretchDIBits(hmemDC, 0, 0, ScreenWidth, ScreenHeight, 0, 0,ScreenWidth, ScreenHeight, lpvpxldata, &bmInfo, DIB_RGB_COLORS,SRCCOPY); // open file and write data int bmfile = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,S_IWRITE); write(bmfile, &bmFileHeader, 14); write(bmfile, &bmInfo, 40); write(bmfile, lpvpxldata, ScreenWidth * ScreenHeight * 3); // clean up close(bmfile); GlobalUnlock(hpxldata); GlobalFree(hpxldata); DeleteObject(hmemBM); DeleteDC(hmemDC); ReleaseDC(0, hScreenDC); }
int GPrintDC::Y() { return GetDeviceCaps(hDC, VERTRES); }
int fb_PrinterOpen( DEV_LPT_INFO *devInfo, int iPort, const char *pszDevice ) { int result = fb_ErrorSetNum( FB_RTERROR_OK ); const DEV_PRINTER_EMU_MODE *pFoundEmu = NULL; DWORD dwJob = 0; BOOL fResult; HANDLE hPrinter = NULL; HDC hDc = NULL; char *printer_name = NULL; char *doc_title = NULL; DEV_LPT_PROTOCOL *lpt_proto; if ( !fb_DevLptParseProtocol( &lpt_proto, pszDevice, strlen(pszDevice), TRUE ) ) { if( lpt_proto!=NULL ) free(lpt_proto); return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ); } /* Allow only valid emulation modes */ if( *lpt_proto->emu!=0 ) { int i; for( i=0; i!=sizeof(aEmulationModes)/sizeof(aEmulationModes[0]); ++i ) { const DEV_PRINTER_EMU_MODE *pEmu = aEmulationModes + i; if( strcasecmp( lpt_proto->emu, pEmu->pszId )==0 ) { pFoundEmu = pEmu; break; } } if( !pFoundEmu ) { if( lpt_proto!=NULL ) free(lpt_proto); return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ); } } if( iPort==0 ) { /* LPT:[PrinterName] */ if( *lpt_proto->name ) { printer_name = strdup( lpt_proto->name ); } else { printer_name = GetDefaultPrinterName(); } } else { /* LPTx: */ FB_LIST dev_printer_devs; DEV_PRINTER_DEVICE* node; fb_hListDevInit( &dev_printer_devs ); fb_hPrinterBuildList( &dev_printer_devs ); /* Find printer attached to specified device */ node = fb_hListDevFindDevice( &dev_printer_devs, lpt_proto->proto ); if( node!=NULL ) { printer_name = strdup( node->printer_name ); } fb_hListDevClear( &dev_printer_devs ); } if( printer_name == NULL ) { result = fb_ErrorSetNum( FB_RTERROR_FILENOTFOUND ); } else { if( *lpt_proto->emu!= '\0' ) { /* When EMULATION is used, we have to use the DC instead of * the PRINTER directly */ hDc = CreateDCA( "WINSPOOL", printer_name, NULL, NULL ); fResult = hDc!=NULL; } else { /* User PRINTER directly */ fResult = OpenPrinter(printer_name, &hPrinter, NULL); } if( !fResult ) { result = fb_ErrorSetNum( FB_RTERROR_FILENOTFOUND ); } } if( lpt_proto->title && *lpt_proto->title ) { doc_title = strdup( lpt_proto->title ); } else { doc_title = strdup( "FreeBASIC document" ); } if( result==FB_RTERROR_OK ) { if( *lpt_proto->emu!= '\0' ) { int iJob; DOCINFO docInfo; memset( &docInfo, 0, sizeof(DOCINFO) ); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = doc_title; iJob = StartDoc( hDc, &docInfo ); if( iJob <= 0 ) { result = fb_ErrorSetNum( FB_RTERROR_FILEIO ); } else { dwJob = (DWORD) iJob; } } else { DOC_INFO_1 DocInfo; DocInfo.pDocName = doc_title; DocInfo.pOutputFile = NULL; DocInfo.pDatatype = TEXT("RAW"); dwJob = StartDocPrinter( hPrinter, 1, (BYTE*) &DocInfo ); if( dwJob==0 ) { result = fb_ErrorSetNum( FB_RTERROR_FILEIO ); } } } if( result==FB_RTERROR_OK ) { W32_PRINTER_INFO *pInfo = calloc( 1, sizeof(W32_PRINTER_INFO) ); if( pInfo==NULL ) { result = fb_ErrorSetNum( FB_RTERROR_OUTOFMEM ); } else { devInfo->driver_opaque = pInfo; pInfo->hPrinter = hPrinter; pInfo->dwJob = dwJob; pInfo->hDc = hDc; if( hDc!=NULL ) { LOGFONT lf; pInfo->Emu.dwFullSizeX = GetDeviceCaps( hDc, PHYSICALWIDTH ); pInfo->Emu.dwFullSizeY = GetDeviceCaps( hDc, PHYSICALHEIGHT ); pInfo->Emu.dwSizeX = GetDeviceCaps( hDc, HORZRES ); pInfo->Emu.dwSizeY = GetDeviceCaps( hDc, VERTRES ); pInfo->Emu.dwOffsetX = GetDeviceCaps( hDc, PHYSICALOFFSETX ); pInfo->Emu.dwOffsetY = GetDeviceCaps( hDc, PHYSICALOFFSETY ); pInfo->Emu.dwDPI_X = GetDeviceCaps( hDc, LOGPIXELSX ); pInfo->Emu.dwDPI_Y = GetDeviceCaps( hDc, LOGPIXELSY ); #if 0 pInfo->Emu.dwCurrentX = pInfo->Emu.dwOffsetX; pInfo->Emu.dwCurrentY = pInfo->Emu.dwOffsetY; #else pInfo->Emu.dwCurrentX = 0; pInfo->Emu.dwCurrentY = 0; #endif pInfo->Emu.clFore = RGB(0,0,0); pInfo->Emu.clBack = RGB(255,255,255); /* Start in 12 CPI monospace mode */ EmuBuild_LOGFONT( &lf, pInfo, 12 ); /* Should never fail - except when some default fonts were * removed by hand (which is very unlikely) */ pInfo->Emu.hFont = CreateFontIndirect( &lf ); DBG_ASSERT( pInfo->Emu.hFont!=NULL ); /* Register PRINT function */ pInfo->Emu.pfnPrint = pFoundEmu->pfnPrint; /* Should not be necessary because this is the default */ SetTextAlign( hDc, TA_TOP | TA_LEFT | TA_NOUPDATECP ); EmuUpdateInfo( pInfo ); } } } if( result!=FB_RTERROR_OK ) { if( dwJob!=0 ) { if( *lpt_proto->emu != '\0' ) { EndDoc( hDc ); } else { EndDocPrinter( hPrinter ); } } if( hPrinter!=NULL ) { ClosePrinter( hPrinter ); } if( hDc!=NULL ) { DeleteDC( hDc ); } } if( printer_name!=NULL ) free( printer_name ); if( doc_title!=NULL ) free( doc_title ); if( lpt_proto!=NULL ) free(lpt_proto); return result; }
unsigned int WINAPI TheThread(void *) { _InterlockedExchange(&emuThreadReady, THREAD_INIT); setCurrentThreadName("Emu"); // And graphics... // Native overwrites host. Can't allow that. Host *oldHost = host; // Convert the command-line arguments to Unicode, then to proper UTF-8 // (the benefit being that we don't have to pollute the UI project with win32 ifdefs and lots of Convert<whatever>To<whatever>). // This avoids issues with PPSSPP inadvertently destroying paths with Unicode glyphs // (using the ANSI args resulted in Japanese/Chinese glyphs being turned into question marks, at least for me..). // -TheDax std::vector<std::wstring> wideArgs = GetWideCmdLine(); std::vector<std::string> argsUTF8; for (auto& string : wideArgs) { argsUTF8.push_back(ConvertWStringToUTF8(string)); } std::vector<const char *> args; for (auto& string : argsUTF8) { args.push_back(string.c_str()); } NativeInit(static_cast<int>(args.size()), &args[0], "1234", "1234", "1234"); Host *nativeHost = host; host = oldHost; host->UpdateUI(); //Check Colour depth HDC dc = GetDC(NULL); u32 colour_depth = GetDeviceCaps(dc, BITSPIXEL); ReleaseDC(NULL, dc); if (colour_depth != 32){ MessageBox(0, L"Please switch your display to 32-bit colour mode", L"OpenGL Error", MB_OK); ExitProcess(1); } std::string error_string; if (!host->InitGraphics(&error_string)) { Reporting::ReportMessage("Graphics init error: %s", error_string.c_str()); std::string full_error = StringFromFormat( "Failed initializing OpenGL. Try upgrading your graphics drivers.\n\nError message:\n\n%s", error_string.c_str()); MessageBox(0, ConvertUTF8ToWString(full_error).c_str(), L"OpenGL Error", MB_OK | MB_ICONERROR); ERROR_LOG(BOOT, full_error.c_str()); // No safe way out without OpenGL. ExitProcess(1); } NativeInitGraphics(); NativeResized(); INFO_LOG(BOOT, "Done."); _dbg_update_(); if (coreState == CORE_POWERDOWN) { INFO_LOG(BOOT, "Exit before core loop."); goto shutdown; } _InterlockedExchange(&emuThreadReady, THREAD_CORE_LOOP); if (g_Config.bBrowse) PostMessage(MainWindow::GetHWND(), WM_COMMAND, ID_FILE_LOAD, 0); Core_EnableStepping(FALSE); while (GetUIState() != UISTATE_EXIT) { // We're here again, so the game quit. Restart Core_Run() which controls the UI. // This way they can load a new game. if (!Core_IsActive()) UpdateUIState(UISTATE_MENU); Core_Run(); } shutdown: _InterlockedExchange(&emuThreadReady, THREAD_SHUTDOWN); NativeShutdownGraphics(); host->ShutdownSound(); host = nativeHost; NativeShutdown(); host = oldHost; host->ShutdownGraphics(); _InterlockedExchange(&emuThreadReady, THREAD_END); return 0; }
//+--------------------------------------------------------------------------- // // Member: CScrollbar::DrawTrack // // Synopsis: Draw the scroll bar track. // // Arguments: rcTrack bounds of track // fPressed TRUE if this portion of track is pressed // fDisabled TRUE if scroll bar is disabled // hdc HDC to draw into // params customizable scroll bar parameters // // Notes: // //---------------------------------------------------------------------------- void CScrollbar::DrawTrack( const CRect& rcTrack, BOOL fPressed, BOOL fDisabled, HDC hdc, const CScrollbarParams& params) { ThreeDColors& colors = *params._pColors; HBRUSH hbr = NULL; BOOL fDither = TRUE; if(params._fFlat) { hbr = GetCachedBmpBrush(IDB_DITHER); SetTextColor(hdc, colors.BtnFace()); SetBkColor(hdc, (fPressed)?colors.BtnShadow():colors.BtnHighLight()); } else { // Check to see if we have to dither // LaszloG: The condition is directly from the NT GDI implementation // of DefWindowProc's handling of WM_CTLCOLORSCROLLBAR. // The codeis on \\rastaman\ntwinie\src\ntuser\kernel\dwp.c fDither = GetDeviceCaps(hdc, BITSPIXEL)<8 || colors.BtnHighLight()==GetSysColorQuick(COLOR_WINDOW) || colors.BtnHighLight()!=GetSysColorQuick(COLOR_SCROLLBAR); if(fDither) { hbr = GetCachedBmpBrush(IDB_DITHER); COLORREF dither1 = colors.BtnFace(); COLORREF dither2 = colors.BtnHighLight(); if(fPressed) { dither1 ^= 0x00ffffff; dither2 ^= 0x00ffffff; } SetTextColor(hdc, dither1); SetBkColor(hdc, dither2); } else { COLORREF color = colors.BtnHighLight(); if(fPressed) { color ^= 0x00ffffff; } hbr = GetCachedBrush(color); } } if(fDither) { CPoint pt; ::GetViewportOrgEx(hdc, &pt); pt += rcTrack.TopLeft().AsSize(); // not supported on WINCE ::UnrealizeObject(hbr); ::SetBrushOrgEx(hdc, POSITIVE_MOD(pt.x,8), POSITIVE_MOD(pt.y,8), NULL); } HBRUSH hbrOld = (HBRUSH)::SelectObject(hdc, hbr); ::PatBlt( hdc, rcTrack.left, rcTrack.top, rcTrack.Width(), rcTrack.Height(), PATCOPY); ::SelectObject(hdc, hbrOld); // Release only the non-bitmap brushes if(!fDither) { ::ReleaseCachedBrush(hbr); } }
void CBarcode::LoadData(CString csMessage, double dNarrowBar, double dFinalHeight, HDC pDC, int nStartingXPixel, int nStartingYPixel, double dRatio ) { int i,nXAxisDpi,nYAxisDpi,nTemp; char c; // values that can be saved without translation m_csMessage = csMessage; m_nStartingXPixel = nStartingXPixel; m_nStartingYPixel = nStartingYPixel; m_hDC = pDC; // get dpi for the two axes nXAxisDpi = GetDeviceCaps(m_hDC, LOGPIXELSX); nYAxisDpi = GetDeviceCaps(m_hDC, LOGPIXELSY); // load the final attributes that depend on the device context m_nPixelHeight = (int)((nYAxisDpi*dFinalHeight)+0.5); m_nNarrowBarPixelWidth = (int)((nXAxisDpi*dNarrowBar)+0.5); m_nWideBarPixelWidth = (int)(dRatio*m_nNarrowBarPixelWidth); switch (m_nSymbology) { case RATIONALCODABAR: // initialize to zero m_nFinalBarcodePixelWidth = 0; // add the width of each character for (i=0;i<csMessage.GetLength();i++) { c = csMessage.GetAt(i); switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '-': case '$': m_nFinalBarcodePixelWidth += (6*m_nNarrowBarPixelWidth)+(2*m_nWideBarPixelWidth); break; case ':': case '/': case '.': case '+': case 'A': case 'B': case 'C': case 'D': m_nFinalBarcodePixelWidth += (5*m_nNarrowBarPixelWidth)+(3*m_nWideBarPixelWidth); break; } } break; case I2OF5: // add start code m_nFinalBarcodePixelWidth = 4 * m_nNarrowBarPixelWidth; // add message m_nFinalBarcodePixelWidth += ((3*m_nNarrowBarPixelWidth)+(2*m_nWideBarPixelWidth))*m_csMessage.GetLength(); // add stop code m_nFinalBarcodePixelWidth += (2*m_nNarrowBarPixelWidth)+(m_nWideBarPixelWidth); break; case CODE39: // get final character width nTemp = m_csMessage.GetLength() + 2; // add message m_nFinalBarcodePixelWidth = nTemp * ((3*m_nWideBarPixelWidth) + (7*m_nNarrowBarPixelWidth)); break; case COD128: // get final character width nTemp = m_csMessage.GetLength(); m_nFinalBarcodePixelWidth = ((nTemp*11)+35)*m_nNarrowBarPixelWidth; break; case CODE93: // get final character width nTemp = m_csMessage.GetLength(); m_nFinalBarcodePixelWidth = (((nTemp+4)*9)+1)*m_nNarrowBarPixelWidth; case UPCEAN: case TRADITIONALCODABAR: break; case EAN13: case EAN8: break; } return; }