Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 January 15th, 2007, 10:54 PM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Launch the .Net Win Forms from Excel spreadsheet

Hi,
Actually first I am mentioning some details about my application:

1. It is a Windows Application written in C#.
2. It is an Trading application that has one Main screen (Its a normal
Window Form not MDI Form) from where we can launch Trade Specific screens by
clicking on New and Edit button.
3. We can launch these Trade specific screens from Excel sheet as well but
the precondition for this is that Main screen of Trading application must be
open by that time.

Now the Problem is that:

If any Trade specific Screen is already open then it doesn't open the new
Trade specific Screen from Excel sheet. Actually I have written the following
Snippet of code to open the screen:

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam,
IntPtr lParam);
public bool UploadToTradeScreen( string tradeID, bool saveDebugFile )
{
    Process[] myProcesses = Process.GetProcessesByName("TradeApp");

    if(myProcesses.Length == 0)
        return false;

    XmlDocument xmlDoc = FetchXMLDoc( tradeID );
    //Other Logic ...

    IntPtr ret = SendMessage(myProcesses[0].MainWindowHandle,
WM_USER_TradeApp_OPENTRADE, iNow, (IntPtr)0 );

    int iRet = ret.ToInt32( );
    if( saveDebugFile == false )
        File.Delete( fileName );
    return iRet == 0 ? false : true;
}

and I am trapping this Window Message in the following code snippet to open
the screen:

protected override void WndProc(ref Message m)
{
    switch(m.Msg)
    {

        case ((int) WindowsMessages.WM_USER_TradeApp_OPENTRADE):
        {
            //..code..
            StaticHelperClass.FrameWorkHelper.AppHelper.Displa yTradeData( fileName );
            break;
        }
        case ((int) WindowsMessages.WM_USER_TradeApp_SAVETRADE):
        {
            //..code..
            StaticHelperClass.FrameWorkHelper.AppHelper.SaveTr adeData( fileName );
            break;
        }
        default:
            base.WndProc(ref m);
            break;
    }
}

When the Main screen opens and very first time we launch Trade Specific Screen from Excelsheet then it opens the Trade Specific Screen. But next time it doesn't open the new Trade Specific screen
from Excel sheet.

My guess about this problem is that when we open any Trade Specific Screen then the MainWindowHandle transfers to the Trade Specific Screen from the Main Screen.

Could you please suggest me some solutions to overcome this problem, so that I can open the multiple Trade specific screens from the Excel sheet.

Thanks
AAruni





Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate Excel spreadsheet with ASP.Net (VB) James Diamond ASP.NET 1.0 and 1.1 Professional 2 December 11th, 2013 08:15 AM
Theme/skin win forms controls planoie .NET Framework 2.0 3 August 21st, 2008 04:28 PM
To launch Excel from ASP thecomputersaint Classic ASP Basics 4 December 8th, 2004 07:11 PM
Excel in win 2000 to excel winxp (excel 2002) Max Excel VBA 3 August 28th, 2003 04:44 AM





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