本帖最后由 Angle_sean4 于 2012-03-05 03:06:19 编辑

解决方案 »

  1.   

    工程我已经上传了,帮我看看问题在哪儿吧,老是不显示文本啊,资源在
    http://download.csdn.net/download/angle_sean4/4114508 下载不要分的
      

  2.   

    怎么这么大11M。可以把debug下的删除后压缩。
      

  3.   

    //load 2次?
    hResource=LoadResource(hInst,FindResource(hInst,TEXT("AnnbelLee"),TEXT("TEXT")));
    pText=(char*)LoadResource(NULL,hResource);
    // 改为:
    pText=(char*)LoadResource(hInst,FindResource(hInst,TEXT("ANNBELLEE"),TEXT("TEXT")));
      

  4.   

    //可以显示了:#include <Windows.h>
    #include "resource.h"
    HINSTANCE hInst;
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow ){
    TCHAR szAppName[16],szCaption[64],szErrMsg[64];
    HWND hwnd;
    MSG msg;
    WNDCLASS wndclass;
    LoadString(hInstance,IDS_APPNAME,szAppName,sizeof(szAppName)/sizeof(TCHAR));
    LoadString(hInstance,IDS_CAPTION,szCaption,sizeof(szCaption)/sizeof(TCHAR)); wndclass.style=CS_HREDRAW|CS_VREDRAW;
    wndclass.lpfnWndProc=WndProc;
    wndclass.cbClsExtra=0;
    wndclass.cbWndExtra=0;
    wndclass.hInstance=hInstance;
    wndclass.hIcon=LoadIcon(hInstance,szAppName);
    wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
    wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName=NULL;
    wndclass.lpszClassName=szAppName; if(!RegisterClass(&wndclass)){
    LoadStringA(hInstance,IDS_APPNAME,(char*)szAppName,sizeof(szAppName));
    LoadStringA(hInstance,IDS_ERRMSG,(char*)szErrMsg,sizeof(szErrMsg));
    MessageBoxA(NULL,(char*)szErrMsg,(char*)szAppName,MB_ICONERROR);
    return 0;
    }
    hwnd=CreateWindow(szAppName,szCaption,WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
    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;
    }LRESULT CALLBACK WndProc(HWND hwnd,UINT mesaage,WPARAM wparam,LPARAM lparam)
    {
    static char *pText;
    static HGLOBAL hResource=0;
    static HWND hScroll=0;
    static int iPostion,cxChar,cyChar,cyClient,iNumLines,xScroll;
    //
    char *pTmpText;
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;
    TEXTMETRIC tm;
    switch(mesaage)
    {
    case WM_CREATE:
    hdc=GetDC(hwnd);
    GetTextMetrics(hdc,&tm);
    cxChar=tm.tmAveCharWidth;
    cyChar=tm.tmHeight+tm.tmExternalLeading;
    ReleaseDC(hwnd,hdc);
    xScroll=GetSystemMetrics(SM_CXVSCROLL);
    hScroll=CreateWindow(TEXT("scrollbar"),NULL,WS_CHILD|WS_VISIBLE|SBS_VERT,
    0,0,0,0,hwnd,(HMENU)1,hInst,NULL);
    hResource=FindResource(hInst,TEXT("ANNBELLEE"),TEXT("TEXT"));
    pText=(char*)LoadResource(hInst,hResource);
    iNumLines=0;
    // save the point
    pTmpText=pText;

    while(*pText!='\\' && *pText!='\0')
    {
    if(*pText=='\n') iNumLines++;
    pText = CharNext(pText);
    }
    *pText='\0';
    // restore
    pText=pTmpText; SetScrollRange(hScroll,SB_CTL,0,iNumLines,FALSE);
    SetScrollPos(hScroll,SB_CTL,0,FALSE);
    return 0;
    case WM_SIZE:
    MoveWindow(hScroll,LOWORD(lparam)-xScroll,0,xScroll,cyClient=HIWORD(lparam),TRUE);
    // SetFocus(hwnd);
    return 0;
    // case WM_SETFOCUS:
    // SetFocus(hScroll);
    // return 0;
    case WM_VSCROLL:
    switch(wparam)
    {
    case SB_TOP:
    iPostion=0;
    break;
    case SB_BOTTOM:
    iPostion=iNumLines;
    break;
    case SB_LINEUP:
    --iPostion;
    break;
    case SB_LINEDOWN:
    ++iPostion;
    break;
    case SB_PAGEUP:
    iPostion-=cyClient/cyChar;
    break;
    case SB_PAGEDOWN:
    iPostion+=cyClient/cyChar;
    break;
    case SB_THUMBPOSITION:
    iPostion=LOWORD(lparam);
    break;
    }
    iPostion=max(0,min(iPostion,iNumLines));
    if(iPostion!=GetScrollPos(hScroll,SB_CTL)){
    SetScrollPos(hScroll,SB_CTL,iPostion,TRUE);
    InvalidateRect(hwnd,NULL,TRUE);
    }
    return 0;
    case WM_PAINT:
    hdc=BeginPaint(hwnd,&ps);
    //pText=(char*)LoadResource(NULL,hResource);
    GetClientRect(hwnd,&rect);
    rect.left+=cxChar;
    rect.top+=cyChar*(1-iPostion);
    DrawTextA(hdc,pText,-1,&rect,DT_EXTERNALLEADING);
    EndPaint(hwnd,&ps);
    return 0;
    case WM_DESTROY:
    FreeResource(hResource);
    PostQuitMessage(0);
    return 0;
    }
    return DefWindowProc(hwnd,mesaage,wparam,lparam);
    }
      

  5.   

    应该是pText=(char*)LockResource(hResource);