Andy Wigley Device Application Development MVP APPA Mundi Ltd SESSION CODE: WEM309.

Slides:



Advertisements
Similar presentations
Ron Jacobs Technical Evangelist Microsoft Corporation SESSION CODE: DEV207.
Advertisements

Jason Tolley Technical Director ROK Technology Pty Ltd SESSION CODE: WEM305.
Joe Kuemerle Lead Developer PreEmptive Solutions - SESSION CODE: DEV306.
Sometimes it is the stuff you know that hinders true progress.
Loren Goodman Chief Technology Officer InRule Technology SESSION CODE: ARC301 Putting Business Rules To Work.
The Secrets of Effective Technical Talks: How to Explain Tech without Tucking Them In! Presented by Mark Minasi and Mark Russinovich SESSION CODE: SIA334.
Ashwin Sarin Program Manager Microsoft Corporation SESSION CODE: COS204.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Maciej Pilecki Consultant, SQL Server MVP Project Botticelli Ltd. SESSION CODE: DAT403.
Olivier Bloch Technical Evangelist Microsoft Corporation SESSION CODE: WEM307.
Boris Jabes Senior Program Manager Microsoft Corporation SESSION CODE: DEV319 Scale & Productivity in Visual C
Peter Provost Sr. Program Manager Microsoft Corporation SESSION CODE: DEV403.
Douglas Boling President Boling Consulting Inc. SESSION CODE: WEM304.
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
END USER TOOLS AND PERFORMANCE MANAGEMENT APPS Excel PerformancePoint Svcs/ProClarity BI PLATFORM SQL Server Reporting Services SQL Server Reporting Services.
Brad Younge Principal Statera, Inc. SESSION CODE: COS304.
Janssen Jones Virtual Machine MVP Indiana University SESSION CODE: VIR403.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Bradley Millington Senior Program Manager Microsoft Corporation SESSION CODE: WEB 306.
Suhail Dutta Program Manager Microsoft Corporation SESSION CODE: DEV402.
Matt winkler program manager microsoft corporation SESSION CODE: ASI303.
Aaron Skonnard & Keith Brown Cofounders, Pluralsight SESSION CODE: ASI308 Programming AppFabric: Moving.NET to the Cloud.
Chandrika Shankarnarayan Senior Program Manager Microsoft Corporation SESSION CODE: ASI301.
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
Thomas Deml Principal Program Manager Web Platform and Tools Microsoft Corporation SESSION CODE: WEB308.
Paul Litwin Programmer Manager Fred Hutchinson Cancer Research Center SESSION CODE: WEB206.
Dynamic Link Libraries: Inside Out. Dynamic Link Libraries  About Dynamic-Link Libraries  Dynamic-Link Libraries Hands On  Dynamic Link Library Reference.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Omar Khan SESSION CODE: WSV331. Simplification.
Jeff King Senior Program Manager, Visual Studio Microsoft Corporation SESSION CODE: WEB305.
Lori Dirks Expression Community Manager Microsoft Corporation SESSION CODE: WEB309.
Paul Schaeflein, MCT Manager of Advanced Technologies LaSalle Consulting Partners, Inc. SESSION CODE: OSP309.
Alexander Wechsler Wechsler Consulting GmbH & Co. KG SESSION CODE: WEM306.
Vineet Sarda Senior Consultant Microsoft Corporation SESSION CODE: WCL302.
Bob Beauchemin Developer Skills Partner SQLskills SESSION CODE: DAT402.
Olivier Bloch Technical Evangelist Microsoft Corporation SESSION CODE: WEM308.
Richard Campbell Co-Founder Strangeloop Networks SESSION CODE: WEB315.
By: Paul D. Sheriff or SESSION CODE: DEV320.
Kate Gregory Gregory Consulting SESSION CODE: DEV316.
Reza Chitsaz Senior Program Manager Microsoft Corporation SESSION CODE: DEV302 Building a SharePoint Collaboration Application in Visual Studio 2010.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Andrew Connell, MVP Developer, Instructor & Author Critical Path Training, LLC. SESSION CODE: OSP305.
Introducing Visual Studio 2010: What It Is and Why You Should Care
Pat Altimore Sr. Consultant Microsoft Corporation SESSION CODE: WCL321.
David Ollason Lead Program Manager Microsoft Corporation SESSION CODE: UNC322 The New Communicator “14” Platform.
BIO202 | Building Effective Data Visualizations and Maps with Microsoft SQL Server 2008 Reporting Services BIU08-INT | Using.
Ted Pattison Author / Instructor Critical Path Training SESSION CODE: OSP315.
Martin Woodward Program Manager Microsoft Corporation SESSION CODE: DEV308.
CPSC 481 – Week #7 Sowmya Somanath
Don Jones Senior Partner and Technologist Concentrated Technology, LLC SESSION CODE: DAT203.
Jesus Rodriguez Chief Architect, Tellago, Inc Microsoft Architect Advisor Microsoft MVP Oracle SOA ACE SESSION CODE: DEV406.
SESSION CODE: COS301. So what do we do?
David A. Carley Senior SDE Microsoft Corporation SESSION CODE: DEV318.
Introduction to OpenGL
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
By: Paul D. Sheriff or SESSION CODE: WCL206.
Brian A. Randell Senior Consultant MCW Technologies SESSION CODE: DEV311.
Christophe Fiessinger & Jan Kalis Senior Technical Product Manager Microsoft Corporation SESSION CODE: OSP209.
Aaron Skonnard President/CEO, Pluralsight SESSION CODE: ASI312.
REC [ ] How to implement CAMERA RECORDING for USB WEBCAM or IP CAMERA in C#.NET SOURCE CODE: ! Welcome to this presentation that explains.
Ken Getz Senior Consultant MCW Technologies, LLC SESSION CODE: WCL202.
Tobias Ternstrom Senior Program Manager Lead SQL Server Engine SESSION CODE: DAT404.
Luke Hoban Senior Program Manager Microsoft Corporation SESSION CODE: DEV307.
Richard Hundhausen President, Accentient, Inc. Visual Studio ALM MVP SESSION CODE: DEV312.
Miguel A. Castro Architect IDesign SESSION CODE: WEB310.
Andrew Connell, MVP Developer, Instructor & Author Critical Path Training, LLC. SESSION CODE: OSP319.
Douglas Boling President Boling Consulting Inc. SESSION CODE: WEM303.
Stephen Forte Chief Strategy Officer Telerik stephenforte.net SESSION CODE: DEV303 Building Data Driven RESTful Applications.
Microsoft SharePoint Conference 2009 Jon Flanders
Tech Ed North America /6/2019 2:07 PM Required Slide
Presentation transcript:

Andy Wigley Device Application Development MVP APPA Mundi Ltd SESSION CODE: WEM309

private void Button1_Click(object sender, RoutedEventArgs e) { // Turn screen background red this.LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0)); }

// Locate the button in the object tree IXRButtonPtr pButton; pVisualHost->GetRootElement(&pRootElement); FindName(pRootElement, L"Button1", IID_IAXButton, &pButton); // Add OnClick Event handler pButton->AddClickEventHandler(CreateDelegate(pEventHandler, &EventHandler::OnButtonClick)); … class EventHandler { public: HRESULT OnButtonClick(IAXDependencyObject* pSender, AXEventArgs* pArgs) { // Do something when the user clicks the button… }

C:\Projects\SWETest> xaml2cpp Page.xamlC:\Projects\SWETest> xaml2cpp Page.xaml XAML2CPP version XAML2CPP version C:\Projects\SWETest>

// ========================================================================== // WinMain – Application control logic for the native SWE app // ========================================================================== INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hInstPrev*/, LPWSTR /*lpCmdLine*/, int /*nShowCmd*/) { App AppInstance; HRESULT hr = AppInstance.Initialize(hInstance); if(SUCCEEDED(hr)) { hr = AppInstance.Run(); } return AppInstance.GetWinMainResultCode(); }

HRESULT MainPage::OnLoaded(__in IXRDependencyObject* pRoot) { UNREFERENCED_PARAMETER(pRoot); HRESULT hr = InitializeComponent(); // Add calls to FindName or Add___EventHandler() methods after this comment. if (m_pMyButton) { m_pMyButton->AddClickEventHandler( CreateDelegate(this, &MainPage::OnButtonClick)); } return hr; } // OnLoaded

// =========================================================================== // OnButtonClick // Description: Event handler implementation // // Parameters: pSender - The dependency object that raised the click event. // pArgs - Event specific arguments. // =========================================================================== HRESULT MainPage::OnButtonClick (IXRDependencyObject* pSender, XRMouseButtonEventArgs* pArgs) { HRESULT hr = E_NOTIMPL; if ((NULL == pSender) || (NULL == pArgs)) { hr = E_INVALIDARG; } return hr; }

Native DLL Managed EXE Page Click Me Textbox

#ifdef SWENATIVE_EXPORTS #define SWENATIVE_API __declspec(dllexport) #else #define SWENATIVE_API __declspec(dllimport) #endif extern "C" SWENATIVE_API int RunXamlUI(); extern "C" SWENATIVE_API int GetControlText(LPWSTR lName, BSTR* pValue); extern "C" SWENATIVE_API int SetControlText(LPWSTR lName, LPWSTR lValue); extern "C" SWENATIVE_API int StartStoryboard(LPWSTR lName);

HINSTANCE hDll; static App *app; BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: hDll = (HINSTANCE)hModule; // Save the HINSTANCE handle of the dll break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } extern "C" SWENATIVE_API int RunXamlUI() // Start the XAML UI { app = new App(); if (FAILED(app->Initialize(hDll))) return -1; // Call Initialize passing HINSTANCE of the dll if (FAILED(app->Run())) return -1; // Run doesn’t return until XAML UI exits return 0; }

using System.Runtime.InteropServices; namespace ManagedConsoleHost { class Program { [DllImport("SWEnative.dll")] static extern int RunXamlUI(); static void Main(string[] args) { // Call the native method to run the UI RunXamlUI(); }

// This in SWEnative.h. Callback function prototype typedef void (CALLBACK *CLICKCALLBACK)(LPWSTR lParam); // Modify the RunXamlUI function to accept a parameter that specifies the callback extern "C" SWENATIVE_API int RunXamlUI(CLICKCALLBACK callback); extern "C" SWENATIVE_API int RunXamlUI(CLICKCALLBACK callback) { app = new App(); app->ClickCallback = callback; // Save the callback function for later …

// This in MainPage.cpp: Declare event handler in UI class // ============================================================================ // OnButtonClick // // Description: Event handler implementation // Parameters: pSender - The dependency object that raised the click event. // pArgs - Event specific arguments. // ============================================================================ HRESULT MainPage::OnButtonClick (IXRDependencyObject* pSender, XRMouseButtonEventArgs* pArgs) { if (App::ClickCallback != NULL) { BSTR controlName; pSender->GetName(&controlName); // Call the callback function, passing the name of the control raising the event App::ClickCallback((LPWSTR)controlName); } return S_OK; }

using System.Runtime.InteropServices; namespace SWEManagedHost { class Program { [DllImport("SWEnative.dll")] static extern int RunXamlUI(ClickCallBackDelegate cbdele); // Declare a delegate that matches the signature of the native CALLBACK public delegate void ClickCallBackDelegate(StringBuilder msg); // Make this a static - to make sure // that the function pointer doesn't get garbage collected later on static ClickCallBackDelegate cbdele; // Continued…

static void Main(string[] args) { // Declare the delegate to the callback function cbdele = new ClickCallBackDelegate(SilverlightClickEventHandler); // Call the native method to start up the UI, passing the delegate RunXamlUI(cbdele); } // Event handler executes when called from native private void SilverlightClickEventHandler(StringBuilder msg) { MessageBox.Show("Click from Silverlight, control name: " + msg.ToString); }

Native DLL Managed EXE Page Textbox Click Me Get Start/Stop Set

Model – View – Presenter design pattern View1View2 Presenter logic Model - data Interface

SLNative.lib

Control View Button TextBox Others… View Framework App code Application logic SLNative.lib Native Managed

public class SampleApplicationView : SLBaseView { private Appamundi.Windows.Controls.Button helloButton = null; private Appamundi.Windows.Controls.TextBox txtForename = null; private Appamundi.Windows.Controls.TextBox txtSurname = null; public SampleApplicationView(BaseShell shell):base(shell) { InitializeView(); // Create control objects that are proxies for those created in XAML helloButton = new Appamundi.Windows.Controls.Button("btnSayHello", this); txtForename = new Appamundi.Windows.Controls.TextBox("txtForename", this); txtSurname = new Appamundi.Windows.Controls.TextBox("txtSurname", this); helloButton.Click += new EventHandler( (s, a) => { txtForename.Text = "Vladimir"; // Set a control property MessageBox.Show("Hello " + txtForename.Text + " " + txtSurname.Text); }); }

<UserControl xmlns= xmlns:x= xmlns:xr="clr-namespace:EmbeddedXamlRuntime" x:Class="SimpleSLapp.Page" Width="640" Height="480" Background="#FFC42929"> <xr:Win32Control x:Name="WinFormTest" Height="200" Width="200" HorizontalAlignment="Left" Margin="203,0,237,23“ VerticalAlignment="Bottom" />

int ShowWin32Control(HWND win32Handle) { HRESULT retcode; IXRWin32ControlPtr pIWin32Ctl; // Find the placeholder IXRWin32Control control in the Silverlight object tree if (FAILED(retcode=root->FindName(L"WinFormTest",&pIWin32Ctl))) return retcode; // Swap the handle of the found control with the one of the Win32 control pIWin32Ctl->SetHandle(win32Handle, false); // The Win32 control is now represented in the visual tree // and is integrated with the on-screen layout of peer controls in the window. // activate the visual host window and repaint the changed portion HWND HostWindow = NULL; GetVisualHost()->GetContainerHWND(&HostWindow); ShowWindow(HostWindow, SW_SHOW); UpdateWindow(HostWindow); return 0; }

public partial class Form1 : Form { [DllImport("SWEnative.dll")] static extern int ShowWinFormControl(IntPtr handle);... private void SilverlightClickEventHandler(StringBuilder msg) { // Create an instance of the winforms user control we want to // plug into the Silverlight display UserControl1 uc = new UserControl1(); uc.Visible = true; // Tell the Silverlight UI about it and it will display it ShowWinFormControl(uc.Handle); }

Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31 st You can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year