deviceIconEditor.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #include "main.h"
  2. #include "./deviceIconEditor.h"
  3. #define DEVICEICONEDITOR_PROP L"NullsoftDevicesIconEditorProp"
  4. static INT_PTR
  5. DeviceIconEditor_DialogProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam);
  6. INT_PTR
  7. DeviceIconEditor_Show(HWND parentWindow, DeviceIconInfo *iconInfo)
  8. {
  9. if (NULL == iconInfo)
  10. return -1;
  11. return WASABI_API_DIALOGBOXPARAMW((INT_PTR)IDD_ICON_EDITOR, parentWindow,
  12. DeviceIconEditor_DialogProc, (LPARAM)iconInfo);
  13. }
  14. static void
  15. DeviceIconEditor_UpdateInfo(HWND hwnd)
  16. {
  17. DeviceIconInfo *iconInfo;
  18. HWND controlWindow;
  19. wchar_t *string;
  20. iconInfo = (DeviceIconInfo*)GetProp(hwnd, DEVICEICONEDITOR_PROP);
  21. if (NULL == iconInfo)
  22. return;
  23. controlWindow = GetDlgItem(hwnd, IDC_EDIT_PATH);
  24. if (NULL != controlWindow)
  25. {
  26. String_Free(iconInfo->path);
  27. iconInfo->path = String_FromWindow(controlWindow);
  28. }
  29. controlWindow = GetDlgItem(hwnd, IDC_EDIT_WIDTH);
  30. if (NULL != controlWindow)
  31. {
  32. string = String_FromWindow(controlWindow);
  33. if (NULL == string ||
  34. FALSE == StrToIntEx(string, STIF_DEFAULT, &iconInfo->width))
  35. {
  36. iconInfo->width = 0;
  37. }
  38. String_Free(string);
  39. }
  40. controlWindow = GetDlgItem(hwnd, IDC_EDIT_HEIGHT);
  41. if (NULL != controlWindow)
  42. {
  43. string = String_FromWindow(controlWindow);
  44. if (NULL == string ||
  45. FALSE == StrToIntEx(string, STIF_DEFAULT, &iconInfo->height))
  46. {
  47. iconInfo->height = 0;
  48. }
  49. String_Free(string);
  50. }
  51. }
  52. static INT_PTR
  53. DeviceIconEditor_OnInitDialog(HWND hwnd, HWND focusWindow, LPARAM param)
  54. {
  55. DeviceIconInfo *iconInfo;
  56. HWND controlWindow;
  57. iconInfo = (DeviceIconInfo*)param;
  58. SetProp(hwnd, DEVICEICONEDITOR_PROP, iconInfo);
  59. if (NULL != iconInfo)
  60. {
  61. wchar_t buffer[64];
  62. controlWindow = GetDlgItem(hwnd, IDC_EDIT_PATH);
  63. if (NULL != controlWindow)
  64. SetWindowText(controlWindow, iconInfo->path);
  65. controlWindow = GetDlgItem(hwnd, IDC_EDIT_WIDTH);
  66. if (NULL != controlWindow)
  67. {
  68. _itow_s(iconInfo->width, buffer, 10);
  69. SetWindowText(controlWindow, buffer);
  70. }
  71. controlWindow = GetDlgItem(hwnd, IDC_EDIT_HEIGHT);
  72. if (NULL != controlWindow)
  73. {
  74. _itow_s(iconInfo->height, buffer, 10);
  75. SetWindowText(controlWindow, buffer);
  76. }
  77. }
  78. return 0;
  79. }
  80. static void
  81. DeviceIconEditor_DisplayFileOpen(HWND hwnd)
  82. {
  83. wchar_t buffer[MAX_PATH * 2];
  84. OPENFILENAME ofn;
  85. HWND controlWindow;
  86. buffer[0] = L'\0';
  87. ZeroMemory(&ofn, sizeof(ofn));
  88. ofn.lStructSize = sizeof(ofn);
  89. ofn.hwndOwner = hwnd;
  90. ofn.lpstrFilter = L"Portable Network Graphics\0" L"*.png\0"
  91. L"\0";
  92. ofn.lpstrFile = buffer;
  93. ofn.nMaxFile = ARRAYSIZE(buffer);
  94. ofn.lpstrTitle = L"Load Icon";
  95. ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
  96. if (FALSE == GetOpenFileName(&ofn))
  97. return;
  98. controlWindow = GetDlgItem(hwnd, IDC_EDIT_PATH);
  99. if (NULL != controlWindow)
  100. SetWindowText(controlWindow, buffer);
  101. }
  102. static void
  103. DeviceIconEditor_OnDestroy(HWND hwnd)
  104. {
  105. RemoveProp(hwnd, DEVICEICONEDITOR_PROP);
  106. }
  107. static void
  108. DeviceIconEditor_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND controlWindow)
  109. {
  110. switch(commandId)
  111. {
  112. case IDOK:
  113. switch(eventId)
  114. {
  115. case BN_CLICKED:
  116. DeviceIconEditor_UpdateInfo(hwnd);
  117. EndDialog(hwnd, IDOK);
  118. break;
  119. }
  120. break;
  121. case IDCANCEL:
  122. switch(eventId)
  123. {
  124. case BN_CLICKED:
  125. EndDialog(hwnd, IDCANCEL);
  126. break;
  127. }
  128. break;
  129. case IDC_BUTTON_BROWSE:
  130. switch(eventId)
  131. {
  132. case BN_CLICKED:
  133. DeviceIconEditor_DisplayFileOpen(hwnd);
  134. break;
  135. }
  136. break;
  137. }
  138. }
  139. static INT_PTR
  140. DeviceIconEditor_DialogProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  141. {
  142. switch(uMsg)
  143. {
  144. case WM_INITDIALOG: return DeviceIconEditor_OnInitDialog(hwnd, (HWND)wParam, lParam);
  145. case WM_DESTROY: DeviceIconEditor_OnDestroy(hwnd); return TRUE;
  146. case WM_COMMAND: DeviceIconEditor_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
  147. }
  148. return 0;
  149. }