引言:
近日鄙人研习网络通信编程课业,于导师所布置的第一项的习作便遇到困难,望各位偶然相遇的陌生人能予以解答,感激不尽!
问题描述:
相应代码如下
程序语种:C++
编译软件:Microsoft Visual C++6.0
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd, //handle to window
UINT uMsg, //message identifier
WPARAM wParam,//first message parameter
LPARAM lParam //second message parameter
);
int WINAPT WinMain(
HINSTANCE hInstance, //handle to current instance
HINSTANCE hPrevInstance, //handle to previous instance
LPSTR lpCmdLine, //command line
int nCmdShow //show state
)
{
//设计一个窗口类
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcle.cbWndEctra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance; //应用程序实例句柄由WinMain函数传输
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="wangyugan2020";
wndcls.lpszMenuName=NULL;
wndcls.style=CS+HREDRAW | CS_VREDRAM;
RegisterClass(&wndcls);
//创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄
HWND hwnd;
hwnd=CreateWindow("wangyugan2020","http://www.wangyugan.org",
WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
//显示及刷新窗口
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
//定义消息结构体,开始消息循环
MSG msg;
while(GetMessage(&mag,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//编写窗口过程函数
LRESULT CALLBACK WinSUNproc(
HWND hwnd,//handle to window
UINT uMsg,//message identifier
WPARAM wParam,//first message parameter
LPARAM lParam//secon message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20],
sprintf(szChar,"char code is %d",wParam);
MessageBox(hwnd,szChar,"char",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","message",0);
HDC hdc;
hdc=GetDC(hwnd); //不能在响应WM_PAINT消息是调用
TexeOut(hdc,0,50,"程序员之家",strlen("程序员之家"));
//ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps); //BeginPaint只能在响应WM_PAINT消息时调用
TextOut(hDC,0,0,"http://www.wangyugan.org",strlen("http://www.wangyugan.org"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","message",MB_YESNO))
{
DestrotWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindoeProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
程序报错为
--------------------Configuration: WinMain - Win32 Debug--------------------
Compiling...
WinMain.cpp
D:\VC++6.0\MyProjects\WinMain\WinMain.cpp(11) : error C2146: syntax error : missing ';' before identifier 'WinMain'
D:\VC++6.0\MyProjects\WinMain\WinMain.cpp(11) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
WinMain.exe - 1 error(s), 0 warning(s)
补充说明:
另还有一问题想向各位请教,C/C++的application程序不能于eclipse编译么?在下查遍网络,明明eclipse能配置C/C++环境,但涉及到窗体开发的内容却无一不是java application?
以上!