unix系统下的banner是用于显示点阵字体的程序cygwin下有类似的程序可以在windows下跑,但是不支持中文.
所以自己写了一个windows下的类似程序,自己建一个控制台工程(需支持mfc)后,把下面的代码复制一下就可以了.同时,新年快到了,祝大家:
# ## ## # ## # ####
###### ### ######### # # # #######
# # # ## ## # # ######## # ##
###### ####### ########## # # # # ## ##
# ## ## ## # ## ## # # #### ############
###### # ## ############### # ########## # ###
### ### ## ## ## #### # # # # ## ## ##
#### ## ## ## # ## ## ### ## ####
# ## # ## ## # ### ## # # ## ##
# ## ## ##
8 88 8 8 8 88
8888888888 88888888888 88 8 88 88888 88
8 8 888888888 8 8 8 8 8 88888888
8888 888888 8888888 888888888 8 8 8 8888
888 88 88 88 88888 8 8 8 888
88 8 888 8888 88 88 8 8 8 8888
8888 8 8888 888 88888888888888 88 88 888 8888 88
8 88 88 8 88888888 8888 88 888 8888 88
8 888 8 8 88 88 8888 8888 888 88 8888
88 88888888 8 8
使用方式
wbanner [-c 填充字符] [-f 字体名称] [-s 字体大小] 显示文本
/////////////////
//
wbanner_6.cpp : Defines the entry point for the console application.
//
#include
"
stdafx.h
"
#include
"
wbanner_6.h
"
#ifdef _DEBUG
#define
new DEBUG_NEW
#undef
THIS_FILE
static
char
THIS_FILE[]
=
__FILE__;
#endif
///////////////////////////////////////////////////////////////////////////
//
//
The one and only application object
CWinApp theApp;
using
namespace
std;
#define
BMP_WIDTH 100
#define
BMP_HEIGHT 30
void
ParseArg(CString
&
info, CString
&
fill_str,CString
&
font_name,
int
&
font_size,
int
argc,TCHAR
*
argv[])
{
int
i;
for
(i
=
1
; i
<
argc; i
++
) {
if
(strcmp(argv[i],
"
-c
"
)
==
0
&&
i
<
argc) {
fill_str
=
argv[
++
i];
continue
;
}
if
(strcmp(argv[i],
"
-f
"
)
==
0
&&
i
<
argc) {
font_name
=
argv[
++
i];
continue
;
}
if
(strcmp(argv[i],
"
-s
"
)
==
0
&&
i
<
argc) {
font_size
=
atoi(argv[
++
i]);
if
(font_size
<=
120
)
font_size
=
120
;
continue
;
}
info
=
argv[i];
break
;
}
}
void
ShowBanner(LPCTSTR fill_str, LPCTSTR info, LPCTSTR font_name,
int
font_size)
{
CFont lfont;
CDC ldc;
CBitmap lbmp;
ldc.CreateCompatibleDC(NULL);
lbmp.CreateCompatibleBitmap(
&
ldc, BMP_WIDTH, BMP_HEIGHT);
CBitmap
*
pold
=
(CBitmap
*
)ldc.SelectObject(
&
lbmp);
lfont.CreatePointFont(font_size, font_name,
&
ldc);
CFont
*
poldfont
=
(CFont
*
)ldc.SelectObject(
&
lfont);
CRect lrect(
0
,
0
, BMP_WIDTH,BMP_HEIGHT);
ldc.FillSolidRect(
0
,
0
, BMP_WIDTH, BMP_HEIGHT, RGB(
255
,
255
,
255
));
ldc.DrawText(info,
&
lrect, DT_LEFT);
BITMAP bmp_head;
lbmp.GetBitmap(
&
bmp_head);
DWORD bufsize
=
bmp_head.bmWidthBytes
*
bmp_head.bmHeight;
char
*
buf
=
new
char
[bufsize];
memset(buf,
0
, bufsize);
DWORD get_ret
=
lbmp.GetBitmapBits(bufsize, (
void
*
)buf);
int
i,j;
if
(get_ret
!=
0
) {
char
ret[
2
]
=
{
13
,
10
};
CString
out
[
2
]
=
{fill_str,
"
"
};
for
(i
=
0
; i
<
bmp_head.bmHeight; i
++
)
{
int
charcount
=
0
;
for
(j
=
0
; j
<
bmp_head.bmWidth; j
++
) {
int
offset
=
bmp_head.bmWidthBytes
*
i
+
j
/
8
;
char
cur;
cur
=
buf[offset];
char
tt
=
cur
&
(
0x80
>>
(j
%
8
));
CString temp;
if
(tt
==
0
) {
temp
=
out
[
0
];
}
else
{
temp
=
out
[
1
];
}
cout
<<
(LPCTSTR)temp;
charcount
++
;
}
cout
<<
endl;
}
}
ldc.SelectObject(pold);
ldc.SelectObject(poldfont);
delete [] buf;
}
void
PrintUsage(
int
argc, TCHAR
*
argv[])
{
cout
<<
"
not enough arguments
"
<<
endl;
cout
<<
"
Usage:
"
<<
endl;
cout
<<
argv[
0
]
<<
"
[-c #] [-f font_name] [-s font_size] A string to print
"
<<
endl;
}
int
_tmain(
int
argc, TCHAR
*
argv[], TCHAR
*
envp[])
{
int
nRetCode
=
0
;
//
initialize MFC and print and error on failure
if
(AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),
0
))
{
//
TODO: change error code to suit your needs
CString info
=
"
wbanner
"
;
CString font_name
=
"
宋体
"
;
CString fill_str
=
"
#
"
;
int
font_size
=
120
;
if
(argc
<
2
) {
PrintUsage(argc, argv);
}
else
{
ParseArg(info, fill_str, font_name, font_size, argc, argv);
ShowBanner(fill_str, info, font_name, font_size);
}
}
else
{
cerr
<<
_T(
"
Fatal Error: MFC initialization failed
"
)
<<
endl;
nRetCode
=
1
;
}
return
nRetCode;
}