home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c163 / 3.ddi / SCRE_SOU.EXE / W4INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  8.7 KB  |  305 lines

  1. /* w4init.c  Setup Routines  (c)Copyright Sequiter Software Inc., 1991.  All rights reserved. */
  2.  
  3. #include "c4window.h"
  4. #include "e4error.h"
  5.  
  6. #ifdef __TURBOC__
  7.    #pragma hdrstop
  8. #endif
  9.  
  10. C4WINDOWS *S4FUNCTION w4init( HANDLE hInst, HANDLE hParentWindow )
  11. {
  12.    WNDCLASS   wc ;
  13.    C4WINDOWS *cw ;
  14.  
  15.    #ifdef S4DEBUG
  16.       if ( GetWindowWord( hParentWindow, GWW_HINSTANCE ) != hInst )
  17.       {
  18.          e4severe( e4parm, "w4init", (char *) 0 ) ;
  19.          return 0 ;
  20.       }
  21.    #endif
  22.  
  23.    if ( GetClassInfo( hInst, "B4BROWSE", &wc ) == 0 )
  24.    {
  25.       wc.style         = NULL ;
  26.       wc.lpfnWndProc   = entry4_proc ;
  27.       wc.cbClsExtra    = 0 ;
  28.       wc.cbWndExtra    = sizeof( LONG ) ;
  29.       wc.hInstance     = hInst ;
  30.       wc.hIcon         = LoadIcon( NULL, IDI_APPLICATION ) ;
  31.       wc.hCursor       = LoadCursor( NULL, IDC_ARROW ) ;
  32.       wc.hbrBackground = GetStockObject( WHITE_BRUSH ) ;
  33.       wc.lpszMenuName  =  0 ;
  34.       wc.lpszClassName = "W4ENTRY" ;
  35.  
  36.       if ( RegisterClass( &wc ) == 0 )
  37.          return 0 ;
  38.  
  39.       wc.lpfnWndProc   =  browse4_proc ;
  40.       wc.lpszClassName =  "B4BROWSE" ;
  41.       wc.lpszMenuName  =  "B4MENU" ;
  42.  
  43.       if ( RegisterClass( &wc ) == 0 )
  44.          return 0 ;
  45.  
  46.       wc.lpfnWndProc   =  browse4_area_proc ;
  47.       wc.lpszClassName =  "B4AREA" ;
  48.       wc.lpszMenuName  =   0 ;
  49.  
  50.       if ( RegisterClass( &wc ) == 0 )
  51.          return 0 ;
  52.  
  53.       wc.style         =  CS_PARENTDC ;
  54.       wc.lpfnWndProc   =  edit4_proc ;
  55.       wc.lpszClassName =  "G4EDIT" ;
  56.  
  57.       if ( RegisterClass( &wc ) == 0 )
  58.          return 0 ;
  59.    }
  60.  
  61.    cw = (C4WINDOWS *) u4alloc( sizeof( C4WINDOWS ) ) ;
  62.    if ( cw == 0 )                              
  63.    {
  64.       e4severe( e4memory, "w4init()", (char *) 0 ) ;
  65.       return 0 ;
  66.    }
  67.    d4init( &cw->cb ) ;
  68.  
  69.    cw->TypeOver = 0 ;
  70.    cw->bad_date = 0 ;
  71.  
  72.    cw->cb.hWnd  = hParentWindow ;
  73.    cw->cb.hInst = hInst ;
  74.  
  75.    #ifdef S4DLL
  76.       cw->button4_proc = (FARPROC) button4_proc ;
  77.       cw->combo4_proc  = (FARPROC) combo4_proc ;
  78.       cw->list4_proc   = (FARPROC) list4_proc ;
  79.    #else
  80.       cw->button4_proc = MakeProcInstance( (FARPROC) button4_proc, hInst ) ;
  81.       cw->combo4_proc  = MakeProcInstance( (FARPROC) combo4_proc,  hInst ) ;
  82.       cw->list4_proc   = MakeProcInstance( (FARPROC) list4_proc,   hInst ) ;
  83.    #endif
  84.  
  85.    cw->combo_arrow = LoadBitmap( NULL, (LPSTR) OBM_COMBO ) ;
  86.  
  87.    if ( (cw->button4_proc == 0) || (cw->combo4_proc == 0) ||
  88.         (cw->list4_proc  == 0)  || (cw->combo_arrow == 0) )
  89.    {
  90.       w4init_undo( cw ) ;
  91.       return 0 ;
  92.    }
  93.    return cw ;
  94. }
  95.  
  96. void S4FUNCTION w4init_undo( C4WINDOWS *cw )
  97. {
  98. /* this assumes that all windows from these classes have been destroyed */
  99.  
  100.    UnregisterClass( "W4ENTRY",  cw->cb.hInst ) ;
  101.    UnregisterClass( "B4BROWSE", cw->cb.hInst ) ;
  102.    UnregisterClass( "B4AREA",   cw->cb.hInst ) ;
  103.    UnregisterClass( "G4EDIT",   cw->cb.hInst ) ;
  104.  
  105.    #ifndef S4DLL
  106.       FreeProcInstance( (FARPROC) cw->button4_proc ) ;
  107.       FreeProcInstance( (FARPROC) cw->combo4_proc ) ;
  108.       FreeProcInstance( (FARPROC) cw->list4_proc ) ;
  109.       cw->button4_proc = 0 ;
  110.       cw->combo4_proc  = 0 ;
  111.       cw->list4_proc   = 0 ;
  112.    #endif
  113.  
  114.    if ( cw->combo_arrow != 0 )
  115.       DeleteObject( cw->combo_arrow ) ;
  116.  
  117.    d4init_undo( &cw->cb ) ;
  118.    u4free( cw ) ;   
  119. }
  120.  
  121. long FAR PASCAL _export browse4_area_proc( HWND hWnd, UINT message,
  122.                                             UINT wParam, LONG lParam )
  123. {
  124.    int rc = 0 ;
  125.  
  126.    B4AREA *ba = (B4AREA *) GetWindowLong( hWnd, 0 ) ;
  127.  
  128.    if ( ba != 0 )
  129.       rc = browse4_area_process_message( ba, message, wParam, lParam ) ;
  130.    if ( rc == 0 )
  131.       return DefWindowProc( hWnd, message, wParam, lParam ) ;
  132.  
  133.    return 0 ;
  134. }
  135.  
  136. long FAR PASCAL _export browse4_proc( HWND hWnd, UINT message, UINT wParam,
  137.                                        LONG lParam )
  138. {
  139.    int rc = 0 ;
  140.  
  141.    B4BROWSE *bw = (B4BROWSE *) GetWindowLong( hWnd, 0 ) ;
  142.  
  143.    if ( bw != 0 )
  144.       rc = browse4_process_message( bw, message, wParam, lParam ) ;
  145.    if ( rc == 0 )
  146.       return DefWindowProc( hWnd, message, wParam, lParam ) ;
  147.  
  148.    return 0 ;
  149. }
  150.  
  151. long FAR PASCAL _export entry4_proc( HWND hWnd, UINT message, UINT wParam,
  152.                                      LONG lParam )
  153. {
  154.    int rc = 0 ;
  155.  
  156.    W4ENTRY *ew = (W4ENTRY *) GetWindowLong( hWnd, 0 ) ;
  157.  
  158.    if ( ew != 0 )
  159.       rc = entry4_process_message( ew, message, wParam, lParam ) ;
  160.    if ( rc == 0 )
  161.       return DefWindowProc( hWnd, message, wParam, lParam ) ;
  162.  
  163.    return 0 ;
  164. }
  165.  
  166. long FAR PASCAL _export edit4_proc( HWND hWnd, UINT message, UINT wParam,
  167.                                     LONG lParam )
  168. {
  169.    int rc = 0 ;
  170.  
  171.    G4EDIT *ea = (G4EDIT *) GetWindowLong( hWnd, 0 ) ;
  172.  
  173.    if ( ea != 0 )
  174.       rc = edit4_process_message( ea, message, wParam, lParam ) ;
  175.    if ( rc == 0 )
  176.       return DefWindowProc( hWnd, message, wParam, lParam ) ;
  177.  
  178.    return 0 ;
  179. }
  180.  
  181. long FAR PASCAL _export button4_proc( HWND hWnd, UINT message, UINT wParam,
  182.                                       LONG lParam )
  183. {
  184.    int id      = GetWindowWord( hWnd, GWW_ID ) ;
  185.    int parent  = GetWindowWord( hWnd, GWW_HWNDPARENT ) ;
  186.    W4ENTRY *ew = (W4ENTRY *) GetWindowLong( parent, 0 ) ;
  187.  
  188.    if ( ew != 0 )
  189.    {
  190.       G4BUTTON *button = g4lookup_button( ew, id ) ;
  191.       if ( button != 0 )
  192.       {
  193.          int rc = button4_process_message( button, message, wParam, lParam ) ;
  194.          if ( rc == 0 )
  195.             return CallWindowProc( button->ca.gw.OldWindowProc, hWnd, message,
  196.                                    wParam, lParam ) ;
  197.       }
  198.       return 0 ;
  199.    }
  200.    return DefWindowProc( hWnd, message, wParam, lParam ) ;
  201. }
  202.  
  203. long FAR PASCAL _export list4_proc( HWND hWnd, UINT message, UINT wParam,
  204.                                     LONG lParam )
  205. {
  206.    int id      = GetWindowWord( hWnd, GWW_ID ) ;
  207.    int parent  = GetWindowWord( hWnd, GWW_HWNDPARENT ) ;
  208.    W4ENTRY *ew = (W4ENTRY *) GetWindowLong( parent, 0 ) ;
  209.  
  210.    if ( ew != 0 )
  211.    {
  212.       G4LIST *list = g4lookup_list( ew, id ) ;
  213.       if ( list != 0 )
  214.       {
  215.          int rc = list4_process_message( list, message, wParam, lParam ) ;
  216.          if ( rc == 0 )
  217.             return CallWindowProc( list->ca.gw.OldWindowProc, hWnd, message,
  218.                                    wParam, lParam ) ;
  219.       }
  220.       return 0 ;
  221.    }
  222.    return DefWindowProc( hWnd, message, wParam, lParam ) ;
  223. }
  224.  
  225. long FAR PASCAL _export combo4_proc( HWND hWnd, UINT message, UINT wParam,
  226.                                      LONG lParam )
  227. {
  228.    int id      = GetWindowWord( hWnd, GWW_ID ) ;
  229.    int parent  = GetWindowWord( hWnd, GWW_HWNDPARENT ) ;
  230.    W4ENTRY *ew = (W4ENTRY *) GetWindowLong( parent, 0 ) ;
  231.  
  232.    if ( ew != 0 )
  233.    {
  234.       G4EDIT *edit = g4lookup_edit( ew, id ) ;
  235.       G4COMBO *combo = (G4COMBO *) edit->combo ;
  236.       if ( combo != 0 )
  237.       {
  238.          int rc = combo4_process_message( combo, message, wParam, lParam ) ;
  239.          if ( rc == 0 )
  240.             return CallWindowProc( combo->edit.ca.gw.OldWindowProc, hWnd,
  241.                                    message, wParam, lParam ) ;
  242.       }
  243.       return 0 ;
  244.    }
  245.    return DefWindowProc( hWnd, message, wParam, lParam ) ;
  246. }
  247.  
  248. HDC S4FUNCTION w4get_dc( C4CODE *cb, HWND hwnd )
  249. {
  250.    HDC hDC = GetDC( hwnd ) ;
  251.    if ( hDC == NULL )
  252.       return e4error( cb, 0, E4_RESULT_GDC, (char *) 0 ) ;
  253.  
  254.    return hDC ;
  255.  }
  256.  
  257. int S4FUNCTION w4release_dc( C4CODE *cb, HWND hwnd, HDC hDC )
  258. {
  259.    if ( ReleaseDC( hwnd, hDC ) )  return 1 ;
  260.  
  261.    return e4error( cb, 0, E4_RESULT_RDC, (char *) 0 ) ;
  262. }
  263.  
  264. HWND S4FUNCTION w4create_window( char *class_name, char *caption, DWORD style, int x, int y, int width,
  265.                       int height, HWND parent, HMENU menu, HANDLE hInst, char *lParam )
  266. {
  267.    HWND hwnd = CreateWindow( class_name, caption, style, x, y, width, height,
  268.                              parent, menu, hInst, lParam ) ;
  269.    if ( hwnd == 0 )
  270.       e4severe( e4result, E4_RESULT_WIN, (char *) 0 ) ;
  271.    return hwnd ;
  272. }
  273.  
  274. void S4FUNCTION w4get_metrics( HDC hDC, TEXTMETRIC *metrics )
  275. {
  276.    if ( GetTextMetrics( hDC, metrics ) == 0 )
  277.       e4severe( e4result, E4_RESULT_GTM, (char *) 0 ) ;
  278. }
  279.  
  280. void S4FUNCTION w4get_rect( HWND hwnd, RECT *r, int type )
  281. {
  282.    if ( type == 0 )
  283.       GetClientRect( hwnd, r ) ;
  284.    else
  285.       GetWindowRect( hwnd, r ) ;
  286.  
  287.    #ifdef S4DEBUG
  288.       if ( (r->bottom <= 0) || (r->right <= 0) )
  289.          e4severe( e4parm, E4_PARM_WIN, (char *) 0 ) ;
  290.    #endif
  291. }
  292.  
  293. /* note, if fields used, the record will be marked as changed, thus will be
  294.    written to disk at next available time */
  295.  
  296. int S4FUNCTION w4save( W4ENTRY *ew )
  297. {
  298.    return entry4_controlssave( ew ) ;
  299. }
  300.  
  301. int S4FUNCTION w4refresh( W4ENTRY *ew )
  302. {
  303.    return entry4_controlsrefresh( ew ) ;
  304. }
  305.