home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / msjv7_5.zip / WINCPP.ARJ / CPP3.ARJ / WINAPP.H < prev    next >
C/C++ Source or Header  |  1992-09-01  |  4KB  |  133 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;       // class declarations
  14. class WinApp;
  15.  
  16. class Window
  17.     {
  18. protected:
  19.     HWND hWnd;
  20. public:
  21.     Window(HWND newhWnd = 0)
  22.         {
  23.         hWnd = newhWnd;
  24.         }
  25.     ~Window(){}
  26.  
  27.     BOOL RegisterClass(UINT style,WNDPROC WndProc,int ClsExtra,
  28.             int WndExtra,HINSTANCE inst,HICON icon,HCURSOR cursor,
  29.             HBRUSH brush,LPCSTR menuname,LPCSTR classname)
  30.         {
  31.         WNDCLASS wc;
  32.  
  33.         wc.style = style;
  34.         wc.lpfnWndProc = WndProc;
  35.         wc.cbClsExtra = ClsExtra;
  36.         wc.cbWndExtra = WndExtra;
  37.         wc.hInstance = inst;
  38.         wc.hIcon = icon;
  39.         wc.hCursor = cursor;
  40.         wc.hbrBackground = brush;
  41.         wc.lpszMenuName = menuname;
  42.         wc.lpszClassName = classname;
  43.  
  44.         return ::RegisterClass(&wc);
  45.         }
  46.  
  47.     BOOL RegisterClass(
  48.             UINT style,
  49.             WNDPROC WndProc,
  50.             LPCSTR menuname, 
  51.             LPCSTR classname,
  52.             HICON icon = LoadIcon(NULL, IDI_APPLICATION),
  53.             HCURSOR cursor = LoadCursor(NULL, IDC_ARROW),
  54.             HBRUSH brush = GetStockObject(WHITE_BRUSH))
  55.         {
  56.         return RegisterClass(style,WndProc,0,0,WinApphInstance,icon,cursor,
  57.             brush,menuname,classname);
  58.         }
  59.  
  60.     BOOL CreateWindow(LPCSTR classname,LPCSTR text,DWORD style,int x,int y,
  61.             int width,int height,HWND parent,HMENU menu,HINSTANCE inst,
  62.             void FAR *params)
  63.         {
  64.         if(hWnd = ::CreateWindow(classname,text,style,x,y,width,height,
  65.                 parent,menu,inst,params))
  66.             return TRUE;
  67.         return FALSE;
  68.         }
  69.  
  70.     BOOL CreateWindow(
  71.             LPCSTR classname,
  72.             LPCSTR text,
  73.             DWORD style,
  74.             HWND parent = NULL,
  75.             HMENU menu = NULL)
  76.         {
  77.         return CreateWindow(classname,text,style,
  78.             CW_USEDEFAULT,              // Default position.       
  79.             CW_USEDEFAULT,              // Default position.       
  80.             CW_USEDEFAULT,              // Default position.       
  81.             CW_USEDEFAULT,              // Default position.       
  82.             parent,menu,WinApphInstance,NULL);
  83.         }
  84.  
  85.     BOOL ShowWindow(int cmdshow = WinAppnCmdShow)
  86.         {
  87.         return ::ShowWindow(hWnd,cmdshow);
  88.         }
  89.     void UpdateWindow(void)
  90.         {
  91.         ::UpdateWindow(hWnd);
  92.         }
  93.     };
  94.  
  95. extern WinApp *pWinApp;
  96.  
  97. class WinApp
  98.     {
  99. public:
  100.     Window      *mainWnd;
  101.  
  102.         // constructor -- initializes data members
  103.     WinApp(void)       : mainWnd(NULL)
  104.         {
  105. #if defined(DEBUG)
  106.         assert(pWinApp == NULL); // only one WinApp object allowed
  107. #endif
  108.         pWinApp = this;    // initialize WinApp pointer
  109.         }
  110.     ~WinApp(){}        // virtual destructor, allows overriding
  111.  
  112.                         // functions to access data members
  113.     HINSTANCE   Instance(void)      {   return  WinApphInstance;      }
  114.     HINSTANCE   PrevInstance(void)  {   return  WinApphPrevInstance;  }
  115.     LPSTR       CmdLine(void)       {   return  WinApplpCmdLine;      }
  116.     int         CmdShow(void)       {   return  WinAppnCmdShow;       }
  117.  
  118.     void Init(HINSTANCE hInst,HINSTANCE hPrev,LPSTR cmdLine,int cmdShow)
  119.         {
  120.         WinApphInstance = hInst;
  121.         WinApphPrevInstance = hPrev;
  122.         WinApplpCmdLine = cmdLine;
  123.         WinAppnCmdShow = cmdShow;
  124.         }
  125.     virtual BOOL InitApplication(void)  {   return TRUE;    }
  126.     virtual BOOL InitInstance(void)     {   return TRUE;    }
  127.     };
  128.  
  129. BOOL FAR PASCAL About(HWND hWnd, LPCSTR resoureName);
  130. #endif
  131.  
  132.  
  133.