2 wemzwym wemzwym 于 2013.12.02 21:45 提问

窗口显示不出汉字 打印机也打印不出汉字 textout函数输出汉字变为 |竖线

#include
#include
LPCTSTR bmp_filename = "C:\photo\aaa.bmp";
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
HWND hwMain;
HANDLE hbmp = NULL;
const int ID_FILE_PRINT = LINE;
int get_line_height(HDC hdc)
{ //return text line height
//return value < 0 if map mode is not MM_TEXT, so that you can always use
//y+= line_height when drawing to device.
int map_mode = GetMapMode(hdc);
TEXTMETRIC tm;
GetTextMetrics(hdc,&tm);
int h = tm.tmHeight + tm.tmExternalLeading;
if(MM_TEXT != map_mode)
h = 0 - h;
return h;
}
double get_screen_pixel_width(int map_mode)
{ //purpose: a pixel displayed in MM_TEXT mode should be about the same size
//when displayed in other map mode.
HDC hdc = GetDC(NULL);
double hroz_size = GetDeviceCaps(hdc,HORZSIZE);//Width, in millimeters, of the physical screen.
double horz_res = GetDeviceCaps(hdc, HORZRES);//Width, in pixels, of the screen.
double pixel_width = hroz_size / horz_res; // Width, in millimeters
// 1 inch = 25.4 mm
const double INCH_TO_MM = 25.4;
const double INCH_TO_TWIP = 1440;
switch(map_mode)
{
case MM_LOMETRIC:
pixel_width = 10;

break;
case MM_HIMETRIC:
pixel_width *= 100;
break;
case MM_TEXT:
break;
case MM_LOENGLISH: //Each logical unit is mapped to 0.01 inch
pixel_width = pixel_width / INCH_TO_MM * 100;
break;
case MM_HIENGLISH: //Each logical unit is mapped to 0.001 inch
pixel_width = pixel_width / INCH_TO_MM * 1000;
break;
case MM_TWIPS: //Each logical unit is mapped to one twentieth of a printer's point (1/1440 inch, also called a twip).
pixel_width = pixel_width / INCH_TO_MM * INCH_TO_TWIP;
break;
default:
break;
}
return pixel_width;//Width, in logical units according to the map_mode
}
void draw(HDC hdc)
{
if(hbmp == NULL)
{
hbmp = (HANDLE)LoadImage( NULL,bmp_filename ,
IMAGE_BITMAP, 0,0,LR_LOADFROMFILE);
}

int map_mode = MM_TWIPS;
LPCTSTR map_name1 ="abc我想打印中文";
LPCTSTR map_name2 = "def我想打印中文";
SetMapMode(hdc,map_mode); //Each logical unit is mapped to 0.1 millimeter.
int x = 0;
int y = 0;
int line_h = get_line_height(hdc);
SelectObject(hdc,GetStockObject(BLACK_PEN));
SetBkMode(hdc, TRANSPARENT);
int len = strlen(map_name1);
len = strlen(map_name2);
TextOut(hdc,x, y,map_name1,strlen(map_name1));
y += line_h;
TextOut(hdc,x, y,map_name2,strlen(map_name2));
if( NULL != hbmp)
{ x=x+2500;y=0;

BITMAP bm;
GetObject( hbmp, sizeof(BITMAP), &bm );
long width=bm.bmWidth;
long height=bm.bmHeight;
HDC memdc = CreateCompatibleDC(hdc);
HGDIOBJ oldbmp = SelectObject(memdc,hbmp);
double pixel_size = get_screen_pixel_width(map_mode);
int bmp_draw_width = (int)(width * pixel_size) ;
int bmp_draw_height = (int)(height * pixel_size) ;
StretchBlt(hdc,x,y, bmp_draw_width ,-bmp_draw_height, memdc, 0,0,width,height,SRCCOPY);
SelectObject(memdc,oldbmp);
DeleteDC(memdc);
}
else
{
LPCTSTR error_msg = "failed to load bitmap from file";
TextOut(hdc,x,5*y,error_msg,strlen(error_msg));
}

}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int iCmdShow)
{
MSG msg;
WNDCLASSEX wndclass ;
HMENU hMenu,hMenuA;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "PrintDemo";
wndclass.hIconSm = NULL;
RegisterClassEx (&wndclass);
hwMain=CreateWindow (wndclass.lpszClassName,NULL,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,500,568,NULL,NULL,hInstance,NULL);
hMenu=CreateMenu();
hMenuA=CreateMenu();
AppendMenu(hMenuA,MF_STRING,ID_FILE_PRINT,"Print");
AppendMenu(hMenu,MF_POPUP,(UINT)hMenuA,"File");
SetMenu(hwMain,hMenu);
ShowWindow (hwMain,iCmdShow);
UpdateWindow (hwMain);
while (GetMessage (&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam ;
}
/
This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static PRINTDLG pd;
static DOCINFO dci;
static LPTSTR lpszDocName="Print Test";
switch (iMsg)
{
case WM_CREATE:
pd.lStructSize=sizeof(pd);
pd.hwndOwner=hwnd;
pd.hDevMode=NULL;
pd.hDevNames=NULL;
pd.Flags=PD_RETURNDC|PD_HIDEPRINTTOFILE |PD_RETURNDEFAULT;
pd.nFromPage=1;
pd.nToPage=1;
pd.nMinPage=1;
pd.nMaxPage=1;
pd.nCopies=1;
dci.cbSize=sizeof(dci);
dci.lpszDocName=lpszDocName;
dci.lpszOutput=NULL;
dci.lpszDatatype=NULL;
dci.fwType=0;
return 0;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_FILE_PRINT:
if (!PrintDlg(&pd))
return 0;
hdc=pd.hDC;
StartDoc(hdc,&dci);
StartPage(hdc);
draw(hdc);
EndPage(hdc);
EndDoc(hdc);
break;
}
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
draw(hdc);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY :
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
解决xcode9之后log打印不出中文的问题
一:创建类扩展文件Xcode9第一步: command + N(新建文件)—&amp;gt;Objective-C File 第二步: (1)填写扩展文件命名 (2)文件类别选择Category (3)选择需要扩展的类。 第三步: 编写代码,扩展自己想要扩展的类方法。二:文件内容////  NSArray+QCLog.h//  WitServices////  Created by QC on 2017/...
Altium design 的smart pdf 打印不出汉字来。
(1)可以观看原理图中给出的汉字标注的属性,可知默认是times new roman的西方字符格式,在对话框的“字符集”下显示“西方”。如下图的字体对话框(双击原理图中的字体标注,点击front的change按钮即可调出)。
关于xcode打印数组或者字典,打印不出中文的解决
在开发中,我们经常需要打印数组或则字典,以方便调试,但是发现当数组或者字典里面含有中文的时候,打印出来的都是未经转码的字母,解决这个问题就是给字典和数组添加了个分类,并且重写了description方法,下面是.h和.m文件,只要在项目的pch文件导入.h文件就行了..h文件// // NSDictionary+LOG.h // shiyan打印 // // Created by aimee
TextOut输出中文汉字——记练习程序员表白程序
程序练习来自博客:_BlueCoder_ http://blog.csdn.net/crocodile__/article/details/9527845
python中不能输出中文的解决方法
法一: print u'正数' 法二: 加入 import sys reload(sys) sys.setdefaultencoding('utf-8')
pycharm输出中文出现乱码的几种解决方法以及读取时打印出现乱码的解决
pycharm打印中文出现乱码,有几种情况 第一种: 对于这种情况,是普通的一种,你需要检查开头,是否加了 # -*- coding:utf-8 -*-还有import sys reload(sys) sys.setdefaultencoding('utf-8') 对于这两个处理中文输出的代码,最好每次处理中文时就加上,会减少很多问题 第二种问题:
stemwin的汉字显示
stemwin功能很强大,封装了对lcd的常见操作,屏蔽了lcd层的接口函数。但却还没有集成中文字库,这不能不说是一个遗憾。网上关于stemwin的中文字库教程能讲详细的只有一篇安富莱的《第18章:汉字显示方式一(FontCvt的使用)》,笔者按教程操作后发现始终不能显示。折腾2天打算放弃之际,终于柳暗花明成功在lcd上显示中文。这里特别感谢《emWin - 汉字字库生成及显示》一文,完美解决了我
qt中qDebug()能正常显示中文,控件却无法显示中文的情况
我从数据库中取出数据,每当取出数据为中文时,则无法正常显示,(通过QString::fromLocal8Bit())来将char*转换,但是发现qDebug中能打印,把网上设置中文乱码的都尝试了一遍,发现并没有啥用.但是根据qt4和qt5的变化中发现,尽管qt4中解决中文乱码的问题无法在qt5中使用,但是qt5依旧保留了一个接口QTextCodec::setCodecForLocale();于是我
Windows SDK程序的输出文字和格式控制(wsprintf、swprintf、Textout)
程序的输出如上图; 输出相关的代码如下; TCHAR szBuffer [40] ; TCHAR szHello[] = TEXT("Hello, C-Free!"); int iLength ; TextOut (hdc, 200, 20, "Hello, C-Free!", 14) ; TextOut (hdc, 200, 40, szHello, 14) ; iLeng
JAVA调用 TSC 打印机 打印中文问题/JNA中文乱码
问题1:项目中需要使用tsc条码打印机打印条形码和中文