刚学windows编程,下面代码错误。不知何解
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("xx");
HWND hwnd;
MSG msg;
WNDCLASSEX wndclassex = {0};
wndclassex.cbSize = sizeof(WNDCLASSEX);
wndclassex.style = CS_HREDRAW | CS_VREDRAW;
wndclassex.lpfnWndProc = WndProc;
wndclassex.cbClsExtra = 0;
wndclassex.cbWndExtra = 0;
wndclassex.hInstance = hInstance;
wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclassex.lpszMenuName = NULL;
wndclassex.lpszClassName = szAppName;
wndclassex.hIconSm = wndclassex.hIcon;
if (!RegisterClassEx (&wndclassex))
{
MessageBox (NULL, TEXT ("RegisterClassEx failed!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW,
szAppName,
TEXT ("good"),
WS_OVERLAPPEDWINDOW,
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 message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
SCROLLINFOsi;
TEXTMETRIC tm;
static struct
{
int idStockFont;
char * szStockFont;
}
stockfont[] =
{
OEM_FIXED_FONT,"OEM_FIXED_FONT",
ANSI_FIXED_FONT, "ANSI_FIXED_FONT",
ANSI_VAR_FONT,"ANSI_VAR_FONT",
SYSTEM_FONT,"SYSTEM_FONT",
DEVICE_DEFAULT_FONT,"DEVICE_DEFAULT_FONT",
SYSTEM_FIXED_FONT, "SYSTEM_FIXED_FONT",
DEFAULT_GUI_FONT, "DEFAULT_GUI_FONT"
};
int i;
static int iFont, cFont = sizeof(stockfont)/sizeof(stockfont[0]);
static int cxChar, cyChar, cxClient, cyClient, iVerPos;
TCHAR szFaceName[LF_FACESIZE], szBuffer[LF_FACESIZE + 64];
switch (message)
{
case WM_CREATE:
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight+tm.tmExternalLeading;
GetTextMetrics(hdc, &tm);
ReleaseDC(hwnd, hdc);
return (0);
case WM_SIZE:
cyClient = LOWORD(lParam);
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_POS;
si.nMax = cFont-1;
si.nMin = 0;
si.nPage = cyClient/cyChar;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
return(0);
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
for(i = 0; i < cFont; i++)
{
SelectObject(hdc, GetStockObject(stockfont[i].idStockFont));
GetTextFace(hdc, LF_FACESIZE, szFaceName);
GetTextMetrics(hdc, &tm);
TextOut(hdc, 0, i+3, szBuffer,
wsprintf(szBuffer, TEXT("%s: Face Name = %s, CharSet = %s"), stockfont[i].szStockFont,
szFaceName, tm.tmCharSet));
}
EndPaint (hwnd, &ps);
return (0);
case WM_VSCROLL:
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwnd, SB_VERT, &si);
iVerPos = si.nPos;
switch (LOWORD(wParam))
{
case SB_TOP:
si.nPos = 0;
break;
case SB_BOTTOM:
si.nPos = cFont-1;
break;
case SB_PAGEUP:
si.nPos -= si.nPage;
break;
case SB_PAGEDOWN:
si.nPos += si.nPage;
break;
case SB_THUMBPOSITION:
si.nPos = si.nTrackPos;
break;
default:
break;
}
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
if( iVerPos != si.nPos)
{
ScrollWindow(hwnd, 0, (iVerPos - si.nPos)*cyChar, NULL, NULL);
UpdateWindow(hwnd);
}
return(0);
case WM_DESTROY:
PostQuitMessage (0);
return (0);
}
return DefWindowProc (hwnd, message, wParam, lParam);
}