FindWindow & SendMessage
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: FindWindow & SendMessage

  1. #1
    Join Date
    Aug 2004
    Posts
    9

    Question FindWindow & SendMessage

    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");

  2. #2
    Join Date
    Feb 2003
    Location
    Hyderabad
    Posts
    181
    what is the error code that u r getting
    Ritesh Tandon
    (Sr. Software Engineer)

  3. #3
    Join Date
    Aug 2004
    Posts
    9
    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

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    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

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

  5. #5
    Join Date
    Aug 2004
    Posts
    9

    Thumbs up yes!!

    Thank you!

    edit:

    Can you tell me about GetMessage?
    Last edited by themanvh; August 12th, 2004 at 01:27 PM.

  6. #6
    Join Date
    Feb 2006
    Posts
    78

    Re: FindWindow & SendMessage

    Can ::SendMessage be called from within the app's InitInstance()?

  7. #7
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: FindWindow & SendMessage

    SendMessage to what window ?

  8. #8
    Join Date
    Oct 2006
    Posts
    229

    Re: FindWindow & SendMessage

    Can someone help me use the findwindow function except with CLI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)