Make duplicate script compatible with Python 3
[wdl/wdl-ol.git] / IPlugExamples / IPlugHostDetect / app_wrapper / app_dialog.cpp
blob306c2f51e27606ece8e5ef99ef48d5b23e763d34
1 #include "app_main.h"
3 #ifdef OS_WIN
4 #include "asio.h"
5 #endif
7 const int kNumIOVSOptions = 9;
8 const int kNumSIGVSOptions = 7;
10 const std::string kIOVSOptions[kNumIOVSOptions] = {"32", "64", "128", "256", "512", "1024", "2048", "4096", "8192" };
11 const std::string kSIGVSOptions[kNumSIGVSOptions] = {"16", "32", "64", "128", "256", "512", "1024" };
13 // check the input and output devices, find matching srs
14 void PopulateSampleRateList(HWND hwndDlg, RtAudio::DeviceInfo* inputDevInfo, RtAudio::DeviceInfo* outputDevInfo)
16 char buf[20];
18 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_SR,CB_RESETCONTENT,0,0);
20 std::vector<int> matchedSRs;
22 for (int i=0; i<inputDevInfo->sampleRates.size(); i++)
24 for (int j=0; j<outputDevInfo->sampleRates.size(); j++)
26 if(inputDevInfo->sampleRates[i] == outputDevInfo->sampleRates[j])
27 matchedSRs.push_back(inputDevInfo->sampleRates[i]);
31 for (int k=0; k<matchedSRs.size(); k++)
33 wsprintf(buf,"%i",matchedSRs[k]);
34 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_SR,CB_ADDSTRING,0,(LPARAM)buf);
37 LRESULT sridx = SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_SR, CB_FINDSTRINGEXACT, -1, (LPARAM)gState->mAudioSR);
38 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_SR,CB_SETCURSEL, sridx, 0);
41 void PopulateAudioInputList(HWND hwndDlg, RtAudio::DeviceInfo* info)
43 char buf[20];
45 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_L,CB_RESETCONTENT,0,0);
46 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_R,CB_RESETCONTENT,0,0);
48 int i;
50 for (i=0; i<info->inputChannels -1; i++)
52 // for (int i=0; i<info.inputChannels; i++) {
53 wsprintf(buf,"%i",i+1);
54 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_L,CB_ADDSTRING,0,(LPARAM)buf);
55 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_R,CB_ADDSTRING,0,(LPARAM)buf);
58 // TEMP
59 wsprintf(buf,"%i",i+1);
60 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_R,CB_ADDSTRING,0,(LPARAM)buf);
62 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_L,CB_SETCURSEL, gState->mAudioInChanL - 1, 0);
63 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_R,CB_SETCURSEL, gState->mAudioInChanR - 1, 0);
66 void PopulateAudioOutputList(HWND hwndDlg, RtAudio::DeviceInfo* info)
68 char buf[20];
70 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_L,CB_RESETCONTENT,0,0);
71 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_R,CB_RESETCONTENT,0,0);
73 int i;
75 // for (int i=0; i<info.outputChannels; i++) {
76 for (i=0; i<info->outputChannels -1; i++)
79 wsprintf(buf,"%i",i+1);
80 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_L,CB_ADDSTRING,0,(LPARAM)buf);
81 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_R,CB_ADDSTRING,0,(LPARAM)buf);
84 // TEMP
85 wsprintf(buf,"%i",i+1);
86 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_R,CB_ADDSTRING,0,(LPARAM)buf);
88 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_L,CB_SETCURSEL, gState->mAudioOutChanL - 1, 0);
89 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_R,CB_SETCURSEL, gState->mAudioOutChanR - 1, 0);
92 // This has to get called after any change to audio driver/in dev/out dev
93 void PopulateDriverSpecificControls(HWND hwndDlg)
95 #ifdef OS_WIN
96 int driverType = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
97 if(driverType) //ASIO
99 ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_AUDIO_IN_DEV), FALSE);
100 Button_Enable(GetDlgItem(hwndDlg, IDC_BUTTON_ASIO), TRUE);
102 else
104 ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_AUDIO_IN_DEV), TRUE);
105 Button_Enable(GetDlgItem(hwndDlg, IDC_BUTTON_ASIO), FALSE);
107 #endif
109 int indevidx = 0;
110 int outdevidx = 0;
112 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_RESETCONTENT,0,0);
113 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_RESETCONTENT,0,0);
115 for (int i = 0; i<gAudioInputDevs.size(); i++)
117 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_ADDSTRING,0,(LPARAM)GetAudioDeviceName(gAudioInputDevs[i]).c_str());
119 if(!strcmp(GetAudioDeviceName(gAudioInputDevs[i]).c_str(), gState->mAudioInDev))
120 indevidx = i;
123 for (int i = 0; i<gAudioOutputDevs.size(); i++)
125 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_ADDSTRING,0,(LPARAM)GetAudioDeviceName(gAudioOutputDevs[i]).c_str());
127 if(!strcmp(GetAudioDeviceName(gAudioOutputDevs[i]).c_str(), gState->mAudioOutDev))
128 outdevidx = i;
131 #ifdef OS_WIN
132 if(driverType)
133 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_SETCURSEL, outdevidx, 0);
134 else
135 #endif
136 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_SETCURSEL, indevidx, 0);
138 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_SETCURSEL, outdevidx, 0);
140 RtAudio::DeviceInfo inputDevInfo = gDAC->getDeviceInfo(gAudioInputDevs[indevidx]);
141 RtAudio::DeviceInfo outputDevInfo = gDAC->getDeviceInfo(gAudioOutputDevs[outdevidx]);
143 PopulateAudioInputList(hwndDlg, &inputDevInfo);
144 PopulateAudioOutputList(hwndDlg, &outputDevInfo);
145 PopulateSampleRateList(hwndDlg, &inputDevInfo, &outputDevInfo);
148 void PopulateAudioDialogs(HWND hwndDlg)
150 PopulateDriverSpecificControls(hwndDlg);
152 if (gState->mAudioInIsMono)
154 SendDlgItemMessage(hwndDlg,IDC_CB_MONO_INPUT,BM_SETCHECK, BST_CHECKED,0);
156 else
158 SendDlgItemMessage(hwndDlg,IDC_CB_MONO_INPUT,BM_SETCHECK, BST_UNCHECKED,0);
161 //Populate IOVS combobox
162 for (int i = 0; i< kNumIOVSOptions; i++)
164 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IOVS,CB_ADDSTRING,0,(LPARAM)kIOVSOptions[i].c_str());
167 LRESULT iovsidx = SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IOVS, CB_FINDSTRINGEXACT, -1, (LPARAM)gState->mAudioIOVS);
168 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IOVS, CB_SETCURSEL, iovsidx, 0);
170 //Populate SIGVS combobox
171 for (int i = 0; i< kNumSIGVSOptions; i++)
173 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_SIGVS,CB_ADDSTRING,0,(LPARAM)kSIGVSOptions[i].c_str());
176 LRESULT sigvsidx = SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_SIGVS, CB_FINDSTRINGEXACT, -1, (LPARAM)gState->mAudioSigVS);
177 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_SIGVS, CB_SETCURSEL, sigvsidx, 0);
180 bool PopulateMidiDialogs(HWND hwndDlg)
182 if ( !gMidiIn || !gMidiOut )
183 return false;
184 else
186 for (int i=0; i<gMIDIInputDevNames.size(); i++ )
188 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_IN_DEV,CB_ADDSTRING,0,(LPARAM)gMIDIInputDevNames[i].c_str());
191 LRESULT indevidx = SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_IN_DEV,CB_FINDSTRINGEXACT, -1, (LPARAM)gState->mMidiInDev);
193 // if the midi port name wasn't found update the ini file, and set to off
194 if(indevidx == -1)
196 strcpy(gState->mMidiInDev, "off");
197 UpdateINI();
198 indevidx = 0;
201 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_IN_DEV,CB_SETCURSEL, indevidx, 0);
203 for (int i=0; i<gMIDIOutputDevNames.size(); i++ )
205 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_OUT_DEV,CB_ADDSTRING,0,(LPARAM)gMIDIOutputDevNames[i].c_str());
208 LRESULT outdevidx = SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_OUT_DEV,CB_FINDSTRINGEXACT, -1, (LPARAM)gState->mMidiOutDev);
210 // if the midi port name wasn't found update the ini file, and set to off
211 if(outdevidx == -1)
213 strcpy(gState->mMidiOutDev, "off");
214 UpdateINI();
215 outdevidx = 0;
218 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_OUT_DEV,CB_SETCURSEL, outdevidx, 0);
220 // Populate MIDI channel dialogs
222 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_IN_CHAN,CB_ADDSTRING,0,(LPARAM)"all");
223 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_OUT_CHAN,CB_ADDSTRING,0,(LPARAM)"all");
225 char buf[20];
227 for (int i=0; i<16; i++)
229 wsprintf(buf,"%i",i+1);
230 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_IN_CHAN,CB_ADDSTRING,0,(LPARAM)buf);
231 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_OUT_CHAN,CB_ADDSTRING,0,(LPARAM)buf);
234 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_IN_CHAN,CB_SETCURSEL, (LPARAM)gState->mMidiInChan, 0);
235 SendDlgItemMessage(hwndDlg,IDC_COMBO_MIDI_OUT_CHAN,CB_SETCURSEL, (LPARAM)gState->mMidiOutChan, 0);
237 return true;
241 #ifdef OS_WIN
242 void PopulatePreferencesDialog(HWND hwndDlg)
244 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_DRIVER,CB_ADDSTRING,0,(LPARAM)"DirectSound");
245 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_DRIVER,CB_ADDSTRING,0,(LPARAM)"ASIO");
246 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_DRIVER,CB_SETCURSEL, gState->mAudioDriverType, 0);
248 PopulateAudioDialogs(hwndDlg);
249 PopulateMidiDialogs(hwndDlg);
252 #elif defined OS_OSX
253 void PopulatePreferencesDialog(HWND hwndDlg)
255 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_DRIVER,CB_ADDSTRING,0,(LPARAM)"CoreAudio");
256 //SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_DRIVER,CB_ADDSTRING,0,(LPARAM)"Jack");
257 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_DRIVER,CB_SETCURSEL, gState->mAudioDriverType, 0);
259 PopulateAudioDialogs(hwndDlg);
260 PopulateMidiDialogs(hwndDlg);
262 #endif
264 WDL_DLGRET PreferencesDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
266 int v = 0;
267 switch(uMsg)
269 case WM_INITDIALOG:
271 PopulatePreferencesDialog(hwndDlg);
272 memcpy(gTempState, gState, sizeof(AppState)); // copy state to temp state
274 return TRUE;
276 case WM_COMMAND:
277 switch (LOWORD(wParam))
279 case IDOK:
280 if(memcmp(gActiveState, gState, sizeof(AppState)) != 0) // if state is different try to change audio
282 TryToChangeAudio();
284 EndDialog(hwndDlg, IDOK); // INI file will be changed see MainDialogProc
285 break;
286 case IDAPPLY:
287 TryToChangeAudio();
288 break;
289 case IDCANCEL:
290 EndDialog(hwndDlg, IDCANCEL);
292 // if state has been changed reset to previous state, INI file won't be changed
293 if (!AudioSettingsInStateAreEqual(gState, gTempState)
294 || !MIDISettingsInStateAreEqual(gState, gTempState))
296 memcpy(gState, gTempState, sizeof(AppState));
298 TryToChangeAudioDriverType();
299 ProbeAudioIO();
300 TryToChangeAudio();
303 break;
305 case IDC_COMBO_AUDIO_DRIVER:
306 if (HIWORD(wParam) == CBN_SELCHANGE)
309 v = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
311 if(v != gState->mAudioDriverType)
313 gState->mAudioDriverType = v;
315 TryToChangeAudioDriverType();
316 ProbeAudioIO();
318 strcpy(gState->mAudioInDev,GetAudioDeviceName(gAudioInputDevs[0]).c_str());
319 strcpy(gState->mAudioOutDev,GetAudioDeviceName(gAudioOutputDevs[0]).c_str());
321 // Reset IO
322 gState->mAudioOutChanL = 1;
323 gState->mAudioOutChanR = 2;
325 PopulateAudioDialogs(hwndDlg);
328 break;
330 case IDC_COMBO_AUDIO_IN_DEV:
331 if (HIWORD(wParam) == CBN_SELCHANGE)
333 int idx = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IN_DEV, CB_GETCURSEL, 0, 0);
334 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IN_DEV, CB_GETLBTEXT, idx, (LPARAM) gState->mAudioInDev);
336 // Reset IO
337 gState->mAudioInChanL = 1;
338 gState->mAudioInChanR = 2;
340 PopulateDriverSpecificControls(hwndDlg);
342 break;
344 case IDC_COMBO_AUDIO_OUT_DEV:
345 if (HIWORD(wParam) == CBN_SELCHANGE)
347 int idx = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_OUT_DEV, CB_GETCURSEL, 0, 0);
348 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_OUT_DEV, CB_GETLBTEXT, idx, (LPARAM) gState->mAudioOutDev);
350 // Reset IO
351 gState->mAudioOutChanL = 1;
352 gState->mAudioOutChanR = 2;
354 PopulateDriverSpecificControls(hwndDlg);
356 break;
358 case IDC_COMBO_AUDIO_IN_L:
359 if (HIWORD(wParam) == CBN_SELCHANGE)
361 gState->mAudioInChanL = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IN_L, CB_GETCURSEL, 0, 0) + 1;
363 //TEMP
364 gState->mAudioInChanR = gState->mAudioInChanL + 1;
365 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_R,CB_SETCURSEL, gState->mAudioInChanR - 1, 0);
368 break;
370 case IDC_COMBO_AUDIO_IN_R:
371 if (HIWORD(wParam) == CBN_SELCHANGE)
372 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_R,CB_SETCURSEL, gState->mAudioInChanR - 1, 0); // TEMP
373 // gState->mAudioInChanR = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IN_R, CB_GETCURSEL, 0, 0);
374 break;
376 case IDC_COMBO_AUDIO_OUT_L:
377 if (HIWORD(wParam) == CBN_SELCHANGE)
379 gState->mAudioOutChanL = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_OUT_L, CB_GETCURSEL, 0, 0) + 1;
381 //TEMP
382 gState->mAudioOutChanR = gState->mAudioOutChanL + 1;
383 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_R,CB_SETCURSEL, gState->mAudioOutChanR - 1, 0);
386 break;
388 case IDC_COMBO_AUDIO_OUT_R:
389 if (HIWORD(wParam) == CBN_SELCHANGE)
390 SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_R,CB_SETCURSEL, gState->mAudioOutChanR - 1, 0); // TEMP
391 // gState->mAudioOutChanR = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_OUT_R, CB_GETCURSEL, 0, 0);
392 break;
394 case IDC_CB_MONO_INPUT:
395 if (SendDlgItemMessage(hwndDlg,IDC_CB_MONO_INPUT, BM_GETCHECK, 0, 0) == BST_CHECKED)
396 gState->mAudioInIsMono = 1;
397 else
398 gState->mAudioInIsMono = 0;
399 break;
401 case IDC_COMBO_AUDIO_IOVS: // follow through
402 case IDC_COMBO_AUDIO_SIGVS:
403 //TODO: FIX
404 if (HIWORD(wParam) == CBN_SELCHANGE)
406 int iovsidx = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IOVS, CB_GETCURSEL, 0, 0);
407 int sigvsidx = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_SIGVS, CB_GETCURSEL, 0, 0);
409 if (atoi(kIOVSOptions[iovsidx].c_str()) < atoi(kSIGVSOptions[sigvsidx].c_str())) // if iovs < sigvs
411 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IOVS, CB_GETLBTEXT, iovsidx, (LPARAM) gState->mAudioIOVS);
412 strcpy(gState->mAudioSigVS, kSIGVSOptions[0].c_str()); // set sigvs to minimum
413 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_SIGVS, CB_SETCURSEL, -1, 0);
415 else
417 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_IOVS, CB_GETLBTEXT, iovsidx, (LPARAM) gState->mAudioIOVS);
418 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_SIGVS, CB_GETLBTEXT, sigvsidx, (LPARAM) gState->mAudioSigVS);
421 break;
422 case IDC_COMBO_AUDIO_SR:
423 if (HIWORD(wParam) == CBN_SELCHANGE)
425 int idx = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_SR, CB_GETCURSEL, 0, 0);
426 SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_SR, CB_GETLBTEXT, idx, (LPARAM) gState->mAudioSR);
428 break;
430 case IDC_BUTTON_ASIO:
431 if (HIWORD(wParam) == BN_CLICKED)
432 #ifdef OS_OSX
433 system("open \"/Applications/Utilities/Audio MIDI Setup.app\"");
434 #elif defined OS_WIN
435 if( gState->mAudioDriverType == DAC_ASIO && gDAC->isStreamRunning()) // TODO: still not right
436 ASIOControlPanel();
437 #endif
438 break;
440 case IDC_COMBO_MIDI_IN_DEV:
441 if (HIWORD(wParam) == CBN_SELCHANGE)
443 int idx = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_MIDI_IN_DEV, CB_GETCURSEL, 0, 0);
444 SendDlgItemMessage(hwndDlg, IDC_COMBO_MIDI_IN_DEV, CB_GETLBTEXT, idx, (LPARAM) gState->mMidiInDev);
445 ChooseMidiInput( gState->mMidiInDev );
447 break;
449 case IDC_COMBO_MIDI_OUT_DEV:
450 if (HIWORD(wParam) == CBN_SELCHANGE)
452 int idx = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_MIDI_OUT_DEV, CB_GETCURSEL, 0, 0);
453 SendDlgItemMessage(hwndDlg, IDC_COMBO_MIDI_OUT_DEV, CB_GETLBTEXT, idx, (LPARAM) gState->mMidiOutDev);
454 ChooseMidiOutput( gState->mMidiOutDev );
456 break;
458 case IDC_COMBO_MIDI_IN_CHAN:
459 if (HIWORD(wParam) == CBN_SELCHANGE)
460 gState->mMidiInChan = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_MIDI_IN_CHAN, CB_GETCURSEL, 0, 0);
461 break;
463 case IDC_COMBO_MIDI_OUT_CHAN:
464 if (HIWORD(wParam) == CBN_SELCHANGE)
465 gState->mMidiOutChan = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_MIDI_OUT_CHAN, CB_GETCURSEL, 0, 0);
466 break;
468 default:
469 break;
471 break;
472 default:
473 return FALSE;
475 return TRUE;
478 #ifdef _WIN32
479 void ClientResize(HWND hWnd, int nWidth, int nHeight)
481 RECT rcClient, rcWindow;
482 POINT ptDiff;
483 int screenwidth, screenheight;
484 int x, y;
486 screenwidth = GetSystemMetrics(SM_CXSCREEN);
487 screenheight = GetSystemMetrics(SM_CYSCREEN);
488 x = (screenwidth / 2) - (nWidth/2);
489 y = (screenheight / 2) - (nHeight/2);
491 GetClientRect(hWnd, &rcClient);
492 GetWindowRect(hWnd, &rcWindow);
493 ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
494 ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
495 MoveWindow(hWnd, x, y, nWidth + ptDiff.x, nHeight + ptDiff.y, FALSE);
497 #endif
499 WDL_DLGRET MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
501 switch (uMsg)
503 case WM_INITDIALOG:
505 gHWND=hwndDlg;
507 if(!AttachGUI()) printf("couldn't attach gui\n");
509 #ifdef _WIN32
510 ClientResize(hwndDlg, GUI_WIDTH, GUI_HEIGHT);
511 //SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1)));
512 //SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1)));
514 #else // OSX
515 CenterWindow(hwndDlg);
516 #endif
518 ShowWindow(hwndDlg,SW_SHOW);
519 return 1;
520 case WM_DESTROY:
521 gHWND=NULL;
523 #ifdef _WIN32
524 PostQuitMessage(0);
525 #else
526 SWELL_PostQuitMessage(hwndDlg);
527 #endif
529 return 0;
530 case WM_CLOSE:
531 DestroyWindow(hwndDlg);
532 return 0;
533 // case WM_GETDLGCODE: {
534 // LPARAM lres;
535 // lres = CallWindowProc(/*TODO GET PROC */, hWnd, WM_GETDLGCODE, wParam, lParam);
536 // if (lParam && ((MSG*)lParam)->message == WM_KEYDOWN && wParam == VK_LEFT) {
537 // lres |= DLGC_WANTMESSAGE;
538 // }
539 // return lres;
540 // }
541 case WM_COMMAND:
542 switch (LOWORD(wParam))
544 case ID_QUIT:
545 DestroyWindow(hwndDlg);
546 return 0;
547 case ID_ABOUT:
548 if(!gPluginInstance->HostRequestingAboutBox())
550 char version[50];
551 sprintf(version, BUNDLE_MFR"\nBuilt on " __DATE__);
552 MessageBox(hwndDlg,version, BUNDLE_NAME, MB_OK);
554 return 0;
555 case ID_PREFERENCES:
557 INT_PTR ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_PREF), hwndDlg, PreferencesDlgProc);
559 if(ret == IDOK)
561 UpdateINI();
564 return 0;
567 return 0;
569 return 0;