用VC编绎API程序的一个初级问题!

一年 2003-10-27 10:35:38
有一段程序很简单是这样的:
#include <windows.h>
#include <stdlib.h>
#include <string.h>

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

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow
)

{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";

char lpszTitle[]="My windows";
wndclass.style=0;
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 = GetStockObject(WHITE_BRUSH);


wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;

if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}


hwnd=CreateWindow(lpszClassName,
lpszTitle,
//"刷子",
//NULL,
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


)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
default :
return DefWindowProc(hwnd,message,wParam,lParam);

}
return(0);
}

我写程序的方法是VC6->新建->文件->C++ SOURCE FILE,在编辑区里写以上代码但编辑不能通过。出错如下:
Linker Tools Error LNK1120
>number unresolved externals
>
>Error LNK1120 gives you a count (number) of unresolved externals for this link. The conditions that cause unresolved externals are described with error LNK2001, which precedes this error message (once for each unresolved external).

我确定不是程序本身的问题应该是写程序的方法问题,敢问高手,这种用API编程序该怎么写?
...全文
36 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZhouBoTong 2003-10-31
  • 打赏
  • 举报
回复
楼上兄弟,再我那里没有你那种问题啊,一切正常。还是有些代码你没有公布阿?
一年 2003-10-31
  • 打赏
  • 举报
回复
意思就是说,编译时,不是产生了我写的那个窗体,或者说我的那个窗体出现得很快然后就释放了,我还没有觉查到,然后他打开了IE浏览器!
rainbowinfog 2003-10-30
  • 打赏
  • 举报
回复
Projects|Settings|Link
/subsystem:console /
改为
/subsystem:windows /
ZhouBoTong 2003-10-30
  • 打赏
  • 举报
回复
不应该是头文件的问题!
我是这么做的,结果没有问题:

VC->新建->工程->win32 application-》a simple win32 application

// ErrorPrag.cpp : アプリケーション用のエントリ ポイントの定義
//

#include "stdafx.h"

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


);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
// TODO: この位置にコードを記述してください。

HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";

char lpszTitle[]="My windows";
wndclass.style=0;
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 = GetStockObject(WHITE_BRUSH);


wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;

if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}


hwnd=CreateWindow(lpszClassName,
lpszTitle,
//"刷子",
//NULL,
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


)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
default :
return DefWindowProc(hwnd,message,wParam,lParam);

}
return(0);
}



ZhouBoTong 2003-10-30
  • 打赏
  • 举报
回复
但是看不到执行结果却打了IE,为什么?

上面那句话是什么意思,具体一点吧
一年 2003-10-30
  • 打赏
  • 举报
回复
我想尽快结贴了!
一年 2003-10-30
  • 打赏
  • 举报
回复
是头文件,我包了个INCLUDE 《WINDOWS。H》就不行。为什么?

还有我用: ZhouBoTong(周伯童) 兄的方法,没有错误了,但是看不到执行结果却打了IE,为什么?
dzqsuper 2003-10-28
  • 打赏
  • 举报
回复
.
.
...
.....
.......
.........
...........
.............

我来顶
一年 2003-10-28
  • 打赏
  • 举报
回复
我偿试如下方法:
VC->新建->工程->win32 application-》a simple win32 application

我删除了所以.CPP中的内容,加上以上内容。还是出错
Fatal Error C1010
unexpected end of file while looking for precompiled header directive

A precompiled header was specified, but it did not contain a precompiled header directive.

This error can be caused by specifying an incorrect file as a header file, or by specifying an include file with the /Yu (Use Precompiled Header) command line option that is not listed in the source file as an include file.

我不知道还要加上什么头文件?
kikicat33 2003-10-27
  • 打赏
  • 举报
回复
建议你去看看有关windows编程的书,熟悉一下消息循环机制。
Petzold写的Programming Windows Fifth Edition ,可以看看
cmsbai 2003-10-27
  • 打赏
  • 举报
回复
呵呵,VC->新建->工程->win32 application
然后加入上面那一个文件,编译就行了
wuxfBrave 2003-10-27
  • 打赏
  • 举报
回复
没有工程文件
thisisjjjj 2003-10-27
  • 打赏
  • 举报
回复
VC6没怎么用过,反正在VS.NET下你应该“新建工程”,然后选择Win32项目。

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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