|
-
Apr 4th, 2003, 07:16 PM
#1
Thread Starter
Fanatic Member
App executex too quick to get hWnd..
I am making a program, when you run it, it finds hWnd of winAmp, and if its 0, itll ask the user 'winamp is not open, wanna open it, Y/N' if the user tYpes Y, it opens and then it finds hwnd again, but its too fast, so the hwnd is always 0, it tries to find it before winamp is fully open. How would I fix this? or go around it?
-
Apr 5th, 2003, 12:17 AM
#2
Hyperactive Member
Can you post the code in question?
-
Apr 5th, 2003, 09:45 AM
#3
Thread Starter
Fanatic Member
Is there anyway to make the system 'wait' until a certain file has finished loading?
code:
Code:
#include <iostream.h>
#include <windows.h>
class WinAmp
{
public:
WinAmp();
~WinAmp();
HWND gethwnd()
{
hwnd_winamp = FindWindow("Winamp v1.x", NULL);
return hwnd_winamp;
}
void play(){SendMessage(hwnd_winamp, WM_COMMAND, 40045, NULL);}
void stop(){SendMessage(hwnd_winamp, WM_COMMAND, 40047, NULL);}
void pause(){SendMessage(hwnd_winamp, WM_COMMAND, 40046, NULL);}
void prev(){SendMessage(hwnd_winamp, WM_COMMAND, 40044, NULL);}
void next(){SendMessage(hwnd_winamp, WM_COMMAND, 40048, NULL);}
//void GetSongTitle(){}
void close(){SendMessage(hwnd_winamp, WM_COMMAND, 40001, NULL);}
private:
HWND hwnd_winamp;
};
WinAmp::~WinAmp(){}
WinAmp::WinAmp(){}
void WinAmpMenu();
int main()
{
WinAmp objWA;
HWND WA_hWnd = objWA.gethwnd();
if(WA_hWnd == 0)
{
cout << "WinAmp is closed, want to open? Y/N\n";
char OWA='X';
cin >> OWA;
if (OWA == 'Y')
{
HINSTANCE ret = ShellExecute(NULL, "open", "C:\\Program Files\\Winamp\\winamp.exe", NULL, NULL, SW_SHOWNORMAL);
}
else
{
return(0);
}
}
WinAmpMenu();
char CHOE = 'D';
do
{
cout << "Enter a letter\n";
cin >> CHOE;
switch(CHOE)
{
case 'P':
objWA.play();
break;
case 'Z':
objWA.pause();
break;
case 'S':
objWA.stop();
break;
case 'C':
objWA.close();
break;
case 'V':
objWA.prev();
break;
case 'N':
objWA.next();
break;
case 'W':
cout << "hWnd: " << objWA.gethwnd() << endl; //lets find the hWnd
break;
case 'M':
WinAmpMenu();
break;
case 'X':
return(0);
default:
cout << "Unknown Letter, press M to view the menu again! -_0\n";
}
} while(CHOE != 'X');
return(0);
}
void WinAmpMenu()
{
cout << "\n\nWinAmp menu ****`_`\n\n"
<<"-------------------\n"
<<"P - Play\tZ - Pause\n"
<<"S - Stop\tC - Close\n"
<<"V - Prev\tN - Next\n"
<<"M - Menu\tW - hWnd\n\n"
<<"-------------------\n";
}
-
Apr 5th, 2003, 01:16 PM
#4
Hyperactive Member
Code:
HWND gethwnd()
{
hwnd_winamp = FindWindow("Winamp v1.x", NULL);
return hwnd_winamp;
}
Are you really sure the window name is "Winamp v1.x"? Use MS spy++ to find out to double confirm.
Spy++ comes with every copy of VC6.
-
Apr 7th, 2003, 09:07 PM
#5
Addicted Member
Sleep() is the API call your looking for get the info for it on MSDN.
-
Apr 7th, 2003, 09:21 PM
#6
Thread Starter
Fanatic Member
Yes transcendetal, it is that classname, I can control the window fine but my prog looks for it too quick.
Thanks WiKiDJeFF.
-
Apr 8th, 2003, 02:56 AM
#7
Fanatic Member
If you want more control, oyu can use GetTickCount instead of sleep, the only problem is you will have to do more coding. Sleep holds the program up for a set time. GetTickCount returns the hnumber of miliseconds your computer has been running for, and thus works as a timer of sorts when used properly.
-
Apr 8th, 2003, 02:40 PM
#8
Thread Starter
Fanatic Member
I know about GetTickCount, I need to find out if a program loaded or not yet.. how would I? The prog loads in like 1 sec on my PC, but like 10 seconds on my other/slow PC.. so the same timer won't work.
-
Apr 8th, 2003, 04:51 PM
#9
howza bout this...
Code:
// ..........................
if(WA_hWnd == 0)
{
cout << "WinAmp is closed, want to open? Y/N\n";
char OWA='X';
cin >> OWA;
if (OWA == 'Y')
{
HINSTANCE ret = ShellExecute(NULL, "open", "C:\\Program Files\\Winamp\\winamp.exe", NULL, NULL, SW_SHOWNORMAL);
while ((WA_hWnd = objWA.gethwnd()) == 0)
{
cout << "Waiting for winamp to start..." << endl;
Sleep(500);
}
}
else
{
return(0);
}
}
// ..........................
Oh, and the Winamp 3 classname is "STUDIO" in case you were wondering, although none of these functions work with v3.
Last edited by sunburnt; Apr 8th, 2003 at 04:56 PM.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Apr 15th, 2003, 05:46 AM
#10
Use CreateProcess instead of ShellExecute, then you can use the process handle you've got with WaitForInputIdle (or something like that) which locks you app until WinAmp has loaded.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|