大家新年好 我是新手 有个问题想请教
不知道问题在哪里。ShowWindow和UPdateWindow都调用了。在进程中可以看到这个程序的运行。就是看不到现实窗口。 程序就是 charles petzold的《windows程序设计》里的sysmets2
#define WINVER 0x501
#include <windows.h>
#include"sysmets.h"
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
static TCHAR szAppName[]=TEXT("sysmets2");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=wndclass.cbClsExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW ?CS_VREDRAW;
RegisterClass(&wndclass);
hwnd=CreateWindow(szAppName,"sysmets2",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_MAXIMIZE);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static cxChar,cxCaps,cyChar,iVscrollPos,cyClient;
HDC hdc;
int i,y;
PAINTSTRUCT ps;
TCHAR szBuffer[10];
TEXTMETRIC tm ;
switch(uMsg)
{
case WM_CREATE:
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
cxChar=tm.tmAveCharWidth;
cxCaps=(tm.tmPitchAndFamily&1?3:2);
cyChar=tm.tmExternalLeading;
ReleaseDC(hwnd,hdc);
SetScrollRange(hwnd,SB_VERT,0,NUMLINES-1,true);
SetScrollPos(hwnd,SB_VERT,iVscrollPos,true);
break;
case WM_SIZE:
cyClient=HIWORD(lParam);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
for(i=0;i <NUMLINES;i++)
{
y=cyChar*(i-iVscrollPos);
TextOut(hdc,0,y,sysmetrics[i].szLabel,strlen(sysmetrics[i].szLabel));
TextOut(hdc,22*cxCaps,y,sysmetrics[i].szDesc,strlen(sysmetrics[i].szDesc));
SetTextAlign(hdc,TA_TOP ?TA_LEFT);
TextOut(hdc,22*cxCaps+40*cxChar,y,szBuffer,wsprintf(szBuffer,TEXT("50%d"),GetSystemMetrics(sysmetrics[i].Index)));
SetTextAlign(hdc,TA_TOP ?TA_LEFT);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}