vs2005 wide byte to multi-byte-multi-byte to wide byte to set the font and color

vs2005 wide-byte to multi-byte

const int bufSize = 512;
    TCHAR buffer2[bufSize];
    //GetWindowText(buffer2, bufSize);
	
	GetWindowText(buffer2, bufSize);
	
   

	//std::string str2;
	//str2 = _bstr_t(buffer2).operator const char*();

	char buffer3[255];
	//sprintf_s(buffer, sizeof(buffer), "%s", buffer2.c_str());

	//sprintf(buffer,"%s",buffer2);
	char * buffer;
    int len= WideCharToMultiByte( CP_ACP ,0,buffer2 ,wcslen( buffer2 ), NULL,0, NULL ,NULL );
    buffer= new char[len+1];
    WideCharToMultiByte( CP_ACP ,0,buffer2 ,wcslen( buffer2 ),buffer,len, NULL ,NULL );
    buffer[len]= '\0';

	//
	// Draw and label the button using draw methods 
	//
    DrawFilledRect(pDC, btnRect, GetBGColor()); 
    DrawFrame(pDC, btnRect, GetBevel());
  	DrawButtonText(pDC, btnRect, buffer, GetFGColor());

Multi-byte to wide byte

void CColorButton::DrawButtonText(CDC *DC, CRect R, const char *Buf, COLORREF TextColor)
{
	CString Buf2;
	//Buf2 = _bstr_t(Buf).operator TCHAR *();
	Buf2=Buf;
    COLORREF prevColor = DC->SetTextColor(TextColor);
    DC->SetBkMode(TRANSPARENT);
//	DC->DrawText(Buf, strlen(Buf), R, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
	DC->DrawText(Buf2,Buf2.GetLength(), R, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	DC->SetTextColor(prevColor);


}

 

Guess you like

Origin blog.csdn.net/txwtech/article/details/113873836