MCPcopy Create free account
hub / github.com/ColorCop/ColorCop / GetScreenBitmap

Method GetScreenBitmap

ColorCop/ColorCopDlg.cpp:1899–1948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1897}
1898
1899void CColorCopDlg::GetScreenBitmap(CPoint point) {
1900 if (hBitmap) { // delete the old bitmap, right before we get a new one
1901 ::DeleteObject(hBitmap);
1902 hBitmap = NULL;
1903 }
1904 if (hZoomBitmap) {
1905 ::DeleteObject(hZoomBitmap);
1906 hZoomBitmap = NULL;
1907 }
1908
1909 WindowDC hdc(NULL); // device context to the whole desktop (RAII)
1910
1911 HDC hdcMem = ::CreateCompatibleDC(hdc);
1912 HDC hdcZoomMem = ::CreateCompatibleDC(hdc);
1913
1914 hBitmap = CreateCompatibleBitmap(hdc, magrect.Width(), magrect.Height());
1915 hZoomBitmap = CreateCompatibleBitmap(hdc, magrect.Width(), magrect.Height());
1916
1917 ::SelectObject(hdcMem, hBitmap);
1918 ::SelectObject(hdcZoomMem, hZoomBitmap);
1919 ::SetStretchBltMode(hdc, COLORONCOLOR);
1920
1921 m_MagLevel = std::clamp<int>(m_MagLevel, kMinZoom, kMaxZoom);
1922
1923 const int level = m_MagLevel;
1924 const int magwidth = magrect.Width() / level;
1925 const int magheight = magrect.Height() / level;
1926
1927 ::BitBlt(hdcZoomMem, // destination DC
1928 0, 0, // destination upper left (always 0, 0)
1929 magrect.Width(), magrect.Height(), // w x h of destination
1930 hdc, // source DC
1931 point.x - (magrect.Width() / 2), // x coordinate of source
1932 point.y - (magrect.Height() / 2), // y coordinate of source
1933 SRCCOPY); // raster mode
1934
1935 ::StretchBlt(hdcMem, // destination DC
1936 0, 0, // destination upper left (always 0, 0)
1937 magrect.Width(), magrect.Height(), // w x h of destination
1938 hdc, // source DC
1939 point.x - (magwidth / 2), // x coordinate of source
1940 point.y - (magheight / 2), // y coordinate of source
1941 magwidth, magheight, // width of source
1942 SRCCOPY); // raster mode
1943
1944 ::DeleteDC(hdcMem);
1945 ::DeleteDC(hdcZoomMem);
1946 // hdc auto‑releases via RAII
1947 return;
1948}
1949
1950void CColorCopDlg::GetHistoryColor(int Cindex) {
1951 // this function sets the current color

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected