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

#include "windows.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);

int WINAPI WinMain(HINSTANCE, hInstance, HINSTANCE, hPrevInstance,
LPSTR lpCmdline, int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
HWND ghWnd = NULL;
char *szAppName = "Windows API Application";
char *szAppTitle = "Windows API 窗口程序";

wcApp.style = CS_HREDRAW;
wcApp.lpfnWndProc = WndProc;
wcApp.cbWndExtra = 0;
wcApp.cbClsExtra = 0;
wcApp.hInstance = hInstance;
wcApp.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wcApp.hCursor = LoadCursor(NULL, IDC_ARROW);
wcApp.hbrBackground = (HBRUSH)COLOR_ACTIVEBORDER;
wcApp.lpszMenuName = NULL;
wcApp.lpszClassName = szAppName;

RegisterClass(&wcApp);

ghWnd = CreateWindow(szAppName,szAppTitle,
WS_OVERLAPPEDWINDOW,
100,
100,
350,
300,
NULL,
NULL,
hInstance,
NULL);

if(NULL==ghWnd)
return 0;
ShowWindow(ghWnd,nCmdShow);
UpdateWindow(ghWnd);

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

LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)

{
char *msgCreate ="收到WM_CREATE消息,建立窗口";
char *msgDestroy ="收到WM_DESTROY消息,关闭窗口";
char *msgCaption ="收到消息";
char *msgLBTN ="鼠标左键按下,收到WM_LBUTTONDOWN消息";

switch(message)
{
case WM_CREATE:
MessageBox(GetFocus(), msgCreate, msgCaption,
MB_OK|MB_ICONEXCLAMATION);
break;
case WM_LBUTTONDOWN:
MessageBox(GetFocus(), msgLBTN, msgCaption,
MB_OK|MB_ICONEXCLAMATION);
break;
case WM_DESTROY:
(GetFocus(), msgDestroy, msgCaption,
MB_OK|MB_ICONEXCLAMATION);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return FALSE;
}


编译后~~~
--------------------Configuration: program46 - Win32 Debug--------------------
Compiling...
WinAPI.cpp
f:\yuanma\program46\winapi.cpp(5) : error C2061: syntax error : identifier 'hInstance'
f:\yuanma\program46\winapi.cpp(7) : error C2731: 'WinMain' : function cannot be overloaded
f:\yuanma\program46\winapi.cpp(5) : see declaration of 'WinMain'
f:\yuanma\program46\winapi.cpp(18) : error C2065: 'hInstance' : undeclared identifier
f:\yuanma\program46\winapi.cpp(18) : error C2440: '=' : cannot convert from 'int' to 'struct HINSTANCE__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
f:\yuanma\program46\winapi.cpp(40) : error C2065: 'nCmdShow' : undeclared identifier
执行 cl.exe 时出错.

WinAPI.obj - 1 error(s), 0 warning(s)


请问各位大虾 怎么回师~~

搜索更多相关主题的帖子: windows int wcApp HINSTANCE 
2007-02-05 14:24
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 

#include "windows.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);

int WINAPI WinMain(HINSTANCE, hInstance, HINSTANCE, hPrevInstance,
LPSTR lpCmdline, int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
...
...
看见红色的地方吗!


=×&D o I p R e E n C g T l X&×=
2007-02-05 19:44
lihu_325
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-2-5
收藏
得分:0 

呵呵 谢谢~
我改了~以后我也会注意的!
编译是没有错误了~但是链接的时候麻烦又来了!

2007-02-06 16:03
lihu_325
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-2-5
收藏
得分:0 

--------------------Configuration: program46 - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/program46.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

program46.exe - 1 error(s), 0 warning(s)

这个是什么原因啊~

谢谢大家的帮助!

2007-02-06 16:04
lihu_325
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-2-5
收藏
得分:0 

为什么?这是为什么?
我的帖子人气挺高~怎么没有给我回贴的~
各位大虾,救救小弟

小弟在此先谢过~~

2007-02-07 12:15
lihu_325
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-2-5
收藏
得分:0 

呵呵 问题我自己解决了~~
在设置(alt+f7)>>链接 里面:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/program46.pdb" /debug /machine:I386 /out:"Debug/program46.exe" /pdbtype:sept
把红色的subsystem(子系统)改为 windows (原先是console>>控制台)
确定后,在链接就没有问题了~~
程序正常运行 我好高兴~~ 呵呵~~
在此我还有对2楼的朋友深表感激~那个错误我找了好久都没有发现~~谢谢你啊~你心真细~

2007-02-07 12:50
快速回复:遇到一个可视化编程的问题
数据加载中...
 
   



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

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