Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.7 KiB

  1. #include "ulib.hxx"
  2. #include "partedit.hxx"
  3. extern "C" {
  4. #include <stdio.h>
  5. }
  6. BOOLEAN
  7. PARTITION_TABLE_EDIT::Initialize(
  8. IN HWND WindowHandle,
  9. IN INT ClientHeight,
  10. IN INT ClientWidth,
  11. IN PLOG_IO_DP_DRIVE Drive
  12. )
  13. {
  14. TEXTMETRIC textmetric;
  15. HDC hdc;
  16. hdc = GetDC(WindowHandle);
  17. if (hdc == NULL)
  18. return FALSE;
  19. GetTextMetrics(hdc, &textmetric);
  20. ReleaseDC(WindowHandle, hdc);
  21. VERTICAL_TEXT_SCROLL::Initialize(
  22. WindowHandle,
  23. 0,
  24. ClientHeight,
  25. ClientWidth,
  26. textmetric.tmExternalLeading + textmetric.tmHeight,
  27. textmetric.tmMaxCharWidth);
  28. return TRUE;
  29. }
  30. VOID
  31. PARTITION_TABLE_EDIT::SetBuf(
  32. IN HWND WindowHandle,
  33. IN OUT PVOID Buffer,
  34. IN ULONG Size
  35. )
  36. {
  37. _buffer = Buffer;
  38. _size = Size;
  39. SetScrollPos(WindowHandle, SB_VERT, 0, FALSE);
  40. }
  41. VOID
  42. PARTITION_TABLE_EDIT::Paint(
  43. IN HDC DeviceContext,
  44. IN RECT InvalidRect,
  45. IN HWND WindowHandle
  46. )
  47. {
  48. PARTITION_TABLE_ENTRY Entry;
  49. PPARTITION_TABLE_ENTRY p;
  50. TEXTMETRIC textmetric;
  51. INT ch, CurrentLine;
  52. TCHAR buf[1024];
  53. ULONG i, Checksum, *pul;
  54. SelectObject(DeviceContext, GetStockObject(ANSI_FIXED_FONT));
  55. if (!_buffer || _size < 512) {
  56. return;
  57. }
  58. p = (PPARTITION_TABLE_ENTRY)((PBYTE)_buffer+0x1be);
  59. GetTextMetrics(DeviceContext, &textmetric);
  60. ch = textmetric.tmExternalLeading + textmetric.tmHeight;
  61. CurrentLine = 0;
  62. swprintf( buf, TEXT("Disk Signature: 0x%x"), *((PULONG)_buffer + 0x6E) );
  63. WriteLine( DeviceContext, CurrentLine++, buf );
  64. // Compute the sector checksum.
  65. //
  66. Checksum = 0;
  67. for( i = 0, pul = (PULONG)_buffer; i < 0x80; i++, pul++ ) {
  68. Checksum += *pul;
  69. }
  70. swprintf( buf, TEXT("Sector Checksum: 0x%x"), Checksum );
  71. WriteLine( DeviceContext, CurrentLine++, buf );
  72. swprintf( buf, TEXT("") );
  73. WriteLine( DeviceContext, CurrentLine++, buf );
  74. for( i = 0; i < 4; i++ ) {
  75. memcpy( &Entry, p, sizeof(PARTITION_TABLE_ENTRY) );
  76. swprintf( buf, TEXT("Entry %d"), i );
  77. WriteLine( DeviceContext, CurrentLine++, buf );
  78. swprintf( buf, TEXT(" Boot Indicator: 0x%x"), Entry.BootIndicator );
  79. WriteLine( DeviceContext, CurrentLine++, buf );
  80. swprintf( buf, TEXT(" Beginning Head: 0x%x"), Entry.BeginningHead );
  81. WriteLine( DeviceContext, CurrentLine++, buf );
  82. swprintf( buf, TEXT(" Beginning Sector: 0x%x"), Entry.BeginningSector );
  83. WriteLine( DeviceContext, CurrentLine++, buf );
  84. swprintf( buf, TEXT(" Beginning Cylinder: 0x%x"), Entry.BeginningCylinder );
  85. WriteLine( DeviceContext, CurrentLine++, buf );
  86. swprintf( buf, TEXT(" System ID: 0x%x"), Entry.SystemID );
  87. WriteLine( DeviceContext, CurrentLine++, buf );
  88. swprintf( buf, TEXT(" Ending Head: 0x%x"), Entry.EndingHead );
  89. WriteLine( DeviceContext, CurrentLine++, buf );
  90. swprintf( buf, TEXT(" Ending Sector: 0x%x"), Entry.EndingSector );
  91. WriteLine( DeviceContext, CurrentLine++, buf );
  92. swprintf( buf, TEXT(" Ending Cylinder: 0x%x"), Entry.EndingCylinder );
  93. WriteLine( DeviceContext, CurrentLine++, buf );
  94. swprintf( buf, TEXT(" Starting Sector: 0x%x"), Entry.StartingSector );
  95. WriteLine( DeviceContext, CurrentLine++, buf );
  96. swprintf( buf, TEXT(" Sectors: 0x%x"), Entry.Sectors );
  97. WriteLine( DeviceContext, CurrentLine++, buf );
  98. swprintf( buf, TEXT("") );
  99. WriteLine( DeviceContext, CurrentLine++, buf );
  100. p++;
  101. }
  102. SetRange(WindowHandle, CurrentLine - 1);
  103. }