一个简单的Windows下 HelloWorld 出错

oDon 2007-11-01 10:54:22
开始学习Windows API编程第一个程序出错 情赐教!
#include <windows.h>

long FAR PASCAL MainWndProc(HWND , unsigned, WORD, LONG);

HWND hWnd;

HBRUSH hBrush;

int PASCAL WinMain(HANDLE hInstance, HANDLE hPreInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Message;
if(!hPreInstance)
if(!initApplication(hPreInstance))
return FALSE;

if(!initInstance(hInstance, nCmdShow))
return FALSE;

while(GetMessage(&Message, NULL, NULL, NULL))
{
TranslateMessage(&Message);
DispatchMessageA(&Message);
}

return (Message.wParam);
}

BOOL initApplication(HANDLE hInstance)
{
WNDCLASS WndClass;

WndClass.style = CS_HREDRAW; //| CS_VERDRAW;
WndClass.lpfnWndProc = MainWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = "Simple App";

return RegisterClass(&WndClass);
}

BOOL initInstance(HANDLE hInstance, int nCmdShow)
{
hWnd = CreateWindow(
"Simple App",
"Simple Application",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}

long FAR PASCAL MainWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
{
HDC hDC;
PAINTSTRUCT ps;

switch(message)
{
case WM_CREATE:
hBrush = CreateSolidBrush(RGB(255, 100, 0));
break;

case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
SelectObject(hDC, hBrush);
Rectangle(hDC, 10, 20, 160, 180);
TextOut(hDC, 30, 50, "Hello World", 13);
EndPaint(hWnd, &ps);
break;

case WM_CLOSE:
DestroyWindow(hWnd);
break;

case WM_DESTROY:
DeleteObject(hBrush);
PostQuitMessage(0);
break;

default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (NULL);
}


===============================================================
error: conflicting types for 'WinMain'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1096: error: previous declaration of 'WinMain' was here
..\WndC.c:11: error: conflicting types for 'WinMain'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1096: error: previous declaration of 'WinMain' was here
...全文
108 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
oDon 2007-11-01
  • 打赏
  • 举报
回复
PASCAL 指示compiler把参数按照PASCAL规定的 Left 2 Right压栈顺序。

===

int WINAPI后错误变多了,不成。
独孤过儿 2007-11-01
  • 打赏
  • 举报
回复

BOOL initApplication(HANDLE hInstance);
BOOL initInstance(HANDLE hInstance, int nCmdShow);

把函数声明添加到前面。

long FAR PASCAL MainWndProc(HWND , unsigned, WORD, LONG);

这句是什么意思?返回值是 long 怎么赋值给 WndClass.lpfnWndProc = MainWndProc; 啊?我不知道你用的 PASCAL 是什么用意。但是返回值类型不匹配,总是不行的吧。
codeblocks 2007-11-01
  • 打赏
  • 举报
回复
你用这个声明试试看
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
);

70,036

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧