Win32 滚动条显示文本

#include
#include
#include
#include"resource.h" //很重要,要引入资源头文件
/*
   窗口显示文字,目标:文字随着窗口大小变化变化。文字太多时候,可以通过Scroll滚动条来显示。
   思路,在Create中利用GetTextMetric得到系统字体。(需要一次,运行中不会改变)
   利用WM_SIZE 空lParam 获得当前系统的窗口大小
   将Scroll的Range设置为你文字的行数,
   显示的时候根绝Scroll postion 绘图

/*
 这里需要说明下InvalidateRect(hWnd,&reClient,TRUE);  函数理解
 最后一个参数,TRUE当前无效区域将被背景删除。FALSE不被删除。
 背景是我们在设定WNDCLASS时候hBackGround
  
*/
const int MAX_LINE =  100;
void MessageBoxPrintf(char* pszCaputre,char* Format,...)  
{  
    va_list vaList;//equal to Format + sizeof(FOrmat)  
    char szBuff[100];  
    memset(szBuff,0,sizeof(char)*100);  
    va_start(vaList,Format);  
    //vsPrintf 三个参数 buff,format,参数数组的指针,va_list类型的。这个函数  
    // 多用于实现多个参数的自定义函数   
    _vsnprintf(szBuff,100,Format,vaList);   
    va_end(vaList);  
    MessageBoxA(NULL,szBuff,pszCaputre,MB_OK);  
}  
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)//LRESULT long型的指针。 CALLBACK _stacall
{
    HDC hDc =NULL;
    CHAR aszScrollPosMsg[100];
    static int iVerScrollPos = 0;
    static RECT reClient;
    struct tagPAINTSTRUCT ps;
    static tagTEXTMETRICA tTestMetric;
    static int icxClient = 0;
    static int icyClient = 0;
    static int icxChar = 0;
    static int icyChar = 0;
    static int iMaxRow = 0;
    static int iMaxColum = 0;
    static int iCurRow = 0;
    switch(uMsg)
    {
    case WM_CREATE:
        SetScrollRange(hWnd,SB_VERT,0,MAX_LINE - 1,TRUE);
        SetScrollPos(hWnd,SB_VERT,0,TRUE);
        hDc = GetDC(hWnd);
        GetTextMetricsA(hDc,&tTestMetric);
        icxChar = tTestMetric.tmAveCharWidth;
        icyChar = tTestMetric.tmExternalLeading + tTestMetric.tmHeight;
        ReleaseDC(hWnd,hDc);
        break;
    case WM_SIZE://本来通过GetSystemMetric 获得大小,但是Size消息传递了这些信息。
         icxClient = LOWORD(lParam);
         icyClient = HIWORD(lParam);
         iMaxColum = icxClient / icxChar;
         iMaxRow = icyClient / icyChar;

         break;
       
    case WM_PAINT:
         iCurRow = 0;
         hDc = BeginPaint(hWnd,&ps);
         GetClientRect(hWnd,&reClient);
         
         for(int i =0;i

 

你可能感兴趣的:(Win32)