| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3856 人关注过本帖
标题:关于 <生日快乐!> 帖的一些改进
只看楼主 加入收藏
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
结帖率:100%
收藏
 问题点数:0 回复次数:23 
关于 <生日快乐!> 帖的一些改进
程序代码:
#include <tchar.h>
#include <malloc.h>
#include <windows.h>

WINBASEAPI HWND WINAPI GetConsoleWindow();
//////////////////////////////////////////////////////////////////////////
// 把 double 型转换成 FIXED 型数据
FIXED FixedFromDouble(double d)
{
    long l;
    l = (long)(d * 65536L);
    return *(FIXED*)&l;
}

// 初始化单位矩阵
BOOL MatrixIdentity(MAT2* pMatrix, double dbZoom)
{
    if(pMatrix)
    {
        pMatrix->eM11 = FixedFromDouble(dbZoom);
        pMatrix->eM12 = FixedFromDouble(0);
        pMatrix->eM21 = FixedFromDouble(0);
        pMatrix->eM22 = FixedFromDouble(dbZoom);
        return TRUE;
    }
    return FALSE;
}

// 初始化字体
HFONT InitFont()
{
    LOGFONT lf = { -20, 16, 0, 0, 1, 0, 0, 0,
        DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,
        _T("宋体") };
    return CreateFontIndirect(&lf);    
}

// 打印字符
BOOL PrintCharacter(HDC hDC, UINT ch)
{
    if(hDC)
    {
        GLYPHMETRICS gm;
        MAT2 matrix;
        DWORD dwSize;

        // 放大2倍矩阵
        if(!MatrixIdentity(&matrix, 2.0f)) return FALSE;

        // 测试需要申请的空间
        dwSize = GetGlyphOutline(hDC, ch, GGO_BITMAP, &gm, 0, NULL, &matrix);

        if(dwSize > 0 && dwSize < 0xFFFF)
        {
            LPBYTE lpBuffer = (LPBYTE)malloc(dwSize);
            
            if(lpBuffer)
            {
                // 获得字形
                if(GetGlyphOutline(hDC, ch, GGO_BITMAP, &gm, dwSize, lpBuffer, &matrix))
                {
                    int i, j, k;
                    int nByteCount;

                    // 每行字节数
                    nByteCount = ((gm.gmBlackBoxX + 31) >> 5) << 2;

                    // 遍历行
                    for(i = 0; i < gm.gmBlackBoxY; i++)
                    {
                        // 遍历列
                        for(j = 0; j < nByteCount; j++)
                        {
                            BYTE code = lpBuffer[i * nByteCount + j];
                            
                            // 遍历位
                            for(k = 0; k < 8; k++)
                            {
                                if(code & (0x80 >> k)) _tprintf(_T("+"));
                                else _tprintf(_T(" "));
                            }
                        }
                        _tprintf(_T("\r\n"));
                    }
                }
            }

            free(lpBuffer);

            return TRUE;
        }
    }
    return FALSE;
}

int PrintString(HDC hDC, LPCTSTR pString)
{
    if(pString)
    {
        TCHAR* p = pString;
        while(*p)
        {
            if(!PrintCharacter(hDC, *p)) break;
            _tprintf(_T("\r\n"));
            p += 1;
        }
        return p - pString;
    }
    return 0;
}

int main()
{
    // 获得当前控制台设备句柄
    HWND hWnd = GetConsoleWindow();
    HDC hDC = GetDC(hWnd);
    HFONT hFont = InitFont();
    HFONT hOldFont = SelectObject(hDC, hFont);
    
    int cnt = PrintString(hDC, _T("FlyingBlue园林"));
    
    SelectObject(hDC, hOldFont);
    DeleteObject(hFont);
    ReleaseDC(hWnd, hDC);

    return 0;
}

效果:

++++++++++++++++++++++++++
    ++++             ++++++
    ++++                +++
    ++++                 +++
    ++++                  ++
    ++++                   ++
    ++++
    ++++
    ++++            ++
    ++++            ++
    ++++            ++
    ++++           +++
    ++++++++++++++++++
    ++++          ++++
    ++++            ++
    ++++            ++
    ++++            ++
    ++++
    ++++
    ++++
    ++++
    ++++
    ++++
    ++++
    ++++
    ++++
++++++++++++

         +++
++++++++++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
++++++++++++++++++++

+++++++++++     +++++++++++
   ++++++           +++
    +++++           ++
     ++++          +++
     +++++         ++
      ++++        +++
      +++++       ++
       ++++      +++
       +++++     ++
        +++++   +++
         ++++   ++
         +++++ ++
          +++++++
          ++++++
           +++++
           ++++
            +++
            ++
           +++
           ++
          +++
   +++    ++
  +++++  ++
   ++++++

        +++++
       +++++++
       +++++++
        +++++




         +++
++++++++++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
++++++++++++++++++++

      ++
++++++++     ++++++++
    ++++   ++      ++++
    ++++ ++         ++++
    +++++            ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
++++++++++++     ++++++++++++

        +++++++++     ++++
     ++++      ++++++++++++
    +++          +++    +++
   ++++          ++++
  ++++            ++++
  ++++            ++++
  ++++            ++++
  ++++            ++++
   ++++           +++
    ++++         +++
     ++++      ++++
    +++ +++++++++
  ++++
  ++++
  +++++++++++
    ++++++++++++++++++
   +++     +++++++++++++
 ++++               +++++
++++                 ++++
++++                 ++++
++++                 ++++
 ++++               ++++
   +++++          ++++
      +++++++++++++

+++++++++++++++++++++
    ++++          ++++++
    ++++            ++++++
    ++++             +++++
    ++++              +++++
    ++++              +++++
    ++++              +++++
    ++++              +++++
    ++++              ++++
    ++++             +++++
    ++++            ++++
    ++++          ++++
    ++++++++++++++++
    ++++           +++++
    ++++             +++++
    ++++               ++++
    ++++               +++++
    ++++                ++++
    ++++                +++++
    ++++                +++++
    ++++                +++++
    ++++                +++++
    ++++               +++++
    ++++               +++++
    ++++             +++++
    ++++           ++++++
+++++++++++++++++++++

         +++
++++++++++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
        ++++
++++++++++++++++++++

      ++               ++
++++++++         ++++++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++             ++++
    ++++            +++++
     ++++          + ++++
      ++++       ++  ++++++++
        +++++++++    ++

        +++++++++
     ++++       ++++
    +++           +++
  ++++             +++
  +++              ++++
 +++                +++
++++                ++++
++++                ++++
++++++++++++++++++++++++
++++
++++
++++
 ++++
 ++++                ++
  ++++               +
   ++++            ++
     ++++        +++
        +++++++++

+                                            ++
+++++++++++++++++++++++++++++++++++++++++++++++++
+++                                          ++++
+++                                          +++
+++                                          +++
+++                            +++           +++
+++                          ++++++          +++
+++        ++++++++++++++++++      +         +++
+++                                          +++
+++                                          +++
+++                                          +++
+++                                   +      +++
+++                                 ++++     +++
+++  +++++++++++++++++++++++++++++++++++++   +++
+++    +        +++       +++                +++
+++             +++       +++                +++
+++             +++       +++                +++
+++             +++       +++                +++
+++            ++++       +++                +++
+++            +++        +++                +++
+++            +++        +++          ++    +++
+++            +++        +++          ++    +++
+++           +++         +++          ++    +++
+++           +++         +++          ++    +++
+++          +++          ++++         ++    +++
+++         +++           ++++         +++   +++
+++        +++            ++++++      ++++++ +++
+++       ++               +++++++++++++++   +++
+++     +++                                  +++
+++    ++                                    +++
+++   +                                      +++
+++                                          +++
++++++++++++++++++++++++++++++++++++++++++++++++
+++                                          +++
+++                                          +++
+++


             ++++                    ++++
             +++++                   +++++
             ++++                    +++
             ++++                    +++
             ++++                    +++
             ++++                    +++
             ++++                    +++
             ++++     +              +++           ++
             ++++    +++             +++         +++++
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
            +++++                  +++++++
            +++++                  +++++++
           ++++++                 +++++++++
           ++++++                 +++++++ +
           +++++++               ++++++++ ++
          +++++++++++            +++ ++++ ++
         ++++++++  ++++         +++  ++++  ++
         +++ ++++   ++++       +++   ++++  +++
        ++++ ++++    ++++     ++++   ++++   +++
       ++++  ++++    ++++     +++    ++++    +++
       +++   ++++     ++     +++     ++++    ++++
      +++    ++++           +++      ++++     ++++
     +++     ++++          ++        ++++      ++++
    +++      ++++         ++         ++++       +++++
   +++       ++++        ++          ++++        ++++++
  ++         ++++      +++           ++++         +++++++
 ++          ++++     ++             ++++          +++++++
++           ++++    +               ++++           ++
             ++++  ++                ++++
             ++++                    ++++
             ++++                    ++++
             ++++                    ++++
             ++++                    ++++
             ++++                    ++++
             ++++                    ++++
             +++                     ++

Press any key to continue
搜索更多相关主题的帖子: 生日 快乐 改进 
2009-11-04 20:17
pgy
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:C
等 级:小飞侠
威 望:8
帖 子:1248
专家分:2329
注 册:2009-9-23
收藏
得分:0 
好看

[ 本帖最后由 pgy 于 2009-11-4 20:21 编辑 ]

我可好玩啦...不信你玩玩^_^
2009-11-04 20:18
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
收藏
得分:0 
注意编译设置把_MBCS改成 _UNICODE,UNICODE

否则汉字将不能显示

或者在最前面添加以下代码:

#define _UNICODE
#define UNICODE

[ 本帖最后由 flyue 于 2009-11-4 20:24 编辑 ]

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
2009-11-04 20:23
pgy
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:C
等 级:小飞侠
威 望:8
帖 子:1248
专家分:2329
注 册:2009-9-23
收藏
得分:0 
........

[ 本帖最后由 pgy 于 2009-11-4 23:59 编辑 ]

我可好玩啦...不信你玩玩^_^
2009-11-04 20:29
楚雄过客
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2008-11-5
收藏
得分:0 
请问这是不是传说中的高手
2009-11-04 21:51
m456m654
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:3
帖 子:783
专家分:2806
注 册:2009-9-17
收藏
得分:0 
是不是用能用tc运行啊,因为它说找不到上面的头文件。
2009-11-04 21:51
stify
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2009-10-12
收藏
得分:0 
C++?
2009-11-04 23:49
UserYuH
Rank: 12Rank: 12Rank: 12
来 自:毅华
等 级:火箭侠
威 望:8
帖 子:720
专家分:3300
注 册:2009-8-10
收藏
得分:0 
用到API了,我的是纯手工打造,你的是机械化,进步了很多.

努力—前进—变老—退休—入土
2009-11-05 01:59
你们都要疼我哦
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:火星
等 级:贵宾
威 望:49
帖 子:1296
专家分:2746
注 册:2008-7-13
收藏
得分:0 
支持纯手工

小妹,哥哥看你骨骼清奇,绝非凡人,将来必成大业,不如这样,你先把裤裤脱了,待哥哥为你开启灵窍,然后我们一起努力钻研如何
2009-11-05 03:54
尐傑哭嘞
Rank: 4
来 自:苏州
等 级:业余侠客
帖 子:81
专家分:257
注 册:2009-10-26
收藏
得分:0 
告诉

为什么我永远那么倒霉!!!!!!
2009-11-05 12:19
快速回复:关于 <生日快乐!> 帖的一些改进
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030607 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved