Esempio n. 1
0
    void* PrepareWindow(void* nativeWindow)
    {
        SafeHDC hDC((HWND)nativeWindow);
	    int format = ChoosePixelFormat(hDC, &defaultPixelFormatDescriptor);
	    SetPixelFormat(hDC, format, &defaultPixelFormatDescriptor);
        
        return nativeWindow;
    }
	void OGLWindow::setupPalette()
	{
		int pixelFormat = GetPixelFormat(hDC ());
		PIXELFORMATDESCRIPTOR pfd;
		LOGPALETTE* pPal;
		int paletteSize;

		int redMask, greenMask, blueMask;
		int i;

		DescribePixelFormat(hDC (), pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

		if (pfd.dwFlags & PFD_NEED_PALETTE)
			paletteSize = 1 << pfd.cColorBits;
		else
			return;

		pPal = (LOGPALETTE*)LocalAlloc(LPTR, sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
		pPal->palVersion = 0x300;
		pPal->palNumEntries = (short)paletteSize;

		//	build a simple RGB color palette
		redMask   = (1 << pfd.cRedBits)   - 1;
		greenMask = (1 << pfd.cGreenBits) - 1;
		blueMask  = (1 << pfd.cBlueBits)  - 1;

		for (i=0; i<paletteSize; ++i)
		{	pPal->palPalEntry[i].peRed = (BYTE)(
				(((i >> pfd.cRedShift) & redMask) * 255) / redMask);
			pPal->palPalEntry[i].peGreen = (BYTE)(
				(((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask);
			pPal->palPalEntry[i].peBlue = (BYTE)(
				(((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask);
			pPal->palPalEntry[i].peFlags = 0;
		}

		hPalette_ = CreatePalette(pPal);
		LocalFree(pPal);

		if (hPalette_)
		{
			DeleteObject(SelectPalette(hDC (), hPalette_, FALSE));
			RealizePalette(hDC ());
		}
	}
	void OGLWindow::close ()
	{
		if (hDC() == NULL) throw Uninitialized ();

		// deselect rendering context and delete it
		//wglMakeCurrent(hDC_, NULL);  //This causes a crash!
		//wglDeleteContext(hRC_);		//So does this!

		// send WM_QUIT to message queue
		PostQuitMessage(0);
	}
Esempio n. 4
0
    Platform_win32() 
    { 
	    mInternalWindow = CreateWindowEx(WS_EX_CLIENTEDGE, "STATIC", "Mini3DHiddenWindow", 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HWND_MESSAGE, 0, GetModuleHandle(NULL), 0);
        SafeHDC hDC(mInternalWindow);

        int pixelFormat = ChoosePixelFormat(hDC, &defaultPixelFormatDescriptor);
        mini3d_assert(pixelFormat != 0, "Failed to create default opengl context. CreatePixelFormat failed: (%u)", GetLastError());

        BOOL result = SetPixelFormat(hDC, pixelFormat, &defaultPixelFormatDescriptor);
	    mini3d_assert(result != 0, "Failed to create default opengl context. SetPixelFormat failed: (%u)", GetLastError());
	
        mRenderContext = wglCreateContext(hDC);
	    wglMakeCurrent(hDC, mRenderContext);
    }
Esempio n. 5
0
font_info get_font_info(HFONT _hFont)
{
	font_info fi;
	LOGFONT lf = {0};
	::GetObject(_hFont, sizeof(lf), &lf);
	fi.name = lf.lfFaceName;
	fi.bold = lf.lfWeight > FW_NORMAL;
	fi.italic = !!lf.lfItalic;
	fi.underline = !!lf.lfUnderline;
	fi.strikeout = !!lf.lfStrikeOut;
	fi.antialiased = lf.lfQuality != NONANTIALIASED_QUALITY;
	scoped_getdc hDC(GetDesktopWindow());
	fi.point_size = logical_height_to_pointf(hDC, lf.lfHeight);
	return fi;
}
Esempio n. 6
0
void CWIN_MFC_KBView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CClientDC hDC(this);
	HBRUSH hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);	//创建 白画刷。
	HPEN hPen = (HPEN)GetStockObject(WHITE_PEN);		//创建白画笔。
	SelectObject(hDC, hPen);				//选入白画刷
	SelectObject(hDC, hBrush);			//选入白画笔
	SetTextColor(hDC, RGB(255, 0, 0));		//设置字体颜色为红色。

											//输出信息。
	if (nUpKeyDown == TRUE) {
		Rectangle(hDC, 0, 0, 300, 200);                         //覆盖字符串
		TextOut(hDC, 0, 0, cUp, _tcslen(cUp));
		nUpKeyDown = FALSE;
	}
	else if (nCtrlAKeyDown == TRUE) {
		Rectangle(hDC, 0, 0, 300, 200);
		TextOut(hDC, 0, 100, cCtrl_A, _tcslen(cCtrl_A));
		nCtrlAKeyDown = FALSE;
		nCtrlKeyDown = FALSE;
	}
	//else if(nCtrlAKeyDown == TRUE) 
	else if (nCtrlKeyDown == TRUE&&nCtrlAKeyDown == FALSE) {
		Rectangle(hDC, 0, 0, 300, 200);
		TextOut(hDC, 0, 60, cCtrl, _tcslen(cCtrl));
		nCtrlKeyDown = FALSE;
	}
	else if (nShiftBKeyDown == TRUE) {
		Rectangle(hDC, 0, 0, 300, 200);
		TextOut(hDC, 0, 0, cShift_B, _tcslen(cShift_B));
		nShiftBKeyDown = FALSE;
		nShiftKeyDown = FALSE;
	}
	else if (nShiftBKeyDown == FALSE&&nShiftKeyDown == TRUE) {
		Rectangle(hDC, 0, 0, 300, 200);
		TextOut(hDC, 0, 0, cShift, _tcslen(cShift));
		nShiftKeyDown = FALSE;
	}
	else if (nOtherKeyDown == TRUE) {
		Rectangle(hDC, 0, 0, 300, 200);
		nOtherKeyDown = FALSE;
	}
	else;


	CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
Esempio n. 7
0
	Implementation(HWND hWnd, size_t width, size_t height, void* memory)
		: hDC_(0), hBitmap_(0), pBitmapData_(0), width_(width), height_(height)
	{
		DCWrapper hDC(hWnd);

		hDC_ = CreateCompatibleDC(hDC);
		if(CreateBitmap(hDC_, width_, height_, hBitmap_, reinterpret_cast<void**>(&pBitmapData_), memory))
			SelectObject(hDC_, hBitmap_);	
		else
		{
			hDC_ = 0;
			hBitmap_ = 0;
			pBitmapData_ = 0;
			throw std::exception("Failed to create bitmap");
		}
	}
Esempio n. 8
0
WXHBRUSH wxNotebook::QueryBgBitmap()
{
    wxRect r = GetPageSize();
    if ( r.IsEmpty() )
        return 0;

    WindowHDC hDC(GetHwnd());
    MemoryHDC hDCMem(hDC);
    CompatibleBitmap hBmp(hDC, r.x + r.width, r.y + r.height);

    SelectInHDC selectBmp(hDCMem, hBmp);

    if ( !DoDrawBackground((WXHDC)(HDC)hDCMem) )
        return 0;

    return (WXHBRUSH)::CreatePatternBrush(hBmp);
}
Esempio n. 9
0
CSize CTaskDialog::GetTextExtent(HFONT hFont, LPCWSTR szText, int cx_width) const
{
	CSize size(0, 0);

	// obtains the number of caracters that fit on each line

	CWindowDC hDC(m_hWnd);
	CFontHandle _hFont = hDC.SelectFont(hFont);

	if (!::GetTextExtentEx(hDC, szText, ::lstrlenW(szText), cx_width, &size)) {
		size.cx = 0;
		size.cy = 0;
	}

	hDC.SelectFont(_hFont);

	return size;
}
	void OGLWindow::destruct()
	{
		if (hRC_)
		{	
			wglMakeCurrent(hDC (), NULL);
			wglDeleteContext(hRC_);
		}
		if (hPalette_)
		{	
			DeleteObject(hPalette_);
		}

		SetWindowLong(hWND_, GWL_USERDATA, (LONG)NULL);

		DestroyWindow(hWND_);

		// if we're in fullscreen, get out of it
		endFullScreen();
	}
Esempio n. 11
0
HFONT make_font(const font_info& _Desc)
{
	scoped_getdc hDC(GetDesktopWindow());
	HFONT hFont = CreateFont(
		point_to_logical_heightf(hDC, _Desc.point_size)
		, 0
		, 0
		, 0
		, _Desc.bold ? FW_BOLD : FW_NORMAL
		, _Desc.italic
		, _Desc.underline
		, _Desc.strikeout
		, DEFAULT_CHARSET
		, OUT_DEFAULT_PRECIS
		, CLIP_DEFAULT_PRECIS
		, _Desc.antialiased ? CLEARTYPE_QUALITY : NONANTIALIASED_QUALITY
		, DEFAULT_PITCH
		, _Desc.name);
	return hFont;
}
Esempio n. 12
0
void CLotteryDlg::_readFrontPagePic()
{
	ShowWindow(SW_HIDE);
	CString strFilePath = _getCurPath() + L"frontpage.bmp";
	CPaintDC hDC(this);
	m_PicWidth = 1;
	m_PicHeight = 1;
	//一次读取生成的随机数对应的编号中的字符串
	if (!_loadPic(strFilePath, &m_FrontPageInfo))
	{
		AfxMessageBox(_T("加载首页图片:") + strFilePath + _T("出错"));
		return ;
	}
	m_FrontPageInfo._width = MulDiv(m_FrontPageInfo._cx, GetDeviceCaps(hDC, LOGPIXELSX), 2540);
	m_FrontPageInfo._height = MulDiv(m_FrontPageInfo._cy, GetDeviceCaps(hDC, LOGPIXELSY), 2540);
	m_PicWidth += m_FrontPageInfo._width;
	if (m_PicHeight < m_FrontPageInfo._height)
		m_PicHeight = m_FrontPageInfo._height;
	_calcMargin();
	ShowWindow(SW_SHOW);
}
Esempio n. 13
0
LRESULT CWidgetAddress::OnEraseBkgnd(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY_CATCH
	HDC hdc=reinterpret_cast<HDC>(wParam);
	PAINTSTRUCT m_ps;
	HDC hDC(hdc?hdc:(BeginPaint(&m_ps)));
	RECT windowRect;
	GetWindowRect(&windowRect);
	ScreenToClient(&windowRect);
	LRESULT res = 0L;
	bHandled=TRUE;
	HPEN pen = CreatePen(PS_SOLID, 1, EdgeColor1);
	HPEN penOld = (HPEN)SelectObject(hDC, pen);
	res = Rectangle(hDC, windowRect.left, windowRect.top, windowRect.right, windowRect.bottom);
	SelectObject(hDC, penOld);
	DeleteObject(pen);
	if (!hdc) 
		EndPaint(&m_ps);
	return res;
CATCH_LOG()
	bHandled=FALSE;
	return 0;
}
	void Window::destruct()
	{
		if (hRC_)
		{	
			wglMakeCurrent(hDC (), NULL);
			wglDeleteContext(hRC_);
			hRC_ = NULL; 
		}
		if (hPalette_)
		{	
			DeleteObject(hPalette_);
		}

		// Should I add this? 
		// release the DC if we have one
		// if (hDC_ && !ReleaseDC(g_hwnd, hDC_))
		// {
		//MessageBox(NULL, "Unable to release device context", "Error", MB_OK | MB_ICONINFORMATION);
		//hDC_ = NULL;
		// }
	  
		SetWindowLong(hWND_, GWL_USERDATA, (LONG)NULL);

		if (hWND_) DestroyWindow(hWND_); 

		//Should I add this? Consider later
		// // unregister our class so we can create a new one if we need to
		// if (!UnregisterClass(WND_CLASS_NAME, g_hInstance))
		// {
		//MessageBox(NULL, "Unable to unregister window class", "Error", MB_OK | MB_ICONINFORMATION);
		//g_hInstance = NULL;
		// }

		// if we're in fullscreen, get out of it
		endFullScreen();
	}
Esempio n. 15
0
DGraphics::FontResourcePtr DGraphics::loadFont(const wchar_t *fontName,
	uint32_t startChar, uint32_t endChar, uint32_t w, uint32_t h)
{
	HRESULT hr = S_OK;

	// Create font
	HFONT htmpFont = ::CreateFont(
		h, 0, 0, 0, 0, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
		OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
		FIXED_PITCH | FF_MODERN, fontName);
	checkWin32Result(htmpFont != nullptr, "CreateFont() failed");
	auto fontDel = [](HFONT hFont) { ::DeleteObject(hFont); };
	std::unique_ptr<std::remove_pointer<HFONT>::type, decltype(fontDel)>
		hFont(htmpFont, fontDel);
	// Get DC
	HDC htmpDC = ::GetDC(nullptr);
	checkWin32Result(htmpDC != nullptr, "GetDC() failed");
	auto dcRel = [](HDC hDC) { ::ReleaseDC(nullptr, hDC); };
	std::unique_ptr<std::remove_pointer<HDC>::type, decltype(dcRel)>
		hDC(htmpDC, dcRel);
	// Select font
	HFONT tmpOldFont = static_cast<HFONT>(::SelectObject(hDC.get(), hFont.get()));
	checkWin32Result(tmpOldFont != nullptr, "SelectObject() failed");
	auto restoreObj = [&hDC](HFONT oldFont) { ::SelectObject(hDC.get(), oldFont); };
	std::unique_ptr<std::remove_pointer<HFONT>::type, decltype(restoreObj)>
		hOldFont(tmpOldFont, restoreObj);

	TEXTMETRIC tm = { 0 };
	checkWin32Result(::GetTextMetrics(hDC.get(), &tm) != FALSE,
		"GetTextMetrics() failed");

	std::vector<FontTexture::TexPtr> texList;
	std::vector<FontTexture::RvPtr> rvList;
	texList.reserve(endChar - startChar + 1);
	rvList.reserve(endChar - startChar + 1);

	for (uint32_t c = startChar; c <= endChar; c++) {
		// Get font bitmap
		GLYPHMETRICS gm = { 0 };
		const MAT2 mat = { { 0, 1 },{ 0, 0 },{ 0, 0 },{ 0, 1 } };
		DWORD bufSize = ::GetGlyphOutline(hDC.get(), c, GGO_GRAY8_BITMAP, &gm, 0, nullptr, &mat);
		checkWin32Result(bufSize != GDI_ERROR, "GetGlyphOutline() failed");
		auto buf = std::make_unique<uint8_t[]>(bufSize);
		DWORD ret = ::GetGlyphOutline(hDC.get(), c, GGO_GRAY8_BITMAP, &gm, bufSize, buf.get(), &mat);
		checkWin32Result(ret != GDI_ERROR, "GetGlyphOutline() failed");
		uint32_t pitch = (gm.gmBlackBoxX + 3) / 4 * 4;
		// Black box pos in while box
		uint32_t destX = gm.gmptGlyphOrigin.x;
		uint32_t destY = tm.tmAscent - gm.gmptGlyphOrigin.y;

		// Create texture
		D3D11_TEXTURE2D_DESC desc = { 0 };
		desc.Width = w;
		desc.Height = h;
		desc.MipLevels = 1;
		desc.ArraySize = 1;
		desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		desc.SampleDesc.Count = 1;
		desc.Usage = D3D11_USAGE_DYNAMIC;
		desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		ID3D11Texture2D *ptmpTex = nullptr;
		hr = m_pDevice->CreateTexture2D(&desc, nullptr, &ptmpTex);
		checkDXResult<D3DError>(hr, "ID3D11Device::CreateTexture2D() failed");
		// make unique_ptr and push
		texList.emplace_back(ptmpTex);

		// Write
		D3D11_MAPPED_SUBRESOURCE mapped;
		UINT subres = ::D3D11CalcSubresource(0, 0, 1);
		hr = m_pContext->Map(ptmpTex, subres, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
		checkDXResult<D3DError>(hr, "ID3D11DeviceContext::Map() failed");
		uint8_t *pTexels = static_cast<uint8_t *>(mapped.pData);
		::ZeroMemory(pTexels, w * h * 4);
		for (uint32_t y = 0; y < gm.gmBlackBoxY; y++) {
			for (uint32_t x = 0; x < gm.gmBlackBoxX; x++) {
				if (destX + x >= w || destY + y >= h) {
					continue;
				}
				uint32_t alpha = buf[y * pitch + x] * 255 / 64;
				uint32_t destInd = (((destY + y) * w) + (destX + x)) * 4;
				pTexels[destInd + 0] = 0;
				pTexels[destInd + 1] = 0;
				pTexels[destInd + 2] = 0;
				pTexels[destInd + 3] = alpha;
			}
		}
		m_pContext->Unmap(ptmpTex, subres);

		// Create resource view
		ID3D11ShaderResourceView *ptmpRV = nullptr;
		hr = m_pDevice->CreateShaderResourceView(ptmpTex, nullptr, &ptmpRV);
		checkDXResult<D3DError>(hr, "ID3D11Device::CreateShaderResourceView() failed");
		// make unique_ptr and push
		rvList.emplace_back(ptmpRV);
	}

	// add (id, FontTexture(...))
	auto res = std::make_shared<FontTexture>(
		w, h, startChar, endChar);
	res->pTexList.swap(texList);
	res->pRVList.swap(rvList);
	return res;
}
Esempio n. 16
0
 void SwapWindowBuffers(void* nativeSurface) { SafeHDC hDC((HWND)nativeSurface); SwapBuffers(hDC); }
Esempio n. 17
0
void CLotteryDlg::OnPaint()
{
	if (IsIconic())
	{
	}
	else
	{
		CPaintDC hDC(this);
		CRect rect(m_RenderRect);
		GetClientRect(&rect);
		//rect.InflateRect(10, 10);

		//绘制数字图片
		int xPos = m_leftWidth, yPos = m_RenderRect.top;
		int index = 0;
		//int num = sizeof(m_RenderInfo)/sizeof(m_RenderInfo[0]);
		//for (int i = 0; i < num; ++i)
		//{
		//	index = m_RenderInfo[i]._no;
		//	HRESULT hRes = m_PicInfo[index]._iPic->Render(hDC, xPos, yPos, m_PicInfo[index]._width, m_PicInfo[index]._height, 
		//		m_PicInfo[index]._x, m_PicInfo[index]._cy, m_PicInfo[index]._cx, -m_PicInfo[index]._cy, NULL);
		//	xPos += m_PicWidth + m_innerWidth;
		//}
		try
		{
			//一次只显示一个图片
			index = m_CurPartnerNoInRandList;
			int picHeight = m_PartnerPicInfo[index]._height;
			int picWidth = m_PartnerPicInfo[index]._width;
			if (picWidth == 0)
				picWidth = 1;
			double ratio = double(picHeight) / double(picWidth);
			if (ratio < 0.001)
				ratio = 1.0;

			if (picHeight > rect.Height() * HEIGHTRATIO)//这里计算保证最大在指定的区域内
			{
				picHeight = int(rect.Height() * HEIGHTRATIO);
				picWidth = int(rect.Height() * HEIGHTRATIO / ratio);
			}
			yPos = rect.CenterPoint().y - picHeight/2;
			xPos = rect.CenterPoint().x - picWidth/2;
			if (!m_bFirstFlash)
			{
				HRESULT hRes = m_PartnerPicInfo[index]._iPic->Render(hDC, xPos, yPos-1, picWidth, picHeight, 
					m_PartnerPicInfo[index]._x, m_PartnerPicInfo[index]._cy, m_PartnerPicInfo[index]._cx, -m_PartnerPicInfo[index]._cy, NULL);
			}
			else
			{
				if (m_FrontPageInfo._iPic != NULL)
				{
					HRESULT hRes = m_FrontPageInfo._iPic->Render(hDC, xPos, yPos, picWidth, picHeight, 
						m_FrontPageInfo._x, m_FrontPageInfo._cy, m_FrontPageInfo._cx, -m_FrontPageInfo._cy, NULL);
				}
			}
		}
		catch(...)
		{
			return ;
		}
		SetTextAlign(hDC, TA_LEFT | TA_BOTTOM);
		//绘制界面信息
		_drawWinnerInfo(&hDC);
		_drawLotteryInfo(&hDC);
		_drawTips(&hDC);
		//print();

		CDialog::OnPaint();
	}
}