| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1607 人关注过本帖
标题:为什么窗口没有弹出,C++初学者
取消只看楼主 加入收藏
shuting
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-22
收藏
 问题点数:0 回复次数:5 
为什么窗口没有弹出,C++初学者

我是初学者,请大家指教错误在哪里.编译后进程里面有,但窗口弹不出.代码如下:
#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.cbClsExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="shuting";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);

HWND hwnd;
hwnd=CreateWindow("shuting","我的第一个程序",WS_OVERLAPPEDWINDOW,
0,0,800,600,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,"shuting",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","shuting",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,"My first program",strlen("My first program"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"你真的要退出吗","shuting",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}

搜索更多相关主题的帖子: windows 窗口 int 
2007-08-25 10:19
shuting
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-22
收藏
得分:0 
我不知道怎么判断啊,请指教
2007-08-25 16:54
shuting
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-22
收藏
得分:0 
谢谢,我试一试
2007-08-25 17:07
shuting
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-22
收藏
得分:0 
按楼上所说,提示:this program requires Windows NT!
是什么意思呀,需要怎么修改?
2007-08-25 17:27
shuting
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-22
收藏
得分:0 

这两段代码有什么地方不一样,为什么用第二段的时候就没有弹出窗口,(第一段正确)我看了n遍也没有发现不同之处,郁闷
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="shuting";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);

/*WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbClsExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="shuting";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
//RegisterClass(&wndcls);
RegisterClass(&wndcls);*/

2007-08-25 18:10
shuting
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-22
收藏
得分:0 

谢谢楼上两位,哎,还是粗心惹的祸.

[此贴子已经被作者于2007-8-26 12:41:57编辑过]

2007-08-26 12:41
快速回复:为什么窗口没有弹出,C++初学者
数据加载中...
 
   



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

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