第四章、文本输出

头文件:

/*-----------------------------------------------
   SYSMETS.H -- System metrics display structure
  -----------------------------------------------*/

#define NUMLINES ((int) (sizeof sysmetrics / sizeof sysmetrics [0]))

struct
{
     int     iIndex ;
     TCHAR * szLabel ;
     TCHAR * szDesc ;
}
sysmetrics [] =
{
     SM_CXSCREEN,             TEXT ("SM_CXSCREEN"),
                              TEXT ("Screen width in pixels"),
     SM_CYSCREEN,             TEXT ("SM_CYSCREEN"),
                              TEXT ("Screen height in pixels"),
     SM_CXVSCROLL,            TEXT ("SM_CXVSCROLL"),
                              TEXT ("Vertical scroll width"),
     SM_CYHSCROLL,            TEXT ("SM_CYHSCROLL"),
                              TEXT ("Horizontal scroll height"),
     SM_CYCAPTION,            TEXT ("SM_CYCAPTION"),
                              TEXT ("Caption bar height"),
     SM_CXBORDER,             TEXT ("SM_CXBORDER"),
                              TEXT ("Window border width"),
     SM_CYBORDER,             TEXT ("SM_CYBORDER"),
                              TEXT ("Window border height"),
     SM_CXFIXEDFRAME,         TEXT ("SM_CXFIXEDFRAME"),
                              TEXT ("Dialog window frame width"),
     SM_CYFIXEDFRAME,         TEXT ("SM_CYFIXEDFRAME"),
                              TEXT ("Dialog window frame height"),
     SM_CYVTHUMB,             TEXT ("SM_CYVTHUMB"),
                              TEXT ("Vertical scroll thumb height"),
     SM_CXHTHUMB,             TEXT ("SM_CXHTHUMB"),
                              TEXT ("Horizontal scroll thumb width"),
     SM_CXICON,               TEXT ("SM_CXICON"),
                              TEXT ("Icon width"),
     SM_CYICON,               TEXT ("SM_CYICON"),
                              TEXT ("Icon height"),
     SM_CXCURSOR,             TEXT ("SM_CXCURSOR"),
                              TEXT ("Cursor width"),
     SM_CYCURSOR,             TEXT ("SM_CYCURSOR"),
                              TEXT ("Cursor height"),
     SM_CYMENU,               TEXT ("SM_CYMENU"),
                              TEXT ("Menu bar height"),
     SM_CXFULLSCREEN,         TEXT ("SM_CXFULLSCREEN"),
                              TEXT ("Full screen client area width"),
     SM_CYFULLSCREEN,         TEXT ("SM_CYFULLSCREEN"),
                              TEXT ("Full screen client area height"),
     SM_CYKANJIWINDOW,        TEXT ("SM_CYKANJIWINDOW"),
                              TEXT ("Kanji window height"),
     SM_MOUSEPRESENT,         TEXT ("SM_MOUSEPRESENT"),
                              TEXT ("Mouse present flag"),
     SM_CYVSCROLL,            TEXT ("SM_CYVSCROLL"),
                              TEXT ("Vertical scroll arrow height"),
     SM_CXHSCROLL,            TEXT ("SM_CXHSCROLL"),
                              TEXT ("Horizontal scroll arrow width"),
     SM_DEBUG,                TEXT ("SM_DEBUG"),
                              TEXT ("Debug version flag"),
     SM_SWAPBUTTON,           TEXT ("SM_SWAPBUTTON"),
                              TEXT ("Mouse buttons swapped flag"),
     SM_CXMIN,                TEXT ("SM_CXMIN"),
                              TEXT ("Minimum window width"),
     SM_CYMIN,                TEXT ("SM_CYMIN"),
                              TEXT ("Minimum window height"),
     SM_CXSIZE,               TEXT ("SM_CXSIZE"),
                              TEXT ("Min/Max/Close button width"),
     SM_CYSIZE,               TEXT ("SM_CYSIZE"),
                              TEXT ("Min/Max/Close button height"),
     SM_CXSIZEFRAME,          TEXT ("SM_CXSIZEFRAME"),
                              TEXT ("Window sizing frame width"),
     SM_CYSIZEFRAME,          TEXT ("SM_CYSIZEFRAME"),
                              TEXT ("Window sizing frame height"),
     SM_CXMINTRACK,           TEXT ("SM_CXMINTRACK"),
                              TEXT ("Minimum window tracking width"),
     SM_CYMINTRACK,           TEXT ("SM_CYMINTRACK"),
                              TEXT ("Minimum window tracking height"),
     SM_CXDOUBLECLK,          TEXT ("SM_CXDOUBLECLK"),
                              TEXT ("Double click x tolerance"),
     SM_CYDOUBLECLK,          TEXT ("SM_CYDOUBLECLK"),
                              TEXT ("Double click y tolerance"),
     SM_CXICONSPACING,        TEXT ("SM_CXICONSPACING"),
                              TEXT ("Horizontal icon spacing"),
     SM_CYICONSPACING,        TEXT ("SM_CYICONSPACING"),
                              TEXT ("Vertical icon spacing"),
     SM_MENUDROPALIGNMENT,    TEXT ("SM_MENUDROPALIGNMENT"),
                              TEXT ("Left or right menu drop"),
     SM_PENWINDOWS,           TEXT ("SM_PENWINDOWS"),
                              TEXT ("Pen extensions installed"),
     SM_DBCSENABLED,          TEXT ("SM_DBCSENABLED"),
                              TEXT ("Double-Byte Char Set enabled"),
     SM_CMOUSEBUTTONS,        TEXT ("SM_CMOUSEBUTTONS"),
                              TEXT ("Number of mouse buttons"),
     SM_SECURE,               TEXT ("SM_SECURE"),
                              TEXT ("Security present flag"),
     SM_CXEDGE,               TEXT ("SM_CXEDGE"),
                              TEXT ("3-D border width"),
     SM_CYEDGE,               TEXT ("SM_CYEDGE"),
                              TEXT ("3-D border height"),
     SM_CXMINSPACING,         TEXT ("SM_CXMINSPACING"),
                              TEXT ("Minimized window spacing width"),
     SM_CYMINSPACING,         TEXT ("SM_CYMINSPACING"),
                              TEXT ("Minimized window spacing height"),
     SM_CXSMICON,             TEXT ("SM_CXSMICON"),
                              TEXT ("Small icon width"),
     SM_CYSMICON,             TEXT ("SM_CYSMICON"),
                              TEXT ("Small icon height"),
     SM_CYSMCAPTION,          TEXT ("SM_CYSMCAPTION"),
                              TEXT ("Small caption height"),
     SM_CXSMSIZE,             TEXT ("SM_CXSMSIZE"),
                              TEXT ("Small caption button width"),
     SM_CYSMSIZE,             TEXT ("SM_CYSMSIZE"),
                              TEXT ("Small caption button height"),
     SM_CXMENUSIZE,           TEXT ("SM_CXMENUSIZE"),
                              TEXT ("Menu bar button width"),
     SM_CYMENUSIZE,           TEXT ("SM_CYMENUSIZE"),
                              TEXT ("Menu bar button height"),
     SM_ARRANGE,              TEXT ("SM_ARRANGE"),
                              TEXT ("How minimized windows arranged"),
     SM_CXMINIMIZED,          TEXT ("SM_CXMINIMIZED"),
                              TEXT ("Minimized window width"),
     SM_CYMINIMIZED,          TEXT ("SM_CYMINIMIZED"),
                              TEXT ("Minimized window height"),
     SM_CXMAXTRACK,           TEXT ("SM_CXMAXTRACK"),
                              TEXT ("Maximum draggable width"),
     SM_CYMAXTRACK,           TEXT ("SM_CYMAXTRACK"),
                              TEXT ("Maximum draggable height"),
     SM_CXMAXIMIZED,          TEXT ("SM_CXMAXIMIZED"),
                              TEXT ("Width of maximized window"),
     SM_CYMAXIMIZED,          TEXT ("SM_CYMAXIMIZED"),
                              TEXT ("Height of maximized window"),
     SM_NETWORK,              TEXT ("SM_NETWORK"),
                              TEXT ("Network present flag"),
     SM_CLEANBOOT,            TEXT ("SM_CLEANBOOT"),
                              TEXT ("How system was booted"),
     SM_CXDRAG,               TEXT ("SM_CXDRAG"),
                              TEXT ("Avoid drag x tolerance"),
     SM_CYDRAG,               TEXT ("SM_CYDRAG"),
                              TEXT ("Avoid drag y tolerance"),
     SM_SHOWSOUNDS,           TEXT ("SM_SHOWSOUNDS"),
                              TEXT ("Present sounds visually"),
     SM_CXMENUCHECK,          TEXT ("SM_CXMENUCHECK"),
                              TEXT ("Menu check-mark width"),
     SM_CYMENUCHECK,          TEXT ("SM_CYMENUCHECK"),
                              TEXT ("Menu check-mark height"),
     SM_SLOWMACHINE,          TEXT ("SM_SLOWMACHINE"),
                              TEXT ("Slow processor flag"),
     SM_MIDEASTENABLED,       TEXT ("SM_MIDEASTENABLED"),
                              TEXT ("Hebrew and Arabic enabled flag"),
     SM_MOUSEWHEELPRESENT,    TEXT ("SM_MOUSEWHEELPRESENT"),
                              TEXT ("Mouse wheel present flag"),
     SM_XVIRTUALSCREEN,       TEXT ("SM_XVIRTUALSCREEN"),
                              TEXT ("Virtual screen x origin"),
     SM_YVIRTUALSCREEN,       TEXT ("SM_YVIRTUALSCREEN"),
                              TEXT ("Virtual screen y origin"),
     SM_CXVIRTUALSCREEN,      TEXT ("SM_CXVIRTUALSCREEN"),
                              TEXT ("Virtual screen width"),
     SM_CYVIRTUALSCREEN,      TEXT ("SM_CYVIRTUALSCREEN"),
                              TEXT ("Virtual screen height"),
     SM_CMONITORS,            TEXT ("SM_CMONITORS"),
                              TEXT ("Number of monitors"),
     SM_SAMEDISPLAYFORMAT,    TEXT ("SM_SAMEDISPLAYFORMAT"),
                              TEXT ("Same color format flag")
} ;

第一个版本滚动条:效率差

#include <Windows.h>
#include "SysMets.h"
#include <tchar.h>

HINSTANCE  g_hInst = NULL;

LRESULT CALLBACK ParentProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
    static int cxChar, cyChar, cxCaps, cyClient, iVscrollPos;
    HDC hDC;
    int i, y;
    PAINTSTRUCT ps;
    TCHAR szBuffer[10] = {0};
    TEXTMETRIC tm;

    switch(nMsg)
    {
    case WM_CREATE:
        hDC = GetDC(hWnd);
        GetTextMetrics(hDC,&tm);
        cxChar = tm.tmAveCharWidth;
        cyChar = tm.tmHeight + tm.tmExternalLeading;
        cxCaps =(tm.tmPitchAndFamily & 1? 3: 2) * cxChar/2;
        ReleaseDC(hWnd,hDC);

        SetScrollRange(hWnd, SB_VERT, 0, NUMLINES -1, FALSE);
        SetScrollPos(hWnd, SB_VERT, iVscrollPos, TRUE);
        return 0;
    case WM_SIZE:
        cyClient = HIWORD(lParam);
        return 0;
    case WM_VSCROLL:
        switch(LOWORD(wParam))
        {
        case SB_LINEUP:
            iVscrollPos += 1;
            break;
        case SB_LINEDOWN:
            iVscrollPos -= 1;
            break;
        case SB_PAGEUP:
            iVscrollPos +=  cyClient/cyChar;
            break;
        case SB_PAGEDOWN:
            iVscrollPos -= cyClient/cyChar;
            break;
        case SB_THUMBTRACK:
            iVscrollPos = HIWORD(wParam);
            break;
        }

        iVscrollPos = max(0, min(iVscrollPos, NUMLINES -1));
        if(iVscrollPos != GetScrollPos(hWnd, SB_VERT))
        {
            SetScrollPos(hWnd, SB_VERT, iVscrollPos, TRUE);
            InvalidateRect(hWnd, NULL, TRUE);
        }
        return 0;
    case WM_PAINT:
        hDC = BeginPaint(hWnd, &ps);

        for(i = 0; i < NUMLINES; i++)
        {
            y = cyChar * (i - iVscrollPos);
            TextOut(hDC, 0, y, sysmetrics[i].szLabel, lstrlen(sysmetrics[i].szLabel));

            TextOut(hDC, 22 * cxChar, y, sysmetrics[i].szDesc, lstrlen(sysmetrics[i].szDesc));
            SetTextAlign(hDC, TA_RIGHT| TA_TOP);
            TextOut(hDC, 22*cxCaps + 40*cxChar, y, szBuffer, wsprintf(szBuffer, TEXT("%5d"), GetSystemMetrics(sysmetrics[i].iIndex)));
            SetTextAlign(hDC, TA_LEFT| TA_TOP);
        }

        EndPaint(hWnd, &ps);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }

    return DefWindowProc(hWnd, nMsg, wParam, lParam);
}

BOOL RegisterWnd(LPSTR pszClassName)
{
    WNDCLASSEX wce = {0};
    wce.cbSize = sizeof(wce);
    wce.cbClsExtra = 0;
    wce.cbWndExtra = 0;
    wce.hbrBackground = HBRUSH(COLOR_WINDOW);
    wce.lpfnWndProc = ParentProc;
    wce.hCursor = NULL;
    wce.hIcon = NULL;
    wce.hIconSm = NULL;
    wce.hInstance = g_hInst;
    wce.lpszClassName = pszClassName;
    wce.lpszMenuName = NULL;
    wce.style = CS_HREDRAW | CS_VREDRAW;

    ATOM nAtom = RegisterClassEx(&wce);
    if(0 == nAtom)
    {
        return FALSE;
    }

    return TRUE;
}

HWND CreateWnd(LPSTR pszClassName)
{
    HWND hWnd = CreateWindowEx(
                0,pszClassName,"窗口",WS_OVERLAPPEDWINDOW | WS_VSCROLL ,CW_USEDEFAULT,
                CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,g_hInst,NULL);

    return hWnd;
}

void DisplayWnd(HWND hWnd)
{
    ShowWindow(hWnd,SW_SHOW);
    UpdateWindow(hWnd);
}

void Message()
{
    MSG msg = {0};
    while(GetMessage(&msg,NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

int WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR pszCmdLine,
                    int nShowCmd)
{
    g_hInst = hInstance;
    RegisterWnd("MYWND");
    HWND hWnd = CreateWnd("MYWND");
    DisplayWnd(hWnd);
    Message();
    return 0;
}
时间: 2024-11-05 04:52:06

第四章、文本输出的相关文章

第四章输入/输出(I/O)4.1I/O涉及的设备及相关概念简介

PCL中所有的处理都是基于点云展开的,利用不同的设备获取点云.存储点云等都是点云处理前后必须做的流程,PCL中有自己设计的内部PCD文件格式,为此,设计读写该该格式以及与其他3D文件格式之间进行转化的接口类都是很有必要的:目前PCL内部支持对常用的3D格式文件的打开与存储操作,以及与PCD内部格式之间的相互转化. 1.OpenNI开源框架 OpenNI(开放式自然交互)专注于提高和改善自然交互设备与应用软件的互操作能力. OpenNI是一个多语言.跨平台的框架,它定义了一套用于编写通用自然交互应

第四章输入/输出(I/O)4.2PCL中I/O模块及类介绍

PCL中I/O库提供了点云文件输入输出相关的操作类,并封装了OpenNI兼容的设备源数据获取接口,可直接从众多感知设备获取点云图像等数据.I/O模块利用21个类和28个函数实现了对点云的获取.读入.存储等相关操作,其依赖于pcl_common和pcl_octree模块以及OpenNI外部开发包. 1)I/O模块中类以及全局函数说明

Shell脚本学习指南 [ 第三、四章 ] 查找与替换、文本处理工具

摘要:第三章讨论的是编写Shell脚本时经常用到的两个基本操作.第四章总共介绍了约30种处理文本文件的好用工具. 第三章 查找与替换 概括:本章讨论的是编写Shell脚本时经常用到的两个基本操作:文本查找.文本替换. 3.1  查找文本 如需从输入的数据文件中取出特定的文本行,主要的工具为grep程序.POSIX采用三种不同grep变体:grep.egrep.fgrep整合为单个版本,通过不同的选项,分别提供这三种行为模式.who | grep -F root上面使用-F选项,以查找固定字符串r

《Linux Shell脚本攻略》 笔记 第四章:高效文本处理

<Linux Shell脚本攻略> 笔记 第四章:高效文本处理 1.IP地址的正则表达式: [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} 2.grep用法 //在多级目录中对文本进行递归检索 [[email protected] program_test]# grep "yang" ./ -Rn ./test.txt:6:laoyang ./right.txt:1:1 yang man //忽略大小写匹配 [[email pr

第17章 文本和字体_17.1-17.2 简单文本输出、 字体的背景知识

17.1 简单文本输出 17.1.1 文本输出函数 (1)TextOut(hdc,xStart,yStart,pString,iCount) ①xStart和yStart使用的是逻辑坐标,TextOut并不以NULL来做字符串的结束,需指定字符的个数iCount的值 ②SetTextAlign会改变xStart和yStart的含义 SetTextAlign 坐标值的含义 TA_LEFT xStart:第一个字符的左侧坐标 TA_RIGHT xStart:最后一个字符的右侧坐标 TA_CENTER

第四章 初步进入linux世界

第四章 初步进入linux世界 [Linux 系统启动过程] Linux的启动其实和windows的启动过程很类似,不过windows我们是无法看到启动信息的,而linux启动时我们会看到许多启动信息,例如某个服务是否启动. Linux系统的启动过程大体上可分为五部分:内核的引导:运行init:系统初始化:建立终端 :用户登录系统. A 内核引导 当计算机打开电源后,首先是BIOS开机自检,按照BIOS中设置的启动设备(通常是硬盘)来启动.紧接着由启动设备上的grub程序开始引导linux,当引

ArcGIS for Desktop入门教程_第四章_入门案例分析 - ArcGIS知乎-新一代ArcGIS问答社区

原文:ArcGIS for Desktop入门教程_第四章_入门案例分析 - ArcGIS知乎-新一代ArcGIS问答社区 1 入门案例分析 在第一章里,我们已经对ArcGIS系列软件的体系结构有了一个全面的了解,接下来在本章中,将通过一个案例来熟悉ArcGIS for Desktop的使用,从解决问题的过程中,逐渐适应ArcGIS桌面的界面和操作方式. 本章的练习数据是一个住宅小区的简单平面示意图,需要在已有的基础上把楼房的轮廓补充完整,并加以整饰,完成一幅地图. 1.1 打开地图文档并浏览

[现代操作系统笔记][第四章文件系统]

第四章 文件系统 4.1 文件 从用户角度来考察文件.用户如何使用文件,文件有那些特性. 4.1.1 文件命名 文件一种抽象机制,提供了一种在磁盘上保留信息而且以后方便读取的方法. 有的文件系统区分大小写,有的则不区分 Unix是前者,MS-DOS是后者 FAT-16,FAT-32,NTFS. FAT-16(File Allocation Table,文件配置表) : Windows 95 FAT-32 : Windows 98 NTFS(New Technology File System,新

《Linux内核设计与实现》读书笔记 第四章 进程调度

第四章进程调度 进程调度程序可看做在可运行太进程之间分配有限的处理器时间资源的内核子系统.调度程序是多任务操作系统的基础.通过调度程序的合理调度,系统资源才能最大限度地发挥作用,多进程才会有并发执行的效果. 最大限度地利用处理器时间的原则是,只要有可以执行的进程,那么总会有进程在执行. 4.1多任务 多任务操作系统就是能同时并发地交互执行多个进程的操作系统.多任务能使多个进程处于堵塞或者睡眠状态.就是任务位于内存内但是不被执行,直到某一事件发生. 分类: l  非抢占式:除非进程自己主动停止运行

第四章 目录和文件管理(二)

第四章  目录和文件管理(二) 享受生活 热爱挑战                                                                                                                          明远分享 每章一段话:                       无论做什么,你都要勇往直前:无论有多难,你都要多坚持一下.千万不要低估你实现梦想的能力.                   要求: Ø