#include <stdio.h>
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, WPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin");
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 ("This program requires Windows NT!"), szAppName, MB_ICONERROR);
}
hwnd = CreateWindow (szAppName,
TEXT ("The Hello Program"),
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;
RECT rect;
switch (message)
/*case WM_CREATE;
PlaySound (TEXT("hellowin.wav"), NULL, SND_FILENAME|SND_ASYNCE);
return 0; */
{case WM_PAINT:
hdc = BeginPaint (hwnd,&ps);
GetClientRect (hwnd, &rect);
DrawText (hdc, TEXT ("Hello, Win 98!"), -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd,message, wParam, lParam);
}
您好, 我试图复制出Petzold的编程Windows。在大多数情况下,它进展顺利。但是当我尝试编译时,我得到了wndclass.lpfnWndProc的错误。我试着查看它是否可能是一个操作系统问题,但无济于事。顺便错误说了一些关于无效转换为LRESULT .....但我找不到任何解决方案,所以我想知道它是否是一个操作系统问题(长点或什么)或什么。如果有任何网站可能有助于更好地“现代化”这本书,我们将不胜感激。谢谢 扎克
答案 0 :(得分:0)
修好这两个拼写错误后:
LRESULT CALLBACK WndProc ( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
我发现代码编译并运行得很好:
C:\TEMP>cl test.c user32.lib gdi32.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.c
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
user32.lib
gdi32.lib
C:\TEMP>test.exe