Open
CloseCode:::ShellExecute(NULL,
"open",
"Calc.exe",
"",
"",
SW_SHOWNORMAL);
Code:CWnd *window = CWnd::FindWindow(NULL, LPCTSTR("Calculator"));
if (window != NULL)
{
window->PostMessage(WM_CLOSE);
}
Printable View
Open
CloseCode:::ShellExecute(NULL,
"open",
"Calc.exe",
"",
"",
SW_SHOWNORMAL);
Code:CWnd *window = CWnd::FindWindow(NULL, LPCTSTR("Calculator"));
if (window != NULL)
{
window->PostMessage(WM_CLOSE);
}
Hey,
thanks John. Examples really seem to help me grasp this stuff quicker.
thanks a million !
cheers.
hey John,
the open calc.exe code works great !
the close one I'm doing something wrong.... perhaps I need to include another header ?
I get
error `CWnd' was not declared in this scope.
here's what I tried....
Code:#include <windows.h>
#include <stdio.h>
int main()
{
CWnd *window = CWnd::FindWindow(NULL, LPCTSTR("Calculator"));
if (window != NULL)
{
window->PostMessage(WM_CLOSE);
}
}
I'm sure I'm missing something being a newbie and all.
any clues are appreciated.
Thanks everyone. : )
*window is a pointer right ?
so I guess I have to declare that first...
again... I'm so " newbie " I don't know, that's my best guess.
any insight is appreciated.
cheers.
: )
My example was for an MFC application. If you are using straight Win32 then you will have to change it to the following.
Actually both methods should work with MFC.
Code:HWND hwnd = ::FindWindow(NULL, LPCTSTR("Calculator"));
if (hwnd != NULL)
{
::PostMessage(hwnd, WM_CLOSE);
}
Hey thanks again John.
I'm still having trouble getting it to work. get an error now about bool too few arguments for HWND_*
I obviously need more knowledge to figure this stuff out.
Can You recommend a good book for me perhaps ? there seems to be so frickin' many I can't tell which is a good one.
I need one that starts from the beginning. However I am a good problem solver, I understand electronics very well, and I am good with HTML and a little PHP so....
not tooooooo beginner either.
any insight on a good book would be greatly appreciated.
cheers.
Can you post some minimal code to replicate the compiler error?
sure thanks for the help John.
Code:#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
int main()
{
::ShellExecute(NULL,
"open",
"calc.exe",
"",
"",
SW_SHOWNORMAL);
cout<< " alright ! ";
cin.get();
HWND hwnd = ::FindWindow(NULL, LPCTSTR("Calculator"));
if (hwnd != NULL)
{
::PostMessage(hwnd, WM_CLOSE);
}
}
PostMessage takes four arguments, not two. Pass zeros for WPARAM and LPARAM.
hey thanks plasmator,
that's got it.
however....Code:#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
int main()
{
::ShellExecute(NULL,
"open",
"calc.exe",
"",
"",
SW_SHOWNORMAL);
cout<< " alright ! ";
cin.get();
HWND hwnd = ::FindWindow(NULL, LPCTSTR("Calculator"));
if (hwnd != NULL)
{
::PostMessage(hwnd, WM_CLOSE, 0 , 0 );
}
}
I don't underSTAND it. what should I read up on to understand
the -
part...Code:HWND hwnd = :FindWindow(NULL, LPCTSTR("Calculator"));
and the 4 arguments you mentioned.
what " topic " would this be considered ?
thanks.
The issue you need to realize is that you have two stumbling blocks. The first is learning the C++ language. The second is learning Windows programming. Learning the C++ language itself is difficult. Learning the Windows API is a totally different topic, and should be undertaken once you know the language you will be using. It makes no sense learning the API of an operating system using a computer language you don't know how to use properly.
See above. Get a good C++ only book. There is no need to introduce Windows programming.Quote:
Can You recommend a good book for me perhaps ? there seems to be so frickin' many I can't tell which is a good one.
Afterwards you use that knowledge to interface to the OS, in this case Windows. You then get Windows programming books. Most of these books are not language tutorial books -- they assume you know how to use 'C' or C++ already.
But it seems you're just throwing random things together to learn, and learning C++ doesn't work that way.Quote:
I need one that starts from the beginning. However I am a good problem solver,
I have seen very bad programmers who supposedly knew "eletronics", and HTML and PHP are a far cry from C++ in terms of learning and complexity.Quote:
wit I understand electronics very well, and I am good with HTML and a little PHP so....
Regards,
Paul McKenzie
hey Paul. I'm actually a teacher, so I know that everyone learns different. I will take your advice, however I am better at reverse engineering to see how something works. I learn much faster that way. I didn't want to use windows programming, it was the only short code way of opening the calculator in my first game. I'm sure my knowledge of C++ will get better.
maybe so, but trying things out bring up problems and errors. Then I learn why there's a problem or error. Then when I do come across that situation in a tutorial... I understand what they're saying more... that's all. In other words, it helps me learn LATER by making mistakes now. It's just how I work. Might not be for everyone. I do listen to people when they tell me to try it a better way. thanks for your help though.
cheers.