home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / WINDOW.PRG < prev    next >
Text File  |  1994-06-13  |  36KB  |  1,280 lines

  1. #include "FiveWin.ch"
  2. #include "Constant.ch"
  3.  
  4. #define SW_MINIMIZE            6
  5.  
  6. #define WM_MENUSELECT        287
  7. #define WM_SYSCOMMAND        274    // 0x112
  8. #define WM_LBUTTONDBLCLK     515    // 0x203
  9. #define WM_SETFONT            48    // 0x30
  10. #define WM_QUERYDRAGICON      55    // 0x37
  11. #define WM_CTLCOLOR           25    // 0x19
  12. #define WM_ERASEBKGND         20    // 0x14
  13. #define WM_CHILDACTIVATE      34    // 0x22
  14. #define WM_ICONERASEBKGND     39    // 0x27
  15. #define WM_MEASUREITEM        44    // 0x2C
  16. #define WM_DRAWITEM           43    // 0x2B
  17. #define WM_GETFONT            49    // 0x0031
  18. #define WM_NCPAINT           133    // 0x085
  19.  
  20. #define WS_EX_DLGMODALFRAME    1
  21.  
  22. #define CBN_SELCHANGE          1
  23.  
  24. #define IDC_ARROW          32512
  25.  
  26. #define SIZE_MINIMIZED         1
  27.  
  28. #define SC_RESTORE         61728
  29. #define SC_CLOSE           61536   // 0xF060
  30. #define SC_MINIMIZE        61472
  31. #define SC_NEXT            61504
  32. #define SC_MAXIMIZE        61488   // 0xF030
  33.  
  34. #define SW_HIDE                0
  35. #define SW_SHOWNA              8
  36.  
  37. #define BM_SETSTYLE  WM_USER + 4
  38. #define DLGC_BUTTON         8192   // 0x2000
  39.  
  40. #define CS_DBLCLKS             8
  41. #define CW_USEDEFAULT      32768
  42.  
  43. static aWindows    := {}
  44. static lRegistered := .f.
  45. static oWndDefault                 // Defaulf DEFINEd Window
  46.  
  47. //----------------------------------------------------------------------------//
  48.  
  49. function nWindows() ; return Len( aWindows )
  50.  
  51. //----------------------------------------------------------------------------//
  52.  
  53. CLASS TWindow
  54.  
  55.    DATA   hWnd, nOldProc
  56.    DATA   bInit, bMoved, bLClicked, bKeyDown, bPainted, bRClicked
  57.    DATA   bResized, bLDblClick, bWhen, bValid, bKeyChar, bMMoved
  58.    DATA   cCaption, cPS, nPaintCount, cMsg
  59.    DATA   Cargo                              // Ok here you have it <g>
  60.    DATA   hDC, nId
  61.    DATA   lActive, lVisible, lFocused
  62.    DATA   nStyle, nChrHeight, nChrWidth
  63.    DATA   nTop, nLeft, nBottom, nRight
  64.    DATA   nClrPane, nClrText
  65.    DATA   nResult, lValidating, nHelpId, hCtlFocus
  66.    DATA   aControls
  67.    DATA   oBar, oBrush, oCursor, oFont, oIcon, oMenu
  68.    DATA   oSysMenu, oPopup, oMsgBar, oWnd, oVScroll, oHScroll
  69.  
  70.    METHOD New( nTop, nLeft, nBottom, nRight, cTitle, nStyle, oMenu,;
  71.                oBrush, oIcon, oParent, lVScroll, lHScroll,;
  72.                nClrFore, nClrBack, oCursor,;
  73.                cBorder, lSysMenu, lCaption, lMin, lMax ) CONSTRUCTOR
  74.  
  75.    METHOD Activate( cShow, bLClicked, bRClicked, bMoved, bResized, bPainted,;
  76.                     bKeyDown, bInit,;
  77.                     bUp, bDown, bPgUp, bPgDn,;
  78.                     bLeft, bRight, bPgLeft, bPgRight, bValid )
  79.  
  80.    METHOD AddControl( oControl ) INLINE ;
  81.                         If( ::aControls == nil, ::aControls := {},),;
  82.                         AAdd( ::aControls, oControl ), ::lValidating := .f.
  83.  
  84.    METHOD BeginPaint() BLOCK ;      // it has to be BLOCK
  85.           { | Self, cPS | ::nPaintCount := 1,;
  86.                           ::hDC := BeginPaint( ::hWnd, @cPS ), ::cPS := cPS }
  87.  
  88.    METHOD Box( nTop, nLeft, nBottom, nRight )
  89.  
  90.    METHOD Capture() INLINE  SetCapture( ::hWnd )
  91.  
  92.    METHOD Center( oWnd ) INLINE  WndCenter( ::hWnd, oWnd:hWnd )
  93.  
  94.    METHOD Command( nWParam, nLParam )
  95.    METHOD Circle( nRow, nCol, nWidth )
  96.  
  97.    METHOD CoorsUpdate()
  98.  
  99.    METHOD Copy( lAll ) INLINE  WndCopy( ::hWnd, lAll )
  100.  
  101.    METHOD Create( cClsName )
  102.  
  103.    METHOD cTitle( cNewTitle ) SETGET
  104.    
  105.    METHOD Disable()  INLINE ::lActive := .f.,;
  106.                             If( ::hWnd != nil, EnableWindow( ::hWnd, .f. ),)
  107.  
  108.    METHOD Enable()   INLINE ::lActive := .t.,;
  109.                             If( ::hWnd != nil, EnableWindow( ::hWnd, .t. ),)
  110.  
  111.    METHOD End() BLOCK ;   // It has to be Block
  112.       { | Self, lEnd | If( lEnd := ::lValid(), ::PostMsg( WM_CLOSE ),), lEnd }
  113.  
  114.    METHOD EndPaint() INLINE ::nPaintCount--,;
  115.                      EndPaint( ::hWnd, ::cPS ), ::cPS := nil, ::hDC := nil
  116.  
  117.    METHOD FocusNext( hCtrl, lPrevious )
  118.  
  119.    METHOD cGenPrg()
  120.  
  121.    METHOD nGetChrHeight() INLINE ;
  122.                           ::nChrHeight := nWndChrHeight( ::hWnd,;
  123.                           If( ::oFont != nil, ::oFont:hFont,) )
  124.  
  125.    METHOD GetCliRect()
  126.  
  127.    METHOD GetRect()
  128.  
  129.    METHOD GetDC() INLINE ;
  130.        If( ::hDC == nil, ::hDC := GetDC( ::hWnd ),),;
  131.        If( ::nPaintCount == nil, ::nPaintCount := 1, ::nPaintCount++ ), ::hDC
  132.  
  133.    METHOD GetDlgCode() VIRTUAL
  134.  
  135.    METHOD GoNextCtrl( hCtrl )
  136.    METHOD GoPrevCtrl( hCtrl )
  137.  
  138.    METHOD GotFocus()
  139.  
  140.    METHOD HandleEvent( nMsg, nWParam, nLParam )
  141.  
  142.    METHOD HardCopy( nScale )
  143.  
  144.    METHOD Hide() INLINE ShowWindow( ::hWnd, SW_HIDE )
  145.  
  146.    METHOD HScroll( nWParam, nLParam )
  147.  
  148.    METHOD Iconize() INLINE CloseWindow( ::hWnd )
  149.  
  150.    METHOD KeyDown( nKey, nFlags )
  151.    METHOD KeyChar( nKey, nFlags )
  152.  
  153.    METHOD LButtonDown( nRow, nCol, nKeyFlags )
  154.    METHOD LDblClick( nRow, nCol, nKeyFlags )
  155.  
  156.    METHOD Line( nTop, nLeft, nBottom, nRight )
  157.    METHOD Link( lSubClass )
  158.    
  159.    METHOD LostFocus() INLINE ::lFocused := .f.
  160.  
  161.    METHOD lWhen() INLINE  If( ::bWhen != nil, Eval( ::bWhen ), .t. )
  162.  
  163.    METHOD Minimize() INLINE  ShowWindow( ::hWnd, SW_MINIMIZE )
  164.  
  165.    METHOD MouseMove( nRow, nCol, nKeyFlags ) INLINE ;
  166.                     If( ::oCursor != nil, SetCursor( ::oCursor:hCursor ),;
  167.                         CursorArrow() ),;
  168.                     If( ::bMMoved != nil,;
  169.                         Eval( ::bMMoved, nRow, nCol, nKeyFlags ),), 0
  170.  
  171.    METHOD Move( nTop, nLeft, nWidth, nHeight, lRepaint )
  172.    
  173.    // METHOD NcPaint() VIRTUAL
  174.  
  175.    METHOD Paint()
  176.  
  177.    METHOD PostMsg( nMsg, nWParam, nLParam ) INLINE ;
  178.                PostMessage( ::hWnd, nMsg, nWParam, nLParam )
  179.  
  180.    METHOD Print( oTarget, nRow, nCol, nScale ) INLINE ;
  181.                       WndPrint( ::hWnd, oTarget:hDC, nRow, nCol, nScale )
  182.  
  183.    METHOD RButtonDown( nRow, nCol, nKeyFlags )
  184.    METHOD Release()
  185.  
  186.    METHOD ReleaseDC() INLINE  If( --::nPaintCount == 0,;
  187.                               If( ReleaseDC( ::hWnd, ::hDC ), ::hDC := nil,),)
  188.  
  189.    
  190.    METHOD Refresh( lErase ) INLINE InvalidateRect( ::hWnd,;
  191.                                    If( lErase != nil, lErase, .t. ) )
  192.  
  193.    METHOD Register( nClsStyle )
  194.           
  195.  
  196.    METHOD ReSize( nSizeType, nWidth, nHeight )
  197.    METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel )
  198.  
  199.    METHOD SayBitmap( nRow, nCol, coBitmap, nWidth, nHeight )
  200.  
  201.    METHOD SayRect( nRow, nCol, cText, nClrFore, nClrBack, nWidth )
  202.  
  203.    METHOD SelColor( lFore )  INLINE ;
  204.           lFore := If( lFore == nil, lFore := .f., lFore ),;
  205.           ::SetColor( If( lFore, ChooseColor( ::nClrText ), ::nClrText ),;
  206.                       If( lFore, ::nClrPane, ChooseColor( ::nClrPane ) ) ),;
  207.           ::Refresh()
  208.  
  209.    METHOD SendMsg( nMsg, nWParam, nLParam ) INLINE ;
  210.                            SendMessage( ::hWnd, nMsg, nWParam, nLParam )
  211.    
  212.    METHOD SetBrush( oBrush ) INLINE If( ::oBrush != nil, ::oBrush:Release(),),;
  213.                                     ::oBrush := oBrush, ::Refresh()
  214.  
  215.    METHOD SetColor( nClrFore, nClrBack, oBrush )
  216.  
  217.    METHOD SetCoors( oRect )
  218.  
  219.    METHOD SetFocus() INLINE  If( ::lWhen(), SetFocus( ::hWnd ),)
  220.  
  221.    METHOD SelFont() BLOCK { | Self, nClr | nClr := ::nClrText,;
  222.                             ::SetFont( If( ::oFont == nil,;
  223.                             TFont():New( ,,,.t. ),;
  224.                             ::oFont:Choose( @nClr ) ) ),;
  225.                             ::nClrText := nClr, ::Refresh() }
  226.  
  227.    METHOD SetFont( oFont ) INLINE ::oFont := oFont,;
  228.                                   ::SendMsg( WM_SETFONT, oFont:hFont ),;
  229.                                   ::Refresh( .t. )
  230.  
  231.    METHOD SetMenu( oMenu ) INLINE  SetMenu( ::hWnd, oMenu:hMenu ),;
  232.                                    ::oMenu := oMenu, oMenu:oWnd := Self
  233.    
  234.    METHOD SetMsg( cText )
  235.  
  236.    METHOD SetPixel( nX, nY, nColor ) INLINE ;
  237.                                SetPixel( ::GetDC(), nX, nY, nColor ),;
  238.                                ::ReleaseDC()
  239.  
  240.    METHOD SetText( cText ) INLINE ;
  241.                           ::cCaption := cText, SetWindowText( ::hWnd, cText )
  242.  
  243.    METHOD Show() INLINE  ShowWindow( ::hWnd, SW_SHOWNA )
  244.  
  245.    METHOD SysCommand( nWParam, nLParam )
  246.    METHOD UnLink()
  247.  
  248.    METHOD Update() INLINE AEval( ::aControls,;
  249.                    { | oCtrl | If( oCtrl:lUpdate, oCtrl:Refresh(),) } )
  250.  
  251.    METHOD lValid() INLINE If( ::bValid != nil, Eval( ::bValid ), .t. )
  252.  
  253.    METHOD VScroll( nCode, nPos )
  254.  
  255. ENDCLASS
  256.  
  257. //----------------------------------------------------------------------------//
  258.  
  259. METHOD Register( nClsStyle )  CLASS TWindow
  260.  
  261.    DEFAULT nClsStyle  := nOR( CS_VREDRAW, CS_HREDRAW, CS_DBLCLKS ),;
  262.            ::nClrPane := CLR_GRAY, ::oBrush := TBrush():New( ,::nClrPane )
  263.  
  264.    RegisterClass( ::ClassName(), nClsStyle,,,, 0,;
  265.                   ::oBrush:hBrush )
  266.  
  267. Return nil
  268.  
  269. //----------------------------------------------------------------------------//
  270.  
  271. METHOD Create( cClsName )  CLASS TWindow
  272.  
  273.    DEFAULT cClsName := ::ClassName(), ::cCaption := "",;
  274.            ::nStyle := WS_OVERLAPPEDWINDOW,;
  275.            ::nTop   := 0, ::nLeft := 0, ::nBottom := 10, ::nRight := 10,;
  276.            ::nId    := 0
  277.  
  278.    if ::oWnd != nil
  279.       ::nStyle = nOR( ::nStyle, WS_CHILD )
  280.    endif
  281.  
  282.    if ::nBottom != CW_USEDEFAULT
  283.       ::hWnd = CreateWindow( cClsName, ::cCaption, ::nStyle, ;
  284.                              ::nLeft, ::nTop, ::nRight - ::nLeft + 1, ;
  285.                              ::nBottom - ::nTop + 1, ;
  286.                              If( ::oWnd != nil, ::oWnd:hWnd, 0 ), ;
  287.                              ::nId )
  288.     else
  289.       ::hWnd = CreateWindow( cClsName, ::cCaption, ::nStyle, ;
  290.                              ::nLeft, ::nTop, ::nRight, ::nBottom, ;
  291.                              If( ::oWnd != nil, ::oWnd:hWnd, 0 ), ;
  292.                              ::nId )
  293.     endif
  294.  
  295.    ::Link()
  296.  
  297.    if ::oFont != nil
  298.       ::SetFont( ::oFont )
  299.    endif
  300.    
  301. return nil
  302.  
  303. //----------------------------------------------------------------------------//
  304.  
  305. METHOD New( nTop, nLeft, nBottom, nRight, cTitle, nStyle, oMenu,;
  306.             oBrush, oIcon, oWnd, lVScroll, lHScroll, nClrFore, nClrBack,;
  307.             oCursor, cBorder, lSysMenu, lCaption, lMin, lMax ) ;
  308.                                                                CLASS TWindow
  309.  
  310.    DEFAULT nTop     := 2, nLeft := 2, nBottom := 20, nRight := 70,;
  311.            lVScroll := .f., lHScroll := .f.,;
  312.            nClrFore := CLR_WHITE, nClrBack := CLR_GRAY,;
  313.            nStyle   := 0,;
  314.            cBorder  := "SINGLE", lSysMenu := .f., lCaption := .t.,;
  315.            lMin     := .t., lMax := .t.
  316.  
  317.    if nStyle == 0
  318.       nStyle = nOr( If( cBorder == "NONE",   WS_POPUP, 0 ),;
  319.                     If( cBorder == "SINGLE", WS_THICKFRAME, 0 ),;
  320.                     If( lCaption, WS_CAPTION, 0 ),;
  321.                     If( lSysMenu .and. lCaption, WS_SYSMENU, 0 ),;
  322.                     If( lMin .and. lCaption, WS_MINIMIZEBOX, 0 ),;
  323.                     If( lMax .and. lCaption, WS_MAXIMIZEBOX, 0 ),;
  324.                     If( lVScroll, WS_VSCROLL, 0 ),;
  325.                     If( lHScroll, WS_HSCROLL, 0 ) )
  326.    endif
  327.  
  328.    ::nTop      = nTop    * WIN_CHARPIX_H    // 16
  329.    ::nLeft     = nLeft   * WIN_CHARPIX_W    // 8
  330.    ::nBottom   = nBottom * WIN_CHARPIX_H    //16
  331.    ::nRight    = nRight  * WIN_CHARPIX_W    // 8
  332.    ::nStyle    = nStyle
  333.    ::cCaption  = cTitle
  334.    ::oCursor   = oCursor
  335.    ::oMenu     = oMenu
  336.    ::oWnd      = oWnd
  337.    ::oIcon     = oIcon
  338.    ::lVisible  = .t.               // As soon as we create it, it exists!
  339.    ::aControls = {}
  340.  
  341.    ::SetColor( nClrFore, nClrBack, oBrush )
  342.  
  343.    if ! lRegistered               // Windows API conexion
  344.       ::Register()
  345.    endif
  346.    
  347.    ::Create()
  348.  
  349.    if oMenu != nil
  350.       SetMenu( ::hWnd, oMenu:hMenu )
  351.       oMenu:oWnd = Self
  352.    endif
  353.  
  354.    if lVScroll
  355.       DEFINE SCROLLBAR ::oVScroll VERTICAL OF Self
  356.    endif
  357.    if lHScroll
  358.       DEFINE SCROLLBAR ::oHScroll HORIZONTAL OF Self
  359.    endif
  360.  
  361.    if ::oFont == nil
  362.       ::oFont = TFont()
  363.       ::oFont:hFont = ::SendMsg( WM_GETFONT )
  364.    endif
  365.  
  366.    SetWndDefault( Self )                   // Set Default DEFINEd Window
  367.  
  368. return nil
  369.  
  370. //----------------------------------------------------------------------------//
  371.  
  372. METHOD Activate( cShow, bLClicked, bRClicked, bMoved, bResized, bPainted,;
  373.                  bKeyDown, bInit,;
  374.                  bUp, bDown, bPgUp, bPgDown,;
  375.                  bLeft, bRight, bPgLeft, bPgRight, bValid ) CLASS TWindow
  376.  
  377.    local oVScroll, oHScroll
  378.  
  379.    DEFAULT cShow := "NORMAL"
  380.  
  381.    ::nResult     = nil
  382.    ::lValidating = .f.
  383.    ::bValid      = bValid
  384.  
  385.    if bPainted != nil
  386.       if ::ClassName() == "TMDIFRAME"
  387.          ::oWndClient:bPainted  = bPainted
  388.       else
  389.          ::bPainted  = bPainted
  390.       endif
  391.    endif
  392.  
  393.    if bRClicked != nil
  394.       if ::ClassName() == "TMDIFRAME"
  395.          ::oWndClient:bRClicked = bRClicked
  396.       else
  397.          ::bRClicked = bRClicked
  398.       endif
  399.    endif
  400.  
  401.    if ::oFont != nil
  402.       ::SetFont( ::oFont )
  403.    endif
  404.  
  405.  
  406.    // For WS_VSCROLL and WS_HSCROLL styles
  407.  
  408.    if ::ClassName() == "TMDIFRAME"
  409.       oVScroll = ::oWndClient:oVScroll
  410.       oHScroll = ::oWndClient:oHScroll
  411.    else
  412.       oVScroll = ::oVScroll
  413.       oHScroll = ::oHScroll
  414.    endif
  415.  
  416.    if oVScroll != nil       // When using VSCROLL clause
  417.       if bUp != nil
  418.          oVScroll:bGoUp = bUp
  419.       endif
  420.       if bDown != nil
  421.          oVScroll:bGoDown = bDown
  422.       endif
  423.       if bPgUp != nil
  424.          oVScroll:bPageUp = bPgUp
  425.       endif
  426.       if bPgDown != nil
  427.          oVScroll:bPageDown = bPgDown
  428.       endif
  429.    endif
  430.  
  431.    if oHScroll != nil       // When using HSCROLL clause
  432.       if bLeft != nil
  433.          oHScroll:bGoUp = bLeft
  434.       endif
  435.       if bRight != nil
  436.          oHScroll:bGoDown = bRight
  437.       endif
  438.       if bPgLeft != nil
  439.          oHScroll:bPageUp = bPgLeft
  440.       endif
  441.       if bPgRight != nil
  442.          oHScroll:bPageDown = bPgRight
  443.       endif
  444.    endif
  445.  
  446.    ShowWindow( ::hWnd, AScan( { "NORMAL", "ICONIZED", "MAXIMIZED" }, cShow ) )
  447.    UpdateWindow( ::hWnd )
  448.  
  449.    ::lVisible = .t.
  450.  
  451.    if ! lWRunning()
  452.        SetWndApp( ::hWnd )
  453.    endif
  454.    
  455.    if ::bInit != nil
  456.       Eval( ::bInit, Self )
  457.    endif
  458.  
  459.    if ::oWnd == nil
  460.       if ! lWRunning()
  461.          WinRun( Self:hWnd )
  462.       endif
  463.    endif
  464.  
  465.    ::lVisible = .f.
  466.  
  467. return nil
  468.  
  469. //----------------------------------------------------------------------------//
  470.  
  471. METHOD Circle( nRow, nCol, nWidth ) CLASS TWindow
  472.  
  473.    ::GetDC()
  474.    Ellipse( ::hDC, nCol, nRow, nCol + nWidth - 1, nRow + nWidth - 1 )
  475.    ::ReleaseDC()
  476.  
  477. return nil
  478.  
  479. //----------------------------------------------------------------------------//
  480.  
  481. METHOD Command( nWParam, nLParam ) CLASS TWindow
  482.  
  483.    do case
  484.       case ::oPopup != nil
  485.            ::oPopup:Command( nWParam )
  486.            ::oPopup = nil
  487.  
  488.       case nLoWord( nLParam ) == 0 .and. ::oMenu != nil
  489.            ::oMenu:Command( nWParam )
  490.  
  491.       case nWParam > 0
  492.            do case
  493.               case nHiWord( nLParam ) == BN_CLICKED
  494.                    SendMessage( nLoWord( nLParam ), WM_CLICK, 0, 0 )
  495.  
  496.               case nHiWord( nLParam ) == CBN_SELCHANGE
  497.                    SendMessage( nLoWord( nLParam ), WM_CHANGE, 0, 0 )
  498.            endcase
  499.    endcase
  500.  
  501. return nil
  502.  
  503. //----------------------------------------------------------------------------//
  504.  
  505. METHOD CoorsUpdate() CLASS TWindow
  506.  
  507.    local aRect := GetWndRect( ::hWnd )
  508.  
  509.    ::nTop    = aRect[ 1 ]
  510.    ::nLeft   = aRect[ 2 ]
  511.    ::nBottom = aRect[ 3 ]
  512.    ::nRight  = aRect[ 4 ]
  513.  
  514. return nil
  515.  
  516. //----------------------------------------------------------------------------//
  517.  
  518. METHOD cTitle( cNewTitle ) CLASS TWindow
  519.  
  520.    if cNewTitle != nil
  521.       SetWindowText( ::hWnd, cNewTitle )
  522.    endif
  523.  
  524. return GetWindowText( ::hWnd )
  525.  
  526. //----------------------------------------------------------------------------//
  527.  
  528. METHOD cGenPRG( cFileName ) CLASS TWindow
  529.  
  530.    local cPrg := ""
  531.  
  532.    ::CoorsUpdate()
  533.  
  534.    cPrg += '#include "FiveWin.ch"' + CRLF + CRLF
  535.    cPrg += "static oWnd" + CRLF + CRLF
  536.    cPrg += "//" + Replicate( "-", 76 ) + "//" + CRLF + CRLF
  537.    cPrg += "function Main()" + CRLF + CRLF
  538.  
  539.    if ::oBar != nil
  540.       cPrg += "   local oBar" + CRLF
  541.    endif
  542.  
  543.    if ::oBrush != nil
  544.       cPrg += "   local oBrush" + CRLF
  545.    endif
  546.  
  547.    if ::oBrush != nil
  548.       cPrg += ::oBrush:cGenPRG()
  549.    endif
  550.  
  551.    cPrg += CRLF + ;
  552.            '   DEFINE WINDOW oWnd TITLE "' + ::cTitle + '" ;' + CRLF + ;
  553.            "      FROM " + ;
  554.            Str( ::nTop / WIN_CHARPIX_H , 3 ) + ", " + Str( ::nLeft / WIN_CHARPIX_W, 3 ) + " TO " + ;                  // 16, 8
  555.            Str( ::nBottom / WIN_CHARPIX_H, 3 ) + ", " + Str( ::nRight / WIN_CHARPIX_W, 3 )                              // 16,8
  556.  
  557.    if ::oMenu != nil
  558.       cPrg += " ;" + CRLF + "      MENU BuildMenu()"
  559.    endif
  560.  
  561.    if ::oBrush != nil
  562.       cPrg += " ;" + CRLF + "      BRUSH oBrush" + CRLF
  563.    endif
  564.  
  565.    if ::oBar != nil
  566.       cPrg += ::oBar:cGenPRG()
  567.    endif
  568.  
  569.    if ::oMsgBar != nil
  570.       cPrg += CRLF + CRLF + '   SET MESSAGE OF oWnd TO "' + ;
  571.               ::oMsgBar:cMsgDef + '"'
  572.    endif
  573.  
  574.    AEval( ::aControls, { | oCtrl | cPrg += oCtrl:cGenPRG() } )
  575.  
  576.    cPrg += CRLF + "   ACTIVATE WINDOW oWnd" + CRLF + CRLF
  577.    cPrg += "return nil" + CRLF + CRLF
  578.    cPrg += "//" + Replicate( "-", 76 ) + "//" + CRLF
  579.  
  580.    if ! Empty( cFileName )
  581.       MemoWrit( cFileName, cPrg )
  582.    endif
  583.  
  584. return cPrg
  585.  
  586. //----------------------------------------------------------------------------//
  587.  
  588. METHOD GetCliRect() CLASS TWindow
  589.  
  590.    local aRect := GetClientRect( ::hWnd )
  591.  
  592. return TRect():New( aRect[ 1 ], aRect[ 2 ], aRect[ 3 ], aRect[ 4 ] )
  593.  
  594. //----------------------------------------------------------------------------//
  595.  
  596. METHOD GetRect() CLASS TWindow
  597.  
  598.    local aRect := GetWndRect( ::hWnd )
  599.  
  600. return TRect():New( aRect[ 1 ], aRect[ 2 ], aRect[ 3 ], aRect[ 4 ] )
  601.  
  602. //----------------------------------------------------------------------------//
  603.  
  604. METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TWindow
  605.  
  606.    local oItem
  607.    local nAt
  608.  
  609.    do case
  610.       case nMsg == WM_COMMAND
  611.            return ::Command( nWParam, nLParam )
  612.  
  613.       case nMsg == WM_ERASEBKGND
  614.            if IsIconic( ::hWnd )
  615.               if ::oWnd != nil
  616.                  FillRect( nWParam, GetClientRect( ::hWnd ), ::oWnd:oBrush:hBrush )
  617.                  return 1
  618.               endif
  619.               return 0
  620.            endif
  621.  
  622.            if ::oBrush != nil
  623.               FillRect( nWParam, GetClientRect( ::hWnd ), ::oBrush:hBrush )
  624.               return 1
  625.            endif
  626.  
  627.       case nMsg == WM_MENUSELECT .and. ( ::oMenu != nil .or. ::oPopup != nil )
  628.                                   // wParam ItemID ó hPopUp
  629.                                   // HIword lParam hMenu
  630.                                   // LOword lParam MenuFlags : MF_...
  631.            if ::oPopup != nil
  632.               oItem = ::oPopup:GetMenuItem( nWParam )
  633.            else
  634.               oItem = ::oMenu:GetMenuItem( nWParam )
  635.            endif
  636.            ::SetMsg( If( oItem != nil, oItem:cMsg,) )
  637.  
  638.       case nMsg == WM_CTLCOLOR
  639.            return SendMessage( nLoWord( nLParam ),;   // Handle Child
  640.                                WM_COLOR,;             // FiveWin Message
  641.                                nWParam )              // Child hDC
  642.  
  643.       // case nMsg == WM_NCPAINT
  644.       //      return ::NCPaint()
  645.  
  646.       case nMsg == WM_PALETTECHANGED
  647.            return PalChgEvent( nWParam )
  648.  
  649.       case nMsg == WM_QUERYNEWPALETTE
  650.            return QryNewPalEvent()
  651.  
  652.       case nMsg == WM_DDE_ACK
  653.            DdeAck( nWParam, nLParam )
  654.  
  655.       case nMsg == WM_DESTROY
  656.            ::Release()
  657.  
  658.       case nMsg == WM_GETDLGCODE
  659.            return ::GetDlgCode()
  660.  
  661.       case nMsg == WM_PAINT
  662.            ::BeginPaint()
  663.            ::Paint()
  664.            ::EndPaint()
  665.            return 0
  666.  
  667.       case nMsg == WM_LBUTTONDOWN
  668.            return ::LButtonDown( nHiWord( nLParam ), nLoWord( nLParam ), nWParam )
  669.  
  670.       case nMsg == WM_QUERYDRAGICON
  671.            return If( ::oIcon != nil, ::oIcon:hIcon,;
  672.                       ExtractIcon( "user.exe" ) )
  673.  
  674.       case nMsg == WM_RBUTTONDOWN
  675.            return ::RButtonDown( nHiWord( nLParam ), nLoWord( nLParam ), nWParam )
  676.  
  677.       case nMsg == WM_LBUTTONDBLCLK
  678.            return ::LDblClick( nHiWord( nLParam ), nLoWord( nLParam ), nWParam )
  679.  
  680.       case nMsg == WM_CHAR
  681.            return ::KeyChar( nWParam, nLParam )
  682.  
  683.       case nMsg == WM_KEYDOWN
  684.            return ::KeyDown( nWParam, nLParam )
  685.  
  686.       case nMsg == WM_SIZE
  687.            return ::ReSize( nWParam, nLoWord( nLParam ), nHiWord( nLParam ) )
  688.  
  689.       /*
  690.       case nMsg == WM_MOVE
  691.            if ::oBrush != nil
  692.               SetBrushOrg( ::hWnd, ::oBrush:hBrush, 0, 0 )
  693.            endif
  694.       */
  695.  
  696.       case nMsg == WM_SYSCOMMAND
  697.            return ::SysCommand( nWParam, nLParam )
  698.  
  699.       case nMsg == WM_TIMER
  700.            return TimerEvent( nWParam )
  701.  
  702.       case nMsg == WM_VSCROLL
  703.            return ::VScroll( nWParam, nLParam )
  704.  
  705.       case nMsg == WM_HSCROLL
  706.            return ::HScroll( nWParam, nLParam )
  707.  
  708.       case nMsg == WM_DRAWITEM
  709.            return SendMessage( GetDlgItem( ::hWnd, nWParam ),;
  710.                                FW_DRAW, 0, nLParam )
  711.  
  712.       case nMsg == WM_MEASUREITEM
  713.  
  714.            // Warning: On this message the Controls still are not initialized
  715.            // because WM_MEASUREITEM is sent before of WM_INITDIALOG
  716.  
  717.            if ( nAt := AScan( ::aControls, { | oCtrl | oCtrl:nId == nWParam } ) ) != 0
  718.               return ::aControls[ nAt ]:FillMeasure( nLParam )
  719.            endif
  720.  
  721.        case nMsg == WM_SETFOCUS
  722.             return ::GotFocus()
  723.  
  724.        case nMsg == WM_MOUSEMOVE
  725.             return ::MouseMove( nHiWord( nLParam ), nLoWord( nLParam ),;
  726.                                 nWParam )
  727.  
  728.        case nMsg == WM_QUERYENDSESSION
  729.             return If( ::End(), 1, 0 )
  730.    endcase
  731.  
  732. return nil
  733.  
  734. //----------------------------------------------------------------------------//
  735.  
  736. METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel ) CLASS TWindow
  737.  
  738.    DEFAULT nClrFore := ::nClrText,;
  739.            nClrBack := ::nClrPane,;
  740.            oFont    := ::oFont,;
  741.            lPixel   := .f.
  742.  
  743.    if ValType( nClrFore ) == "C"      //  xBase Color string
  744.       nClrBack = nClrFore
  745.       nClrFore = nGetForeRGB( nClrFore )
  746.       nClrBack = nGetBackRGB( nClrBack )
  747.    endif
  748.  
  749.    ::GetDC()
  750.    WSay( ::hWnd, ::hDC, nRow, nCol, cValToChar( cText ), nClrFore, nClrBack,;
  751.          If( oFont != nil, oFont:hFont, 0 ), lPixel )
  752.    ::ReleaseDC()
  753.  
  754. return nil
  755.  
  756. //----------------------------------------------------------------------------//
  757.  
  758. METHOD SayBitmap( nRow, nCol, coBitmap, nWidth, nHeight ) CLASS TWindow
  759.  
  760.    local hDib, hPal
  761.    local cType := ValType( coBitmap )
  762.  
  763.    if cType == "C"
  764.       if File( coBitmap )
  765.          hDib = DibRead( coBitmap )
  766.          hPal = DibPalette( hDib )
  767.       endif
  768.    endif
  769.  
  770.    if cType == "O"
  771.       hDib = If( coBitmap:hGlobal != 0, coBitmap:hGlobal, coBitmap:hResource )
  772.       hPal = DibPalette( hDib )
  773.    endif
  774.  
  775.    ::GetDC()
  776.    DibDraw( ::hDC, hDib, hPal, nRow, nCol, nWidth, nHeight )
  777.    ::ReleaseDC()
  778.  
  779.    if cType == "C"
  780.       GlobalFree( hDib )
  781.       DeleteObject( hPal )
  782.    endif
  783.  
  784. return nil
  785.  
  786. //----------------------------------------------------------------------------//
  787.  
  788. METHOD SayRect( nRow, nCol, cText, nClrFore, nClrBack, nWidth ) CLASS TWindow
  789.  
  790.    DEFAULT nClrFore := CLR_BLACK, nClrBack := CLR_WHITE
  791.  
  792.    ::GetDC()
  793.    WSayRect( ::hWnd, ::hDC, nRow, nCol, cText, nClrFore, nClrBack, nWidth )
  794.    ::ReleaseDC()
  795.  
  796. return nil
  797.  
  798. //----------------------------------------------------------------------------//
  799.  
  800. METHOD LButtonDown( nRow, nCol, nKeyFlags ) CLASS TWindow
  801.  
  802.    if ::bLClicked != nil
  803.       Eval( ::bLClicked, nRow, nCol, nKeyFlags )
  804.    endif
  805.  
  806. return nil
  807.  
  808. //----------------------------------------------------------------------------//
  809.  
  810. METHOD LDblClick( nRow, nCol, nKeyFlags ) CLASS TWindow
  811.  
  812.    if ::bLDblClick != nil
  813.       Eval( ::bLDblClick, nRow, nCol, nKeyFlags )
  814.    endif
  815.  
  816. return nil
  817.  
  818. //----------------------------------------------------------------------------//
  819.  
  820. METHOD Line( nTop, nLeft, nBottom, nRight ) CLASS TWindow
  821.  
  822.    ::GetDC()
  823.    MoveTo( ::hDC, nLeft, nTop )
  824.    LineTo( ::hDC, nRight, nBottom )
  825.    ::ReleaseDC()
  826.  
  827. return nil
  828.  
  829. //----------------------------------------------------------------------------//
  830.  
  831. METHOD RButtonDown( nRow, nCol, nKeyFlags ) CLASS TWindow
  832.  
  833.    if ::bRClicked != nil
  834.       Eval( ::bRClicked, nRow, nCol, nKeyFlags )
  835.    endif
  836.  
  837. return nil
  838.  
  839. //----------------------------------------------------------------------------//
  840.  
  841. METHOD SetMsg( cText ) CLASS TWindow
  842.  
  843.    if ::oWnd != nil
  844.       ::oWnd:SetMsg( cText )
  845.    else
  846.       if ::oMsgBar != nil
  847.          ::oMsgBar:SetMsg( cText )
  848.       endif
  849.    endif
  850.  
  851. return nil
  852.  
  853. //----------------------------------------------------------------------------//
  854.  
  855. METHOD Box( nTop, nLeft, nBottom, nRight ) CLASS TWindow
  856.  
  857.    ::GetDC()
  858.    WndBox( ::hDC, nTop, nLeft, nBottom, nRight )
  859.    ::ReleaseDC()
  860.  
  861. return nil
  862.  
  863. //----------------------------------------------------------------------------//
  864.  
  865. METHOD Link( lSubClass ) CLASS TWindow
  866.  
  867.    local nAt := AScan( aWindows, 0 )
  868.  
  869.    DEFAULT lSubClass := .t.
  870.  
  871.    if nAt != 0
  872.       aWindows[ nAt ] = Self
  873.       SetProp( ::hWnd, "WP", nAt )
  874.    else
  875.       AAdd( aWindows, Self )
  876.       SetProp( ::hWnd, "WP", Len( aWindows ) )
  877.    endif
  878.  
  879.    if Len( aWindows ) == 1
  880.       WindowsFix()
  881.    endif
  882.  
  883.    if lSubClass
  884.       ::nOldProc = ChangeProc( ::hWnd )
  885.    endif
  886.  
  887. return nil
  888.  
  889. //----------------------------------------------------------------------------//
  890.  
  891. METHOD Release() CLASS TWindow
  892.  
  893.    if ::oBrush != nil
  894.       ::oBrush:Release()
  895.    endif
  896.    if ::oCursor != nil
  897.       ::oCursor:Release()
  898.    endif
  899.    if ::oIcon != nil
  900.       ::oIcon:Release()
  901.    endif
  902.    if ::oFont != nil
  903.       ::oFont:Release()
  904.    endif
  905.    if ::oMenu != nil
  906.       ::oMenu:Release()
  907.    endif
  908.    if ::oSysMenu != nil
  909.       ::oSysMenu:Release()
  910.    endif
  911.  
  912.    ::UnLink()
  913.  
  914.    if GetWndApp() == ::hWnd
  915.       PostQuitMessage( 0 )
  916.    endif
  917.  
  918.    if ::ChildLevel( TDialog() ) != 0   // TDialog Class or inherited Class
  919.       DeRegDialog( ::hWnd )
  920.       SetProp( ::hWnd, "WP", 0 )
  921.    endif
  922.  
  923. return nil
  924.  
  925. //----------------------------------------------------------------------------//
  926.  
  927. METHOD ReSize( nSizeType, nWidth, nHeight ) CLASS TWindow
  928.  
  929.    ::CoorsUpdate()
  930.  
  931.    if ::oMsgBar != nil
  932.       ::oMsgBar:Adjust()
  933.    endif
  934.  
  935.    if ::oBar != nil
  936.       ::oBar:Adjust()
  937.    endif
  938.  
  939.    if ::bResized != nil
  940.       Eval( ::bResized, nWidth, nHeight )
  941.    endif
  942.  
  943. return 0
  944.  
  945. //----------------------------------------------------------------------------//
  946.  
  947. METHOD SetCoors( oRect ) CLASS TWindow
  948.  
  949.    SetWindowPos( ::hWnd, 0, oRect:nTop, oRect:nLeft,;
  950.                  oRect:nRight - oRect:nLeft + 1,;
  951.                  oRect:nBottom - oRect:nTop + 1, 4 )    // Important:
  952.                                                         // Use 4 for
  953.    ::nTop    = oRect:nTop                               // for keeping
  954.    ::nLeft   = oRect:nLeft                              // ZOrder !!!!
  955.    ::nBottom = oRect:nBottom
  956.    ::nRight  = oRect:nRight
  957.  
  958. return nil
  959.  
  960. //----------------------------------------------------------------------------//
  961.  
  962. METHOD UnLink() CLASS TWindow
  963.  
  964.    local nAt := If( ::hWnd != 0, GetProp( ::hWnd, "WP" ), 0 )
  965.  
  966.    if ::nOldProc != nil .and. ::hWnd != 0
  967.       RestProc( ::hWnd, ::nOldProc )
  968.       ::nOldProc = nil
  969.    endif
  970.  
  971.    if nAt > 0
  972.       aWindows[ nAt ] = 0
  973.    endif
  974.  
  975. return nil
  976.  
  977. //----------------------------------------------------------------------------//
  978.  
  979. METHOD VScroll( nWParam, nLParam ) CLASS TWindow
  980.  
  981.    local nScrHandle := nHiWord( nLParam )
  982.  
  983.    if nScrHandle == 0                   // Window ScrollBar
  984.       do case
  985.          case nWParam == SB_LINEUP
  986.               ::oVScroll:GoUp()
  987.  
  988.          case nWParam == SB_LINEDOWN
  989.               ::oVScroll:GoDown()
  990.  
  991.          case nWParam == SB_PAGEUP
  992.               ::oVScroll:PageUp()
  993.  
  994.          case nWParam == SB_PAGEDOWN
  995.               ::oVScroll:PageDown()
  996.  
  997.          case nWParam == SB_THUMBPOSITION
  998.               ::oVScroll:ThumbPos( nLoWord( nLParam ) )
  999.  
  1000.          case nWParam == SB_ENDSCROLL
  1001.               return 0
  1002.       endcase
  1003.    else                                 // Control ScrollBar
  1004.       do case
  1005.          case nWParam == SB_LINEUP
  1006.               SendMessage( nScrHandle, WM_SCROLLUP )
  1007.  
  1008.          case nWParam == SB_LINEDOWN
  1009.               SendMessage( nScrHandle, WM_SCROLLDOWN )
  1010.  
  1011.          case nWParam == SB_PAGEUP
  1012.               SendMessage( nScrHandle, WM_SCROLLPGUP )
  1013.  
  1014.          case nWParam == SB_PAGEDOWN
  1015.               SendMessage( nScrHandle, WM_SCROLLPGDN )
  1016.  
  1017.          case nWParam == SB_THUMBPOSITION
  1018.               SendMessage( nScrHandle, FW_THUMBPOS, nLoWord( nLParam ) )
  1019.       endcase
  1020.    endif
  1021.  
  1022. return 0
  1023.  
  1024. //----------------------------------------------------------------------------//
  1025.  
  1026. METHOD HScroll( nWParam, nLParam ) CLASS TWindow
  1027.  
  1028.    local nScrHandle := nHiWord( nLParam )
  1029.  
  1030.    if nScrHandle == 0                   // Window ScrollBar
  1031.       do case
  1032.          case nWParam == SB_LINEUP
  1033.               ::oHScroll:GoUp()
  1034.  
  1035.          case nWParam == SB_LINEDOWN
  1036.               ::oHScroll:GoDown()
  1037.  
  1038.          case nWParam == SB_PAGEUP
  1039.               ::oHScroll:PageUp()
  1040.  
  1041.          case nWParam == SB_PAGEDOWN
  1042.               ::oHScroll:PageDown()
  1043.  
  1044.          case nWParam == SB_THUMBPOSITION
  1045.               ::oHScroll:ThumbPos( nLoWord( nLParam ) )
  1046.  
  1047.          case nWParam == SB_ENDSCROLL
  1048.               return 0
  1049.       endcase
  1050.    else                                 // Control ScrollBar
  1051.       do case
  1052.          case nWParam == SB_LINEUP
  1053.               SendMessage( nScrHandle, WM_SCROLLUP )
  1054.  
  1055.          case nWParam == SB_LINEDOWN
  1056.               SendMessage( nScrHandle, WM_SCROLLDOWN )
  1057.  
  1058.          case nWParam == SB_PAGEUP
  1059.               SendMessage( nScrHandle, WM_SCROLLPGUP )
  1060.  
  1061.          case nWParam == SB_PAGEDOWN
  1062.               SendMessage( nScrHandle, WM_SCROLLPGDN )
  1063.  
  1064.          case nWParam == SB_THUMBPOSITION
  1065.               SendMessage( nScrHandle, FW_THUMBPOS, nLoWord( nLParam ) )
  1066.       endcase
  1067.    endif
  1068.  
  1069. return 0
  1070.  
  1071. //----------------------------------------------------------------------------//
  1072.  
  1073. METHOD SysCommand( nWParam, nLParam ) CLASS TWindow
  1074.  
  1075.    if ::oSysMenu != nil .and. nWParam < 61440           // 0xF000
  1076.       ::oSysMenu:Command( nWParam )
  1077.    else
  1078.       do case
  1079.          case nWParam == SC_CLOSE
  1080.               return ::End()
  1081.       endcase
  1082.    endif
  1083.  
  1084. return nil
  1085.  
  1086. //----------------------------------------------------------------------------//
  1087.  
  1088. METHOD Paint() CLASS TWindow
  1089.  
  1090.    if IsIconic( ::hWnd )
  1091.       ::SendMsg( WM_ERASEBKGND, ::hDC, 0 )
  1092.       DrawIcon( ::hDC, 0, 0,;
  1093.       If( ::oIcon != nil, ::oIcon:hIcon, ExtractIcon( "user.exe" ) ) )
  1094.    else
  1095.       if ValType( ::bPainted ) == "B"
  1096.          Eval( ::bPainted, Self )
  1097.       endif
  1098.    endif
  1099.  
  1100. return nil
  1101.  
  1102. //----------------------------------------------------------------------------//
  1103.  
  1104. METHOD HardCopy( nScale ) CLASS TWindow
  1105.  
  1106.    local oPrn
  1107.  
  1108.    PRINT oPrn NAME ::cTitle
  1109.       PAGE
  1110.          ::Refresh()
  1111.          SysRefresh()                      // Let Windows process
  1112.          ::Print( oPrn, 0, 0, nScale )
  1113.       ENDPAGE
  1114.    ENDPRINT
  1115.  
  1116. return nil
  1117.  
  1118. //----------------------------------------------------------------------------//
  1119.  
  1120. METHOD Move( nTop, nLeft, nBottom, nRight, lRepaint ) CLASS TWindow
  1121.  
  1122.    MoveWindow( ::hWnd, nTop, nLeft, nBottom, nRight, lRepaint )
  1123.  
  1124.    ::nBottom = nTop + ( ::nBottom - ::nTop )
  1125.    ::nRight  = nLeft + ( ::nRight - ::nLeft )
  1126.    ::nTop    = nTop
  1127.    ::nLeft   = nLeft
  1128.  
  1129. return nil
  1130.  
  1131. //----------------------------------------------------------------------------//
  1132.  
  1133. METHOD SetColor( nClrFore, nClrBack, oBrush ) CLASS TWindow
  1134.  
  1135.    // DEFAULT colors get assigned at :Colors() method
  1136.    // because there we _do_ have a hDC already created
  1137.  
  1138.    if ValType( nClrFore ) == "C"
  1139.       nClrBack = nClrFore                   // It is a dBase Color string
  1140.       nClrFore = nGetForeRGB( nClrFore )
  1141.       nClrBack = nGetBackRGB( nClrBack )
  1142.    endif
  1143.  
  1144.    ::nClrText = nClrFore
  1145.    ::nClrPane = nClrBack
  1146.  
  1147.    if ::oBrush != nil
  1148.       ::oBrush:Release()
  1149.    endif
  1150.    if oBrush != nil
  1151.       ::oBrush = oBrush
  1152.    else
  1153.       ::oBrush = TBrush():New(,nClrBack,)
  1154.    endif
  1155.  
  1156. return nil
  1157.  
  1158. //----------------------------------------------------------------------------//
  1159.  
  1160. METHOD KeyChar( nKey, nFlags ) CLASS TWindow
  1161.  
  1162.    local bKeyAction := SetKey( nKey )
  1163.  
  1164.    if bKeyAction != nil     // Clipper SET KEYs !!!
  1165.       return Eval( bKeyAction, ProcName( 4 ), ProcLine( 4 ) )
  1166.    endif
  1167.  
  1168.    if ::bKeyChar != nil
  1169.       return Eval( ::bKeyChar, nKey, nFlags )
  1170.    endif
  1171.  
  1172. return nil
  1173.  
  1174. //----------------------------------------------------------------------------//
  1175.  
  1176. METHOD KeyDown( nKey, nFlags ) CLASS TWindow
  1177.  
  1178.    local bKeyAction := SetKey( nKey )
  1179.  
  1180.    if nKey == VK_TAB .and. ::oWnd != nil
  1181.       ::oWnd:GoNextCtrl( ::hWnd )
  1182.       return 0
  1183.    endif
  1184.  
  1185.    if nKey == VK_F4 .and. GetKeyState( VK_CONTROL ) .and. ;
  1186.       ::oWnd != nil .and. ::oWnd:ChildLevel( TMdiChild() ) > 0
  1187.       ::oWnd:KeyDown( nKey, nFlags )
  1188.       return 0
  1189.    endif
  1190.  
  1191.    if nKey == VK_F6 .and. GetKeyState( VK_CONTROL ) .and. ;
  1192.       ::oWnd != nil .and. ::oWnd:ChildLevel( TMdiChild() ) > 0
  1193.       ::oWnd:KeyDown( nKey, nFlags )
  1194.       return 0
  1195.    endif
  1196.  
  1197.    if nKey == VK_F1
  1198.       HelpTopic( ::nHelpId )
  1199.       return 0
  1200.    endif
  1201.  
  1202.    if bKeyAction != nil     // Clipper SET KEYs !!!
  1203.       Eval( bKeyAction, ProcName( 4 ), ProcLine( 4 ) )
  1204.       return 0
  1205.    endif
  1206.  
  1207.    if ::bKeyDown != nil
  1208.       return Eval( ::bKeyDown, nKey, nFlags )
  1209.    endif
  1210.  
  1211. return nil
  1212.  
  1213. //----------------------------------------------------------------------------//
  1214. // Some friends functions
  1215.  
  1216. function SetWndDefault( oWnd ) ; oWndDefault := oWnd ; return nil
  1217.  
  1218. function GetWndDefault() ; return oWndDefault
  1219.  
  1220. //----------------------------------------------------------------------------//
  1221.  
  1222. METHOD GotFocus() CLASS TWindow
  1223.  
  1224.    ::lFocused = .t.
  1225.  
  1226.    if ::hCtlFocus != nil
  1227.       SetFocus( ::hCtlFocus )
  1228.       return 0
  1229.    else
  1230.       if ::aControls != nil .and. Len( ::aControls ) > 0
  1231.          ::hCtlFocus = ::aControls[ 1 ]:hWnd
  1232.          SetFocus( ::hCtlFocus )
  1233.          return 0
  1234.       endif
  1235.    endif
  1236.  
  1237. return nil           // Default API behavior
  1238.  
  1239. //----------------------------------------------------------------------------//
  1240.  
  1241. METHOD FocusNext( hCtrl, lPrevious ) CLASS TWindow
  1242.  
  1243.    DEFAULT lPrevious := .f.
  1244.  
  1245.    if lPrevious
  1246.       return ::GoPrevCtrl( hCtrl )
  1247.    else
  1248.       return ::GoNextCtrl( hCtrl )
  1249.    endif
  1250.  
  1251. return nil
  1252.  
  1253. //----------------------------------------------------------------------------//
  1254.  
  1255. METHOD GoNextCtrl( hCtrl ) CLASS TWindow
  1256.  
  1257.    local hCtlNext := NextDlgTab( ::hWnd, hCtrl )
  1258.  
  1259.    if hCtlNext != hCtrl
  1260.       SetFocus( hCtlNext )
  1261.       ::hCtlFocus = hCtlNext
  1262.    endif
  1263.  
  1264. return nil
  1265.  
  1266. //----------------------------------------------------------------------------//
  1267.  
  1268. METHOD GoPrevCtrl( hCtrl ) CLASS TWindow
  1269.  
  1270.    local hCtlPrev := NextDlgTab( ::hWnd, hCtrl, .t. )
  1271.  
  1272.    if hCtlPrev != hCtrl
  1273.       SetFocus( hCtlPrev )
  1274.       ::hCtlFocus = hCtlPrev
  1275.    endif
  1276.  
  1277. return nil
  1278.  
  1279. //----------------------------------------------------------------------------//
  1280.