home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / cscrap / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-11  |  5.6 KB  |  203 lines

  1. /***************************************************************
  2.  
  3.    Scraper.c
  4.  
  5.    Tests the Scraper control
  6.  
  7. ****************************************************************/
  8. #define  STRICT
  9. #include <windows.h>
  10. #include <stdlib.h>
  11. #include "Scraper.h"
  12. #include "test.h"
  13.  
  14.    //These are globals for convenience only.
  15. HINSTANCE   hInstMain;
  16. HWND        hWndScraper;
  17. HWND        hWndConfig;
  18. HWND        hWndScrape;
  19. HWND        hWndData;
  20.  
  21. /***************************************************************
  22.  
  23.                   Main Window Procedure
  24.  
  25. ****************************************************************/
  26. int PASCAL WinMain (HINSTANCE hInstance, 
  27.                     HINSTANCE hPrevInstance,
  28.                     LPSTR     lpszCmdLine, 
  29.                     int       nCmdShow)
  30. {
  31.    WNDCLASS    wc;
  32.    HWND        hWnd;
  33.    MSG         msg;
  34.  
  35.    if (!hPrevInstance)
  36.    {
  37.       wc.style          = CS_HREDRAW | CS_VREDRAW;
  38.       wc.lpfnWndProc    = testWndProc;
  39.       wc.cbClsExtra     = 0;
  40.       wc.cbWndExtra     = 0;
  41.       wc.hInstance      = hInstance;
  42.       wc.hIcon          = LoadIcon(hInstance, "testIcon");
  43.       wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
  44.       wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  45.       wc.lpszMenuName   = "testMenu";
  46.       wc.lpszClassName  = "Scrapertest";
  47.  
  48.  
  49.       if (!RegisterClass(&wc))
  50.          return FALSE;
  51.    }
  52.  
  53.    hInstMain=hInstance;
  54.  
  55.    //Create and show main window.
  56.    hWnd=CreateWindow("Scrapertest", "Scraper Test",
  57.                      WS_MINIMIZEBOX | WS_OVERLAPPEDWINDOW,
  58.                      35, 35, 350, 340,
  59.                      NULL, NULL, hInstance, NULL);
  60.  
  61.    ShowWindow(hWnd, nCmdShow);
  62.    UpdateWindow(hWnd);
  63.  
  64.      // Force the dll to load
  65.    registerScraper();
  66.  
  67.       // Create a scraper control
  68.    hWndScraper=CreateWindow("Scraper", "Scraper1",
  69.                      WS_CHILD | WS_VISIBLE,
  70.                      35, 35, 350, 340,
  71.                      hWnd, NULL, hInstance, NULL);
  72.  
  73.       // Set the scraper ID
  74.    SendMessage(hWndScraper,SCM_SETSCRAPEID,0,(LPARAM)(LPSTR)"scrape1");
  75.  
  76.       // Create a button to do the "configure" command
  77.    hWndConfig=CreateWindow("Button", "Configure",
  78.                      WS_CHILD | WS_VISIBLE,
  79.                      80, 33, 76, 22,
  80.                      hWnd, (HMENU)IDC_CONFIGURE, hInstance, NULL);
  81.  
  82.       // Create a button to do the "Scrape" command
  83.    hWndScrape=CreateWindow("Button", "Scrape",
  84.                      WS_CHILD | WS_VISIBLE,
  85.                      80, 60, 76, 22,
  86.                      hWnd, (HMENU)IDC_SCRAPE, hInstance, NULL);
  87.  
  88.       // Create a label for the scraped data
  89.    CreateWindow("Static", "Scraped Data:",
  90.                      WS_CHILD | WS_VISIBLE,
  91.                      35, 110, 120, 16,
  92.                      hWnd, (HMENU)-1, hInstance, NULL);
  93.  
  94.       // Create a window for the scraped data
  95.    hWndData=CreateWindow("Static", "",
  96.                      WS_CHILD | WS_VISIBLE,
  97.                      35, 130, 200, 100,
  98.                      hWnd, (HMENU)IDC_DATA, hInstance, NULL);
  99.  
  100.  
  101.       // Create frame
  102.    CreateWindow("Static", "",
  103.                 WS_CHILD|SS_BLACKFRAME|WS_VISIBLE,
  104.                 34, 129, 202, 102,
  105.                 hWnd, (HMENU)-1, hInstance, NULL);
  106.  
  107.  
  108.  
  109.    while (GetMessage(&msg, NULL, 0, 0))
  110.    {
  111.       TranslateMessage(&msg);
  112.       DispatchMessage(&msg);
  113.    }
  114.  
  115.    return msg.wParam;
  116. }
  117.  
  118.  
  119.  
  120. /*
  121.  * testWndProc
  122.  *
  123.  * Purpose:
  124.  *  Window class procedure.  Standard callback.
  125.  *
  126.  */
  127. long FAR PASCAL testWndProc(HWND hWnd, UINT iMessage,
  128.                    WPARAM wParam, LPARAM lParam)
  129. {
  130.    LRESULT     lResult;
  131.    char        buf[500];
  132.    int         nLen;
  133.  
  134.  
  135.    switch (iMessage)
  136.    {
  137.       case WM_CREATE:
  138.          break;
  139.  
  140.       case WM_DESTROY:
  141.          PostQuitMessage(0);
  142.          break;
  143.  
  144.       case WM_COMMAND:
  145.          switch (wParam)
  146.          {
  147.             case IDC_CONFIGURE:
  148.                SendMessage(hWndScraper,SCM_SETCOMMAND,SCC_CONFIGURE,0L);
  149.                break;
  150.  
  151.             case IDC_SCRAPE:
  152.                lResult=SendMessage(hWndScraper,SCM_SETCOMMAND,SCC_SCRAPE,0L);
  153.                switch (lResult)
  154.                {
  155.                   case ERR_TASKNOTFOUND:
  156.                      MessageBox(hWnd,"Task Not Running","Scraper Test",MB_OK);
  157.                      break;
  158.  
  159.                   case ERR_WINDOWNOTFOUND:
  160.                      MessageBox(hWnd,"Window not found","Scraper Test",MB_OK);
  161.                      break;
  162.  
  163.                   case ERR_INVALIDACTION:
  164.                      MessageBox(hWnd,"Invalid Action Specified","Scraper Test",MB_OK);
  165.                      break;
  166.  
  167.                   case ERR_NODATA:
  168.                      MessageBox(hWnd,"No Data to Scrape","Scraper Test",MB_OK);
  169.                      break;
  170.  
  171.                   case ERR_INVALIDLPARAM:
  172.                      MessageBox(hWnd,"Invalid Parameter Sent","Scraper Test",MB_OK);
  173.                      break;
  174.  
  175.                   case 0:
  176.  
  177.                         // Successful scrape - get the data
  178.                      nLen=(int)SendMessage(hWndScraper,SCM_GETDATA,sizeof(buf),(LPARAM)(LPSTR)&buf);
  179.  
  180.                         //Display the data
  181.                      SetDlgItemText(hWnd,IDC_DATA,buf);
  182.                      break;
  183.  
  184.                   default:
  185.                         // Unknown error
  186.                      break;
  187.                }
  188.                break;
  189.  
  190.             case IDM_EXIT:
  191.                PostMessage(hWnd, WM_CLOSE, 0, 0L);
  192.                break;
  193.          }
  194.          break;
  195.  
  196.       default:
  197.           return (DefWindowProc(hWnd, iMessage, wParam, lParam));
  198.    }
  199.  
  200.    return 0L;
  201. }
  202.  
  203.