求助 如上

解决方案 »

  1.   

    #include <windows.h>
            
    #include "sysmets.h"
            LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
            
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
            
                                                             PSTR szCmdLine, int iCmdShow)
            
    {
            
               static TCHAR szAppName[] = TEXT ("SysMets") ;
            
               HWND                                 hwnd ;
            
               MSG                                  msg ;
            
               WNDCLASS                      wndclass ;
            
             wndclass.style                                       = CS_HREDRAW | CS_VREDRAW ;
            
               wndclass.lpfnWndProc                                 = WndProc ;
            
               wndclass.cbClsExtra                                  = 0 ;
            
               wndclass.cbWndExtra                                  = 0 ;
            
               wndclass.hInstance                                   = hInstance ;
            
               wndclass.hIcon                                      = LoadIcon (NULL, IDI_APPLICATION) ;
            
               wndclass.hCursor                                     = LoadCursor (NULL, IDC_ARROW) ;
            
               wndclass.hbrBackground                       = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
            
               wndclass.lpszMenuName                        = NULL ;
            
               wndclass.lpszClassName                       = szAppName ;
            
       
            
       if (!RegisterClass (&wndclass))
            
               {
            
                MessageBox (  NULL, TEXT ("Program requires Windows NT!"),
            
                                                                            szAppName, MB_ICONERROR) ;
            
                      return 0 ;
            
               }
            
       
            
        hwnd = CreateWindow (szAppName, TEXT ("Get System Metrics"),
            
                             WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
            
                               CW_USEDEFAULT, CW_USEDEFAULT,
            
                              CW_USEDEFAULT, CW_USEDEFAULT,
            
                             NULL, NULL, hInstance, NULL) ;
            
       
            
               ShowWindow (hwnd, iCmdShow) ;
            
                      UpdateWindow (hwnd) ;
            
       
            
       while (GetMessage (&msg, NULL, 0, 0))
            
               {
            
                      TranslateMessage (&msg) ;
            
                      DispatchMessage (&msg) ;
            
        }
            
        return msg.wParam ;
            
    }
      

  2.   

    刚巧前段时间写了一个,其实msdn是有例子的#define TOTAL_LINE_CNT 10000
    #define MAX_SCROLL_VAL 100LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    PAINTSTRUCT ps;
    HDC hdc;
    char szTextBuf[128];TEXTMETRIC tm;static int iCharHigh;
    static int iLineCntInView;static int iCurStartLine;int iOldPos;
    int iOldStartLine;
    RECT rt;
    RECT textrt;
    int i; // loop counter
    SCROLLINFO si;switch (message) /* handle the messages */
    {
    case WM_CREATE:hdc = GetDC (hWnd);
    GetTextMetrics (hdc, &tm);
    iCharHigh = tm.tmHeight + tm.tmExternalLeading;
    ReleaseDC (hWnd, hdc);GetClientRect(hWnd, &rt);
    iLineCntInView = ( rt.bottom -rt.top ) / iCharHigh;iCurStartLine = 0;si.cbSize = sizeof(si);
    si.fMask = SIF_POS | SIF_RANGE;
    si.nPos = 0;
    si.nMin = 0;
    si.nMax = MAX_SCROLL_VAL;
    SetScrollInfo(hWnd, SB_VERT, &si, TRUE);break;case WM_VSCROLL:si.cbSize = sizeof (si);
    si.fMask = SIF_ALL;
    GetScrollInfo( hWnd, SB_VERT, &si );iOldStartLine = iCurStartLine;
    iOldPos = si.nPos;
    switch( LOWORD (wParam) )
    {
    case SB_PAGEUP:if ( iCurStartLine > iLineCntInView )
    iCurStartLine -= iLineCntInView;
    else
    iCurStartLine = 0;break;case SB_PAGEDOWN:if ( iCurStartLine + iLineCntInView < TOTAL_LINE_CNT - iLineCntInView )
    iCurStartLine += iLineCntInView;
    else
    iCurStartLine = TOTAL_LINE_CNT - iLineCntInView;break;case SB_LINEUP:
    if ( iCurStartLine > 0 )
    iCurStartLine --;break;case SB_LINEDOWN:
    if( iCurStartLine < TOTAL_LINE_CNT - iLineCntInView )
    iCurStartLine ++;
    else
    iCurStartLine = TOTAL_LINE_CNT - iLineCntInView;break;case SB_THUMBTRACK:
    iCurStartLine = si.nTrackPos * ( TOTAL_LINE_CNT / MAX_SCROLL_VAL );
    if( iCurStartLine > TOTAL_LINE_CNT )
    iCurStartLine = TOTAL_LINE_CNT - iLineCntInView;
    break;}if ( iCurStartLine != iOldStartLine )
    {
    si.nPos = iCurStartLine / ( TOTAL_LINE_CNT / MAX_SCROLL_VAL );if ( iOldPos != si.nPos )
    {
    si.fMask = SIF_POS;
    SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
    }ScrollWindow(hWnd, 0, iCharHigh * (iOldStartLine - iCurStartLine), NULL, NULL);
    UpdateWindow(hWnd);}
    break;case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);GetClientRect(hWnd, &rt);
    textrt = rt;
    for( textrt = rt, i = iCurStartLine; textrt.top < rt.bottom; textrt.top += iCharHigh, i ++ )
    {
    sprintf( szTextBuf, "%d", i );
    DrawText(hdc, szTextBuf, strlen(szTextBuf), &textrt, DT_CENTER);
    }EndPaint(hWnd, &ps);
    break;case WM_DESTROY:
    PostQuitMessage (0); /* send a WM_QUIT to the message queue */
    break;default: /* for messages that we don't deal with */
    return DefWindowProc (hWnd, message, wParam, lParam);
    }return 0;
      

  3.   

    谢谢了啊 我的英文不太好  CSDN上的例子也没有消息处理呢  给分了