SendMessage problem.

This is a discussion on SendMessage problem. within the Windows Programming forums, part of the Platform Specific Boards category; Scroll down to see how far i have got with my code Code: void CAstraView::OnGoHomeButton() { int hWnd = (int)FindWindow(NULL, ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    55

    Exclamation SendMessage problem.

    Scroll down to see how far i have got with my code

    Code:
    void CAstraView::OnGoHomeButton() 
    {
    	int hWnd = (int)FindWindow(NULL, "Microsoft Internet Explorer");
    
    	if(hWnd == NULL)
    	{
    		MessageBox("Couldn't find window", "Error", MB_OK);
    	}
    	else
    	{
    		LRESULT SendMessage(hWnd,
    				     WM_MOUSEACTIVATE);	
    		LRESULT SendMessage(hWnd,
    				     WM_NCHITTEST(HTCLIENT));
    		LRESULT SendMessage(hWnd,
    				     WM_LBUTTONDOWN);
    	}
    }
    i've made a program with a button, and i want my program to (when i click my button) select the first internet explorer window and click the home button.

    What have i done wrong so far?

    Help appreciated, i've spent the last 4 hours searching google and getting nowhere.

    Happy New Years all.
    Last edited by Astra; 01-01-2007 at 03:42 PM.

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    307
    Err....is not that easy.

    First:
    FindWindow(NULL, "Microsoft Internet Explorer");
    Is looking for a Window with the class Microsoft Internet Explorer, since the IE browser class is mostly IEFrame in version 7... so, try that..

    I also recommend to see what usefull this can be for you.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    55
    Ah Ok thanks, heres my code so far, now im only getting 1 error:

    Code:
    void CAstraView::OnGOHOME()
    {
    	HWND IE;
    
    	IE = (struct HWND__ *)FindWindow("IEFrame", 0);
        	
    	if(IE == NULL)
    	{
    		MessageBox("IE Window not found", "Error" ,MB_OK);
    	}
    	else if(IE != NULL)
    	{
    		SendMessage(WM_MOUSEACTIVATE, IE, HTCLIENT);
    		SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(208, 46));
    	}
    }
    Error: error C2664: 'SendMessageA' : cannot convert parameter 2 from 'struct HWND__ *' to 'unsigned int'

    and for the findwindow thing, it should be correct because the class name comes first > http://msdn2.microsoft.com/en-us/library/ms633499.aspx
    Last edited by Astra; 01-01-2007 at 11:50 AM.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    55
    Help please.... how else can i set this out to avoid having to typecast IE as an unsigned int later on? as it compiles that way but doesn't work.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    You'll probably have to use COM. Check out the iexplore.cpp sample in COM Helper, DispHelper.

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Your arguments to FindWindow are ok. (Although I'd make the second one NULL, since it's a string, and not an integer.) However, don't cast FindWindow()'s result. It returns a HWND, which is what you're storing it to. Don't cast the result.

    Second, SendMessage(). Look it up in the MSDN library. It has four parameters: SendMessage(hWnd, Msg, wParam, lParam); The first is what window to send the message to, the second is the message to send, the last two are message specific parameters. So, SendMessage(IE, WM_something, _parameter1_, _parameter2_); For the parameters, you'll need to look up the message you're sending to know what the parameters are for.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    55
    I'm using the MFC selection of classes for windows programming, which has only 3 parameters for sendmessage (basically the same as the 4 parameter one but leaves out the first parameter as it's taken as global with MFC)

    heres my code as it stands:

    Code:
    void CAstraView::OnGOHOME()
    {
    	CWnd* IE;
    
    	IE = FindWindow("IEFrame", NULL);
        	
    	if(IE == NULL)
    	{
    		MessageBox("IE Window not found", "Error" ,MB_OK);
    	}
    	else
    	{
    		IE->SendMessage(WM_MOUSEACTIVATE, IE, HTCLIENT);
    		IE->SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(208, 46));
    	}
    }
    and here's my only error:

    error C2664: 'SendMessageA' : cannot convert parameter 2 from 'class CWnd *' to 'unsigned int'

    which refers to this line ''IE->SendMessage(WM_MOUSEACTIVATE, IE, HTCLIENT);''

    Thanks in advance

  8. #8
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    use m_hWnd member of the CWnd class
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Didn't you read what Cactus_Hugger said? SendMessage has 4 parameters.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  10. #10
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> Didn't you read what Cactus_Hugger said? SendMessage has 4 parameters.

    It's MFC. Didn't you read what Astra said?

    >> use m_hWnd member of the CWnd class

    That's private, but you may use CWnd::GetSafeHwnd which just accesses that

    Code:
    IE->SendMessage(WM_MOUSEACTIVATE, WPARAM(IE->GetSafeHwnd()), LPARAM(HTCLIENT));
    Last edited by Tonto; 01-02-2007 at 05:42 AM.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21