home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_03 / Handles / FindTab.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  3.5 KB  |  125 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   : findtab.cpp                                                         //
  10. //  Description: Locate GDI handle table, Chapter 3                                  //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #include <windows.h>
  16. #include <assert.h>
  17. #include <tchar.h>
  18. #include <stdio.h>
  19.  
  20. #include "pefile.h"
  21.  
  22. #include "resource.h"
  23. #include "findTab.h"
  24.  
  25. //////////////////////////////////////////////////////////////////////
  26. // Construction/Destruction
  27. //////////////////////////////////////////////////////////////////////
  28.  
  29. KLocateGdiTablePage::KLocateGdiTablePage()
  30. {
  31.  
  32. }
  33.  
  34. KLocateGdiTablePage::~KLocateGdiTablePage()
  35. {
  36.  
  37. }
  38.  
  39.  
  40. typedef unsigned (CALLBACK * Proc0) (void);
  41.  
  42.  
  43. void KLocateGdiTablePage::GdiQueryTable(void)
  44. {
  45.     Proc0 p = (Proc0) GetProcAddress(GetModuleHandle("GDI32.DLL"), "GdiQueryTable");
  46.  
  47.     if (p)
  48.     {
  49.         TCHAR temp[32];
  50.  
  51.         wsprintf(temp, "%8lX", p());
  52.         MessageBox(NULL, temp, "GdiQueryTable() returns", MB_OK);
  53.     }
  54. }
  55.  
  56.  
  57. BOOL KLocateGdiTablePage::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  58. {
  59.     switch (uMsg)
  60.     {
  61.         case WM_INITDIALOG:
  62.             m_hWnd = hWnd;
  63.             
  64.             m_Regions.FromDlgItem(hWnd, IDC_REGIONS);
  65.             
  66.             m_Regions.AddIcon(LVSIL_SMALL, m_hInst, IDI_EMPTY);
  67.             m_Regions.AddIcon(LVSIL_SMALL, m_hInst, IDI_EQUAL);
  68.             m_Regions.AddIcon(LVSIL_SMALL, m_hInst, IDI_CHANGE);
  69.  
  70.             m_Regions.AddColumn(0, 62, "oldCRC");
  71.             m_Regions.AddColumn(1, 46, "CRC");
  72.                 
  73.             m_Regions.AddColumn(2, 76, "Base");
  74.             m_Regions.AddColumn(3, 76, "Size");
  75.             m_Regions.AddColumn(4, 60, "Type");
  76.             m_Regions.AddColumn(5, 100, "Module");
  77.             return TRUE;
  78.         
  79.         case WM_COMMAND:
  80.             if (LOWORD(wParam) == IDC_QUERY)
  81.             {
  82.                 m_Regions.DeleteAll();
  83.  
  84.                 m_snapshot.Shot(& m_Regions);
  85.                 return TRUE;
  86.             }
  87.             else if ( LOWORD(wParam)==IDC_GDIQUERY )
  88.             {
  89.                 GdiQueryTable();
  90.                 return TRUE;
  91.             }
  92.             break;
  93.  
  94.         case WM_NOTIFY:
  95.             if (wParam == IDC_REGIONS)
  96.             {
  97.                 NM_LISTVIEW * pInfo = (NM_LISTVIEW *) lParam;
  98.                 
  99.                 if ( (pInfo->hdr.code == NM_DBLCLK) && (pInfo->iItem != -1) )  
  100.                 {
  101.                     TCHAR Start[16], Size[16];
  102.  
  103.                     m_Regions.GetItemText(pInfo->iItem, 2, Start, sizeof(Start));
  104.                     m_Regions.GetItemText(pInfo->iItem, 3, Size,  sizeof(Size));
  105.  
  106.                     unsigned nStart, nSize;
  107.  
  108.                     sscanf(Start, "%x", & nStart);
  109.                     sscanf(Size,  "%x", & nSize);
  110.  
  111.                     m_snapshot.ShowDetail(m_hInst, nStart, nSize);
  112.                     return TRUE;
  113.                 }
  114.             }
  115.             break;
  116.  
  117.         case WM_DESTROY:
  118.             m_Regions.DeleteAll();
  119.             return TRUE;
  120.     }
  121.     
  122.     return FALSE;
  123. }
  124.  
  125.