我晕,这个WIN32 API程序怎么不显示文本? 本帖最后由 Angle_sean4 于 2012-03-05 03:06:19 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 工程我已经上传了,帮我看看问题在哪儿吧,老是不显示文本啊,资源在http://download.csdn.net/download/angle_sean4/4114508 下载不要分的 怎么这么大11M。可以把debug下的删除后压缩。 //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"))); //可以显示了:#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);} 应该是pText=(char*)LockResource(hResource); 如何从一个字符串中获取最后的一部分 一个关于注册dll的问题? 终于升星星咯(▲▲▲▲▲→★) HOHO 散分~ 消息路由的CWnd::OnCmdMsg()搞不懂~~~ 有人精通AVI文件编程吗? 散分 有关可行性报告! 在vc中用什么函数可以画个矩形,并把其中的一个边是圆弧形? 100分求一Oracle查询语句!! C&C++高手。。。。 关于用c++编写仿真电路的算法问题 CWnd::SubclassWindow 把谁的窗口过程用谁的窗口过程替换?
http://download.csdn.net/download/angle_sean4/4114508 下载不要分的
hResource=LoadResource(hInst,FindResource(hInst,TEXT("AnnbelLee"),TEXT("TEXT")));
pText=(char*)LoadResource(NULL,hResource);
// 改为:
pText=(char*)LoadResource(hInst,FindResource(hInst,TEXT("ANNBELLEE"),TEXT("TEXT")));
#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);
}