示例#1
0
void CSkinDialog::OnNcMouseMove(UINT nHitTest, CPoint point)
{
    // TODO: Add your message handler code here and/or call default

    // CXTPDialog::OnNcMouseMove(nHitTest, point);

    if(nHitTest == HTCAPTION)// || (nHitTest!=HTCAPTION && m_nButtonMove>0))
    {
        int nHit = GetSysButtonsHitTest(point);

        Rect rc, rc1;

        if(m_nButtonMove!=nHit)
        {
            m_nButtonMove = nHit;

            CRect rcWindow;
            GetWindowRect(rcWindow);

            Bitmap bmpBuf(rcWindow.Width(), rcWindow.Height());
            Graphics graphics(&bmpBuf);
            Graphics g(GetWindowDC()->GetSafeHdc());

            // x
            rc = nHit==HT_CLOSE?m_mapRect["NcBtnCloseOvr"]:m_mapRect["NcBtnClose"];
            rc1.X = rcWindow.Width()-m_mapRect["NcBtnClosePos"].X;
            rc1.Y = m_mapRect["NcBtnClosePos"].Y;
            rc1.Width = rc.Width;
            rc1.Height = rc.Height;
            graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

            // 口

            if(GetStyle()&WS_MAXIMIZEBOX)
            {
                rc = nHit==HT_MAX?(IsZoomed()?m_mapRect["NcBtnResOvr"]:m_mapRect["NcBtnMaxOvr"]):(IsZoomed()?m_mapRect["NcBtnRes"]:m_mapRect["NcBtnMax"]);
                rc1.X = rcWindow.Width()-m_mapRect["NcBtnMaxPos"].X;
                rc1.Y = m_mapRect["NcBtnMaxPos"].Y;
                rc1.Width = rc.Width;
                rc1.Height = rc.Height;
                graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
            }

            // -
            if(GetStyle()&WS_MINIMIZEBOX)
            {
                rc = nHit==HT_MIN?m_mapRect["NcBtnMinOvr"]:m_mapRect["NcBtnMin"];
                rc1.X = rcWindow.Width()-m_mapRect["NcBtnMinPos"].X;
                rc1.Y = m_mapRect["NcBtnMinPos"].Y;
                rc1.Width = rc.Width;
                rc1.Height = rc.Height;
                graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
            }
            g.DrawImage(&bmpBuf, 0, 0);
        }
    }

}
示例#2
0
文件: Display.cpp 项目: sevico/MyVM
// 把DispTextBuf的内容输出到屏幕上去
// 对于属性相同的连续的字符,是以字符串而不是字符的形式TextOut的
int TextBufOut()
{
	PAINTSTRUCT ps;	
	HDC hdc = BeginPaint(hMyWnd, &ps);
	Graphics    rgraphics(hdc);
	SolidBrush  brush(Color(255, 255, 255, 255));	
	FontFamily  fontFamily(L"Courier New");
#ifdef _GDIP_
	double		WHscale=0.54112554;									//Courier New字体的宽高比
#else
	double		WHscale=0.5;
#endif	
	Gdiplus::Font        font(&fontFamily, (float)rect.bottom/TextSolutionY*0.882759, FontStyleBold, UnitPixel);			//0.882759=font.GetSize()/font.GetHeight(0.0);  这是对应于Courier New字体的值。	
	SolidBrush	CurBrush(Color(255, 255, 255, 255));

	Bitmap		bmpBuf(rect.right,rect.bottom);							//双缓冲
	Graphics	graphics(&bmpBuf);	

	PointF      pointF(0.0f, 0.0f);
	float		tempFX;
	float		CurX,CurY;

	wchar_t		ws[100];
	int			lao;
	
//////////////////////////////////////////////////////////////////////////
	HFONT   hFont;
	hFont=CreateFont((float)rect.bottom/TextSolutionY,0,0,0,FW_MEDIUM,   
		FALSE,FALSE,FALSE,DEFAULT_CHARSET,   
		OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,   
		VARIABLE_PITCH|PROOF_QUALITY,FF_DONTCARE,"Lucida Console");
	SelectObject(hdc,hFont);   
//////////////////////////////////////////////////////////////////////////
	
	
	//下面被注释掉的语句都是用GDI+时使用的。
	//graphics.Clear(Color(0,0,0));									//清除原先的内容。
	
	int pTextBufCur=0;
#ifdef _GDIP_
	unsigned short Txt[80*25+1]={L"石维康"};
#else
	char Txt[80*25+1]={"石维康"};
#endif
	pointF.Y=0;
	int j;
	for (int i=0;i<TextSolutionY;i++)
	{		
		int TxtLen=0;
		int PTxtLen=0;		
		char CurCharAttr=DispTextBuf[i*(*TextSolutionX)*2+1];	//第一个字符的属性
		pointF.X=0;
		for (j=0;j<(*TextSolutionX);j++)
		{
			if (CurCharAttr!=DispTextBuf[pTextBufCur+1])			//遇到不同属性,要输出字符串了
																									//不在串开关的LowAscii将不得不输出,所以每遇到LowAscii都要重起一串
			{
#ifdef _GDIP_
				pointF.X=(float)(PTxtLen)*font.GetHeight(0.0)*WHscale;//(rect.right/(*TextSolutionX));
				pointF.Y=font.GetHeight(0.0)*(i);
#else				
				GetCharWidthFloat(hdc,'A','A',&tempFX);
				pointF.X+=(float)(PTxtLen)*16*tempFX;
#endif
				PTxtLen=TxtLen;
				
#ifdef _GDIP_
				brush.SetColor(AttrToColorP(CurCharAttr&0x0f),CurCharAttr&0x80);
				graphics.DrawString(Txt,TxtLen,&font,pointF,&brush);
#else
				SetTextColor(hdc,AttrToColor(CurCharAttr&0x0f,CurCharAttr&0x80));
				SetBkColor(hdc,AttrToColor(((CurCharAttr&0xf0)>>4)&0x07,false)&0xffffff);				
// 				if (Txt[0]>=0xa9 && Txt[0]<=0xdf)					//只输出扩展Ascii里面的制表符。其实MyVM里应该有一个地方来设定是否可以输出中文
// 					OutHighAscii(hdc,&pointF.X,&pointF.Y,Txt,&TxtLen,(float)16*tempFX);				
// 				if ((unsigned char)Txt[0]<0x20 && Txt[0]!=0x00)									//输出箭头和心形等
// 				{
// 					lao=OutLowAscii(hdc,&pointF.X,&pointF.Y,(unsigned char *)Txt,&TxtLen,(float)16*tempFX);
// 					//pTextBufCur+=lao*2;
// 				}
// 				else
// 					lao=0;
				MultiByteToWideChar(437,0,Txt,TxtLen,ws,100);
				TextOutW(hdc,pointF.X,pointF.Y,ws,TxtLen);
#endif								
				TxtLen=0;
				CurCharAttr=DispTextBuf[pTextBufCur+1];
			}
			//else													//遇到相同属性,把它加到Txt后面就可以了
			{
#ifdef _GDIP_
				if (DispTextBuf[pTextBufCur+1]>0 && DispTextBuf[pTextBufCur+1]<0x80)	//ASCII码
#endif
				{				
					Txt[TxtLen]=DispTextBuf[pTextBufCur];
					Txt[++TxtLen]=0;
					pTextBufCur+=2;
				}
#ifdef _GDIP_
				else																//Unicode字符
				{
					Txt[TxtLen]=(unsigned char)DispTextBuf[pTextBufCur];
					Txt[TxtLen]<<=8;
					pTextBufCur+=2;
					j++;
					Txt[TxtLen]+=(unsigned char)DispTextBuf[pTextBufCur];
					Txt[++TxtLen]=0;
					pTextBufCur+=2;
				}
#endif
			}	
		}

#ifdef _GDIP_
		pointF.X=(float)(j-TxtLen)*font.GetHeight(0.0)*WHscale;
		pointF.Y=font.GetHeight(0.0)*(i);
#else
		GetCharWidthFloat(hdc,'A','A',&tempFX);
		pointF.X=(float)(j-TxtLen)*16*tempFX;
#endif
		
#ifdef _GDIP_
		brush.SetColor(AttrToColorP(CurCharAttr&0x0f,CurCharAttr&0x80));
		graphics.DrawString(Txt,TxtLen,&font,pointF,&brush);		
#else
		SetTextColor(hdc,AttrToColor(CurCharAttr&0x0f,CurCharAttr&0x80));
		SetBkColor(hdc,AttrToColor(((CurCharAttr&0xf0)>>4)&0x07,false)&0xffffff);		
// 		if (Txt[0]>=0xa9 && Txt[0]<=0xdf)					//只输出扩展Ascii里面的制表符。其实MyVM里应该有一个地方来设定是否可以输出中文
// 			OutHighAscii(hdc,&pointF.X,&pointF.Y,Txt,&TxtLen,(float)16*tempFX);
// 		if ((unsigned char)Txt[0]<0x20 && Txt[0]!=0x00)									//输出箭头和心形等
// 		{
// 			lao=OutLowAscii(hdc,&pointF.X,&pointF.Y,(unsigned char *)Txt,&TxtLen,(float)16*tempFX);
// 			//pTextBufCur+=lao*2;
// 		}
// 		else
// 			lao=0;
		MultiByteToWideChar(437,0,Txt,TxtLen,ws,100);
		TextOutW(hdc,pointF.X,pointF.Y,ws,TxtLen);
		pointF.Y+=(int)font.GetHeight(0.0);							//pointF.Y是浮点,TextOut的参数是整形,浮点误差的积累会产生黑线
#endif
	}
示例#3
0
void CSkinDialog::OnNcPaint()
{
    // TODO: Add your message handler code here

    if(!CImgSkin::IsLoaded())
    {
        CXTPDialog::OnNcPaint();
        return;
    }

    if(HasStyle(WS_CHILD))
    {
        return;
    }

    /*
    RECT ClientRect;
    GetClientRect(&ClientRect);
    OffsetRect(&ClientRect, 100, 100);
    ExcludeClipRect(GetWindowDC()->GetSafeHdc(), ClientRect.left, ClientRect.top,
    	ClientRect.right, ClientRect.bottom);
    */

    CRect rcWindow;
    GetWindowRect(&rcWindow);

    Bitmap bmpBuf(rcWindow.Width(), rcWindow.Height());
    Graphics graphics(&bmpBuf);
    Graphics g(GetWindowDC()->GetSafeHdc());

    Rect rc, rc1;

    // Title Left
    rc = m_bActive?m_mapRect["TitleLeftActive"]:m_mapRect["TitleLeft"];
    rc1.X = 0;
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Center
    rc = m_bActive?m_mapRect["TitleCenterActive"]:m_mapRect["TitleCenter"];
    rc1.X = m_mapRect["TitleLeftActive"].Width;
    rc1.Y = 0;
    rc1.Width = rcWindow.Width()-m_mapRect["TitleLeftActive"].Width-m_mapRect["TitleRightActive"].Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Right
    rc = m_bActive?m_mapRect["TitleRightActive"]:m_mapRect["TitleRight"];
    rc1.X = rc1.GetRight();
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Left
    rc = m_bActive?m_mapRect["BorderLeftActive"]:m_mapRect["BorderLeft"];
    rc1.X = 0;
    rc1.Y = m_mapRect["TitleLeftActive"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Bottom
    rc = m_bActive?m_mapRect["BorderBotActive"]:m_mapRect["BorderBot"];
    rc1.X = 0;
    rc1.Y = rcWindow.Height()-rc.Height-1;
    rc1.Width = rcWindow.Width();
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Right
    rc = m_bActive?m_mapRect["BorderRightActive"]:m_mapRect["BorderRight"];
    rc1.X = rcWindow.Width()-rc.Width-1;
    rc1.Y = m_mapRect["TitleLeftActive"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Close Button
    rc = m_nButtonDown==HT_CLOSE?m_mapRect["NcBtnCloseDown"]:m_mapRect["NcBtnClose"];
    rc1.X = rcWindow.Width()-m_mapRect["NcBtnClosePos"].X;
    rc1.Y = m_mapRect["NcBtnClosePos"].Y;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Max Button
    if(GetStyle()&WS_MAXIMIZEBOX)
    {
        rc = IsZoomed()?(m_nButtonDown==HT_MAX?m_mapRect["NcBtnResDown"]:m_mapRect["NcBtnRes"]):(m_nButtonDown==HT_MAX?m_mapRect["NcBtnMaxDown"]:m_mapRect["NcBtnMax"]);
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMaxPos"].X;
        rc1.Y = m_mapRect["NcBtnMaxPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    // Min Button
    if(GetStyle()&WS_MINIMIZEBOX)
    {
        rc = m_nButtonDown==HT_MIN?m_mapRect["NcBtnMinDown"]:m_mapRect["NcBtnMin"];
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMinPos"].X;
        rc1.Y = m_mapRect["NcBtnMinPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    Font myFont(L"宋体", 9);
    Color col(255,0,0,0);
    col.SetFromCOLORREF(m_mapColor["Caption"]);
    SolidBrush blackBrush(col);

    StringFormat format;
    format.SetAlignment(StringAlignmentNear);

    RectF layoutRect(::GetSystemMetrics(SM_CYICON)+m_mapRect["TitleTextStart"].X, m_mapRect["TitleTextStart"].Y, rcWindow.Width(), rcWindow.Height());

    WCHAR string[MAX_PATH] = {0};
    CString str;
    GetWindowText(str);

    MultiByteToWideChar( CP_ACP, 0, str, -1, string, MAX_PATH) ;

    graphics.DrawString(string,	-1, &myFont, layoutRect, &format, &blackBrush);

    g.DrawImage(&bmpBuf, 0, 0);

    // Do not call CXTPDialog::OnNcPaint() for painting messages
}
示例#4
0
void CSkinDialog::OnPaint()
{
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here

    if(!CImgSkin::IsLoaded())
    {
        CXTPDialog::OnPaint();
        return;
    }

    Rect rc, rc1;
    CRect rcWindow;
    GetClientRect(&rcWindow);

    Bitmap bmpBuf(rcWindow.Width(), rcWindow.Height());
    Graphics graphics(&bmpBuf);
    Graphics g(dc.GetSafeHdc());

    // dialog frame
    //if(!HasStyle(WS_CHILD))
    //	DrawFrame(g);

    rc = m_mapRect["Background"];

    // Top
    rc1.X = rcWindow.left;
    rc1.Y = rcWindow.top;
    rc1.Width = rc.Width/3;
    rc1.Height = rc.Height/3;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width/3, rc.Height/3, UnitPixel);

    rc1.X = rcWindow.left+rc.Width/3;
    rc1.Width = rcWindow.Width()-rc.Width/3*2;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft()+rc.Width/3, rc.GetTop(), rc.Width/3, rc.Height/3, UnitPixel);

    rc1.X = rcWindow.right-rc.Width/3;
    rc1.Width = rc.Width/3;
    graphics.DrawImage(m_pImg, rc1, rc.GetRight()-rc.Width/3, rc.GetTop(), rc.Width/3, rc.Height/3, UnitPixel);


    //Center
    rc1.X = rcWindow.left;
    rc1.Y = rcWindow.top+rc.Height/3;
    rc1.Width = rc.Width/3;
    rc1.Height = rcWindow.bottom-rc.Height/3*2;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop()+rc.Height/3, rc.Width/3, rc.Height/3, UnitPixel);

    rc1.X = rcWindow.left+rc.Width/3;
    rc1.Width = rcWindow.Width()-rc.Width/3*2;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft()+rc.Width/3, rc.GetTop()+rc.Height/3, rc.Width/3, rc.Height/3, UnitPixel);

    rc1.X = rcWindow.right-rc.Width/3;
    rc1.Width = rc.Width/3;
    graphics.DrawImage(m_pImg, rc1, rc.GetRight()-rc.Width/3, rc.GetTop()+rc.Height/3, rc.Width/3, rc.Height/3, UnitPixel);

    //Bottom
    rc1.X = rcWindow.left;
    rc1.Y = rcWindow.bottom-rc.Height/3;
    rc1.Width = rc.Width/3;
    rc1.Height = rc.Height/3;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetBottom()-rc.Height/3, rc.Width/3, rc.Height/3, UnitPixel);

    rc1.X = rcWindow.left+rc.Width/3;
    rc1.Width = rcWindow.right-rc.Width/3*2;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft()+rc.Width/3, rc.GetBottom()-rc.Height/3, rc.Width/3, rc.Height/3, UnitPixel);

    rc1.X = rcWindow.right-rc.Width/3;
    rc1.Width = rc.Width/3;
    graphics.DrawImage(m_pImg, rc1, rc.GetRight()-rc.Width/3, rc.GetBottom()-rc.Height/3, rc.Width/3, rc.Height/3, UnitPixel);

    g.DrawImage(&bmpBuf, 0, 0);
    // Do not call CXTPDialog::OnPaint() for painting messages
}