home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / WILDASS / SOURCE / TILE.CPP < prev    next >
C/C++ Source or Header  |  1993-08-09  |  4KB  |  146 lines

  1. // tile.cpp
  2. //
  3. // code for tilling windows, extracted from app.cpp
  4. //
  5. // update: 1.00 08-Aug-93 tw
  6.  
  7. #include <afxwin.h>
  8. #include <afxext.h> 
  9. #include <ctl3d.h>
  10.  
  11. #include "resource.h"                  
  12. #include "app.h"
  13. #include "wndlst.h"
  14.  
  15. void 
  16. CMyApp::OnTile1()
  17. {
  18.    // tile, and don`t care for the icons
  19.    TileHorizontal( 0 );   
  20. }
  21.  
  22. void 
  23. CMyApp::OnTile2()
  24. {  
  25.    TileVertical( 0 );
  26. }
  27.  
  28. void 
  29. CMyApp::OnTile3()
  30. {  
  31.    // take care of the icons
  32.    int cyIconSpace = GetSystemMetrics( SM_CYICON ) + 
  33.                      GetSystemMetrics( SM_CYICONSPACING );
  34.    TileHorizontal( cyIconSpace );                     
  35. }
  36.  
  37. void 
  38. CMyApp::OnTile4()
  39. {
  40.    // take care of the icons
  41.    int cyIconSpace = GetSystemMetrics( SM_CYICON ) + 
  42.                      GetSystemMetrics( SM_CYICONSPACING );
  43.    TileVertical( cyIconSpace );                     
  44. }
  45.  
  46. void 
  47. CMyApp::TileHorizontal( int cyIcon )
  48. {  
  49.    // hide our window, so we don`t get tiled ourselves
  50.    m_pMainWnd->ShowWindow( SW_HIDE );
  51.  
  52.    // Create a list of all main windows   
  53.    // by using a callback as a member fxn
  54.    CMainWndList lstWindows;
  55.  
  56.    // iterate the window list and move the windows to their place
  57.    // (using that magic DeferWindowPos() stuff...
  58.    int nWindows = lstWindows.GetTileCount(); 
  59.    
  60.    // nothing to do ?
  61.    if ( nWindows == 0 )
  62.       return;
  63.       
  64.    HDWP hdwp;
  65.    
  66.    VERIFY( hdwp = BeginDeferWindowPos( nWindows ) );
  67.                                          
  68.    // prepare the pixle frame                                         
  69.    int cxFrame = Settings_PixelFrame() * 2;
  70.    int cyFrame = Settings_PixelFrame() * 2;
  71.    
  72.    int cyWnd = ( GetSystemMetrics( SM_CYSCREEN ) - (cyIcon+cyFrame) ) / nWindows;
  73.    int cxWnd = GetSystemMetrics( SM_CXSCREEN ) - cxFrame;
  74.    int iWnd=0; 
  75.    int xUpperLeftWnd = cxFrame/2;
  76.     
  77.    for ( POSITION pos=lstWindows.GetHeadPosition(); pos!=NULL; )
  78.    {           
  79.       CRawHWnd * pWnd = lstWindows.GetNext( pos );
  80.       if ( pWnd->IsTileWindow() )
  81.       {
  82.          int yUpperLeftWnd = (iWnd * cyWnd) + cyFrame;
  83.          iWnd++;
  84.          VERIFY( hdwp = DeferWindowPos( hdwp, pWnd->m_hWnd, HWND_BOTTOM, 
  85.                  xUpperLeftWnd, yUpperLeftWnd, cxWnd, cyWnd, 
  86.                  SWP_NOZORDER | SWP_SHOWWINDOW ));
  87.       }                 
  88.    }      
  89.    
  90.    VERIFY( EndDeferWindowPos( hdwp ));
  91.  
  92.    // make ourselves visible again
  93.    m_pMainWnd->ShowWindow( SW_SHOWNORMAL );
  94.  
  95. }
  96.  
  97.  
  98. void 
  99. CMyApp::TileVertical( int cyIcon )
  100. {  
  101.    
  102.    // collect the windows, but Hide ourselves beforem, so we don`t get
  103.    // moved too
  104.    m_pMainWnd->ShowWindow( SW_HIDE );
  105.    
  106.    CMainWndList lstWindows;
  107.    
  108.    int nWindows = lstWindows.GetTileCount(); 
  109.    
  110.    // nothing to do ?
  111.    if ( nWindows == 0 )
  112.       return;
  113.       
  114.    HDWP hdwp;
  115.    
  116.    VERIFY( hdwp = BeginDeferWindowPos( nWindows ) );
  117.    int cxFrame = Settings_PixelFrame() * 2;
  118.    int cyFrame = Settings_PixelFrame() * 2;
  119.    int cyWnd = GetSystemMetrics( SM_CYSCREEN ) - (cyIcon+cyFrame);
  120.    int cxWnd = ( GetSystemMetrics( SM_CXSCREEN ) - cxFrame ) / nWindows;
  121.    int iWnd=0; 
  122.    int yUpperLeftWnd = cyFrame/2;
  123.     
  124.    for ( POSITION pos=lstWindows.GetHeadPosition(); pos!=NULL; )
  125.    {       
  126.       CRawHWnd * pWnd = lstWindows.GetNext( pos );
  127.       if ( pWnd->IsTileWindow() )
  128.       {
  129.          int xUpperLeftWnd = (iWnd * cxWnd) + cxFrame/2;
  130.          iWnd++;
  131.    
  132.          VERIFY( hdwp = DeferWindowPos( hdwp, pWnd->m_hWnd, HWND_BOTTOM, 
  133.               xUpperLeftWnd, yUpperLeftWnd, cxWnd, cyWnd, 
  134.               SWP_NOZORDER | SWP_SHOWWINDOW ));
  135.       }              
  136.    }      
  137.    
  138.    VERIFY( EndDeferWindowPos( hdwp ));
  139.  
  140.    // make ourselves visible again
  141.    m_pMainWnd->ShowWindow( SW_SHOWNORMAL );
  142.  
  143.  
  144. }
  145.  
  146.