home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / WEXAMPLE.ZIP / TODOWIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.8 KB  |  152 lines

  1. //---------------------------------------------------------------------
  2. //
  3. //  TODOWIN.CPP - part of TODO example program
  4. //
  5. //      Copyright (c) 1991, 1992 by Borland International
  6. //      All Rights Reserved.
  7. //
  8. //---------------------------------------------------------------------
  9.  
  10. #define STRICT
  11.  
  12. #if !defined( __WINDOWS_H )
  13. #include <Windows.h>
  14. #endif  // __WINDOWS_H
  15.  
  16. #if !defined( __ASSERT_H )
  17. #include <assert.h>
  18. #endif  // __ASSERT_H
  19.  
  20. #if !defined( __TODOWIN_H )
  21. #include "TodoWin.h"
  22. #endif  // __TODOWIN_H
  23.  
  24. //---------------------------------------------------------------------
  25. //
  26. //  initialize static data members of class WinBase.
  27. //  NOTE: these are compiler dependent.  If you are not using
  28. //  Borland C++ you will have to replace this code with something
  29. //  that works with your compiler.
  30. //
  31. //---------------------------------------------------------------------
  32.  
  33. extern HINSTANCE _hInstance, _hPrev;
  34. extern LPSTR _pszCmdline;
  35. extern int _cmdShow;
  36.  
  37. HINSTANCE WinBase::hInst = _hInstance;
  38.  
  39. HINSTANCE WinBase::hPrevInst = _hPrev;
  40.  
  41. LPSTR WinBase::cmd = _pszCmdline;
  42.  
  43. int WinBase::show = _cmdShow;
  44.  
  45. //---------------------------------------------------------------------
  46. //
  47. //  members and data for class ModalDialog
  48. //
  49. //---------------------------------------------------------------------
  50.  
  51. ModalDialog *ModalDialog::curDlg = 0;
  52.  
  53. WORD ModalDialog::run()
  54. {
  55.     FARPROC dlgProc =
  56.     MakeProcInstance( (FARPROC)ModalDialog::dlgProc, (HINSTANCE)hInst );
  57.     DialogBox( (HINSTANCE)hInst, (LPCSTR)getDialogName(), (HWND)hWnd(), (DLGPROC)dlgProc );
  58.     FreeProcInstance( dlgProc );
  59.     return result;
  60. }
  61.  
  62. BOOL CALLBACK _export ModalDialog::dlgProc( HWND hDlg,
  63.                           UINT msg,
  64.                           WPARAM wParam,
  65.                           LPARAM lParam
  66.                                             )
  67. {
  68.     return curDlg->dispatch( hDlg, msg, wParam, lParam );
  69. }
  70.  
  71. BOOL ModalDialog::dispatch( HWND, UINT, WPARAM, LPARAM )
  72. {
  73.     return FALSE;
  74. }
  75.  
  76. //---------------------------------------------------------------------
  77. //
  78. //  members and data for class Window
  79. //
  80. //---------------------------------------------------------------------
  81.  
  82. Window *Window::inCreate = 0;
  83. Window *Window::winList = 0;
  84.  
  85. BOOL Window::create()
  86. {
  87.     if( hPrevInst == 0 && registerClass() == FALSE )
  88.         {
  89.         return FALSE;
  90.         }
  91.  
  92.     inCreate = this;            // flag that we're inside CreateWindow()
  93.  
  94.     createWindow();
  95.  
  96.     nextWin = winList;          // insert this object into the Window list
  97.     winList = this;
  98.  
  99.     inCreate = 0;               // now it's OK to use normal dispatching
  100.  
  101.     return TRUE;
  102. }
  103.  
  104. WORD Window::run()
  105. {
  106.     assert( hWnd() != 0 );      // check that we really exist
  107.  
  108.     MSG msg;
  109.     while( GetMessage( &msg, NULL, NULL, NULL ) != 0 )
  110.         {
  111.         TranslateMessage( &msg );
  112.         DispatchMessage( &msg );
  113.         }
  114.     return msg.wParam;
  115. }
  116.  
  117. LONG Window::dispatch( UINT msg, WPARAM wParam, LPARAM lParam )
  118. {
  119.     return DefWindowProc( (HWND)hWnd(), msg, wParam, lParam );
  120. }
  121.  
  122. LRESULT CALLBACK Window::wndProc( HWND hWnd,
  123.                                  UINT msg,
  124.                                  WPARAM wParam,
  125.                                  LPARAM lParam
  126.                                )
  127. {
  128.  
  129.     Window *cur = Window::winList;
  130.  
  131.     //  look up the handle in our Window list
  132.     while( cur != 0 && cur->hWnd() != hWnd )
  133.         cur = cur->nextWin;
  134.  
  135.     //  normal dispatching
  136.     if( cur != 0 )
  137.         return cur->dispatch( msg, wParam, lParam );
  138.  
  139.     //  if we're inside CreateWindow(), assume that the message is for us
  140.     if( inCreate != 0 )
  141.         {
  142.         inCreate->hWindow = hWnd;
  143.         return inCreate->dispatch( msg, wParam, lParam );
  144.         }
  145.  
  146.     //  otherwise, pass it on to windows
  147.     return DefWindowProc( hWnd, msg, wParam, lParam );
  148. }
  149.  
  150.  
  151.  
  152.