新手求教!

xiongtw168 2012-05-20 02:48:24
代码好下:

#include <windows.h>
LRESULT CALLBACK Wndproc(HWND hWnd,UINT uMsgId,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
static char thisAppName[]="welcome to vc++";
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
wndclass.lpszClassName=thisAppName;
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=Wndproc;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadIcon(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL,"窗口注册失败!","出错提示",MB_OK);
return 0;
}

HWND CreateWindows(thisAppName,
thisAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if (hWnd==0)
{
return 0;
}
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while (GetStockObject(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK Wndproc(HWND hWnd,UINT uMsgId,WPARAM wParam,LPARAM lParam)
{
switch(uMsgId)
{
case WM_CREATE:
return 0;
case WM_LBUTTONDOWN:
MessageBox(NULL,"HELLO,THE WORLD!","HELLO",MB_OK);
return O;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,uMsgId,wParam,lParam);
}
}



编译报错如下:
--------------------Configuration: windows应用程序 - Win32 Debug--------------------
Compiling...
file01.cpp
D:\软件工程\windows应用程序\file01.cpp(35) : error C2078: too many initializers
D:\软件工程\windows应用程序\file01.cpp(42) : error C2660: 'GetStockObject' : function does not take 4 parameters
D:\软件工程\windows应用程序\file01.cpp(42) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.

windows应用程序.exe - 1 error(s), 0 warning(s)




求高手指教,小弟多谢了!
...全文
103 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ecplaza 2012-05-25
  • 打赏
  • 举报
回复
CreateWindow,不是CreateWindows
xiongtw168 2012-05-25
  • 打赏
  • 举报
回复
多谢楼上地,谢谢!!
xiongtw168 2012-05-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

HWND CreateWindows(thisAppName,
改成
hWnd = CreateWindows(thisAppName,
[/Quote]


更改后报错如下:
--------------------Configuration: windows API±à³Ì - Win32 Debug--------------------
Compiling...
file01.cpp
D:\xiongtw\software engineering\windows API±à³Ì\file01.cpp(25) : error C2065: 'CreateWindows' : undeclared identifier
D:\xiongtw\software engineering\windows API±à³Ì\file01.cpp(35) : error C2440: '=' : cannot convert from 'int' to 'struct HWND__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Ö´ÐÐ cl.exe ʱ³ö´í.

file01.obj - 1 error(s), 0 warning(s)
dataxdata 2012-05-23
  • 打赏
  • 举报
回复

HWND CreateWindows(thisAppName,
改成
hWnd = CreateWindows(thisAppName,
xiongtw168 2012-05-23
  • 打赏
  • 举报
回复
主要是35行这个问题,有谁知道是什么问题!
xiongtw168 2012-05-23
  • 打赏
  • 举报
回复
更改后报错如下:

--------------------Configuration: windows API±à³Ì - Win32 Debug--------------------
Compiling...
file01.cpp
D:\xiongtw\software engineering\windows API±à³Ì\file01.cpp(35) : error C2078: too many initializers
D:\xiongtw\software engineering\windows API±à³Ì\file01.cpp(58) : error C2065: 'O' : undeclared identifier
Ö´ÐÐ cl.exe ʱ³ö´í.

windows API±à³Ì.exe - 1 error(s), 0 warning(s)

求教啊,多谢了!

Decimalism 2012-05-22
  • 打赏
  • 举报
回复
把代码中的

while (GetStockObject(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

改为

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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