CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

我想做一个最简单的(对我来说很复杂)的程序窗口程序.请各位帮忙.

楼主sea_way(狒狒)2002-01-10 20:38:51 在 C/C++ / C语言 提问

我用BORLANDC++3.1新建一个MATH.CPP文件  
  现在呢我要建立一个空白窗口怎么办  
  我想建立这样的程序  
  +----------------------------+  
  +----------------------------+  
  |请输入第一个数:[_________]     |  
  |请输入第二个数:[_________]     |  
  |两个浮点数相加的结果:               |  
  |   [________________________]   |  
  |         [计算]         [关闭]                 |  
  +----------------------------+  
  请各位帮我用纯实现吧.先从第一步开始.我该怎么做阿? 问题点数:30、回复次数:15Top

1 楼ccnuxjg()回复于 2002-01-10 20:46:19 得分 0

说起来很麻烦,自己看SDK吧,很容易的Top

2 楼sea_way(狒狒)回复于 2002-01-10 21:06:27 得分 0

可是我手头没有sdk的书阿.帮帮我吧.我以前学VB就是从这样的程序开始的.可是这个C++太麻烦了.什么都要自己做*_*  
  大概给我说一下也行阿..或者介绍几本书..随便说说啦..Top

3 楼sea_way(狒狒)回复于 2002-01-10 21:56:33 得分 0

没有那位帮帮小第吗?我也有点C语言基础,学C++的窗口程序设计不算过分吧.  
  对了我还不会在这里给分阿.教教我阿.Top

4 楼sea_way(狒狒)回复于 2002-01-10 22:22:03 得分 0

真的有那么难吗?大家都不会,还是不屑于回答.不是大家都用MFC建立窗体吧!Top

5 楼weixiaohua(我爱Delphi)回复于 2002-01-11 00:04:40 得分 0

呵呵~!  
  在这里没几个人能真真自己动手做一个像你要求的这个程序.......Top

6 楼kinghawk(惊鸿)回复于 2002-01-11 08:23:58 得分 0

我有窗口,汉字显示,鼠标控制的源程序,TC2.0的,可能符合你的要求(不一定),要给我邮箱!  
  kinghawk8000@sohu.com  
  Top

7 楼sea_way(狒狒)回复于 2002-01-11 10:09:30 得分 0

好阿..谢谢了..Top

8 楼alou()回复于 2002-01-11 10:59:26 得分 0

Windows?DOS?  
  Windows的话需要使用Windows   SDK,DOS的话使用Turbo   Vision(不好用,如果找到附带的例子的话可以改改   --   如果你对窗口系统比较熟悉的话,另外有一本书Borland   C++   3.1类库.....是讲这个的)。Top

9 楼qiyao(享受每一天)回复于 2002-01-11 11:04:52 得分 0

有那位高手,可以搞定这个!!!  
  http://www.csdn.net/Expert/topic/470/470143.shtm   Top

10 楼TalentSprite(举头望明月)回复于 2002-01-11 11:39:15 得分 0

dos还是windows的?Top

11 楼sea_way(狒狒)回复于 2002-01-11 11:47:11 得分 0

当然是建立windows窗体了.我有个演示程序.但是我看不太懂.  
  //   Borland   C++   -   (C)   Copyright   1991,   1992   by   Borland   International  
  //  
  //     Windows   HELLO   WORLD   -   C++   Version    
   
  #define     STRICT  
  #include   <windows.h>  
  #include   <stdlib.h>  
  #include   <string.h>  
   
  LRESULT   CALLBACK   _export   WndProc(   HWND   hWnd,   UINT   iMessage,  
                                                                    WPARAM   wParam,   LPARAM   lParam   );  
   
  class   Main  
  {  
  public:  
  static   HINSTANCE   hInstance;  
  static   HINSTANCE   hPrevInstance;  
  static   int   nCmdShow;  
  static   int   MessageLoop(   void   );  
  };  
   
  class   Window  
  {  
  protected:  
          HWND   hWnd;  
  public:  
          //   Provide   (read)   access   to   the   window's   handle   in   case   it   is   needed  
          //   elsewhere.  
          HWND   GetHandle(   void   )   {   return   hWnd;   }  
   
          BOOL   Show(   int   nCmdShow   )   {   return   ShowWindow(   hWnd,   nCmdShow   );   }  
          void   Update(   void   )   {   UpdateWindow(   hWnd   );   }  
          //   Pure   virtual   function   makes   Window   an   abstract   class.  
          virtual   long   WndProc(   UINT   iMessage,   WPARAM   wParam,   LPARAM   lParam   )   =   0;  
  };  
   
  class   MainWindow   :   public   Window  
  {  
  private:  
          static   char   szClassName[14];  
          //   Helper   function   used   by   Paint   function;   it   is   used   as   a  
          //   callback   function   by   LineDDA.  
          static   void   FAR   PASCAL   LineFunc(   int   X,   int   Y,   LPSTR   lpData   );  
  public:  
          //   Register   the   class   only   AFTER   WinMain   assigns   appropriate  
          //   values   to   static   members   of   Main   and   only   if   no   previous  
          //   instances   of   the   program   exist   (a   previous   instance   would  
          //   have   already   performed   the   registration).  
          static   void   Register(   void   )  
          {  
                  WNDCLASS   wndclass;       //   Structure   used   to   register   Windows   class.  
   
                  wndclass.style                   =   CS_HREDRAW   |   CS_VREDRAW;  
                  wndclass.lpfnWndProc       =   ::WndProc;  
                  wndclass.cbClsExtra         =   0;  
                  //   Reserve   extra   bytes   for   each   instance   of   the   window;  
                  //   we   will   use   these   bytes   to   store   a   pointer   to   the   C++  
                  //   (MainWindow)   object   corresponding   to   the   window.  
                  //   the   size   of   a   'this'   pointer   depends   on   the   memory   model.  
                  wndclass.cbWndExtra         =   sizeof(   MainWindow   *   );  
                  wndclass.hInstance           =   Main::hInstance;  
                  wndclass.hIcon                   =   LoadIcon(   Main::hInstance,   "whello"   );  
                  wndclass.hCursor               =   LoadCursor(   NULL,   IDC_ARROW   );  
                  wndclass.hbrBackground   =   (HBRUSH)GetStockObject(   WHITE_BRUSH   );  
                  wndclass.lpszMenuName     =   NULL;  
                  wndclass.lpszClassName   =   szClassName;  
   
                  if   (   !   RegisterClass(   &wndclass   )   )  
                          exit(   FALSE   );  
          }  
   
          //   Do   not   create   unless   previously   registered.  
          MainWindow(   void   )  
          {  
                  //   Pass   'this'   pointer   in   lpParam   of   CreateWindow().  
                  hWnd   =   CreateWindow(   szClassName,  
                          szClassName,  
                          WS_OVERLAPPEDWINDOW,  
                          CW_USEDEFAULT,  
                          0,  
                          CW_USEDEFAULT,  
                          0,  
                          NULL,  
                          NULL,  
                          Main::hInstance,  
                          (LPSTR)   this   );  
                  if   (   !   hWnd   )  
                          exit(   FALSE   );  
   
                  Show(   Main::nCmdShow   );  
                  Update();  
          }  
          long   WndProc(   UINT   iMessage,   WPARAM   wParam,   LPARAM   lParam   );      
   
          //   Print   a   message   in   the   client   rectangle.  
          void   Paint(   void   );  
          //   Struct   used   by   Paint   to   pass   information   to   callback   function  
          //   used   by   LineDDA  
          struct   LINEFUNCDATA  
          {  
                  HDC   hDC;  
                  char   FAR   *LineMessage;  
                  int   MessageLength;  
                  LINEFUNCDATA(   char   *Message   )  
                  {  
                          hDC   =   0;  
                          MessageLength   =   strlen(   Message   );  
                          LineMessage   =   new   far   char   [MessageLength+1];  
                          lstrcpy(   LineMessage,   Message   );  
                  };  
                  ~LINEFUNCDATA(   void   )   {   delete   LineMessage;   }  
          };  
  };  
   
  HINSTANCE   Main::hInstance   =   0;  
  HINSTANCE   Main::hPrevInstance   =   0;  
  int   Main::nCmdShow   =   0;  
   
  int   Main::MessageLoop(   void   )  
  {  
          MSG   msg;  
   
          while(   GetMessage(   &msg,   NULL,   0,   0   )   )  
          {  
                  TranslateMessage(   &msg   );  
                  DispatchMessage(   &msg   );  
          }  
          return   msg.wParam;  
  }  
   
  char   MainWindow::szClassName[]   =   "你好,世界!";  
   
  void   MainWindow::Paint(   void   )  
  {  
          PAINTSTRUCT   ps;  
          RECT   rect;  
          FARPROC   lpLineFunc;  
          LINEFUNCDATA   LineFuncData(   "BORLAND   C++   欢迎你来到这奇妙的WINDOWS编程世界!"   );  
   
          lpLineFunc   =   MakeProcInstance(   (FARPROC)   MainWindow::LineFunc,   (HINSTANCE)Main::hInstance   );  
          BeginPaint(   hWnd,   &ps   );  
          GetClientRect(   hWnd,   (LPRECT)   &rect   );  
          LineFuncData.hDC   =   ps.hdc;  
          SetTextAlign(   ps.hdc,   TA_BOTTOM   );  
          LineDDA(   0,   0,   0,  
    rect.bottom   /   2,   (LINEDDAPROC)lpLineFunc,   (LPARAM)   &LineFuncData   );  
          EndPaint(   hWnd,   &ps   );  
          FreeProcInstance(   lpLineFunc   );  
  }  
   
  void   FAR   PASCAL   _export   MainWindow::LineFunc(   int   X,   int   Y,   LPSTR   lpData   )  
  {  
          LINEFUNCDATA   FAR   *   lpLineFuncData   =   (LINEFUNCDATA   FAR   *)   lpData;  
          TextOut(   lpLineFuncData->hDC,   X,   Y,  
                            lpLineFuncData->LineMessage,   lpLineFuncData->MessageLength   );  
  }  
   
  long   MainWindow::WndProc(   UINT   iMessage,   WPARAM   wParam,   LPARAM   lParam   )  
  {  
          switch   (iMessage)  
          {  
                  case   WM_CREATE:  
          break;  
                  case   WM_PAINT:  
                          Paint();  
                          break;  
                  case   WM_DESTROY:  
                          PostQuitMessage(   0   );  
                          break;  
                  default:  
                          return   DefWindowProc(   hWnd,   iMessage,   wParam,   lParam   );  
          }  
          return   0;  
  }  
   
  //   If   data   pointers   are   near   pointers  
  #if   defined(__SMALL__)   ||   defined(__MEDIUM__)  
  inline   Window   *GetPointer(   HWND   hWnd   )  
  {  
          return   (Window   *)   GetWindowWord(   hWnd,   0   );  
  }  
  inline   void   SetPointer(   HWND   hWnd,   Window   *pWindow   )  
  {  
          SetWindowWord(   hWnd,   0,   (WORD)   pWindow   );  
  }  
   
  //   else   pointers   are   far  
  #elif   defined(__LARGE__)   ||   defined(__COMPACT__)  
  inline   Window   *GetPointer(   HWND   hWnd   )  
  {  
          return   (Window   *)   GetWindowLong(   hWnd,   0   );  
  }  
  inline   void   SetPointer(   HWND   hWnd,   Window   *pWindow   )  
  {  
          SetWindowLong(   hWnd,   0,   (LONG)   pWindow   );  
  }  
   
  #else  
          #error   Choose   another   memory   model!  
  #endif  
   
  LRESULT     CALLBACK   _export   WndProc(   HWND   hWnd,   UINT   iMessage,   WPARAM   wParam,  
                                                                    LPARAM   lParam   )  
  {  
          //   Pointer   to   the   (C++   object   that   is   the)   window.  
          Window   *pWindow   =   GetPointer(   hWnd   );  
   
          //   The   pointer   pWindow   will   have   an   invalid   value   if   the   WM_CREATE  
          //   message   has   not   yet   been   processed   (we   respond   to   the   WM_CREATE  
          //   message   by   setting   the   extra   bytes   to   be   a   pointer   to   the  
          //   (C++)   object   corresponding   to   the   Window   identified  
          //   by   hWnd).     The   messages   that  
          //   precede   WM_CREATE   must   be   processed   without   using   pWindow   so   we  
          //   pass   them   to   DefWindowProc.  
          //   How   do   we   know   in   general   if   the   pointer   pWindow   is   invalid?  
          //   Simple:   Windows   allocates   the   window   extra   bytes   using   LocalAlloc  
          //   which   zero   initializes   memory;   thus,   pWindow   will   have   a   value   of  
          //   zero   before   we   set   the   window   extra   bytes   to   the   'this'   pointer.  
          //   Caveat   emptor:   the   fact   that   LocalAlloc   will   zero   initialize   the  
          //   window   extra   bytes   is   not   documented;   therefore,   it   could   change  
          //   in   the   future.  
   
          if   (   pWindow   ==   0   )  
          {  
                  if   (   iMessage   ==   WM_CREATE   )  
                  {  
                          LPCREATESTRUCT   lpcs;  
   
                          lpcs   =   (LPCREATESTRUCT)   lParam;  
                          pWindow   =   (Window   *)   lpcs->lpCreateParams;  
   
                          //   Store   a   pointer   to   this   object   in   the   window's   extra   bytes;  
                          //   this   will   enable   us   to   access   this   object   (and   its   member  
                          //   functions)   in   WndProc   where   we   are  
                          //   given   only   a   handle   to   identify   the   window.  
                          SetPointer(   hWnd,   pWindow   );  
                          //   Now   let   the   object   perform   whatever  
                          //   initialization   it   needs   for   WM_CREATE   in   its   own  
                          //   WndProc.  
          return   pWindow->WndProc(   iMessage,   wParam,   lParam   );  
                  }  
                  else  
                          return   DefWindowProc(   hWnd,   iMessage,   wParam,   lParam   );  
          }  
          else  
                  return   pWindow->WndProc(   iMessage,   wParam,   lParam   );  
  }  
   
  //   Turn   off   warning:   Parameter   'lpszCmdLine'   is   never   used   in   function   WinMain(unsigned   int,unsigned   int,char   far*,int)  
  #pragma   argsused  
   
  //   Turn   off   warning:   'MainWnd'   is   assigned   a   value   that   is   never   used   in   function   WinMain(unsigned   int,unsigned   int,char   far*,int)  
  #pragma   option   -w-aus  
   
  int   PASCAL   WinMain(   HINSTANCE   hInstance,   HINSTANCE   hPrevInstance,   LPSTR   lpszCmdLine,  
                                          int   nCmdShow   )  
  {  
          Main::hInstance   =   hInstance;  
          Main::hPrevInstance   =   hPrevInstance;  
          Main::nCmdShow   =   nCmdShow;  
   
          //   A   Windows   class   should   be   registered   with   Windows   before   any   windows  
          //   of   that   type   are   created.  
          //   Register   here   all   Windows   classes   that   will   be   used   in   the   program.  
          //   Windows   classes   should   not   be   registered   if   an   instance   of  
          //   the   program   is   already   running.  
          if   (   !   Main::hPrevInstance   )   {  
                  MainWindow::Register();  
          }  
   
          MainWindow   MainWnd;  
   
          return   Main::MessageLoop();  
  }  
  Top

12 楼sea_way(狒狒)回复于 2002-01-11 12:42:35 得分 0

看看再说阿...Top

13 楼sea_way(狒狒)回复于 2002-01-11 12:43:39 得分 0

dingTop

14 楼sea_way1()回复于 2002-01-11 20:19:36 得分 30

dingTop

15 楼sea_way(狒狒)回复于 2002-01-11 20:20:22 得分 0

dingTop

相关问题

  • 简单的问题? 但对我来说就.....
  • 很简单的问题,对我来说很难。
  • 求救!我想很简单,只是对我来说有点难!
  • 简单小程序!
  • 求简单程序!
  • 【不知是复杂还是简单的问题】在unicode程序里SetWindowText无一例外地得到乱码
  • 【不知是复杂还是简单的问题】在unicode程序里SetWindowText无一例外地得到乱码
  • 一个程序的两个界面互相切换问题(简单界面与复杂界面相互切换)
  • 大家知道怎么样做安装程序不?最简单的到最复杂的都可以说
  • 你说它简单,对我来说就很难,因为我不懂.请指教.

关键词

  • c++
  • borland
  • 程序
  • hwnd
  • ncmdshow
  • 阿
  • wparam
  • 建立
  • lparam
  • hinstance

得分解答快速导航

  • 帖主:sea_way
  • sea_way1

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo