home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / msjv7_5.zip / WINCPP.ARJ / CPP2.ARJ / WINAPP.H < prev    next >
C/C++ Source or Header  |  1992-09-01  |  4KB  |  121 lines

  1. // WinApp.h RHS 4/15/92
  2.  
  3. #if !defined(WINAPP_H)
  4. #define WINAPP_H
  5.  
  6. #include<windows.h>
  7.  
  8. extern HINSTANCE   WinApphInstance;
  9. extern HINSTANCE   WinApphPrevInstance;
  10. extern LPSTR       WinApplpCmdLine;
  11. extern int         WinAppnCmdShow;
  12.  
  13. class Window
  14.     {
  15. protected:
  16.     HWND hWnd;
  17. public:
  18.     Window(HWND newhWnd = 0)
  19.         {
  20.         hWnd = newhWnd;
  21.         }
  22.     ~Window(){}
  23.    
  24.     BOOL RegisterClass(UINT style,WNDPROC WndProc,int ClsExtra,
  25.             int WndExtra,HINSTANCE inst,HICON icon,HCURSOR cursor,
  26.             HBRUSH brush,LPCSTR menuname,LPCSTR classname)
  27.         {
  28.         WNDCLASS wc;
  29.  
  30.         wc.style = style;
  31.         wc.lpfnWndProc = WndProc;
  32.         wc.cbClsExtra = ClsExtra;
  33.         wc.cbWndExtra = WndExtra;
  34.         wc.hInstance = inst;
  35.         wc.hIcon = icon;
  36.         wc.hCursor = cursor;
  37.         wc.hbrBackground = brush;
  38.         wc.lpszMenuName = menuname;
  39.         wc.lpszClassName = classname;
  40.  
  41.         return ::RegisterClass(&wc);
  42.         }
  43.  
  44.     BOOL RegisterClass(
  45.             UINT style,
  46.             WNDPROC WndProc,
  47.             LPCSTR menuname, 
  48.             LPCSTR classname,
  49.             HICON icon = LoadIcon(NULL, IDI_APPLICATION),
  50.             HCURSOR cursor = LoadCursor(NULL, IDC_ARROW),
  51.             HBRUSH brush = GetStockObject(WHITE_BRUSH))
  52.         {
  53.         return RegisterClass(style,WndProc,0,0,WinApphInstance,icon,cursor,
  54.             brush,menuname,classname);
  55.         }
  56.  
  57.     BOOL CreateWindow(LPCSTR classname,LPCSTR text,DWORD style,int x,int y,
  58.             int width,int height,HWND parent,HMENU menu,HINSTANCE inst,
  59.             void FAR *params)
  60.         {
  61.         if(hWnd = ::CreateWindow(classname,text,style,x,y,width,height,
  62.                 parent,menu,inst,params))
  63.             return TRUE;
  64.         return FALSE;
  65.         }
  66.  
  67.      BOOL CreateWindow(
  68.             LPCSTR classname,
  69.             LPCSTR text,
  70.             DWORD style,
  71.             HWND parent = NULL,
  72.             HMENU menu = NULL)
  73.         {
  74.         return CreateWindow(classname,text,style,
  75.             CW_USEDEFAULT,              // Default position.       
  76.             CW_USEDEFAULT,              // Default position.       
  77.             CW_USEDEFAULT,              // Default position.       
  78.             CW_USEDEFAULT,              // Default position.       
  79.             parent,menu,WinApphInstance,NULL);
  80.         }
  81.  
  82.     BOOL ShowWindow(int cmdshow = WinAppnCmdShow)
  83.         {
  84.         return ::ShowWindow(hWnd,cmdshow);
  85.         }
  86.     void UpdateWindow(void)
  87.         {
  88.         ::UpdateWindow(hWnd);
  89.         }
  90.     };
  91.  
  92. class WinApp
  93.     {
  94. public:
  95.     Window      *mainWnd;
  96.  
  97.     WinApp(void)        : mainWnd(NULL)
  98.         {}      // constructor -- initializes data members
  99.     ~WinApp()           // virtual destructor, allows overriding
  100.         {
  101.         if(mainWnd)
  102.             delete mainWnd;
  103.         }
  104.                         // functions to access data members
  105.     HINSTANCE   Instance(void)      {   return  WinApphInstance;      }
  106.     HINSTANCE   PrevInstance(void)  {   return  WinApphPrevInstance;  }
  107.     LPSTR       CmdLine(void)       {   return  WinApplpCmdLine;      }
  108.     int         CmdShow(void)       {   return  WinAppnCmdShow;       }
  109.  
  110.     void Init(HINSTANCE hInst,HINSTANCE hPrev,LPSTR cmdLine,int cmdShow)
  111.         {
  112.         WinApphInstance = hInst;
  113.         WinApphPrevInstance = hPrev;
  114.         WinApplpCmdLine = cmdLine;
  115.         WinAppnCmdShow = cmdShow;
  116.         }
  117.     };
  118. #endif
  119.  
  120.  
  121.