HBITMAP CaptureWindow(HWND hWnd) { HDC hDC; BOOL bOk = FALSE; HBITMAP hImage = NULL; hDC = GetDC(hWnd); RECT rcClient; GetClientRect(hWnd, &rcClient); if ((hImage = CreateCompatibleBitmap(hDC, rcClient.right, rcClient.bottom)) != NULL) { HDC hMemDC; HBITMAP hDCBmp; if ((hMemDC = CreateCompatibleDC(hDC)) != NULL) { hDCBmp = (HBITMAP)SelectObject(hMemDC, hImage); HMODULE hLib = LoadLibrary("User32"); // PrintWindow works for windows outside displayable area // but was only introduced in WinXP. BitBlt requires the window to // be topmost and within the viewable area of the display if (GetProcAddress(hLib, "PrintWindow") == NULL) { SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE); BitBlt(hMemDC, 0, 0, rcClient.right, rcClient.bottom, hDC, 0, 0, SRCCOPY); SetWindowPos(hWnd, HWND_NOTOPMOST, -32000, -32000, 0, 0, SWP_NOSIZE); } else { PrintWindow(hWnd, hMemDC, 0); } SelectObject(hMemDC, hDCBmp); DeleteDC(hMemDC); bOk = TRUE; } } ReleaseDC(hWnd, hDC); if (!bOk) { if (hImage) { DeleteObject(hImage); hImage = NULL; } } return hImage; }
void StageDraw() { DrawMap(map, 0); DrawEnemy(map); DrawItem(map); DrawBomb(map); DrawEffect(map); DrawPlayer(map); #if !MAP_EDIT_MODE DrawTextureObject(res.player_right, 0, 0); FontPrintf(32, 16, "x %d", life); DrawTextureObject(res.font_stage, 128, 16); FontPrintf(128 + 16 * 5, 16, "%d", stageNum + 1); DrawTextureObject(res.font_score, 128 + 16 * 5 + 32, 16); FontPrintf(128 + 16 * 5 + 32 + 16 * 5 + 16 , 16, "%d", score); PrintWindow("fps: %d", engineFps); #endif }
WindowBitmap::WindowBitmap(HWND hWnd, bool directx): _hWnd(hWnd), m_bits(NULL) { HDC hdcWindow = GetWindowDC(hWnd); HDC hdcBuffer = CreateCompatibleDC(hdcWindow); RECT windowRect; int windowWidth, windowHeight; GetWindowRect(hWnd, &windowRect); windowWidth = windowRect.right - windowRect.left; windowHeight = windowRect.bottom - windowRect.top; _hBitmap = CreateCompatibleBitmap(hdcWindow, windowWidth, windowHeight); HBITMAP hBitTemp = (HBITMAP) SelectObject(hdcBuffer, _hBitmap); if(directx){ BitBlt(hdcBuffer, 0, 0, windowWidth, windowHeight, hdcWindow, 0, 0, SRCCOPY); }else{ PrintWindow(hWnd, hdcBuffer, 0); } _hBitmap = (HBITMAP) SelectObject(hdcBuffer, hBitTemp); //WindowBitmap::saveHBitmap2File(_hBitmap, "my.bmp"); GetObject( _hBitmap, sizeof(BITMAP), &m_bmp); LONG bytes = m_bmp.bmWidthBytes * m_bmp.bmHeight; m_bits = new BYTE[bytes]; GetBitmapBits( _hBitmap, bytes, m_bits ); //WindowBitmap::saveHBitmap2File(_hBitmap, "my.bmp"); DeleteObject(hBitTemp); DeleteDC(hdcBuffer); ReleaseDC(hWnd, hdcWindow); }
void CSrmmProxyWindow::OnTimer(int) { g_pTaskbarList->UnregisterTab(m_hwndParent); if (!m_refreshPreview) return; if (!IsWindowVisible(m_hwndWindow) || !IsWindowVisible(m_hwndParent) || IsIconic(m_hwndParent)) return; if (m_hbmpPreview) DeleteObject(m_hbmpPreview); m_refreshPreview = false; RECT rc; GetWindowRect(m_hwndWindow, &rc); m_hbmpPreview = CreateDwmBitmap(rc.right - rc.left, rc.bottom - rc.top); HDC hdc = CreateCompatibleDC(0); HBITMAP hbmpSave = (HBITMAP)SelectObject(hdc, m_hbmpPreview); PrintWindow(m_hwndWindow, hdc, PW_CLIENTONLY); SelectObject(hdc, hbmpSave); DeleteDC(hdc); MakeBitmapOpaque(m_hbmpPreview); InvalidateThumbnail(); }
/** * Saves a rendering of the current site by its host container as a PNG file. * This implementation is derived from IECapt. * * @param outputFile the file to save the PNG output as * @link http://iecapt.sourceforge.net/ */ STDMETHODIMP CCoSnapsie::saveSnapshot( BSTR outputFile, BSTR frameId, LONG drawableScrollWidth, LONG drawableScrollHeight, LONG drawableClientWidth, LONG drawableClientHeight, LONG drawableClientLeft, LONG drawableClientTop, LONG frameBCRLeft, LONG frameBCRTop) { HRESULT hr; HWND hwndBrowser; CComPtr<IOleClientSite> spClientSite; CComQIPtr<IServiceProvider> spISP; CComPtr<IWebBrowser2> spBrowser; CComPtr<IDispatch> spDispatch; CComQIPtr<IHTMLDocument2> spDocument; CComPtr<IHTMLWindow2> spScrollableWindow; CComQIPtr<IViewObject2> spViewObject; CComPtr<IHTMLStyle> spStyle; CComQIPtr<IHTMLElement2> spScrollableElement; CComVariant documentHeight; CComVariant documentWidth; CComVariant viewportHeight; CComVariant viewportWidth; GetSite(IID_IUnknown, (void**)&spClientSite); if (spClientSite == NULL) { Error(L"There is no site."); return E_FAIL; } spISP = spClientSite; if (spISP == NULL) { Error(L"Unable to convert client site to service provider."); return E_FAIL; } // from http://support.microsoft.com/kb/257717 hr = spISP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void **)&spBrowser); if (FAILED(hr)) { // if we can't query the client site for IWebBrowser2, we're probably // in an HTA. Obtain the IHTMLWindow2 interface pointer by directly // querying the client site's service provider. // http://groups.google.com/group/microsoft.public.vc.language/browse_thread/thread/f8987a31d47cccfe/884cb8f13423039e CComPtr<IHTMLWindow2> spWindow; hr = spISP->QueryService(IID_IHTMLWindow2, &spWindow); if (FAILED(hr)) { Error("Failed to obtain IHTMLWindow2 from service provider"); return E_FAIL; } hr = spWindow->get_document(&spDocument); if (FAILED(hr)) { Error("Failed to obtain IHTMLDocument2 from window"); return E_FAIL; } CComQIPtr<IOleWindow> spOleWindow = spDocument; if (spOleWindow == NULL) { Error("Failed to obtain IOleWindow from document"); return E_FAIL; } hr = spOleWindow->GetWindow(&hwndBrowser); if (FAILED(hr)) { Error("Failed to obtain HWND from OLE window"); return E_FAIL; } hwndBrowser = GetAncestor(hwndBrowser, GA_ROOTOWNER); } else { hr = spBrowser->get_HWND((long*)&hwndBrowser); if (FAILED(hr)) { Error("Failed to get HWND for browser (is this a frame?)"); return E_FAIL; } ie = GetAncestor(hwndBrowser, GA_ROOTOWNER); CComPtr<IDispatch> spDispatch; hr = spBrowser->get_Document(&spDispatch); if (FAILED(hr)) return E_FAIL; spDocument = spDispatch; if (spDocument == NULL) return E_FAIL; IServiceProvider* pServiceProvider = NULL; if (SUCCEEDED(spBrowser->QueryInterface( IID_IServiceProvider, (void**)&pServiceProvider))) { IOleWindow* pWindow = NULL; if (SUCCEEDED(pServiceProvider->QueryService( SID_SShellBrowser, IID_IOleWindow, (void**)&pWindow))) { if (SUCCEEDED(pWindow->GetWindow(&hwndBrowser))) { hwndBrowser = FindWindowEx(hwndBrowser, NULL, _T("Shell DocObject View"), NULL); if (hwndBrowser) { hwndBrowser = FindWindowEx(hwndBrowser, NULL, _T("Internet Explorer_Server"), NULL); } } pWindow->Release(); } pServiceProvider->Release(); } } // Nobody else seems to know how to get IViewObject2?! // http://starkravingfinkle.org/blog/2004/09/ spViewObject = spDocument; if (spViewObject == NULL) { Error(L"Unable to convert document to view object."); return E_FAIL; } CComQIPtr<IHTMLDocument5> spDocument5; spDocument->QueryInterface(IID_IHTMLDocument5, (void**)&spDocument5); if (spDocument5 == NULL) { Error(L"Snapsie requires IE6 or greater."); return E_FAIL; } CComBSTR compatMode; spDocument5->get_compatMode(&compatMode); // In non-standards-compliant mode, the BODY element represents the canvas. if (compatMode == L"BackCompat") { CComPtr<IHTMLElement> spBody; spDocument->get_body(&spBody); if (NULL == spBody) { return E_FAIL; } spBody->getAttribute(CComBSTR("scrollHeight"), 0, &documentHeight); spBody->getAttribute(CComBSTR("scrollWidth"), 0, &documentWidth); spBody->getAttribute(CComBSTR("clientHeight"), 0, &viewportHeight); spBody->getAttribute(CComBSTR("clientWidth"), 0, &viewportWidth); } // In standards-compliant mode, the HTML element represents the canvas. else { CComQIPtr<IHTMLDocument3> spDocument3; spDocument->QueryInterface(IID_IHTMLDocument3, (void**)&spDocument3); if (NULL == spDocument3) { Error(L"Unable to get IHTMLDocument3 handle from document."); return E_FAIL; } // The root node should be the HTML element. CComPtr<IHTMLElement> spRootNode; spDocument3->get_documentElement(&spRootNode); if (NULL == spRootNode) { Error(L"Could not retrieve root node."); return E_FAIL; } CComPtr<IHTMLHtmlElement> spHtml; spRootNode->QueryInterface(IID_IHTMLHtmlElement, (void**)&spHtml); if (NULL == spHtml) { Error(L"Root node is not the HTML element."); return E_FAIL; } spRootNode->getAttribute(CComBSTR("scrollHeight"), 0, &documentHeight); spRootNode->getAttribute(CComBSTR("scrollWidth"), 0, &documentWidth); spRootNode->getAttribute(CComBSTR("clientHeight"), 0, &viewportHeight); spRootNode->getAttribute(CComBSTR("clientWidth"), 0, &viewportWidth); } // Figure out how large to make the window. It's not sufficient to just use the dimensions of the scrolled // viewport because the browser chrome occupies space that must be accounted for as well. RECT ieWindowRect; GetWindowRect(ie, &ieWindowRect); int ieWindowWidth = ieWindowRect.right - ieWindowRect.left; int ieWindowHeight = ieWindowRect.bottom - ieWindowRect.top; RECT contentClientRect; GetClientRect(hwndBrowser, &contentClientRect); int contentClientWidth = contentClientRect.right - contentClientRect.left; int contentClientHeight = contentClientRect.bottom - contentClientRect.top; int chromeWidth = ieWindowWidth - contentClientWidth; int chromeHeight = 2 * (ieWindowHeight - contentClientHeight); int imageHeight = documentHeight.intVal; int imageWidth = documentWidth.intVal; maxWidth = imageWidth + chromeWidth; maxHeight = imageHeight + chromeHeight; long originalHeight, originalWidth; spBrowser->get_Height(&originalHeight); spBrowser->get_Width(&originalWidth); // The resize message is being ignored if the window appears to be maximized. There's likely a // way to bypass that. My ghetto way is to unmaximize the window, then move on with setting // the window to the dimensions we really want. This is okay because we revert back to the // original dimensions afterward. BOOL isMaximized = IsZoomed(ie); if (isMaximized) { ShowWindow(ie, SW_SHOWNORMAL); } // Get the path to this DLL so we can load it up with LoadLibrary. TCHAR dllPath[_MAX_PATH]; GetModuleFileName((HINSTANCE) &__ImageBase, dllPath, _MAX_PATH); // Get the path to the Windows hook we use to allow resizing the window greater than the virtual screen resolution. HINSTANCE hinstDLL = LoadLibrary(dllPath); HOOKPROC hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "CallWndProc"); if (hkprcSysMsg == NULL) PrintError(L"GetProcAddress"); // Install the Windows hook. nextHook = SetWindowsHookEx(WH_CALLWNDPROC, hkprcSysMsg, hinstDLL, 0); if (nextHook == 0) PrintError(L"SetWindowsHookEx"); spBrowser->put_Height(maxHeight); spBrowser->put_Width(maxWidth); // Capture the window's canvas to a DIB. CImage image; image.Create(imageWidth, imageHeight, 24); CImageDC imageDC(image); hr = PrintWindow(hwndBrowser, imageDC, PW_CLIENTONLY); if (FAILED(hr)) { Error(L"PrintWindow"); } // I'm not sure if PrintWindow captures alpha blending or not. OleDraw does, but I was having // issues with sizing the browser correctly between quirks and standards modes to capture everything we need. // //RECT rcBounds = { 0, 0, imageWidth, imageHeight }; //hr = OleDraw(spViewObject, DVASPECT_DOCPRINT, imageDC, &rcBounds); //if (FAILED(hr)) //{ // Error(L"OleDraw"); //} UnhookWindowsHookEx(nextHook); // Restore the browser to the original dimensions. if (isMaximized) { ShowWindow(ie, SW_MAXIMIZE); } else { spBrowser->put_Height(originalHeight); spBrowser->put_Width(originalWidth); } hr = image.Save(CW2T(outputFile)); if (FAILED(hr)) { PrintError(L"Failed saving image."); return E_FAIL; } return hr; }
/* It is up to the caller to delete the bitmap returned by this method. */ void Explorerplusplus::GetTabLivePreviewBitmap(int iTabId,TabPreviewInfo_t *ptpi) { HDC hdcTab; HDC hdcTabSrc; HBITMAP hbmTab; HBITMAP hbmTabPrev; Gdiplus::Color color(0,0,0); MENUBARINFO mbi; POINT pt; BOOL bVisible; RECT rcTab; HWND hTab = m_hListView[iTabId]; hdcTab = GetDC(hTab); hdcTabSrc = CreateCompatibleDC(hdcTab); GetClientRect(hTab,&rcTab); Gdiplus::Bitmap bi(GetRectWidth(&rcTab),GetRectHeight(&rcTab),PixelFormat32bppARGB); bi.GetHBITMAP(color,&hbmTab); hbmTabPrev = (HBITMAP)SelectObject(hdcTabSrc,hbmTab); bVisible = IsWindowVisible(hTab); if(!bVisible) { ShowWindow(hTab,SW_SHOW); } PrintWindow(hTab,hdcTabSrc,PW_CLIENTONLY); if(!bVisible) { ShowWindow(hTab,SW_HIDE); } SetStretchBltMode(hdcTabSrc,HALFTONE); SetBrushOrgEx(hdcTabSrc,0,0,&pt); StretchBlt(hdcTabSrc,0,0,GetRectWidth(&rcTab),GetRectHeight(&rcTab),hdcTabSrc, 0,0,GetRectWidth(&rcTab),GetRectHeight(&rcTab),SRCCOPY); MapWindowPoints(hTab,m_hContainer,(LPPOINT)&rcTab,2); mbi.cbSize = sizeof(mbi); GetMenuBarInfo(m_hContainer,OBJID_MENU,0,&mbi); /* The operating system will automatically draw the main window. Therefore, we'll just shift the tab into it's proper position. */ ptpi->ptOrigin.x = rcTab.left; /* Need to include the menu bar in the offset. */ ptpi->ptOrigin.y = rcTab.top + mbi.rcBar.bottom - mbi.rcBar.top; ptpi->hbm = hbmTab; ptpi->iTabId = iTabId; SelectObject(hdcTabSrc,hbmTabPrev); DeleteDC(hdcTabSrc); ReleaseDC(hTab,hdcTab); }
HBITMAP Explorerplusplus::CaptureTabScreenshot(int iTabId) { HDC hdc; HDC hdcSrc; HBITMAP hBitmap; HBITMAP hPrevBitmap; Gdiplus::Color color(0,0,0); RECT rcMain; RECT rcTab; HWND hTab = m_hListView[iTabId]; GetClientRect(m_hContainer,&rcMain); GetClientRect(hTab,&rcTab); /* Main window BitBlt. */ hdc = GetDC(m_hContainer); hdcSrc = CreateCompatibleDC(hdc); /* Any bitmap sent back to the operating system will need to be in 32-bit ARGB format. */ Gdiplus::Bitmap bi(GetRectWidth(&rcMain),GetRectHeight(&rcMain),PixelFormat32bppARGB); bi.GetHBITMAP(color,&hBitmap); /* BitBlt the main window into the bitmap. */ hPrevBitmap = (HBITMAP)SelectObject(hdcSrc,hBitmap); BitBlt(hdcSrc,0,0,GetRectWidth(&rcMain),GetRectHeight(&rcMain),hdc,0,0,SRCCOPY); /* Now BitBlt the tab onto the main window. */ HDC hdcTab; HDC hdcTabSrc; HBITMAP hbmTab; HBITMAP hbmTabPrev; BOOL bVisible; hdcTab = GetDC(hTab); hdcTabSrc = CreateCompatibleDC(hdcTab); hbmTab = CreateCompatibleBitmap(hdcTab,GetRectWidth(&rcTab),GetRectHeight(&rcTab)); hbmTabPrev = (HBITMAP)SelectObject(hdcTabSrc,hbmTab); bVisible = IsWindowVisible(hTab); if(!bVisible) { ShowWindow(hTab,SW_SHOW); } PrintWindow(hTab,hdcTabSrc,PW_CLIENTONLY); if(!bVisible) { ShowWindow(hTab,SW_HIDE); } MapWindowPoints(hTab,m_hContainer,(LPPOINT)&rcTab,2); BitBlt(hdcSrc,rcTab.left,rcTab.top,GetRectWidth(&rcTab),GetRectHeight(&rcTab),hdcTabSrc,0,0,SRCCOPY); SelectObject(hdcTabSrc,hbmTabPrev); DeleteObject(hbmTab); DeleteDC(hdcTabSrc); ReleaseDC(hTab,hdcTab); /* Shrink the bitmap. */ HDC hdcThumbnailSrc; HBITMAP hbmThumbnail; POINT pt; hdcThumbnailSrc = CreateCompatibleDC(hdc); /* Thumbnail bitmap. */ Gdiplus::Bitmap bmpThumbnail(GetRectWidth(&rcMain),GetRectHeight(&rcMain),PixelFormat32bppARGB); bmpThumbnail.GetHBITMAP(color,&hbmThumbnail); hPrevBitmap = (HBITMAP)SelectObject(hdcThumbnailSrc,hbmThumbnail); /* Finally, shrink the full-scale bitmap down into a thumbnail. */ SetStretchBltMode(hdcThumbnailSrc,HALFTONE); SetBrushOrgEx(hdcThumbnailSrc,0,0,&pt); BitBlt(hdcThumbnailSrc,0,0,GetRectWidth(&rcMain),GetRectHeight(&rcMain),hdcSrc,0,0,SRCCOPY); SetBitmapDimensionEx(hbmThumbnail,GetRectWidth(&rcMain),GetRectHeight(&rcMain),NULL); SelectObject(hdcThumbnailSrc,hPrevBitmap); DeleteDC(hdcThumbnailSrc); DeleteObject(hBitmap); SelectObject(hdcSrc,hPrevBitmap); DeleteDC(hdcSrc); ReleaseDC(m_hContainer,hdc); return hbmThumbnail; }
FIBITMAP* CaptureScreen (HDC hDC,SIZE size,HWND hCapture){ //HDC GetDC (NULL) entire desktp //HDC GetDC (HWND hWnd) client area of the specified window. (may include artifacts) //HDC GetWindowDC (HWND hWnd) entire window. FIBITMAP *dib = NULL; HBITMAP hBitmap; // handles to device-dependent bitmaps HDC hScrDC, hMemDC; // screen DC and memory DC // create a DC for the screen and create // a memory DC compatible to screen DC if(!(hScrDC=hDC)) hScrDC=GetDC(hCapture); hMemDC = CreateCompatibleDC(hScrDC); // create a bitmap compatible with the screen DC hBitmap = CreateCompatibleBitmap(hScrDC,size.cx,size.cy); // select new bitmap into memory DC SelectObject(hMemDC, hBitmap); if(hCapture && hDC){ PrintWindow(hCapture,hMemDC,0); }else{// bitblt screen DC to memory DC BitBlt(hMemDC,0,0,size.cx,size.cy,hScrDC,0,0,CAPTUREBLT|SRCCOPY); } dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap); //alpha channel from window is always wrong and sometimes even for desktop (Win7, no aero) //coz GDI do not draw all in alpha mode. //we have to create our own new alpha channel. bool bFixAlpha=true; bool bInvert=false; HBRUSH hBr=CreateSolidBrush(RGB(255,255,255));//Create a SolidBrush object for non transparent area HBITMAP hMask=CreateBitmap(size.cx,size.cy,1,1,NULL);// Create monochrome (1 bit) B+W mask bitmap. HDC hMaskDC=CreateCompatibleDC(0); SelectBitmap(hMaskDC,hMask); HRGN hRgn=CreateRectRgn(0,0,0,0); if(hCapture && GetWindowRgn(hCapture,hRgn)==ERROR){ if((GetWindowLongPtr(hCapture,GWL_EXSTYLE)&WS_EX_LAYERED)){ BYTE bAlpha=0; COLORREF crKey=0;//0x00bbggrr DWORD dwFlags=0; if(GetLayeredWindowAttributes(hCapture,&crKey,&bAlpha,&dwFlags)) { //per window transparency (like fading in a whole window). if((dwFlags&LWA_COLORKEY)){ SetBkColor(hMemDC,crKey); BitBlt(hMaskDC,0,0,size.cx,size.cy,hMemDC,0,0,SRCCOPY); bInvert=true; }else if((dwFlags&LWA_ALPHA)){ bFixAlpha=false; } }else{//per-pixel transparency (won't use the WM_PAINT) bFixAlpha=false; } }else{//not layered - fill the window region SetRectRgn(hRgn,0,0,size.cx,size.cy); FillRgn(hMaskDC,hRgn,hBr); } }else{ if(!hCapture) SetRectRgn(hRgn,0,0,size.cx,size.cy);//client area only, no transparency FillRgn(hMaskDC,hRgn,hBr); } DeleteObject(hRgn); if(bFixAlpha){ FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask); if(bInvert) FIP->FI_Invert(dibMask); FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask); //copy the dib8 alpha mask to dib32 main bitmap FIP->FI_SetChannel(dib,dib8,FICC_ALPHA); FIP->FI_Unload(dibMask); FIP->FI_Unload(dib8); } DeleteDC(hMaskDC); DeleteObject(hMask); DeleteObject(hBr); //clean up DeleteDC(hMemDC); DeleteObject(hBitmap); if(!hDC) ReleaseDC(NULL, hScrDC); #ifdef _DEBUG switch (FIP->FI_GetImageType(dib)){ case FIT_UNKNOWN: OutputDebugStringA("FIBITMAP Typ: FIT_UNKNOWN\r\n" ); break; case FIT_BITMAP: OutputDebugStringA("FIBITMAP Typ: FIT_BITMAP\r\n" ); break; case FIT_UINT16: OutputDebugStringA("FIBITMAP Typ: FIT_UINT16\r\n" ); break; case FIT_INT16: OutputDebugStringA("FIBITMAP Typ: FIT_INT16\r\n" ); break; case FIT_UINT32: OutputDebugStringA("FIBITMAP Typ: FIT_UINT32\r\n" ); break; case FIT_INT32: OutputDebugStringA("FIBITMAP Typ: FIT_INT32\r\n" ); break; case FIT_FLOAT: OutputDebugStringA("FIBITMAP Typ: FIT_FLOAT\r\n" ); break; case FIT_DOUBLE: OutputDebugStringA("FIBITMAP Typ: FIT_DOUBLE\r\n" ); break; case FIT_COMPLEX: OutputDebugStringA("FIBITMAP Typ: FIT_COMPLEX\r\n" ); break; case FIT_RGB16: OutputDebugStringA("FIBITMAP Typ: FIT_RGB16\r\n" ); break; case FIT_RGBA16: OutputDebugStringA("FIBITMAP Typ: FIT_RGBA16\r\n" ); break; case FIT_RGBF: OutputDebugStringA("FIBITMAP Typ: FIT_RGBF\r\n" ); break; case FIT_RGBAF: OutputDebugStringA("FIBITMAP Typ: FIT_RGBAF\r\n" ); break; default: OutputDebugStringA("FIBITMAP Typ: non detectable image type (error)\r\n" ); break; } BOOL inf = FIP->FI_IsTransparent(dib); OutputDebugStringA(inf ? "FIBITMAP Transparent: true\r\n" : "FIBITMAP Transparent: false\r\n"); #endif return dib; }
// LR 1.66 -- complete rewrite (basically) of this entire routine...it was UGLY! OSStatus HandleMenu( long mSelect, short modifiers ) { short menuID = HiWord( mSelect ); short menuItem = LoWord( mSelect ); short colorResID; WindowRef frontWindow; DialogPtr dlgRef = NULL; EditWindowPtr dWin = NULL; Str255 currentWindowName, newFrontWindowName; // NS: v1.6.6, for window menu WindowRef currentWindow; // NS: this too // Predetermine what type of window we have to work with frontWindow = FrontNonFloatingWindow(); if( frontWindow ) { DialogPtr dlg = GetDialogFromWindow( frontWindow ); if( kHexEditWindowTag == GetWindowKind( frontWindow ) ) dWin = (EditWindowPtr) GetWRefCon( frontWindow ); else if( g.gotoDlg == dlg || g.searchDlg == dlg ) dlgRef = dlg; } switch( menuID ) { case kAppleMenu: if( menuItem == AM_About ) HexEditAboutBox(); #if !TARGET_API_MAC_CARBON else { GrafPtr savePort; Str255 name; GetPort( &savePort ); GetMenuItemText( appleMenu, menuItem, name ); OpenDeskAcc( name ); SetPort( savePort ); } #endif break; case kFileMenu: switch( menuItem ) { case FM_New: gPrefs.overwrite = false; //LR 190 -- overwrite mode makes no sense in a new document NewEditWindow(); break; case FM_Open: AskEditWindow( kWindowNormal ); break; // HR/LR 050328 - Handle FM_Disassemble menu item case FM_Disassemble: g.disassemble = !g.disassemble; if ( g.disassemble ) { dWin->drawMode = DM_Disassembly; dWin->bytesPerLine = kDisBytesPerLine; dWin->hexStart = kDisHexStart; dWin->asciiStart = kDisASCIIStart; } else { dWin->drawMode = DM_Dump; dWin->bytesPerLine = kHexBytesPerLine; dWin->hexStart = kHexHexStart; dWin->asciiStart = kHexASCIIStart; } /* Make sure the editOffset position starts on a new line */ dWin->editOffset -= dWin->editOffset % dWin->bytesPerLine; UpdateEditWindows(); break; case FM_OtherFork: // LR: I want to see both! if( dWin ) { short fork; //LR 180 EditWindowPtr ewin; if( dWin->fork == FT_Data ) fork = FT_Resource; else fork = FT_Data; /*LR 180 -- OpenEditWindow checks for this if( NULL != (ewin = LocateEditWindow( &dWin->fsSpec, fork )) ) // LR: 1.7 - boolean typecast causes failure! { SelectWindow( ewin->oWin.theWin ); // just select existing theWin } else // try to open other fork in new theWin! */ { g.forkMode = fork; OpenEditWindow( &dWin->fsSpec, kWindowNormal, true ); } } break; case FM_CompareFiles: //LR 180 -- now pass in modifiers to allow select override if( GetCompareFiles( modifiers ) ) DoComparison(); break; //LR: 1.66 - NOTE: dWin == NULL == frontWindow! case FM_Save: if( dWin && dWin->oWin.Save ) dWin->oWin.Save( frontWindow ); break; case FM_SaveAs: if( dWin && dWin->oWin.SaveAs ) dWin->oWin.SaveAs( frontWindow ); break; case FM_Revert: if( dWin && dWin->oWin.Revert ) //LR 1.72 -- check before reverting (could be dangerous!) { ParamText( dWin->fsSpec.name, NULL, NULL, NULL ); switch( CautionAlert( alertRevert, NULL ) ) { case ok: dWin->oWin.Revert( frontWindow ); break; } } break; case FM_Close: if( dWin ) CloseEditWindow( frontWindow ); else if( dlgRef ) { HideWindow( frontWindow ); //LR: 1.7 -- no need.GetDialogWindow( dlgRef ) ); } break; case FM_Quit: if( CloseAllEditWindows() ) g.quitFlag = true; break; case FM_PageSetup: #if TARGET_API_MAC_CARBON // sel - carbon session based printing _doPageSetupDialog(&g.pageFormat); #else PrOpen(); PrStlDialog( g.HPrint ); PrClose(); #endif break; case FM_Print: if( dWin ) PrintWindow( dWin ); break; } break; case kEditMenu: #if !TARGET_API_MAC_CARBON if( !SystemEdit( menuItem -1 ) ) #endif { if( dWin ) switch( menuItem ) { case EM_Undo: UndoOperation(); break; case EM_Cut: CutSelection( dWin ); break; case EM_Copy: CopySelection( dWin ); break; case EM_Paste: PasteSelection( dWin ); break; case EM_Clear: ClearSelection( dWin ); break; case EM_SelectAll: dWin->startSel = 0; dWin->endSel = dWin->fileSize; UpdateOnscreen( dWin->oWin.theWin ); break; } else if( dlgRef ) switch( menuItem ) { case EM_Cut: DialogCut( dlgRef ); TEToScrap(); break; case EM_Copy: DialogCopy( dlgRef ); TEToScrap(); break; case EM_Paste: TEFromScrap(); DialogPaste( dlgRef ); break; case EM_Clear: DialogDelete( dlgRef ); break; case EM_SelectAll: break; } } break; case kFindMenu: switch ( menuItem ) { case SM_Find: openfind: OpenSearchDialog(); break; case SM_FindForward: gPrefs.searchForward = true; PerformTextSearch( dWin, kSearchUpdateUI ); //LR 190 -- if dWin is NULL will operate on first edit window, if any (allows search in find dialog) break; case SM_FindBackward: gPrefs.searchForward = false; PerformTextSearch( dWin, kSearchUpdateUI ); //LR 190 -- if dWin is NULL will operate on first edit window break; case SM_Replace: //LR 190 -- add replace & find next (must have a window with selection to start!) if( !dWin ) dWin = FindFirstEditWindow(); // allow this to work in find dialog, etc. if( dWin && dWin->startSel != dWin->endSel ) { EditChunk **replaceChunk; if( !g.searchBuffer[0] ) // if nothing to find open dialog goto openfind; replaceChunk = NewChunk( g.replaceText[0], 0, 0, CT_Unwritten ); if( replaceChunk ) { // Copy replacement text to chunk buffer BlockMoveData( g.replaceText+1, *(*replaceChunk)->data, g.replaceText[0] ); // Do the replacement (with undo) g.replaceAll = false; RememberOperation( dWin, EO_Paste, &gUndo ); PasteOperation( dWin, replaceChunk ); // We're done with the chunk now DisposeChunk( NULL, replaceChunk ); } // Then try to find the next occurance (in LAST direction searched!) and display it if( !PerformTextSearch( dWin, kSearchUpdateUI ) ) ScrollToSelection( dWin, dWin->startSel, true ); } break; case SM_GotoAddress: OpenGotoAddress(); break; } break; case kOptionsMenu: switch ( menuItem ) { case OM_HiAscii: gPrefs.asciiMode = !gPrefs.asciiMode; if( gPrefs.asciiMode ) g.highChar = 0xFF; else g.highChar = 0x7F; UpdateEditWindows(); break; case OM_DecimalAddr: gPrefs.decimalAddr = !gPrefs.decimalAddr; UpdateEditWindows(); break; case OM_Backups: gPrefs.backupFlag = !gPrefs.backupFlag; break; case OM_WinSize: gPrefs.constrainSize = !gPrefs.constrainSize; break; case OM_Overwrite: gPrefs.overwrite = !gPrefs.overwrite; break; case OM_NonDestructive: gPrefs.nonDestructive = !gPrefs.nonDestructive; break; case OM_MoveOnlyPaging: gPrefs.moveOnlyPaging = !gPrefs.moveOnlyPaging; break; case OM_Unformatted: gPrefs.formatCopies = !gPrefs.formatCopies; break; case OM_VertBars: gPrefs.vertBars = !gPrefs.vertBars; UpdateEditWindows(); break; case OM_ComparePref: // LR: compare options ComparisonPreferences(); break; case OM_OpenOnLaunch: gPrefs.dialogAtLaunch = !gPrefs.dialogAtLaunch; //LR -- 192 break; } break; // LR: Add color scheme menu case kColorMenu: colorResID = GetColorMenuResID( menuItem ); if( menuItem == CM_UseColor ) { gPrefs.useColor = !gPrefs.useColor; // toggle color usage } else if( dWin && dWin->csResID > 0 ) // can't color B&W windows! { if( _cmCheckedItem ) CheckMenuItem( colorMenu, _cmCheckedItem, false ); if( (modifiers & optionKey) ) // option down == change all windows (set default color) { EditWindowPtr eWin = FindFirstEditWindow(); while( eWin ) { if( GetWindowKind( eWin->oWin.theWin ) == kHexEditWindowTag ) { eWin->csResID = colorResID; eWin->csMenuID = menuItem; //LR 181 -- for menu tagging } eWin = FindNextEditWindow( eWin ); } goto savepref; } else //LR 181 -- default is (back) to changing color of a single window! { if( GetWindowKind( dWin->oWin.theWin ) == kHexEditWindowTag ) { dWin->csResID = colorResID; dWin->csMenuID = menuItem; //LR 181 -- for menu tagging } } } else { savepref: //LR 190 -- no window open == set preferred color gPrefs.csResID = colorResID; //LR 180 -- save prefs when changing all gPrefs.csMenuID = menuItem; } UpdateEditWindows(); break; // LR : 1.7 - rewrite with bug checking (could crash accessing NULL window) case kWindowMenu: GetMenuItemText( windowMenu, menuItem, newFrontWindowName ); currentWindow = FrontNonFloatingWindow(); while( currentWindow ) { GetWTitle( currentWindow, currentWindowName ); if( EqualPStrings( currentWindowName, newFrontWindowName ) ) { SelectWindow( currentWindow ); break; } currentWindow = GetNextWindow( currentWindow ); } break; } HiliteMenu( 0 ); AdjustMenus(); return( noErr ); }