Skip to content

Commit

Permalink
Added saving/restoring of window positions of VST editor dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Falcosoft committed Sep 11, 2023
1 parent 4bd71b8 commit 5b52b99
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
17 changes: 10 additions & 7 deletions Help/Readme.html
Expand Up @@ -22,9 +22,7 @@ <h2>VST MIDI Driver (Falcomod) </h2>
<br>
<br> The change log and new releases can also be found on GitHub:
<br>
<a href="https://github.com/Falcosoft/vstdriver/releases" target="_blank">https://github.com/Falcosoft/vstdriver/releases</a>
<br>
</p>
<a href="https://github.com/Falcosoft/vstdriver/releases" target="_blank">https://github.com/Falcosoft/vstdriver/releases</a></p>
<p>&nbsp;</p>
<p>If you would like to support the development of VST MIDI Driver (Falcomod) you can donate through PayPal.</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="get" target="_blank">
Expand Down Expand Up @@ -221,15 +219,20 @@ <h2>VST MIDI Driver (Falcomod) </h2>
<img src="play.png" style="position: absolute; top: 144px; left: 204px; border:0px;" alt="FSMP + VST Midi driver - 32 channel KONAMI Midi files">
</a>
</div>
</p>

<p>&nbsp;</p>
<p>Have fun.</p>
</p>
<p><br>
Have fun.</p>
<p>Zolt&aacute;n Bacsk&oacute; (Falco)</p>
<p><br>
<a href="https://falcosoft.hu" target="_blank">https://falcosoft.hu/</a>
</p>
<p>zbacsko@falcosoft.hu</p>
<br>
<p>
Ps: One of the best free all around VST2 instrument plugins is S-YXG50.<br>
It's a very good replacement for the Windows default MS GS Soft Synth and it works perfectly with this driver: <br>
<a href="https://veg.by/en/projects/syxg50/" target="_blank">https://veg.by/en/projects/syxg50/</a>
</p>
<p>&nbsp;</p>
<table width="100%" border="0">
<tr>
Expand Down
88 changes: 86 additions & 2 deletions vsthost/vsthost.cpp
Expand Up @@ -331,6 +331,77 @@ static BOOL settings_save(AEffect* pEffect)
return retResult;
}

static void getEditorPosition (int port, int &x, int &y)
{
HKEY hKey;

long result = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\VSTi Driver", 0, KEY_READ, &hKey);
if (result == NO_ERROR)
{
DWORD size = 4;
if (!port)
{
RegQueryValueEx(hKey, L"PortAWinPosX", NULL, NULL, (LPBYTE)&x, &size);
RegQueryValueEx(hKey, L"PortAWinPosY", NULL, NULL, (LPBYTE)&y, &size);
}
else
{
RegQueryValueEx(hKey, L"PortBWinPosX", NULL, NULL, (LPBYTE)&x, &size);
RegQueryValueEx(hKey, L"PortBWinPosY", NULL, NULL, (LPBYTE)&y, &size);

}

RegCloseKey(hKey);

// Deal with changed multimonitor setup to prevent dialogs positioned outside of currently available desktop.
int xWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN); // 0 result means error. This can happen on NT4
int yWidth = GetSystemMetrics(SM_CYVIRTUALSCREEN); // 0 result means error. This can happen on NT4
if (xWidth && xWidth)
{
if (xWidth - 24 < x || yWidth - 24 < y)
{
x = 0;
y = 0;
}

return;
}

xWidth = GetSystemMetrics(SM_CXSCREEN); //for systems that support only primary monitor.
yWidth = GetSystemMetrics(SM_CYSCREEN);
if (xWidth - 24 < x || yWidth - 24 < y)
{
x = 0;
y = 0;
}
}
}


static void setEditorPosition (int port, int x, int y)
{
HKEY hKey;

long result = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\VSTi Driver", 0, KEY_READ | KEY_WRITE, &hKey);
if (result == NO_ERROR)
{
DWORD size = 4;
if (!port)
{
RegSetValueEx(hKey, L"PortAWinPosX", NULL, REG_DWORD, (LPBYTE)&x, size);
RegSetValueEx(hKey, L"PortAWinPosY", NULL, REG_DWORD, (LPBYTE)&y, size);
}
else
{
RegSetValueEx(hKey, L"PortBWinPosX", NULL, REG_DWORD, (LPBYTE)&x, size);
RegSetValueEx(hKey, L"PortBWinPosY", NULL, REG_DWORD, (LPBYTE)&y, size);

}

RegCloseKey(hKey);
}
}

struct MyDLGTEMPLATE : DLGTEMPLATE
{
WORD ext[3];
Expand Down Expand Up @@ -408,8 +479,17 @@ INT_PTR CALLBACK EditorProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SetRect(&wRect, 0, 0, width, height);
AdjustWindowRectEx(&wRect, GetWindowLong(hwnd, GWL_STYLE), FALSE, GetWindowLong(hwnd, GWL_EXSTYLE));
width = wRect.right - wRect.left;
height = wRect.bottom - wRect.top;
SetWindowPos(hwnd, HWND_TOP, 0, 0, width, height, SWP_NOMOVE);
height = wRect.bottom - wRect.top;

int xPos = 0;
int yPos = 0;
getEditorPosition(portNum, xPos, yPos);

if(!xPos && !yPos)
SetWindowPos(hwnd, HWND_TOP, 0, 0, width, height, SWP_NOMOVE);
else
SetWindowPos(hwnd, HWND_TOP, xPos, yPos, width, height, 0);


if (!sameThread[portNum])
{
Expand Down Expand Up @@ -527,6 +607,10 @@ INT_PTR CALLBACK EditorProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
effect = (AEffect*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
portNum = *(int*)effect->user;

RECT rect;
GetWindowRect(hwnd, &rect);
setEditorPosition(portNum, rect.left, rect.top);

KillTimer(hwnd, 1);
if (effect)
{
Expand Down

0 comments on commit 5b52b99

Please sign in to comment.