| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1008 人关注过本帖
标题:不明的编译错误?
只看楼主 加入收藏
唐龙
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2004-11-27
收藏
 问题点数:0 回复次数:6 
不明的编译错误?

#include<windows.h>

LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window ) { char lpszClassName[]="lll"; char lpszTitle[]="lllll"; HWND hwnd; MSG msg; WNDCLASS wndclass;

wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndclass.hInstance=hInstance; wndclass.lpfnWndProc=WindowProc; wndclass.lpszClassName=lpszClassName; wndclass.lpszMenuName=NULL; wndclass.style=CS_HREDRAW | CS_VREDRAW;

if(!RegisterClass(&wndclass)) { MessageBeep(0); return FALSE; } hwnd=CreateWindow(lpszClassName, lpszTitle, WS_OVERLAPPEDWINDOW, 50,50, 700,500, NULL, NULL, hInstance, NULL); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; } //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////

--------------------Configuration: llll - Win32 Debug-------------------- Compiling... ddd.cpp Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/llll.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe.

llll.exe - 2 error(s), 0 warning(s)

上面为什么会出现这两个错误呢?

加上以下的"按钮"代码后编译虽然没有了错误,但是只有框架,却没有按钮,这是不是又是初学者的错误啊!

#include <windows.h> #define IDB_PUSHBUTTON 10 HWND hwndPush; HINSTANCE hInst; char lpszClassName1[]="liitlepig"; LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window ) { char lpszClassName[]="lll"; char lpszTitle[]="lllll"; HWND hwnd; MSG msg; WNDCLASS wndclass;

wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndclass.hInstance=hInstance; wndclass.lpfnWndProc=WindowProc; wndclass.lpszClassName=lpszClassName; wndclass.lpszMenuName=NULL; wndclass.style=CS_HREDRAW | CS_VREDRAW;

if(!RegisterClass(&wndclass)) { MessageBeep(0); return FALSE; } hwnd=CreateWindow(lpszClassName, lpszTitle, WS_OVERLAPPEDWINDOW, 50,50, 700,500, NULL, NULL, hInstance, NULL); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { switch(uMsg) { case WM_CREATE: hwndPush=CreateWindow(lpszClassName1, "litt", BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE, 50,50, 120,25, hwnd, (HMENU)IDB_PUSHBUTTON, hInst, NULL); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; }

搜索更多相关主题的帖子: windows handle message instance 编译 
2004-12-17 20:03
BlueDreame
Rank: 1
等 级:新手上路
帖 子:545
专家分:2
注 册:2004-12-16
收藏
得分:0 
就症状来看,可能每加lib库。

2004-12-19 23:49
唐龙
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2004-11-27
收藏
得分:0 
lib库是怎么加的啊
2004-12-24 20:00
BlueDreame
Rank: 1
等 级:新手上路
帖 子:545
专家分:2
注 册:2004-12-16
收藏
得分:0 

兄弟有没搞错?两个我都编译了一遍,没问题啊。


2004-12-24 21:31
C++大粉丝
Rank: 4
等 级:贵宾
威 望:10
帖 子:477
专家分:0
注 册:2004-4-23
收藏
得分:0 

在你的应用程序最开始加上下面的连接选项:

#pragma comment(linker,"/SUBSYSTEM:WINDOWS")

或者到Project->Setting->Link->Project Options里:

将/subsystem:console换成/subsystem:windows,或者干脆删除就好了.

[此贴子已经被作者于2004-12-27 17:05:16编辑过]


I am a big fan of c plus plus.
2004-12-27 17:04
wandd
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2005-5-12
收藏
得分:0 
太好了!!真是谢谢!!
我也遇到了同样的问题啊!!
收获不小 啊!1
2005-05-13 18:49
zzb_ks
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2005-7-6
收藏
得分:0 
看来这还是很多人都会遇到的问题,我也遇到过这种问题,这是在市一个让人头痛的问题,输了这么多代码就是编辑不了。
一点成就感都没有。解决这个问题之后就爽了

2005-07-20 21:33
快速回复:不明的编译错误?
数据加载中...
 
   



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

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