home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / itemli / itemtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-13  |  3.9 KB  |  165 lines

  1. #include <windows.h>
  2. #include <memory.h>
  3. #include "resource.h"
  4. #include "itemlist.h"
  5.  
  6. #define APPL_NAME        "ItemTest\0"
  7. #define APPL_CAPTION    "Item List Test\0"
  8.  
  9. HINSTANCE    hInst;
  10. HWND        hWndMain;
  11. HFONT        hFont=NULL;
  12.  
  13. void TestIt (VOID);
  14. BOOL _export CALLBACK TestProc (HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam);
  15.  
  16. BOOL InitApplication(HINSTANCE hInstance);
  17. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
  18. void UnRegisterClasses(void);
  19.  
  20. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  21. {
  22.     MSG msg;
  23.  
  24.     if (!hPrevInstance)             
  25.         if (!InitApplication(hInstance)) 
  26.             return (FALSE);
  27.             
  28.     if (!InitInstance(hInstance, nCmdShow))
  29.         return (FALSE);
  30.     
  31.     ItemListInit("",6,0);
  32.     while ( GetMessage(&msg,NULL,NULL, NULL))
  33.     {
  34.         TranslateMessage(&msg);
  35.         DispatchMessage(&msg);
  36.     }
  37.     
  38.     UnRegisterClasses();
  39.  
  40.     return (msg.wParam);      
  41. }
  42.  
  43. LRESULT __export CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  44. {
  45.     switch (message) 
  46.     {
  47.         case WM_COMMAND:
  48.             switch (wParam)
  49.             {              
  50.                 case ID_FILE_TEST:
  51.                 {
  52.                     FARPROC        lproc;
  53.                     int            iret;
  54.                         
  55.                     lproc = MakeProcInstance((FARPROC)TestProc,hInst);
  56.                     iret  = DialogBox (hInst,"TESTDLG",hWnd,lproc);
  57.                     FreeProcInstance(lproc);
  58.                     break;
  59.                 }
  60.                 case ID_FILE_EXIT:
  61.                     PostMessage(hWnd,WM_CLOSE,0,0L);
  62.                     break;
  63.                 default:
  64.                     return (DefWindowProc(hWnd, message, wParam, lParam));
  65.             }
  66.             break;        
  67.         case WM_DESTROY:          
  68.             PostQuitMessage(0);
  69.             break;
  70.         case WM_CLOSE:
  71.             if (hFont)
  72.                 DeleteObject(hFont);     
  73.             ItemListCleanup();
  74.             DestroyWindow(hWnd);
  75.             if (hWnd == hWndMain)
  76.                 PostQuitMessage(0);
  77.         default:             
  78.             return (DefWindowProc(hWnd, message, wParam, lParam));
  79.     }
  80.  
  81.     return (NULL);
  82.     
  83. }
  84.  
  85. BOOL InitApplication(HINSTANCE hInstance)
  86. {
  87.     WNDCLASS  wc;
  88.  
  89.     wc.style = NULL; 
  90.     wc.lpfnWndProc = MainWndProc; 
  91.     wc.cbClsExtra = 0;
  92.     wc.cbWndExtra = 0;
  93.     wc.hInstance = hInstance;
  94.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  95.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  96.     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  97.     wc.lpszMenuName =  "GENMENU";
  98.     wc.lpszClassName = APPL_NAME;
  99.  
  100.     return (RegisterClass(&wc));
  101.  
  102. }
  103. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  104. {
  105.     HWND            hWnd;
  106.  
  107.     hInst = hInstance;
  108.  
  109.     if ((hWnd = CreateWindow(
  110.             APPL_NAME,
  111.             APPL_CAPTION,
  112.             WS_OVERLAPPEDWINDOW,
  113.             CW_USEDEFAULT,      
  114.             CW_USEDEFAULT,      
  115.             CW_USEDEFAULT,      
  116.             CW_USEDEFAULT,      
  117.             NULL,               
  118.             NULL,               
  119.             hInstance,          
  120.             NULL                
  121.         ))==NULL)
  122.         return (FALSE);
  123.  
  124.     hWndMain = hWnd;
  125.     ShowWindow(hWnd, nCmdShow);
  126.     UpdateWindow(hWnd);
  127.     return (TRUE);
  128.  
  129. }
  130.  
  131. void UnRegisterClasses(void)
  132. {
  133.     WNDCLASS   wndclass;   
  134.     memset(&wndclass, 0x00, sizeof(WNDCLASS));
  135.     UnregisterClass(APPL_NAME, hInst);
  136. }
  137. BOOL _export CALLBACK TestProc (HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
  138. {
  139.                                           
  140.     char    szBuffer[128];
  141.     
  142.     switch (msg) {
  143.         case WM_INITDIALOG:
  144.             SetFocus(GetDlgItem(hDlg,IDC_ADDITEM));
  145.             break;
  146.         case WM_COMMAND:
  147.             if (wParam==IDOK)
  148.             {
  149.                 GetDlgItemText ( hDlg, IDC_ADDITEM, szBuffer,sizeof(szBuffer));
  150.                 ItemListAdd (GetMenu(hWndMain),szBuffer);
  151.                 EndDialog(hDlg,TRUE);
  152.                 return TRUE;
  153.             }                                                        
  154.             else
  155.                    if (wParam==IDCANCEL)
  156.                 {
  157.                     GetDlgItemText ( hDlg, IDC_ADDITEM, szBuffer,sizeof(szBuffer));
  158.                     ItemListRemove ( GetMenu(hWndMain),szBuffer);
  159.                     EndDialog(hDlg,FALSE);
  160.                     return TRUE;
  161.                 }   
  162.     }
  163.     
  164.     return FALSE;
  165. }