Click to See Complete Forum and Search --> : FindWindow & SendMessage


themanvh
August 12th, 2004, 01:09 PM
Hey!

I use VC++ .NET with MFC.

Can you please tell me why isn't it working?

HWND hWindow = FindWindow(NULL,"Calculator");
SendMessage(hWindow,WM_SETTEXT,0,(LPARAM)"New title");

riteshtandon
August 12th, 2004, 01:33 PM
what is the error code that u r getting

themanvh
August 12th, 2004, 01:36 PM
api testDlg.cpp(153) : error C2440: 'initializing' : cannot convert from 'CWnd *' to 'HWND'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
api testDlg.cpp(154) : error C2660: 'CWnd::SendMessageA' : function does not take 4 arguments

kirants
August 12th, 2004, 01:50 PM
Use ::FindWindow instead of FindWindow
Use ::SendMessage instead of SendMessage

Reason being, probably you are calling FindWindow and SendMessage from within a method of a CWnd derived class. Note that CWnd class also has methods with the same name. So, you need to tell the compiler which one to use, the methods or the Win32 API.

You are left with 2 choices...
Either do what I said earlier

or

CWnd* pWnd = FindWindow(.....);
if(pWnd)
pWnd->SendMessage(WM_SETTEXT,0,(LPARAM)"New title");

themanvh
August 12th, 2004, 01:56 PM
Thank you!

edit:

Can you tell me about GetMessage?

xikspan
February 21st, 2006, 03:10 PM
Can ::SendMessage be called from within the app's InitInstance()?

kirants
February 21st, 2006, 03:34 PM
SendMessage to what window ?

2MuchRiceMakesMeSick
November 8th, 2006, 04:36 AM
Can someone help me use the findwindow function except with CLI