Hi guys, first just want to say hello as this is my first post here and I hope someone can help me with the problem I have at the moment.
I just want to write a simple program which tells the user if the default 'calculator' application is running at the time of the program being executed.
An HWND is not a string, so this will never be true. If FindWindow was successful, it will be a handle to the window (note: the handle is not the title of the window, it's an object by which you can access window properties).
For your purposes, the only thing you care about at this point is that the window is non-null.
1 2 3 4
if(hWnds == NULL)
{ /* window not found*/ }
else
{ /* window was found */ }
Let me also point out that, even if hWnds was a C-string, you shouldn't compare C-strings like that.
1 2 3 4 5 6 7
char Test[] = "Testing...";
char Test2[] = "Testing...";
if(Test == Test2)
{
// This code will NEVER execute.
}
It's because you will be going to compare pointers, and not the actual content.
You have various ways to test equality:
1 2 3 4 5 6 7 8 9 10 11 12
// 1. strcmp
if(strcmp(Test,Test2) == 0) {
// Equal
}
// 2. stricmp (case Insensitive strcmp)
if(stricmp(Test,Test2) == 0) {
// Equal, even with different case
}
// You can also:
// memcmp, not suggested but still can be done
// manually check character by character
// cast to std::string and use operator==