home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_04 / Pogy / Event.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  5.7 KB  |  182 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : event.cpp                                                             //
  10. //  Description: KEventPage class                                                    //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define NOCRYPT
  15.  
  16. #include <windows.h>
  17. #include <commctrl.h>
  18. #include <assert.h>
  19. #include <stdio.h>
  20.  
  21. #include "..\..\include\win.h"
  22. #include "..\..\include\listview.h"
  23. #include "..\..\include\property.h"
  24.  
  25. #include "..\Diver\Diver.h"
  26. #include "..\Diver\Report.h"
  27.  
  28. #include "Resource.h"
  29.  
  30. #include "ApiTable.h"
  31. #include "ApiPage.h"
  32. #include "Setup.h"
  33. #include "Event.h"
  34.  
  35. LRESULT __declspec(dllimport) h_Reply;
  36.  
  37.  
  38. LRESULT KEventPage::MonitorWindow(HWND hWnd, int oper, const char *owner)
  39. {
  40.     if ( strchr(owner, ':') )
  41.         owner = strchr(owner, ':') + 1;
  42.  
  43.     while ( strchr(owner, '\\') )
  44.         owner = strchr(owner, '\\') + 1;
  45.  
  46.     if ( ApiTable.MainTarget() )
  47.     if ( stricmp(owner, ApiTable.MainTarget())==0 )
  48.     {
  49.          
  50.         if (StartTime==0)
  51.             StartTime = GetTickCount();
  52.  
  53.         if ( oper==M_CREATE )
  54.         {
  55.             h_Reply = REPLY_DIVERSTART;
  56.             return REPLY_DIVERSTART;
  57.         }
  58.         else
  59.         {
  60.             h_Reply = REPLY_DIVERSTOP;
  61.             return REPLY_DIVERSTOP;
  62.         }
  63.     }
  64.  
  65.     return 0;
  66. }
  67.  
  68.  
  69. BOOL KEventPage::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  70. {
  71.     char temp[256];
  72.  
  73.     switch (uMsg)
  74.     {
  75.         case WM_INITDIALOG:
  76.             hMailBox  = NULL;
  77.  
  78.             StartTime = 0;
  79.             m_hWnd    = hWnd;
  80.             SetupDiver(Diver_SetController, m_hWnd);
  81.  
  82.             // the propertysheet have two buttons OK and Cancel, (Apply removed )
  83.             // hide the first OK button, change Cancel to Exit
  84.             {
  85.                 // propertysheet is the parent window
  86.                 HWND h = GetDlgItem(GetParent(hWnd), IDOK);
  87.  
  88.                 if (h)
  89.                     SetWindowPos(h, HWND_BOTTOM, 0, 0, 0, 0,
  90.                         SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
  91.  
  92.                 SetDlgItemText(GetParent(hWnd), IDCANCEL, "&Exit");
  93.             }
  94.  
  95.             return TRUE;
  96.  
  97.         
  98.         case WM_COPYDATA:
  99.             {
  100.                 char t[256];
  101.  
  102.                 h_Reply = 0;
  103.                 LRESULT lr = 0;
  104.  
  105.                 COPYDATASTRUCT *pcds = (COPYDATASTRUCT *) lParam;
  106.                 assert(pcds);
  107.  
  108.                 ReportMessage  *msg  = (ReportMessage *)(pcds->lpData);
  109.                 assert(msg);
  110.  
  111.                 switch (pcds->dwData)
  112.                 {
  113.                     case M_CREATE:
  114.                     case M_DESTROY:
  115.                         t[0] = '\'';
  116.                         GetWindowText((HWND) msg->m_para, t+1, sizeof(t)-2);
  117.                             
  118.                         if ( pcds->dwData==M_CREATE )
  119.                             strcat(t, "\' created");
  120.                         else
  121.                             strcat(t, "\' destroyed");
  122.  
  123.                         if ( strlen(msg->m_text) )
  124.                             strcat(t, " by ");
  125.  
  126.                         lr = MonitorWindow((HWND) msg->m_para, pcds->dwData, msg->m_text);
  127.                         break;
  128.  
  129.                    case M_ENTER: 
  130.                         strcpy(t, "=> "); 
  131.  
  132.                         if (hMailBox)
  133.                             SendMessage(hMailBox, WM_USER, 0x12345678, msg->m_para);
  134.                         break;
  135.  
  136.                    case M_LEAVE: 
  137.                         wsprintf(t, "<= %d us ", msg->m_time); 
  138.                         break;
  139.  
  140.                    case M_ENTERSUMMARY:
  141.                         wsprintf(t, "=> %d th ", msg->m_para);
  142.                         break;
  143.  
  144.                    case M_LEAVESUMMARY:
  145.                         wsprintf(t, "<= %d us %d th ", msg->m_time, msg->m_para);
  146.                         break;
  147.  
  148.                    case M_MAILBOX:
  149.                         hMailBox = (HWND) msg->m_para;
  150.                             
  151.                         assert(IsWindow(hMailBox));
  152.                         wsprintf(t, "Mailbox %d", hMailBox);
  153.  
  154.                         pSetupPage->ReadButtons();
  155.                         ApiTable.InterceptApi(m_hWnd, hMailBox, pSetupPage->bLogCall, pSetupPage->bDispCall);
  156.                         break;
  157.  
  158.                    case M_TEXT:
  159.                         strcpy(t, "Diver: ");
  160.                         break;
  161.  
  162.                    default: 
  163.                         strcpy(t, "Unknown "); break;
  164.                 }
  165.  
  166.                 unsigned time = msg->m_tick - StartTime;
  167.  
  168.                 wsprintf(temp, "(%d)  %d:%02d.%03d ", lr, time / 60000, 
  169.                                                 time / 1000 % 60, 
  170.                                                 time % 1000);
  171.                 strcat(temp, t);
  172.                 strcat(temp, msg->m_text);
  173.                 SendDlgItemMessage(hWnd, IDC_EVENT, LB_ADDSTRING, 0, (LPARAM) temp);
  174.  
  175.                 return lr;
  176.             }
  177.  
  178.     }
  179.         
  180.     return FALSE;
  181. }
  182.