各位哥哥姐姐好,一个小小问题

xinxin1982 2004-04-18 12:51:22
#include<windows.h>
#include<resource.h>

LRESULT CALLBACK WndProc (HWND , UINT ,
WPARAM , LPARAM ) ;


int WINAPI WinMain ( HINSTANCE hInstance ,HINSTANCE hPrevInstance,LPSTR lpcmdLine ,int nCmdShow)
{
static TCHAR szAppName[] = TEXT( " HelloWorld " ) ;
static TCHAR szClassName[] = TEXT( " HelloWorldClass " );
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance,MAKEINTRESOURCE(IDI_ICON1)) ;
wndclass.hCursor = LoadCursor (hInstance,MAKEINTRESOURCE(IDC_CURSOR1)) ;
wndclass.hbrBackground = ( HBRUSH ) GetStockObject ( WHITE_BRUSH ) ;
//wndclass.LpszMenuName = NULL ;
wndclass.lpszClassName = szClassName;

RegisterClass(&wndclass);

hwnd = CreateWindow ( szClassName,TEXT("My Hello World to Windows Program") ,WS_OVERLAPPEDWINDOW ,CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT ,CW_USEDEFAULT , NULL ,NULL ,hInstance , NULL ) ;
ShowWindow (hwnd , nCmdShow ) ;
UpdateWindow ( hwnd ) ;

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

return msg. wParam ;
}

LRESULT CALLBACK WndProc ( HWND hwnd , UINT message ,WPARAM wParam ,LPARAM lParam )
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch ( message )
{
case WM_CREATE :
MessageBox( NULL , " Hello World!" , "Hello World " , MB_OK) ;
MessageBeep ( MB_OK ) ;
return 0 ;
case WM_PAINT:hdc = BeginPaint ( hwnd , &ps ) ;
GetClientRect ( hwnd , &rect ) ;
DrawText ( hdc , TEXT ( "Hello , Windows !") , -1 , &rect ,DT_SINGLELINE | DT_CENTER| DT_VCENTER) ;
EndPaint ( hwnd , &ps ) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage ( 0 ) ;
return 0 ;
}
return DefWindowProc ( hwnd , message , wParam , lParam ) ;
}

------ 已启动生成: 项目: hohohoho, 配置: Debug Win32 ------

正在编译...
hohoho.cpp
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\hohohoho\hohoho.cpp(20) : error C2065: “IDI_ICON1” : 未声明的标识符
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\hohohoho\hohoho.cpp(21) : error C2065: “IDC_CURSOR1” : 未声明的标识符
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\hohohoho\hohoho.cpp(38) : warning C4244: “return” : 从“WPARAM”转换到“int”,可能丢失数据

生成日志保存在“file://c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\hohohoho\Debug\BuildLog.htm”中
hohohoho - 2 错误,1 警告


---------------------- 完成 ---------------------

生成: 0 已成功, 1 已失败, 0 已跳过

然后如果强制运行的话,就会中断错误....之类的,怎么回事?
...全文
35 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinweifu 2004-04-21
  • 打赏
  • 举报
回复
把int WINAPI WinMain ( HINSTANCE hInstance ,HINSTANCE hPrevInstance,LPSTR lpcmdLine ,int nCmdShow)改为VOID WINAPI WinMain ( HINSTANCE hInstance ,HINSTANCE hPrevInstance,LPSTR lpcmdLine ,int nCmdShow)
只是建议 呵呵
xinxin1982 2004-04-20
  • 打赏
  • 举报
回复
我顶一下,谢谢,帮帮忙
xinxin1982 2004-04-18
  • 打赏
  • 举报
回复
我按照你们说的加入了
#define IDI_ICON1 101
#define IDC_CURSOR1 102
在hohoho.cpp中,并且把上方的debug变成release就可以了
但是我的resource.h中为
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by hoho.rc
//
#define IDI_ICON1 101
#define IDC_CURSOR1 102

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
我不是在hohoho.cpp中包含了嘛?怎么不起作用?
还有就是怎么每回按F5都说“这些项目配置已经过时,是否要生成?怎么回事?”
vc2003的,下面还老是
hohoho.cpp(40) : warning C4244: “return” : 从“WPARAM”转换到“int”,可能丢失数据
怎么修改阿?谢谢你们了先
wolftop 2004-04-18
  • 打赏
  • 举报
回复
你没有定义自己的资源文件宏名~!
vcforever 2004-04-18
  • 打赏
  • 举报
回复
IDI_ICON1
IDC_CURSOR1
这两个标识符在你的程序中没有声明,你可以在你的程序中添加一个ICON资源并给他命名为IDI_ICON1,添加一个CURSOR资源,给他命名为IDC_CURSOR1 !

或者直接定义
#define IDI_ICON1 156
#define IDC_CURSOR1 157

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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