| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 467 人关注过本帖
标题:这段windows代码在vc下运行为何有误?
只看楼主 加入收藏
jpg4151
Rank: 1
等 级:新手上路
帖 子:80
专家分:0
注 册:2006-3-12
收藏
 问题点数:0 回复次数:3 
这段windows代码在vc下运行为何有误?

#include <windows.h>
#include <stdio.h>
#define ID_TIMER 1

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

TCHAR szAppName[] = TEXT ("sample") ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
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 (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = szAppName ;
wndclass.lpszClassName = szAppName ;

if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}

hwnd = CreateWindow (szAppName, TEXT ("Menu Demonstration"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;

ShowWindow (hwnd, iCmdShow) ;
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;
char str[40];
TEXTMETRIC tm;
PAINTSTRUCT ps;
static int i=0;
static int cxlong,cylong,cxchar,cychar;
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
cxlong=cylong=10;
GetTextMetrics(hdc,&tm);
cxchar=tm.tmAveCharWidth;
cychar=tm.tmHeight;
ReleaseDC(hwnd,hdc);
return 0;
case WM_CHAR:
hdc=GetWindowDC(hwnd);
cxlong++;
if(cxlong==20)
{
cylong++;
cxlong=10;
}
if(i==40)
{
MessageBox(hwnd,"is not enough",szAppName,MB_OK);
i=0;
}

str[i]=(TCHAR)wParam;
TextOut(hdc,cxlong*cxchar,cylong*cychar,(str+i),1);
++i;
ReleaseDC(hwnd,hdc);
return 0;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click",szAppName,MB_OK);
hdc=GetWindowDC(hwnd);
//TextOut(hdc,20,100,
return 0;
case WM_CLOSE:
if(IDOK==MessageBox(NULL,"you really will go?","hi hi",MB_OKCANCEL))
{
DestroyWindow(hwnd);
}
return 0;
case WM_PAINT:
ps.fErase=0;
hdc=BeginPaint(hwnd,&ps);
//TextOut(hdc,20,20,"知识就使力量",strlen("知识就使力量"));
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
错误提示为:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Cpp1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

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

搜索更多相关主题的帖子: windows 有误 代码 运行 
2006-12-19 12:15
smartwind
Rank: 1
等 级:新手上路
威 望:1
帖 子:277
专家分:0
注 册:2006-11-13
收藏
得分:0 
工程类型错了,改成windows app

2006-12-19 12:44
maoguoqing
Rank: 6Rank: 6
来 自:重庆
等 级:贵宾
威 望:28
帖 子:2980
专家分:19
注 册:2005-12-5
收藏
得分:0 

关掉工程,重新编译还出现这种情况 ?


天行健,君子以自强不息!!QQ:68660681
2006-12-19 13:00
ZW_HAPPY
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-12-20
收藏
得分:0 
project\setting\link subsystem:windows试试,请多指教!
2006-12-20 13:43
快速回复:这段windows代码在vc下运行为何有误?
数据加载中...
 
   



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

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