home *** CD-ROM | disk | FTP | other *** search
/ Windoware / WINDOWARE_1_6.iso / source / winclass / winbase.h < prev    next >
C/C++ Source or Header  |  1991-03-18  |  5KB  |  139 lines

  1. #if !defined(WINBASE_H)
  2. class WindowRegClass {
  3.     WORD style;
  4.     LONG (FAR PASCAL *wndproc)( HWND, WORD, WORD, LONG );
  5.     int clsExtra;
  6.     int wndExtra;
  7.     HANDLE hinst;
  8.     HANDLE hprev;
  9.     HICON hicon;
  10.     HCURSOR hcursor;
  11.     HBRUSH backgrd;
  12.     LPSTR menuname;
  13.     LPSTR classname;
  14.  
  15. public:
  16.     WindowRegClass(LPSTR ClassName, HANDLE hInst, HANDLE hPrev,
  17.                          long (FAR PASCAL *proc)(HWND, WORD, WORD, LONG )) {
  18.         style          = CS_HREDRAW | CS_VREDRAW;
  19.         wndproc        = proc;
  20.         clsExtra       = 0;
  21.         wndExtra       = 0;
  22.         hinst          = hInst;
  23.         hprev          = hPrev;
  24.         hicon          = LoadIcon(NULL, IDI_APPLICATION);
  25.         hcursor        = LoadCursor(NULL, IDC_ARROW);
  26.         backgrd        = COLOR_WINDOW + 1;
  27.         menuname       = NULL;
  28.         classname      = ClassName;
  29.     }
  30.     void SetClassStyle(unsigned newstyle) { style =newstyle; }
  31.     void AddClassStyle(unsigned addstyle) { style |=addstyle; }
  32.     void SetClassBckrnd(HBRUSH newbckrnd) { backgrd =newbckrnd; }
  33.     void SetClassMenu(LPSTR newmenu) { menuname =newmenu; }
  34.     void SetClassWinXbytes(int xtrabytes) { wndExtra=xtrabytes; }
  35.     void SetClassClsXbytes(int xtrabytes) { clsExtra=xtrabytes; }
  36.     void SetClassIcon(LPSTR iconname) {
  37.         if (hinst)
  38.             hicon=LoadIcon(hinst,iconname);
  39.     }
  40.     void SetClassCursor(LPSTR cursorname) {
  41.         if (hinst)
  42.             hcursor=LoadCursor(hinst, cursorname);
  43.     }
  44.     void SetClassName(LPSTR clsname) { classname = clsname; }
  45.     LPSTR GetClassName(void) { return classname; }
  46.     void Register(void);
  47. };
  48.  
  49. void WindowRegClass::Register(void) {
  50.     WNDCLASS wndclass;
  51.  
  52.     if (!hprev)
  53.     {
  54.         wndclass.style          = style;
  55.         wndclass.lpfnWndProc    = wndproc;
  56.         wndclass.cbClsExtra     = clsExtra;
  57.         wndclass.cbWndExtra     = wndExtra;
  58.         wndclass.hInstance      = hinst;
  59.         wndclass.hIcon          = hicon;
  60.         wndclass.hCursor        = hcursor;
  61.         wndclass.hbrBackground  = backgrd;
  62.         wndclass.lpszMenuName   = menuname;
  63.         wndclass.lpszClassName  = classname;
  64.  
  65.         RegisterClass(&wndclass);
  66.     }
  67. }
  68.  
  69. class Window {
  70.      MSG msg;
  71.      HWND hwnd;
  72.      LPSTR classname;
  73.      LPSTR windowname;
  74.      DWORD winstyle;
  75.      int upper_left_x;
  76.      int upper_left_y;
  77.      int winwidth;
  78.      int winheight;
  79.      HWND winParent;
  80.      HMENU menu;
  81.      HANDLE hInstan;
  82.      LPSTR lpParam;
  83.  
  84. public:
  85.      Window(LPSTR clsname, LPSTR winname, HANDLE hinst) {
  86.         classname = clsname;
  87.         windowname = winname;
  88.         winstyle = 0;
  89.         upper_left_x=upper_left_y=winwidth=winheight=CW_USEDEFAULT;
  90.         winParent = NULL;
  91.         menu = NULL;
  92.         hInstan = hinst;
  93.         lpParam = NULL;
  94.     }
  95.  
  96.     void Display(void) { ShowWindow(GetHandle(), SW_SHOWNORMAL); }
  97.     void Display(HANDLE hinst, int disp) { ShowWindow(hinst, disp); }
  98.     void Update(void) { UpdateWindow(GetHandle()); }
  99.     HWND GetHandle(void)   { return hwnd; }
  100.     void Paint(void) {
  101.         PAINTSTRUCT ps;
  102.         RECT rect;
  103.         BeginPaint(GetHandle(), &ps);
  104.         EndPaint(GetHandle(), &ps);
  105.     }
  106.     MessageLoop(void) {
  107.         while (GetMessage(&msg,NULL,0,0))
  108.         {
  109.             TranslateMessage(&msg);
  110.             DispatchMessage(&msg);
  111.         }
  112.         return msg.wParam;
  113.     }
  114.     HWND Create(void) {
  115.         hwnd=CreateWindow(classname,
  116.                           windowname,
  117.                           winstyle,
  118.                           upper_left_x,
  119.                           upper_left_y,
  120.                           winwidth,
  121.                           winheight,
  122.                           winParent,
  123.                           menu, hInstan,
  124.                           lpParam);
  125.         return(hwnd);
  126.     }
  127.     void SetWinName(LPSTR winname)      { windowname=winname;   }
  128.     void SetWinStyle(DWORD dword)       { winstyle=dword;       }
  129.     void AddWinStyle(DWORD dword)       { winstyle |=dword;     }
  130.     void SetWinX(int x)                 { upper_left_x=x;       }
  131.     void SetWinY(int y)                 { upper_left_y=y;       }
  132.     void SetWinWidth(int width)         { winwidth=width;       }
  133.     void SetWinHeight(int height)       { winheight=height;     }
  134.     void SetWinInstance(HANDLE hinst)   { hInstan=hinst;      }
  135.     void SetTitle(LPSTR newtitle)       { SetWindowText(hwnd, newtitle); }
  136. };
  137. #define WINBASE_H
  138. #endif
  139.