home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / borllexp / blx_1_1 / hellow.cpp < prev    next >
Text File  |  1991-01-22  |  3KB  |  80 lines

  1. #include<windows.h>
  2. #include"winapp.h"
  3. #include"stdwin.h"
  4. #include"winfont.h"
  5. #include<string.h>
  6. class WHello : public WinAppStdWindow
  7. {
  8.     static WinClass wc;             // ALL descendants of Window must do this...
  9.     char *message;
  10.     WinFont     myFont;
  11. public:
  12.     static long FAR PASCAL _export WHello :: WndProc(HWND hWnd,
  13.                                    unsigned iMsg, WORD wParam, LONG lParam);
  14.     WHello(WinApp *myApp, char *winname, char *msg) :
  15.                     WinAppStdWindow(myApp, &wc, winname) {
  16.         // insert calls to change window class info here
  17.         message = msg;
  18.         if(GetClassName() == NULL) {
  19.             SetClassName("Hello");
  20.             SetClassWinProc(WHello::WndProc);
  21.         }
  22.         myFont.SetFontWeight(FW_HEAVY);
  23.         myFont.SetFontCharSet(OEM_CHARSET);
  24.         myFont.SetFontPitchAndFamily(FF_SCRIPT | VARIABLE_PITCH);
  25.         myFont.SetFontHeight(70);
  26.         myFont.SetFontWidth(15);
  27.         myFont.Create();
  28.     }
  29.     void Paint(void) {
  30.         PAINTSTRUCT ps; HDC hdc = BeginPaint(GetHandle(), &ps);
  31.         // set alignment flags for centering
  32.         SetTextAlign(ps.hdc, TA_CENTER);
  33.         SelectObject(hdc,myFont.GetHandle());
  34.         RECT rect;
  35.         GetClientRect(GetHandle(),&rect); // new centered rectangle
  36.         TextOut(ps.hdc,rect.right/2, rect.bottom/2,message, strlen(message));
  37.         EndPaint(GetHandle(), &ps);
  38.     }
  39.     void SetMessage(char *newmsg)  { message = newmsg; }
  40. };
  41.  
  42. WinClass WHello::wc;                                                            // ...and this.
  43.  
  44. // this should become a winproc for handling app-specific behavior
  45. long FAR PASCAL _export WHello::WndProc(HWND hWnd,
  46.                       unsigned iMsg, WORD wParam, LONG lParam) {
  47.     WHello *pWHello = (WHello *)GetPointer(hWnd);
  48.     switch (iMsg) {
  49.         case WM_CREATE:                         // insert the pointer
  50.             pWHello = (WHello *)((LPCREATESTRUCT)lParam)->lpCreateParams;
  51.             SetPointer(hWnd, pWHello);
  52.             break;
  53.         case WM_PAINT:
  54.             pWHello->Paint();             // call Paint method
  55.             break;
  56.         case WM_CLOSE:
  57.             DestroyWindow(hWnd);
  58.             break;
  59.         case WM_DESTROY:
  60.             PostQuitMessage(0);
  61.             break;
  62.         default:
  63.             return DefWindowProc(hWnd, iMsg, wParam, lParam);
  64.     }
  65.     return 0L;
  66. }
  67.  
  68. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  69.                                    LPSTR lpszCmdLine, int  nCmdShow) {
  70.     // create an instance of WinApp and initialize it
  71.     WinApp MyApp(hInstance, hPrevInstance, lpszCmdLine, nCmdShow);
  72.     // create an instance of WHello for MyApp with winname, "Hello!"
  73.     WHello MyWin(&MyApp, "Hello!", "Hello, Windows from Borland C++");
  74.     MyWin.Display();                                        // open the window
  75.     // create another instance
  76.     WHello MyWin2(&MyApp, "Hello2!", "And, another Hello!");
  77.     MyWin2.Display();                                      // open it
  78.     return MyApp.MessageLoop();                   // process any messages
  79. }
  80.