V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tghgffdgd
V2EX  ›  问与答

请教一个分层窗口的截不出来的问题

  •  
  •   tghgffdgd · 2016-07-20 21:31:17 +08:00 · 1628 次点击
    这是一个创建于 2988 天前的主题,其中的信息可能已经有所发展或是发生改变。

    之前一直是少了个参数然后不行,可是后来参数加了也不行,后面误打误撞换了写法发现可以。 不知道是哪里出了问题,代码差别在哪里。

    void CPrintScr::Print()
    {
    	HDC hScrDC = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
    	const int nWidth = GetDeviceCaps(hScrDC, HORZRES);
    	const int nHeight = GetDeviceCaps(hScrDC, VERTRES);
    	m_hMemDC = CreateCompatibleDC(hScrDC);
    	HBITMAP hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
    	HBITMAP hBmpOld = (HBITMAP)SelectObject(m_hMemDC, hBitmap);
    	BitBlt(m_hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY | CAPTUREBLT);
    	SelectObject(m_hMemDC, hBmpOld);
    	DeleteDC(m_hMemDC);
    	DeleteDC(hScrDC);
    	SetSavePath(L"c:\\tt.jpg");
    	SaveBitmapToFile(hBitmap, JPG);//获取分层窗口失败,分层窗口都是透明
    ...
    }
    
    HBITMAP CaptureScreen()
    {
    	HDC hScrDC = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
    	const int nWidth = GetDeviceCaps(hScrDC, HORZRES);
    	const int nHeight = GetDeviceCaps(hScrDC, VERTRES);
    	HDC m_hMemDC = CreateCompatibleDC(hScrDC);
    	HBITMAP hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
    	HBITMAP hBmpOld = (HBITMAP)SelectObject(m_hMemDC, hBitmap);
    	BitBlt(m_hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY | CAPTUREBLT);
    	SelectObject(m_hMemDC, hBmpOld);
    	DeleteDC(m_hMemDC);
    	DeleteDC(hScrDC);
    	return hBitmap;
    }
    {
    ...
    	g_PrintScr.SetSavePath(L"c:\\tt2.jpg");
    	g_PrintScr.SaveBitmapToFile(CaptureScreen(), JPG);//获取分层窗口成功
    ...
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2624 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:23 · PVG 23:23 · LAX 08:23 · JFK 11:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.