Go Back   Winamp Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 4th October 2009, 15:53   #1
TheSaw
Senior Member
 
TheSaw's Avatar
 
Join Date: Apr 2009
Posts: 342
Send a message via Yahoo to TheSaw
Opening Winamp preferences / Winamp ini dir

2 questions:

1. Currently I'm opening the preferences window with
SendMessage(hwnd,WM_WA_IPC,-1,IPC_OPENPREFSTOPAGE);
But this doesn't set the window to the foreground. I don't know how to get the Winamp handle, because the title might be in other language, and the class is some generic dialog class... Is there a way to bring it to the foreground when opening?

2. I'm using
SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETINIDIRECTORY);
to get the ini directory, but this only sends ansi string, not unicode (which is needed). I've used the winapi function to get the %appdata% folder and it's working fine, just wondering, is Winamp using that folder in every case, or it might use some other directory to store the settings, maybe if it can be installed for all users, not per user?
TheSaw is offline   Reply With Quote
Old 9th October 2009, 11:45   #2
griffins_Grader
Senior Member
 
Join Date: Aug 2008
Posts: 114
1. well it looks like you are controlling Winamp from an external application. Do it from within a plugin. You could use GetWindowModuleFileName and GetFileVersionInfo to assert it is a real winamp handle.
griffins_Grader is offline   Reply With Quote
Old 11th October 2009, 13:12   #3
DrO
-
 
DrO's Avatar
 
Join Date: Sep 2003
Location: UK
Posts: 22,240
for #1 then the following api may be of use (though i'm sure there are some changes to Vista/Win7 that may hinder external focusing of a window)
code:
#define IPC_GETPREFSWND 619
/* (requires Winamp 5.0+)
** HWND prefs = (HWND)SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETPREFSWND);
** This will return a handle to the preferences dialog if it is open otherwise it will
** return zero. A simple check with the OS api IsWindow(..) is a good test if it's valid.
**
** e.g. this will open (or close if already open) the preferences dialog and show if we
** managed to get a valid
** SendMessage(hwnd_winamp,WM_COMMAND,MAKEWPARAM(WINAMP_OPTIONS_PREFS,0),0);
** MessageBox(hwnd_winamp,(IsWindow((HWND)SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETPREFSWND))?"Valid":"Not Open"),0,MB_OK);
*/



for #2, it depends on what is specified in paths.ini (if one is present) and this post/thread has the information needed to get going with things if done from an external dll.

griffins_Grader: from previous posts by TheSaw, some of his features have to be done in a shell extension which makes it impossible to do as a true Winamp plugin

-daz
DrO is offline   Reply With Quote
Old 11th October 2009, 16:59   #4
griffins_Grader
Senior Member
 
Join Date: Aug 2008
Posts: 114
DrO, Having mentioned the focus issue with vista/Win7. I have a plugin that draw Windows Controls (ActiveX Controls), when I run this plugin on Win7 the Controls do not get focus with a single click, I have to set focus on the window(ATL Window) containing the Controls then be able to get focus on any of the controls with a single click else I have to double click on the control. Please do you have any reference addressing this issue? I thought about listening on WM_NCHITTEST and when the mouse is on my plugin's window RECT and the plugin's window is the top window then the plugin will set focus to the window but it is somewhat "hacky" I would prefer a standard approach probably from the OS SDK. Regards.
griffins_Grader is offline   Reply With Quote
Old 11th October 2009, 20:10   #5
DrO
-
 
DrO's Avatar
 
Join Date: Sep 2003
Location: UK
Posts: 22,240
hmm, not too sure unless something else on the dialog is setting focus to itself which causes the effect you're seeing.

from what i remember wm_setfocus/wm_activate are the better message pair to work with for the handling of the window being activated so you can then do a SetFocus(..) on the relevant control. may even be an idea to use something like spy++ to see what messages are going on when the window is being focused to see what/who is doing things.

i think the main Vista/Win7 focus issues are down to clamping down on certain cross-process methods which were ideal for viruses/malware though i can't remember how much that would affect things (like with what TheSaw is trying to achieve).

TheSaw: had a thought in the reply to griffins_Grader and maybe a PostMessage(hwnd,WM_WA_IPC,-1,IPC_OPENPREFSTOPAGE) will work around the focusing issue (i've a feeling what you're doing forces the focus back to your code which goes against Winamp's preferences opening at the same time).

-daz
DrO is offline   Reply With Quote
Old 13th October 2009, 07:24   #6
TheSaw
Senior Member
 
TheSaw's Avatar
 
Join Date: Apr 2009
Posts: 342
Send a message via Yahoo to TheSaw
Thx DrO, both solutions work (partially). I say partially, because Winamp's windows are acting weird like all the time, so I can only set it to foreground after waiting 500ms, but it should be okay like this.

For the second solution, I'll post the code snippet I've wrote for parsing the paths.ini file, in case someone else finds all this confusing (like I did). It might not be perfect, but it works

code:
inline bool parsePath(std::wstring &thepath)
{
std::wstring::size_type pos1 = std::wstring::npos, pos2 = std::wstring::npos;

pos1 = thepath.find_first_of(L'{');
if (pos1 != std::wstring::npos)
{
pos2 = thepath.find_first_of(L'}', pos1+1);
if (pos2 != std::wstring::npos)
{
std::wstring re;
int clsid;

re = thepath.substr(pos1+1, pos2 - pos1 - 1);
std::wstringstream ss;
ss << re;
ss >> clsid;

re.clear();
re.resize(MAX_PATH);
SHGetSpecialFolderPath(0, &re[0], clsid, 0);
re.resize(wcslen(re.c_str()));

thepath.replace(pos1, pos2 - pos1 + 1, re);
return true;
}
}

pos1 = thepath.find_first_of(L'%');
if (pos1 != std::wstring::npos)
{
pos2 = thepath.find_first_of(L'%', pos1+1);
if (pos2 != std::wstring::npos)
{
std::wstring re;
re = thepath.substr(pos1+1, pos2 - pos1 - 1);
re = _wgetenv(re.c_str());

thepath.replace(pos1, pos2 - pos1 + 1, re);
return true;
}
}

return false;
}

std::wstring getWinampINIPath()
{
std::wstring wini;
wini.resize(MAX_PATH);
GetPrivateProfileString(L"Winamp", L"inidir", L"", &wini[0], MAX_PATH, std::wstring(getInstallPath() + L"\\paths.ini").c_str());
wini.resize(wcslen(wini.c_str()));

wini = L"";
while (getCLSIDPath(wini));

if (wini.empty())
return getInstallPath();

return wini;
}

int main()
{
std::wstring WinampINI = getWinampINIPath();
WinampINI += L"\\winamp.ini";
std::cout << WinampINI << std::endl;
}

TheSaw is offline   Reply With Quote
Old 13th October 2009, 08:46   #7
TheSaw
Senior Member
 
TheSaw's Avatar
 
Join Date: Apr 2009
Posts: 342
Send a message via Yahoo to TheSaw
As an offtopic question: how can I mute winamp from my plug-in? Not setting the volume to 0, but actually muting it?

Winamp integration plug-in with Windows 7

If you like this plug-in, why not buy me a coffee to keep me awake to work more on it?

TheSaw is offline   Reply With Quote
Old 14th October 2009, 13:17   #8
TheSaw
Senior Member
 
TheSaw's Avatar
 
Join Date: Apr 2009
Posts: 342
Send a message via Yahoo to TheSaw
And another one: I'm trying to get the path to the inidir/plugins, but the above code doesn't work for everyone. I'm parsing it from the paths.ini, and if it's not readable, I use installdir/plugins, but that's not the right path.

Basically I want to get the same thing as the return of the IPC_GETINIDIRECTORY message, but wide string.

Winamp integration plug-in with Windows 7

If you like this plug-in, why not buy me a coffee to keep me awake to work more on it?

TheSaw is offline   Reply With Quote
Old 15th October 2009, 19:27   #9
DrO
-
 
DrO's Avatar
 
Join Date: Sep 2003
Location: UK
Posts: 22,240
i don't think there is a way to mute winamp - even it's mute feature just sets the volume in Winamp itself to zero.

the plugins directory should be %winampdir%\plugins unless people have multiple winamp installs...

there is a registry setting for the uninstaller which holds the path of the last valid install (is generally safe to use that) -> HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp -> UninstallString.

-daz
DrO is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump