Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Find Window Tittle then Close


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Mar 26, 2018 8:07 PM Last Post By: roca robin Threads: [ Previous | Next ]
roca robin

Posts: 140
Registered: 9/10/06
Find Window Tittle then Close  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 26, 2018 12:33 PM
//test1 failed
HWND MyHandle;
MyHandle = FindWindow((wchar_t*)"Properties",NULL);
SendMessage(MyHandle, WM_CLOSE, 0, 0);

//test2 failed
HWND Find = ::FindWindowEx(0, 0, (wchar_t*)"Properties", 0);
SendMessage(Find, WM_CLOSE, 0, 0);

in Delphi the FindWindow and SendMessage to closed the window is directly done BUT in c++ builder it does not cooperate.

Any ideas, suggestions, code?

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Find Window Tittle then Close  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 26, 2018 12:53 PM   in response to: roca robin in response to: roca robin
roca robin wrote:

MyHandle = FindWindow((wchar_t*)"Properties",NULL);

You are type-casting a narrow char[] literal to a wide wchar_t*
pointer. You can't do that. To specify a wide string literal, you
need to use the 'L' prefix instead:

MyHandle = FindWindow(L"Properties",NULL);


HWND Find = ::FindWindowEx(0, 0, (wchar_t*)"Properties", 0);

Same here, too:

HWND Find = ::FindWindowEx(0, 0, L"Properties", 0);


Either way, make sure the functions are not returning NULL before you
call SendMessage().

--
Remy Lebeau (TeamB)
roca robin

Posts: 140
Registered: 9/10/06
Re: Find Window Tittle then Close  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 26, 2018 8:07 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
this code execute it,
HWND MyHandle;
MyHandle = FindWindow(NULL,L"Properties");
if (MyHandle!=0) SendMessage(MyHandle, WM_CLOSE, 0, 0);

thank you :D
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02