Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:develop_a_noah_fitting_module_using_.net [2011/07/06 12:16]
smayr [GUI]
swdev:dotnet:develop_a_noah_fitting_module_using_.net [2017/01/20 11:56] (current)
smayr [Noah Fitting Module Logo (assembly Noah3.FitMod.Logo.dll)]
Line 218: Line 218:
   * Create C++ MFC (Microsoft Foundation Class) application project.   * Create C++ MFC (Microsoft Foundation Class) application project.
   * Build application.   * Build application.
-  * Register COM server by executing the generated executable file.  It generates an error "This server can only be run from a container application.", but just ignore it.  Eg: <code dos>C:\> C:\Program Files\MyApp\FitMod.exe</code> This should create the following registry entries: <code reg>+  * Register COM server (select one method): 
 +    * By selecting checkbox "Register for COM interop" in project Properties > Build (tab) > Output. 
 +    * By executing the generated executable file.  It generates an error "This server can only be run from a container application.", but just ignore it.  Eg: <code dos>C:\> C:\Program Files\MyApp\FitMod.exe</code> This should create the following registry entries: <code reg>
 REGEDIT REGEDIT
 ; This .REG file may be used by your SETUP program. ; This .REG file may be used by your SETUP program.
Line 246: Line 248:
 HKEY_CLASSES_ROOT\CLSID\{241255F6-0B94-4EBE-993A-030A8A4968FE}\InprocHandler32 = ole32.dll HKEY_CLASSES_ROOT\CLSID\{241255F6-0B94-4EBE-993A-030A8A4968FE}\InprocHandler32 = ole32.dll
 </code> </code>
-=== GUI Wrapper ===+ 
 + 
 +=== GUI Wrapper (assembly Noah3.FitMod.GUI.dll) ===
   * Create a C# WinForms project.   * Create a C# WinForms project.
   * Create a WinForms user control which will host the WPF GUI control. Eg: <code csharp>   * Create a WinForms user control which will host the WPF GUI control. Eg: <code csharp>
Line 298: Line 302:
 </code> </code>
   * Structure code to deal with resources correctly when WPF is hosted in WinForms control (see [[http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/|Dr WPF: Managing Application Resources When WPF is Hosted]]).   * Structure code to deal with resources correctly when WPF is hosted in WinForms control (see [[http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/|Dr WPF: Managing Application Resources When WPF is Hosted]]).
-=== GUI (Noah3.FitMod.GUI.dll) ===+ 
 + 
 +=== GUI ===
   * Create a C# WPF project.   * Create a C# WPF project.
   * Add references to project:   * Add references to project:
Line 305: Line 311:
   * Create a WPF user control with all the required functionality.    * Create a WPF user control with all the required functionality. 
     * If using custom styles, load them from ''AHI.App.Resources.dll''     * If using custom styles, load them from ''AHI.App.Resources.dll''
 +  * Register control or application with Noah Module Server. Typically the GUI control would call the AppViewModel to do so. Eg: The GUI code: <code csharp>
 +// Connect
 +TAppViewModel AppVM = new TAppViewModel();
 +AppVM.ApplicationExecMode = TAppExecMode.Noah;
 +AppVM.cmdOpenNoahConnection();
 +
 +// Do work...
 +. . .
 +// Disconnect
 +AppVM.cmdCloseNoahConnection();
 +</code> The ''AppViewMode.cs'' methods:<code csharp>
 +///----------------------------------------------------------------------------------------
 +/// <summary>
 +/// Register with Noah.
 +/// </summary>
 +///----------------------------------------------------------------------------------------
 +private void cmdOpenNoahConnection()
 +{
 +    if (m_ApplicationExecMode == TAppExecMode.Noah)
 +    {
 +        // Initialize the module server and register the module with module server.
 +        TAppLog.LogMessage("TAppViewModel.cmdOpenNoahConnection", "ApplicationExecMode = Noah.");
 +        TAppLog.LogMessage("TAppViewModel.cmdOpenNoahConnection", "Initializing NoahApp...");
 +        m_NoahApp = new TNoahApp();
 +    }
 +    else
 +    {
 +        TAppLog.LogMessage("TAppViewModel.cmdOpenNoahConnection", "ApplicationExecMode = Stand-alone.");
 +    }
 +}  
 +
 +///----------------------------------------------------------------------------------------
 +/// <summary>
 +/// Close the Noah connection before closing application.
 +/// </summary>
 +///----------------------------------------------------------------------------------------
 +public void cmdCloseNoahConnection()
 +{
 +    TAppLog.LogMessage("TAppViewModel.cmdClose", "Start.");
 +
 +    if (m_ApplicationExecMode == TAppExecMode.Noah)
 +    {
 +        TAppLog.LogMessage("TAppViewModel.cmdCloseNoahConnection", "ApplicationExecMode = Noah.");
 +
 +        // Close the module server and unregister the module with module server.
 +        if (m_NoahApp != null)
 +        {
 +            TAppLog.LogMessage("TAppViewModel.cmdCloseNoahConnection", "Calling NoahApp.cmdClose()...");
 +            m_NoahApp.cmdClose();
 +        }
 +    }
 +    else
 +    {
 +        TAppLog.LogMessage("TAppViewModel.cmdCloseNoahConnection", "ApplicationExecMode = Stand-alone.");
 +    }
 +
 +    TAppLog.LogMessage("TAppViewModel.cmdCloseNoahConnection", "End.");
 +}
 +</code>
  
 === Noah Fitting Module Library (assembly AHI.App.Noah.dll) === === Noah Fitting Module Library (assembly AHI.App.Noah.dll) ===
Line 323: Line 388:
     * ''GetCurrentAction()'': Get current action information.     * ''GetCurrentAction()'': Get current action information.
  
 +=== Noah Fitting Module Logo (assembly Noah3.FitMod.Logo.dll) === 
 +  * Create Class (assembly) project. 
 +  * Create ''LogoRes.rc'' resource file (for more details: [[swdev:howto:develop_a_noah_fitting_module#fitting_module_icon_logodll|Logo Format]]).  NOTE: Do not ''#define'' the ''LOGO001'' and ''LOGO002'' resources.  Create file as follows: <code> 
 +LOGO001      BITMAP "images/logo16.bmp" 
 +LOGO002      BITMAP "images/logo256.bmp" 
 +STRINGTABLE 
 +
 +  1001, "Acme" 
 +
 +</code> 
 +  * Compile resource file ''LogoRes.rc'' into ''LogoRes.res'' Using the Visual Studio Command Prompt (VS2015: Start > All Applications > Visual Studio 2015 > Visual Studio Tools > Developer Command Prompt for VS2015): <code dos>C:\> rc C:\MyApp\LogoRes.rc </code> 
 +  * Alternatively, use GoRC Resource Compiler ([[http://www.godevtool.com]]) from any command prompt: <code dos>C:\> GoRC.exe C:\MyApp\LogoRes.rc</code> 
 +  * Add res file to assembly.  Project > Properties > Application (tab) > Resource File, and select ''LogoRes.res''
 +  * Build assembly.