Wrox Programmer Forums
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2005, 03:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Post your main/parent form code. If your are writing this code in some other form class, post the code for that class as well.

Ankur
 
Old December 9th, 2005, 07:38 AM
Authorized User
 
Join Date: Nov 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ankur,

I think I found a solution. I will notify you when I finished it.

Best Regards,

Walter

 
Old December 9th, 2005, 09:16 AM
Authorized User
 
Join Date: Nov 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ankur,

I finally got home. I was confused on the order of events related to the dde messages and the start of the application. But in the end I found out :-) Here is the code of my test application.

Thanks,

Walter Vanhimbeeck

    public class ParentForm : System.Windows.Forms.Form
    {
        private System.ComponentModel.Container components = null;

        private const int WM_DDE_INITIATE = 0x03E0;
        private const int WM_DDE_ACK = WM_DDE_INITIATE+4;
        private const int WM_DDE_EXECUTE = WM_DDE_INITIATE+8;

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr h, int m, IntPtr Wp, int Lp);

        public ParentForm()
        {
            InitializeComponent();
        }

        [STAThread]
        static void Main()
        {
            Application.Run(new ParentForm());
        }

        struct TestStruct
        {
            [MarshalAs(UnmanagedType.LPTStr)]
            public string strDDECommand;
        }

        [System.Security.Permissions.PermissionSet(System.S ecurity.Permissions.SecurityAction.Demand, Name="FullTrust")]
        protected override void WndProc(ref Message m)
        {
            // Listen for operating system messages.
            switch (m.Msg)
            {
                case WM_DDE_EXECUTE:
                    TestStruct vss = new TestStruct();
                    vss = (TestStruct) m.GetLParam(vss.GetType());
                    vss.strDDECommand = vss.strDDECommand.Substring(6, vss.strDDECommand.Length - 8);
                    SendMessage(m.WParam,WM_DDE_ACK,this.Handle,0);
                    ChildForm childForm = new ChildForm(vss.strDDECommand);
                    childForm.MdiParent = this;
                    childForm.Show();
                    break;

                case WM_DDE_INITIATE:
                    SendMessage(m.WParam,WM_DDE_ACK,this.Handle,0);
                    break;
            }
            base.WndProc(ref m);
        }


 
Old December 9th, 2005, 10:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

You are welcome, Walter.

Regards
Ankur Verma
 
Old December 10th, 2005, 10:59 AM
Authorized User
 
Join Date: Nov 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ankur,

A problem popped up with my dde solution. When my application is active, and I doubleclick a file of another application (e.g. .xls file), my application also receives a WM_DDE_EXECUTE for this. Any idea what it should do then ?

Best regards,

Walter

 
Old December 10th, 2005, 11:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Well the problem is that your application should respond to WM_DDE_INITIATE positively only if you are sure that the communication initiation request was bound for your application.
U set values for application and topic keys under ddeexec key in registry. The values for both these keys is sent to you along WM_DDE_INITIATE in the lparam. U need to check these values to see if the application and topic values interest you, and after that, only when you respond to WM_DDE_INITIATE you will get WM_DDE_EXECUTE.

Regards
Ankur Verma
 
Old December 10th, 2005, 12:12 PM
Authorized User
 
Join Date: Nov 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Ankur. This brings up more questions though:
Is it enough to just put my application name as value of the application key and check on this ? Or do I also need to use the
topic key ?
In what format is this key stored - is it the same kind of string as with the command in the lparam of the execute message ?
When the check is negative, do I just not reply or is there some negative response to the initiate message ?

Best Regards,

Walter

 
Old December 10th, 2005, 12:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

I think the application name validation would suffice here. And dont see the need for any negative response either, just ignore the request, do not reply to it.
All this is quite easy if you are able to extract the name of the application from lparam -which- is the tricky part of the solution. You get a high order word and a low order word in lparam which contain an atom each that identify the two values respctvly.

I'm on it.
Let me know if you hit the solution, first.

Ankur
 
Old December 11th, 2005, 09:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

There's an API 'UnpackDDElParam', that might help you get the two values out. Map it this way

        [DllImport("user32.dll")]
        public static extern bool UnpackDDElParam(
            int m, IntPtr lp,UIntPtr lo, UIntPtr hi);

Let me know if you are able to make any headway.

Regards
Ankur Verma
 
Old December 12th, 2005, 05:03 AM
Authorized User
 
Join Date: Nov 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ankur,

I have been looking around to make some sensible code using some Win32 Dll stuff and some unmanaged C# code:

[DllImport("kernel32.dll")]
static extern uint GetAtomName(ushort nAtom, [Out] StringBuilder lpBuffer, int nSize);


case WM_DDE_INITIATE:

    UIntPtr lo = UIntPtr.Zero;
    UIntPtr hi = UIntPtr.Zero;
    IntPtr lParam = m.LParam;
    StringBuilder lpBuffer = new StringBuilder(50);
    if (UnpackDDElParam(m.Msg, lParam, lo, hi))
    {
        ushort atom = *(ushort*) (lo.ToPointer());
        if (GetAtomName(atom,lpBuffer, 50) == 0)
        {
            string application = lpBuffer.ToString();
            MessageBox.Show(application);
            if (application == "MyApplication")
                SendMessage(m.WParam,WM_DDE_ACK,this.Handle,0);
        }
    }
    break;

I added a sub key "application" to the ddeexec key, with value "MyApplication".
What I saw is that the variable lo returned from UnpackDDElParam is zero. This of course makes the next statement fail.

Any idea ?

Best Regards,

Walter








Similar Threads
Thread Thread Starter Forum Replies Last Post
MDI application!!!!! angelboy C# 2005 0 February 23rd, 2007 12:36 PM
MDI application !!!!! angelboy C# 2005 0 February 7th, 2007 06:12 AM
MDI Application phillipjones1988 C# 2005 0 December 3rd, 2006 12:56 AM
MDI Application dayaananthanm VB How-To 1 August 24th, 2006 04:39 PM
MDI application wanted xerxes VB.NET 2002/2003 Basics 0 April 12th, 2006 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.