Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Excel 2013 crashing in WPF

$
0
0

I'm trying to embed Excel 2013 in a WPF app. The problem is that when I call SetWindowLongPtr tomake Excel application a child window of my WPF window using the following code, Excel 2013 crashes immediately. I digged it and found that if I comment outWS.CHILD style, it works fine, but the Excel sheet becomes readonly, which is not what I want. The same code works fine with Excel 2010.

Excel.Application _excelApp;
IntPtr _wrappedApplicationHandle;
Int64 lngStyle;
Int64 lExStyle;    

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    _excelApp = new Excel.Application()
    {
        Visible = true,
        DisplayFormulaBar = true,
    };

    _wrappedApplicationHandle = new IntPtr( _excelApp.Hwnd);

    lngStyle = GetWindowLongPtr(_wrappedApplicationHandle, (int)GWL.STYLE).ToInt64();
    lngStyle &= ~(int)WS.CAPTION;
    lngStyle &= ~(int)WS.SIZEBOX;
    lngStyle |= (int)WS.MAXIMIZE;
    lngStyle |= (int)WS.CHILD; //<< crashes with this line
    lngStyle |= (int)WS.CLIPSIBLINGS;
    lngStyle |= (int)WS.CLIPCHILDREN;

    SetWindowLongPtr(new HandleRef(_excelApp, _wrappedApplicationHandle), 
                        (int)GWL.STYLE, 
                        new IntPtr(lngStyle));
    ...
}

I'm using VS2013 Express with .NET Framework 4.5 and this is a WPF Application project, but similar results are achieved when using VS2012 as well.

Shujaat


Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>