当前位置:首页 > 技术问答集
firefox

估计是环境配置问题

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

#include   <windows.h>  
  lresult   callback   wndproc(hwnd,uint,wparam,lparam);  
  int   winapi   winmain(hinstance   hinstance,   hinstance   hprevinstance,   pstr   szcmdline,   int   icmdshow)  
  {  
  static   tchar   szappname[]   =   text("hellowin");  
  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   =   null;  
  wndclass.lpszclassname   =   szappname;  
  if(!registerclass(&wndclass))  
  {  
  messagebox(null,   text("this   program   repuire   windows   nt!"),szappname,   mb_iconerror);  
  return   0;  
  }  
   
  hwnd   =   createwindow(szappname,    
                                  text("the   hello   program"),    
  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;  
  paintstruct   ps;  
  rect   rect;  
  switch(message)  
  {  
  case   wm_create:  
  // playsound(text("eagle2.wav"),   null,   snd_filename|snd_async);  
  return   0;  
  case   wm_paint:  
  hdc=beginpaint(hwnd,   &ps);  
  getclientrect(hwnd,   &rect);  
  drawtext(hdc,   text("hello,   windows   98!"),   -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);  
  }

· 网友精彩回答:

发表者:hidejay

这是一个windows程序设计的例子,我刚学,但compile通过,build不过,系统提示  
  --------------------configuration:   1   -   win32   debug--------------------  
  compiling...  
  1.cpp  
  linking...  
  1.obj   :   error   lnk2001:   unresolved   external   symbol   __imp__playsounda@12  
  libcd.lib(crt0.obj)   :   error   lnk2001:   unresolved   external   symbol   _main  
  debug/1.exe   :   fatal   error   lnk1120:   2   unresolved   externals  
  error   executing   link.exe.  
   
  1.exe   -   3   error(s),   0   warning(s)  
  第一个,我知道,是文件问题,我把它//了,但后面两个就不知道了,故向达人求解!

发表者:hidejay

有人知道吗?

发表者:yifei_123

提醒您注意:如果您使用microsoft   visual   c++   为此程序建立新项目,那么您得加上连结程序所需的链接库文件。从project菜单选择   setting选项,然后选取link页面标签。从   category清单方块中选择general,然后在   object/library   modules文字方块添加winmm.lib。您这样做是因为hellowin将使用多媒体功能呼叫,而内定的项目中又不包括多媒体链接库文件。不然连结程序报告了错误信息,表明playsound函数不可用。  
   
  hellowin将存取文件eagle2.wav,执行hellowin.exe时,内定的目录必须是hellowin。在visual   c++中执行此程序时,虽然执行文件会产生在hellowin的release或debug子目录中,但执行程序的目录还是必须在hellowin中。  
 

发表者:yifei_123

上面是我从《windows程序设计》中文电子版里复制过来的,你的程序应该是“窗口和消息”章的hellowin程序,我运行了一下你的程序,在   object/library   modules文字方块添加winmm.lib后无错误,但要记得eagle2.wav在你所建立的文件夹下才可以听到声音……  
  估计是你的vc有点问题吧,期待高手解答,呵呵  
 

发表者:snowbirdfly

这个是你建的工程错了~~  
  你应该建的工程是win32   application    
  而不是win32   console   application~~  
  试一下~~~

发表者:snowbirdfly

对了~  
  compiling...  
  1.cpp  
  linking...  
  1.obj   :   error   lnk2001:   unresolved   external   symbol   __imp__playsounda@12  
  libcd.lib(crt0.obj)   :   error   lnk2001:   unresolved   external   symbol   _main  
  debug/1.exe   :   fatal   error   lnk1120:   2   unresolved   externals  
  error   executing   link.exe.  
  出现这样的错误可以这样解决~~~  
  ///////////////////////////////  
  打开菜单project->setting(或alt+f7)  
  然后再打开link选项,在下面的project   options将  
  /subsystem:console   /incremental:yes   去掉就可以了~~~

发表者:snowbirdfly

因为编译器会默认你建的是mfc工程!~~  
  所以会出错~~~

发表者:hidejay

我建的是win32   application    
 

.
© 2006-2008 All Rights Reserved