Results 1 to 8 of 8

Thread: Windows Messenger COM Questions

Hybrid View

  1. #1
    Join Date
    Aug 2002
    Location
    New York, NY
    Posts
    253

    Default Windows Messenger COM Questions

    I am making my first foray into LuaCom, and I have some questions. I appreciate any help.

    I'm trying to get information out of Windows (MSN) Messenger. I have this code so far:
    Code:
    LoadLuaCom()
    oMessenger = luacom.CreateObject("Messenger.MessengerApp")
    oMessenger = nil
    collectgarbage()
    UnloadLuaCom()
    But I'd like to put some stuff that actually does something in it. I'm having trouble distilling the information here into usable LuaCOM information. Can someone please help me?

  2. #2
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    Here is something very simple - the MSDN stuff is hard to go through. I would google instead..
    Code:
    
    objMsgr = luacom.CreateObject("Messenger.MsgrObject")
    objMsgrApp = luacom.CreateObject("Messenger.MessengerApp")
    
    print ("Messenger state ",objMsgr.LocalState)
    
    --objMsgrApp:LaunchLogonUI ()
    
    objMsgrApp.Visible = 1

  3. #3
    Join Date
    Aug 2002
    Location
    New York, NY
    Posts
    253

    Default

    Thank Mike, this got me very far.

    Now I have a new question, that I think goes like this: can I/how can I make Girder listen for the "ontextrecieved" event with luacom. I tried reading the stuff in the LUA sticky about events, but I got lost and wasn't even sure I was in the right place.

    Thanks a bunch!

  4. #4
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    Can you post some code (ie VB or script) showing how others programs receive events from messanger and I will convert it to luacom for you.

  5. #5
    Join Date
    Aug 2002
    Location
    New York, NY
    Posts
    253

    Default

    I found a useful website, though i'm still working on deciphering it. One thing I'm having trouble with is methods with no parameters (like the IMSessions method). I always get errors with them, but I think it must be a syntax issue.

    Here is some code that I found with events:

    Code:
    using Interop.Messenger;
    
    private void Form1_Load(object sender, System.EventArgs e)
    {
        //This next line creates our Messenger Class
        MsgrObjectClass Msgr = new MsgrObjectClass();
    
        //These 3 lines create the events to be used
        Msgr.OnTextReceived += new DMsgrObjectEvents_OnTextReceivedEventHandler
            (this.OnTextReceived);
    
        Msgr.OnUnreadEmailChanged += new
            DMsgrObjectEvents_OnUnreadEmailChangedEventHandler
            (this.OnUnreadEmailChanged);
    
        Msgr.OnUserStateChanged += new
            DMsgrObjectEvents_OnUserStateChangedEventHandler
            (this.OnUserStateChanged);
    }
    
    //The TextReceived Event
    private void OnTextReceived(IMsgrIMSession Session, IMsgrUser User, 
        string Header, string MsgText, ref bool Enabled)
    {
        //Simply write this info to the textbox
        textBox1.Text += User.ToString() + " " + Header.ToString();
        textBox1.Text += " " + Text.ToString();
    }
    
    //The OnUnreadEmailChanged event 
    private void OnUnreadEmailChanged(Interop.Messenger.MFOLDER Folder, 
        int UnReadEmails, ref bool Enabled)
    {
        //Simply write this info to the textbox
        textBox1.Text += "MFOLDER " + Folder.ToString();
        textBox1.Text += "a " + UnReadEmails.ToString();
    }
    
    //The OnUserStateChanged event
    private void OnUserStateChanged(Interop.Messenger.IMsgrUser User, 
        Interop.Messenger.MSTATE PreviousState, ref bool Enabled)
    {
        //Again simply write this info to the textbox
        textBox1.Text += User.FriendlyName + "'s state has changed to " 
            + User.State;
    
        textBox1.Text += User.FriendlyName + "'s previous state was " 
            + PreviousState;
    }

  6. #6
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    Try...

    Code:
    MsgrObjectEvents = {}
    
    function MsgrObjectEvents:OnTextReceived ()
      print ("text received")
    end
    
    if not luacom.Connect (MsgrObject,MsgrObjectEvents) then 
      print ("Unable to connect")
    end

  7. #7
    Join Date
    Aug 2002
    Location
    New York, NY
    Posts
    253

    Default

    Mike,

    You are a true fount of knowledge. The code works, but I just get "script finished" at the end.

    I think this is a more general Lua/LuaCom question, but how do I make it run until such an event is triggered, and can I do so without chewing up CPU?

    Thanks!

  8. #8
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    Actually, it does not need to run..

    It is always waiting for an event. So, now you need to trigger the event and make sure you see the print statement execute.

Posting Permissions

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