| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 608 人关注过本帖
标题:源代码问题
只看楼主 加入收藏
sunweihang
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-7-25
收藏
 问题点数:0 回复次数:9 
源代码问题

请看这个程序
#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 win2007;
win2007.cbClsExtra=0;
win2007.cbWndExtra=0;
win2007.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
win2007.hCursor=LoadCursor(NULL,IDC_CROSS);
win2007.hIcon=LoadIcon(NULL,IDI_ERROR);
win2007.hInstance=hInstance;
win2007.lpfnWndProc=WinSunProc;
win2007.lpszClassName="sunweihang";
win2007.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&win2007);
HWND hwnd;
hwnd=CreateWindow("win2007","孙伟航",WS_OVERLAPPEDWINDOW,
0,0,600,400,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,"swh",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","swh",0);
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,"孙伟航",strlen("孙伟航"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","swh",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}

编译的时候没有任何错误,可是为什么就是不能运行呢?
本人初学者,请指教!

搜索更多相关主题的帖子: 源代码 
2007-07-25 20:02
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 

[CODE]#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 win2007;
win2007.cbClsExtra=0;
win2007.cbWndExtra=0;
win2007.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
win2007.hCursor=LoadCursor(NULL,IDC_CROSS);
win2007.hIcon=LoadIcon(NULL,IDI_ERROR);
win2007.hInstance=hInstance;
win2007.lpfnWndProc=WinSunProc;
win2007.lpszClassName="sunweihang";
win2007.lpszMenuName = NULL; //WNDCLASS 成员赋值漏了他
win2007.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&win2007);
HWND hwnd;
hwnd=CreateWindow("sunweihang","孙伟航",WS_OVERLAPPEDWINDOW, //要与你上面的类名相同
0,0,600,400,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,"swh",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","swh",0);
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,"孙伟航",strlen("孙伟航"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","swh",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}[/CODE]

不是很了解api,还好你这个简单。


Fight  to win  or  die...
2007-07-25 21:45
sunweihang
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-7-25
收藏
得分:0 

太感谢了
我这就回去试验一下~~~
对了,请问我安装的c++6.0是那种解压缩的,有没有那种硬盘安装版的
还有在那里能够下载2001版的msdn
谢谢了

2007-07-26 16:03
sunweihang
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-7-25
收藏
得分:0 
没有试验呢,大概看了一下,有个小问题

#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 win2007; 请问这里不是在定义我的类名吗?
win2007.cbClsExtra=0;
win2007.cbWndExtra=0;
win2007.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
win2007.hCursor=LoadCursor(NULL,IDC_CROSS);
win2007.hIcon=LoadIcon(NULL,IDI_ERROR);
win2007.hInstance=hInstance;
win2007.lpfnWndProc=WinSunProc;
win2007.lpszClassName="sunweihang";
win2007.lpszMenuName = NULL; //WNDCLASS 成员赋值漏了他
win2007.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&win2007);
HWND hwnd;
hwnd=CreateWindow("sunweihang","孙伟航",WS_OVERLAPPEDWINDOW, //要与你上面的类名相同” 难道我的类名不是“win2007”吗
0,0,600,400,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,"swh",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","swh",0);
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,"孙伟航",strlen("孙伟航"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","swh",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
2007-07-26 16:07
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 

baidu下吧,应该有的。

现在的vc下载都是镜像文件吧,可以用虚拟光去安装,也可以直接解压安装。


Fight  to win  or  die...
2007-07-26 16:08
sunweihang
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-7-25
收藏
得分:0 
再次感谢,我全部都试验过了,你的解答完全正确!~~
非常感谢
2007-07-26 19:44
sunweihang
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-7-25
收藏
得分:0 
还有个小问题

#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 win2007;
win2007.cbClsExtra=0;
win2007.cbWndExtra=0;
win2007.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
win2007.hCursor=LoadCursor(NULL,IDC_CROSS);
win2007.hIcon=LoadIcon(NULL,IDI_ERROR);
win2007.hInstance=hInstance;
win2007.lpfnWndProc=WinSunProc;
win2007.lpszClassName="sunweihang";
win2007.lpszMenuName = NULL; //WNDCLASS 成员赋值漏了他
win2007.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&win2007);
HWND hwnd;
hwnd=CreateWindow("sunweihang","孙伟航",WS_OVERLAPPEDWINDOW, //要与你上面的类名相同
0,0,600,400,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,"swh",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","swh",0);
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,"孙伟航",strlen("孙伟航"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","swh",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
2007-07-26 19:46
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
回复:(sunweihang)还有个小问题#include
简单来说就是个函数声明。

ex

fun();//声明函数fun

int main(){
fun();
//
}

fun(){
//
}
就这个意思,要在main函数中用它就要先让编译器看见他

Fight  to win  or  die...
2007-07-26 21:44
sunweihang
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-7-25
收藏
得分:0 
谢谢,明白了
非常感谢 ~~~
2007-07-27 15:59
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 
去迅雷下.. 要184MB的rar版... 400多MB那个就是这个解压出来的, 不要下错了..

女侠,约吗?
2007-07-28 18:52
快速回复:源代码问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019576 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved