Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 15th, 2007, 10:54 PM
Registered User
Join Date: Apr 2004
Location: Noida, Uttar Pradesh, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Launch the .Net Win Forms from Excel spreadsheet

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)

        case ((int) WindowsMessages.WM_USER_TradeApp_OPENTRADE):
            StaticHelperClass.FrameWorkHelper.AppHelper.Displa yTradeData( fileName );
        case ((int) WindowsMessages.WM_USER_TradeApp_SAVETRADE):
            StaticHelperClass.FrameWorkHelper.AppHelper.SaveTr adeData( fileName );
            base.WndProc(ref m);

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.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 12:50 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.