Config.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <windows.h>
  2. #include <mmreg.h>
  3. #include <msacm.h>
  4. #include "Config.h"
  5. #include "resource.h"
  6. #include <strsafe.h>
  7. static void ACM_gettext(HWND hwndDlg, char* tx)
  8. {
  9. ConfigWnd *wc = (ConfigWnd *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  10. ACMFORMATTAGDETAILSA aftd;
  11. ZeroMemory(&aftd, sizeof(aftd));
  12. aftd.cbStruct = sizeof(aftd);
  13. aftd.dwFormatTag = wc->cfg.convert_wfx.wfx.wFormatTag;
  14. if (!acmFormatTagDetailsA(0, &aftd, ACM_FORMATTAGDETAILSF_FORMATTAG))
  15. {
  16. char* p = aftd.szFormatTag;
  17. while (p && *p) *(tx++) = *(p++);
  18. *(tx++) = 13;
  19. *(tx++) = 10;
  20. }
  21. ACMFORMATDETAILSA afd;
  22. ZeroMemory(&afd, sizeof(afd));
  23. afd.cbStruct = sizeof(afd);
  24. afd.dwFormatTag = wc->cfg.convert_wfx.wfx.wFormatTag;
  25. afd.pwfx = &wc->cfg.convert_wfx.wfx;
  26. afd.cbwfx = sizeof(wc->cfg.convert_wfx);
  27. if (!acmFormatDetailsA(0, &afd, ACM_FORMATDETAILSF_FORMAT))
  28. {
  29. char* p = afd.szFormat;
  30. while (p && *p) *(tx++) = *(p++);
  31. }
  32. *tx = 0;
  33. }
  34. static void ACM_choose(HWND hwndDlg, bool pcm)
  35. {
  36. ConfigWnd *wc = (ConfigWnd *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  37. ACMFORMATCHOOSE afc;
  38. memset(&afc, 0, sizeof(afc));
  39. afc.cbStruct = sizeof(afc);
  40. afc.fdwStyle = ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT;
  41. afc.pwfx = &wc->cfg.convert_wfx.wfx;
  42. afc.cbwfx = sizeof(wc->cfg.convert_wfx);
  43. afc.hwndOwner = hwndDlg;
  44. if (!acmFormatChoose(&afc))
  45. {
  46. {
  47. char tmp[512];
  48. StringCchPrintfA(tmp, 512,"%s\x0d\x0a%s", afc.szFormatTag, afc.szFormat);
  49. SetDlgItemTextA(hwndDlg, IDC_FORMAT_DESCRIPTION, tmp);
  50. StringCchPrintfA(tmp, 512,"%d", wc->cfg.convert_wfx.wfx.cbSize);
  51. WritePrivateProfileStringA("enc_wav","fmtsize", tmp, wc->configfile);
  52. WritePrivateProfileStructA("enc_wav", "fmt", &wc->cfg.convert_wfx, sizeof(wc->cfg.convert_wfx.wfx) + wc->cfg.convert_wfx.wfx.cbSize, wc->configfile);
  53. }
  54. }
  55. }
  56. INT_PTR WINAPI DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  57. {
  58. ConfigWnd *wc = (ConfigWnd *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  59. switch (uMsg)
  60. {
  61. case WM_INITDIALOG:
  62. {
  63. if (!lParam) // this should NEVER happen
  64. return 0;
  65. SetWindowLongPtr(hwndDlg,GWLP_USERDATA,(LONG)lParam);
  66. wc=(ConfigWnd*)lParam;
  67. char tmp[256];
  68. ACM_gettext(hwndDlg, tmp);
  69. SetDlgItemTextA(hwndDlg, IDC_FORMAT_DESCRIPTION, tmp);
  70. CheckDlgButton(hwndDlg, IDC_HEADER, wc->cfg.header);
  71. CheckDlgButton(hwndDlg, IDC_DO_CONVERT, wc->cfg.convert);
  72. SetDlgItemTextA(hwndDlg, IDC_EXTENSION, wc->cfg.wav_ext);
  73. SendDlgItemMessage(hwndDlg, IDC_EXTENSION, EM_SETLIMITTEXT, 4, 0);
  74. }
  75. break;
  76. case WM_COMMAND:
  77. switch (LOWORD(wParam))
  78. {
  79. case IDC_CHOOSE_FORMAT:
  80. ACM_choose(hwndDlg, 0);
  81. break;
  82. case IDC_HEADER:
  83. wc->cfg.header = !!IsDlgButtonChecked(hwndDlg, IDC_HEADER);
  84. WritePrivateProfileStringA("enc_wav", "header", wc->cfg.header?"1":"0", wc->configfile);
  85. break;
  86. case IDC_DO_CONVERT:
  87. wc->cfg.convert = !!IsDlgButtonChecked(hwndDlg, IDC_DO_CONVERT);
  88. WritePrivateProfileStringA("enc_wav", "convert", wc->cfg.convert?"1":"0", wc->configfile);
  89. break;
  90. case IDC_EXTENSION:
  91. if (HIWORD(wParam) == EN_CHANGE)
  92. {
  93. GetDlgItemTextA(hwndDlg, IDC_EXTENSION, wc->cfg.wav_ext, sizeof(wc->cfg.wav_ext));
  94. WritePrivateProfileStringA("enc_wav", "ext", wc->cfg.wav_ext, wc->configfile);
  95. }
  96. break;
  97. }
  98. break;
  99. }
  100. return 0;
  101. }