求助!!!windows编程出现问题

kitcaii 2008-08-26 11:55:47
我在vs,net2005下建立的win32应用程序,编写了一简单的程序
包含了<windows.h>,出现这么一堆东西,哪位朋友帮忙看看啊


1>e:\winmain\winmain\winmain.c(32) : error C2275: 'HWND' : illegal use of this type as an expression
1> d:\microsoft visual studio 8\vc\platformsdk\include\windef.h(207) : see declaration of 'HWND'
1>e:\winmain\winmain\winmain.c(32) : error C2146: syntax error : missing ';' before identifier 'hwnd'
1>e:\winmain\winmain\winmain.c(32) : error C2065: 'hwnd' : undeclared identifier
1>e:\winmain\winmain\winmain.c(35) : warning C4047: '=' : 'int' differs in levels of indirection from 'HWND'
1>e:\winmain\winmain\winmain.c(37) : warning C4047: 'function' : 'HWND' differs in levels of indirection from 'int'
1>e:\winmain\winmain\winmain.c(37) : warning C4024: 'ShowWindow' : different types for formal and actual parameter 1
1>e:\winmain\winmain\winmain.c(39) : warning C4047: 'function' : 'HWND' differs in levels of indirection from 'int'
1>e:\winmain\winmain\winmain.c(39) : warning C4024: 'UpdateWindow' : different types for formal and actual parameter 1
1>e:\winmain\winmain\winmain.c(41) : error C2275: 'MSG' : illegal use of this type as an expression
1> d:\microsoft visual studio 8\vc\platformsdk\include\winuser.h(1581) : see declaration of 'MSG'
1>e:\winmain\winmain\winmain.c(41) : error C2146: syntax error : missing ';' before identifier 'msg'
1>e:\winmain\winmain\winmain.c(41) : error C2065: 'msg' : undeclared identifier
1>e:\winmain\winmain\winmain.c(42) : warning C4133: 'function' : incompatible types - from 'int *__w64 ' to 'LPMSG'
1>e:\winmain\winmain\winmain.c(44) : warning C4133: 'function' : incompatible types - from 'int *__w64 ' to 'const MSG *'
1>e:\winmain\winmain\winmain.c(45) : warning C4133: 'function' : incompatible types - from 'int *__w64 ' to 'const MSG *'
1>e:\winmain\winmain\winmain.c(63) : error C2143: syntax error : missing ';' before 'type'
1>e:\winmain\winmain\winmain.c(64) : error C2065: 'szChar' : undeclared identifier
1>e:\winmain\winmain\winmain.c(64) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int'
1>e:\winmain\winmain\winmain.c(64) : warning C4024: 'sprintf_s' : different types for formal and actual parameter 1
1>e:\winmain\winmain\winmain.c(64) : warning C4047: 'function' : 'size_t' differs in levels of indirection from 'char [11]'
1>e:\winmain\winmain\winmain.c(64) : warning C4024: 'sprintf_s' : different types for formal and actual parameter 2
1>e:\winmain\winmain\winmain.c(64) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'WPARAM'
1>e:\winmain\winmain\winmain.c(64) : warning C4024: 'sprintf_s' : different types for formal and actual parameter 3
1>e:\winmain\winmain\winmain.c(65) : warning C4047: 'function' : 'LPCWSTR' differs in levels of indirection from 'int'
1>e:\winmain\winmain\winmain.c(65) : warning C4024: 'MessageBoxW' : different types for formal and actual parameter 2
1>e:\winmain\winmain\winmain.c(68) : warning C4133: 'function' : incompatible types - from 'char [14]' to 'LPCWSTR'
1>e:\winmain\winmain\winmain.c(69) : error C2275: 'HDC' : illegal use of this type as an expression
1> d:\microsoft visual studio 8\vc\platformsdk\include\windef.h(260) : see declaration of 'HDC'
1>e:\winmain\winmain\winmain.c(69) : error C2146: syntax error : missing ';' before identifier 'hdc'
1>e:\winmain\winmain\winmain.c(69) : error C2065: 'hdc' : undeclared identifier
1>e:\winmain\winmain\winmain.c(70) : warning C4047: '=' : 'int' differs in levels of indirection from 'HDC'
1>e:\winmain\winmain\winmain.c(71) : warning C4047: 'function' : 'HDC' differs in levels of indirection from 'int'
1>e:\winmain\winmain\winmain.c(71) : warning C4024: 'TextOutW' : different types for formal and actual parameter 1
1>e:\winmain\winmain\winmain.c(71) : warning C4133: 'function' : incompatible types - from 'char [15]' to 'LPCWSTR'
1>e:\winmain\winmain\winmain.c(71) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
1>e:\winmain\winmain\winmain.c(72) : warning C4047: 'function' : 'HDC' differs in levels of indirection from 'int'
1>e:\winmain\winmain\winmain.c(72) : warning C4024: 'ReleaseDC' : different types for formal and actual parameter 2
1>e:\winmain\winmain\winmain.c(75) : error C2275: 'HDC' : illegal use of this type as an expression
1> d:\microsoft visual studio 8\vc\platformsdk\include\windef.h(260) : see declaration of 'HDC'
1>e:\winmain\winmain\winmain.c(75) : error C2146: syntax error : missing ';' before identifier 'hDC'
1>e:\winmain\winmain\winmain.c(75) : error C2065: 'hDC' : undeclared identifier
1>e:\winmain\winmain\winmain.c(76) : error C2275: 'PAINTSTRUCT' : illegal use of this type as an expression
1> d:\microsoft visual studio 8\vc\platformsdk\include\winuser.h(2703) : see declaration of 'PAINTSTRUCT'
1>e:\winmain\winmain\winmain.c(76) : error C2146: syntax error : missing ';' before identifier 'ps'
1>e:\winmain\winmain\winmain.c(76) : error C2065: 'ps' : undeclared identifier
1>e:\winmain\winmain\winmain.c(77) : warning C4133: 'function' : incompatible types - from 'int *__w64 ' to 'LPPAINTSTRUCT'
1>e:\winmain\winmain\winmain.c(77) : warning C4047: '=' : 'int' differs in levels of indirection from 'HDC'
1>e:\winmain\winmain\winmain.c(78) : warning C4047: 'function' : 'HDC' differs in levels of indirection from 'int'
1>e:\winmain\winmain\winmain.c(78) : warning C4024: 'TextOutW' : different types for formal and actual parameter 1
1>e:\winmain\winmain\winmain.c(78) : warning C4133: 'function' : incompatible types - from 'char [4]' to 'LPCWSTR'
1>e:\winmain\winmain\winmain.c(78) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
1>e:\winmain\winmain\winmain.c(79) : warning C4133: 'function' : incompatible types - from 'int *__w64 ' to 'const PAINTSTRUCT *'
1>e:\winmain\winmain\winmain.c(82) : warning C4133: 'function' : incompatible types - from 'char [15]' to 'LPCWSTR'
1>e:\winmain\winmain\winmain.c(82) : error C2198: 'MessageBoxW' : too few arguments for call
1>e:\winmain\winmain\winmain.c(82) : error C2065: 'MBMB_ICONINFORMATION' : undeclared identifier
...全文
577 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyyapple 2008-08-26
  • 打赏
  • 举报
回复
IDYES == MessageBox(hwnd, "是否真的结束?", "ck", MB_ICONINFORMATION //改成MB_YESNO
yyyapple 2008-08-26
  • 打赏
  • 举报
回复
if (IDOK == MessageBox(hwnd, "是否真的结束?", "ck", MB_ICONINFORMATION)) //改成IDOK
yyyapple 2008-08-26
  • 打赏
  • 举报
回复
还有在工程属性中general -> character set 选项选择not set,不要使用unicode
yyyapple 2008-08-26
  • 打赏
  • 举报
回复
#include <windows.h>
#include <stdio.h>

#pragma comment(linker, "/subsystem:windows")
#pragma comment(linker, "/ENTRY:WinMain")

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);

int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{


WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_ARROW);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = TEXT("weixin2008");
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd = CreateWindow(TEXT("weixin2008"), TEXT("gta"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);

ShowWindow(hwnd, SW_SHOWNORMAL);

UpdateWindow(hwnd);

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

return 0;

}

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{

switch (uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf_s(szChar, "char is %d", wParam);
MessageBox(hwnd, szChar, TEXT("weixin"), MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "mouse clicked", TEXT("weixin"), MB_ICONINFORMATION);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc, 0, 50, "计算机编程语言", strlen("计算机编程语言"));
ReleaseDC(hwnd, hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 0, 0, "MFC", strlen("MFC"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, "是否真的结束?", "ck", MB_ICONINFORMATION))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;

}
jiazhh_love 2008-08-26
  • 打赏
  • 举报
回复
我在VC6.0上试了下,只有两行错误:
1.把sprintf_s改成sprintf;(可能不支持这个函数吧)
2.if (IDYES == MessageBox(hwnd, "是否真的结束?", "ck", MB_YESNO|MB_ICONINFORMATION))
就这样了...至于VS.net还没用过...不太懂.
fibbery 2008-08-26
  • 打赏
  • 举报
回复
#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);

int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{


WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_ARROW);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = TEXT("weixin2008");
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd = CreateWindow(TEXT("weixin2008"), TEXT("gta"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);

ShowWindow(hwnd, SW_SHOWNORMAL);

UpdateWindow(hwnd);

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

return 0;

}

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{

switch (uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar, "char is %d", wParam);
MessageBox(hwnd, szChar, TEXT("weixin"), MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "mouse clicked", TEXT("weixin"), MB_ICONINFORMATION);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc, 0, 50, "计算机编程语言", strlen("计算机编程语言"));
ReleaseDC(hwnd, hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 0, 0, "MFC", strlen("MFC"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, "是否真的结束?", "ck",1))//最后一个参数你自己改回去、括号错误
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;

}


VC下编译没有错误,但需要链接库:cl winapp.cpp kernel32.lib user32.lib ...(还有,我没找到GetStockObject、TextOutA所在的库)
kitcaii 2008-08-26
  • 打赏
  • 举报
回复
高手们啊,快快现身啊
kitcaii 2008-08-26
  • 打赏
  • 举报
回复

#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);

int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{


WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_ARROW);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = TEXT("weixin2008");
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd = CreateWindow(TEXT("weixin2008"), TEXT("gta"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);

ShowWindow(hwnd, SW_SHOWNORMAL);

UpdateWindow(hwnd);

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

return 0;

}

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{

switch (uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf_s(szChar, "char is %d", wParam);
MessageBox(hwnd, szChar, TEXT("weixin"), MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "mouse clicked", TEXT("weixin"), MB_ICONINFORMATION);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc, 0, 50, "计算机编程语言", strlen("计算机编程语言"));
ReleaseDC(hwnd, hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 0, 0, "MFC", strlen("MFC"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, "是否真的结束?"), "ck", MBMB_ICONINFORMATION)
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;

}


Windows程序设计的第一个小程序,不是有windows.h就可以了吗?
zjw6861982 2008-08-26
  • 打赏
  • 举报
回复
肯定是好哦多头文件没有包括进来
ttkk_2007 2008-08-26
  • 打赏
  • 举报
回复
贴代码,好像很多错误啊,还有语法错误
fibbery 2008-08-26
  • 打赏
  • 举报
回复
代码贴出来
kitcaii 2008-08-26
  • 打赏
  • 举报
回复

#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);

int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
HWND hwnd;
MSG msg;


WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_ARROW);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = TEXT("weixin2008");
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
//HWND hwnd; 定义在WinMain()函数的最前面
hwnd = CreateWindow(TEXT("weixin2008"), TEXT("gta"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);

ShowWindow(hwnd, SW_SHOWNORMAL);

UpdateWindow(hwnd);

//MSG msg; 定义在WinMain()函数的最前面
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;

}

LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
char szChar[20];
HDC hdc;
HDC hDC;
PAINTSTRUCT ps;

switch (uMsg)
{

case WM_CHAR:
//char szChar[20]; 定义在消息处理函数的最前面
sprintf_s(szChar, 20, "char is %d", wParam);

MessageBox(hwnd, (LPCTSTR)szChar, TEXT("weixin"), MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, TEXT("mouse clicked"), TEXT("weixin"), MB_ICONINFORMATION);
//HDC hdc; 定义在消息处理函数的最前面
hdc = GetDC(hwnd);
TextOut(hdc, 0, 50, TEXT("计算机编程语言"), strlen("计算机编程语言"));
ReleaseDC(hwnd, hdc);
break;
case WM_PAINT:
//HDC hDC; 定义在消息处理函数的最前面
//PAINTSTRUCT ps; 定义在消息处理函数的最前面
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 0, 0, TEXT("MFC"), strlen("MFC"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, TEXT("是否真的结束?"), TEXT("ck"), MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;

}



改成这样就可以通过编译了,改变的仅仅是2个函数里面局部变量定义的顺序(注释部分)
请问这是何故啊?
kitcaii 2008-08-26
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 yyyapple 的回复:]
还有在工程属性中general -> character set 选项选择not set,不要使用unicode
[/Quote]
嗯,使用unicode不能正常显示中文
kitcaii 2008-08-26
  • 打赏
  • 举报
回复
LPCTSTR lpctstr = TEXT("hello")是把const char类型转换成LPCTSTR
denghanjie 2008-08-26
  • 打赏
  • 举报
回复
我也遇到一个问题
里面TEXT(“”)是否一定要用

64,685

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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