Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/interfaces/implementation/src/G4UIWin32.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /interfaces/implementation/src/G4UIWin32.cc (Version 11.3.0) and /interfaces/implementation/src/G4UIWin32.cc (Version 11.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // Original author: G.Barrand, 1998                26 // Original author: G.Barrand, 1998
 27 // Rewrite: O.Pena-Rodriguez, March 2021           27 // Rewrite: O.Pena-Rodriguez, March 2021
 28 // -------------------------------------------     28 // --------------------------------------------------------------------
 29                                                    29 
 30 #include "G4UIWin32.hh"                            30 #include "G4UIWin32.hh"
 31                                                    31 
 32 #include "G4MTcoutDestination.hh"                  32 #include "G4MTcoutDestination.hh"
 33 #include "G4StateManager.hh"                       33 #include "G4StateManager.hh"
 34 #include "G4UIcommand.hh"                          34 #include "G4UIcommand.hh"
 35 #include "G4UIcommandTree.hh"                      35 #include "G4UIcommandTree.hh"
 36 #include "G4UImanager.hh"                          36 #include "G4UImanager.hh"
 37 #include "G4Win32.hh"                              37 #include "G4Win32.hh"
 38                                                    38 
 39 #include <commctrl.h>                              39 #include <commctrl.h>
 40 #include <windows.h>                               40 #include <windows.h>
 41 #include <wingdi.h>                                41 #include <wingdi.h>
 42                                                    42 
 43 #include <cstring>                                 43 #include <cstring>
 44 #include <utility>                                 44 #include <utility>
 45                                                    45 
 46 /*********************************************     46 /***************************************************************************/
 47 static char mainClassName[] = "G4UIWin32";         47 static char mainClassName[] = "G4UIWin32";
 48 static G4bool exitSession = true;                  48 static G4bool exitSession = true;
 49 static G4bool exitPause = true;                    49 static G4bool exitPause = true;
 50 static G4bool exitHelp = true;                     50 static G4bool exitHelp = true;
 51 static G4UIsession* tmpSession = nullptr;          51 static G4UIsession* tmpSession = nullptr;
 52                                                    52 
 53 // Original wndproc for the Combo Editor           53 // Original wndproc for the Combo Editor
 54 static WNDPROC origComboEditorWindowProc;          54 static WNDPROC origComboEditorWindowProc;
 55                                                    55 
 56 static G4bool ConvertStringToInt(const char*,      56 static G4bool ConvertStringToInt(const char*, G4int&);
 57                                                    57 
 58 static G4int actionIdentifier = 0;                 58 static G4int actionIdentifier = 0;
 59                                                    59 
 60 /*********************************************     60 /****************************************************************************************************/
 61 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     61 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
 62 G4UIWin32::G4UIWin32()                             62 G4UIWin32::G4UIWin32()
 63   : fHWndMainWindow(nullptr),                      63   : fHWndMainWindow(nullptr),
 64     fHWndEditor(nullptr),                          64     fHWndEditor(nullptr),
 65     fHWndToolBar(nullptr),                         65     fHWndToolBar(nullptr),
 66     fHWndComboBox(nullptr),                        66     fHWndComboBox(nullptr),
 67     fHWndComboEditor(nullptr),                     67     fHWndComboEditor(nullptr),
 68     fHWndHelpTree(nullptr),                        68     fHWndHelpTree(nullptr),
 69     fHWndStatus(nullptr),                          69     fHWndStatus(nullptr),
 70     menuBar(nullptr),                              70     menuBar(nullptr),
 71     fHelp(false),                                  71     fHelp(false),
 72     fHelpChoice(0),                                72     fHelpChoice(0),
 73     fHistoryPos(-1)                                73     fHistoryPos(-1)
 74 {                                                  74 {
 75   G4UImanager* UI = G4UImanager::GetUIpointer(     75   G4UImanager* UI = G4UImanager::GetUIpointer();
 76   if (UI != nullptr) {                             76   if (UI != nullptr) {
 77     UI->SetSession(this);                          77     UI->SetSession(this);
 78     UI->SetG4UIWindow(this);                       78     UI->SetG4UIWindow(this);
 79   }                                                79   }
 80                                                    80 
 81   // Ensure that the common control DLL is loa     81   // Ensure that the common control DLL is loaded
 82   INITCOMMONCONTROLSEX commCtrls;                  82   INITCOMMONCONTROLSEX commCtrls;
 83   commCtrls.dwSize = sizeof(INITCOMMONCONTROLS     83   commCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
 84   commCtrls.dwICC = ICC_BAR_CLASSES | ICC_LIST     84   commCtrls.dwICC = ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES;
 85   // this loads list-view and toolbar classes.     85   // this loads list-view and toolbar classes.
 86   InitCommonControlsEx(&commCtrls);                86   InitCommonControlsEx(&commCtrls);
 87                                                    87 
 88   interactorManager = G4Win32::getInstance();      88   interactorManager = G4Win32::getInstance();
 89                                                    89 
 90   static G4bool Done = false;                      90   static G4bool Done = false;
 91   if (! Done) {                                    91   if (! Done) {
 92     WNDCLASS wc;                                   92     WNDCLASS wc;
 93     wc.style = 0;                                  93     wc.style = 0;
 94     wc.lpfnWndProc = (WNDPROC)G4UIWin32::MainW     94     wc.lpfnWndProc = (WNDPROC)G4UIWin32::MainWindowProc;
 95     wc.cbClsExtra = 0;                             95     wc.cbClsExtra = 0;
 96     wc.cbWndExtra = 0;                             96     wc.cbWndExtra = 0;
 97     wc.hInstance = ::GetModuleHandle(nullptr);     97     wc.hInstance = ::GetModuleHandle(nullptr);
 98     wc.hIcon = LoadIcon(nullptr, IDI_APPLICATI     98     wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
 99     wc.hCursor = LoadCursor(nullptr, IDC_ARROW     99     wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
100     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW +    100     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
101     wc.lpszMenuName = (PTSTR)mainClassName;    << 101     wc.lpszMenuName = mainClassName;
102     wc.lpszClassName = (PTSTR)mainClassName;   << 102     wc.lpszClassName = mainClassName;
103                                                   103 
104     if (! RegisterClass(&wc)) {                   104     if (! RegisterClass(&wc)) {
105       MessageBoxA(nullptr, "G4UIWin32: Win32 w << 105       MessageBox(nullptr, "G4UIWin32: Win32 window registration failed!", "Error!",
106         MB_ICONEXCLAMATION | MB_OK);              106         MB_ICONEXCLAMATION | MB_OK);
107       G4cout << "G4UIWin32: Win32 window regis    107       G4cout << "G4UIWin32: Win32 window registration failed!" << G4endl;
108       return;                                     108       return;
109     }                                             109     }
110                                                   110 
111     Done = true;                                  111     Done = true;
112   }                                               112   }
113                                                   113 
114   menuBar = CreateMenu();                         114   menuBar = CreateMenu();
115                                                   115 
116   // Add some initial options to the menu         116   // Add some initial options to the menu
117   HMENU hMenu = CreatePopupMenu();                117   HMENU hMenu = CreatePopupMenu();
118   AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)hMe << 118   AppendMenu(menuBar, MF_POPUP, (UINT_PTR)hMenu, "&Geant4");
119   AddInteractor("Geant4", (G4Interactor)hMenu)    119   AddInteractor("Geant4", (G4Interactor)hMenu);
120                                                   120 
121   AppendMenuA(hMenu, MF_STRING, ID_OPEN_MACRO, << 121   AppendMenu(hMenu, MF_STRING, ID_OPEN_MACRO, "&Open macro...");
122   AppendMenuA(hMenu, MF_STRING, ID_SAVE_VIEWER << 122   AppendMenu(hMenu, MF_STRING, ID_SAVE_VIEWER_STATE, "&Save viewer state...");
123   AppendMenuA(hMenu, MF_SEPARATOR, -1, "");    << 123   AppendMenu(hMenu, MF_SEPARATOR, -1, "");
124   AppendMenuA(hMenu, MF_STRING, ID_RUN_BEAMON, << 124   AppendMenu(hMenu, MF_STRING, ID_RUN_BEAMON, "&Beam On");
125   AppendMenuA(hMenu, MF_SEPARATOR, -1, "");    << 125   AppendMenu(hMenu, MF_SEPARATOR, -1, "");
126   AppendMenuA(hMenu, MF_STRING, ID_EXIT_APP, " << 126   AppendMenu(hMenu, MF_STRING, ID_EXIT_APP, "E&xit");
127                                                   127 
128   hMenu = CreatePopupMenu();                      128   hMenu = CreatePopupMenu();
129   AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)hMe << 129   AppendMenu(menuBar, MF_POPUP, (UINT_PTR)hMenu, "&View");
130   AddInteractor("View", (G4Interactor)hMenu);     130   AddInteractor("View", (G4Interactor)hMenu);
131                                                   131 
132   AppendMenuA(hMenu, MF_STRING, ID_VIEW_SOLID, << 132   AppendMenu(hMenu, MF_STRING, ID_VIEW_SOLID, "S&olid");
133   AppendMenuA(hMenu, MF_STRING, ID_VIEW_WIREFR << 133   AppendMenu(hMenu, MF_STRING, ID_VIEW_WIREFRAME, "&Wireframe");
134   AppendMenuA(hMenu, MF_SEPARATOR, -1, "");    << 134   AppendMenu(hMenu, MF_SEPARATOR, -1, "");
135   AppendMenuA(hMenu, MF_STRING, ID_PROJ_ORTHOG << 135   AppendMenu(hMenu, MF_STRING, ID_PROJ_ORTHOGRAPHIC, "&Orthographic");
136   AppendMenuA(hMenu, MF_STRING, ID_PROJ_PERSPE << 136   AppendMenu(hMenu, MF_STRING, ID_PROJ_PERSPECTIVE, "P&erspective");
137   AppendMenuA(hMenu, MF_SEPARATOR, -1, "");    << 137   AppendMenu(hMenu, MF_SEPARATOR, -1, "");
138   AppendMenuA(hMenu, MF_STRING, ID_ORIENTATION << 138   AppendMenu(hMenu, MF_STRING, ID_ORIENTATION_XY, "&X-Y Plane");
139   AppendMenuA(hMenu, MF_STRING, ID_ORIENTATION << 139   AppendMenu(hMenu, MF_STRING, ID_ORIENTATION_XZ, "X-&Z Plane");
140   AppendMenuA(hMenu, MF_STRING, ID_ORIENTATION << 140   AppendMenu(hMenu, MF_STRING, ID_ORIENTATION_YZ, "&Y-Z Plane");
141   AppendMenuA(hMenu, MF_STRING, ID_ORIENTATION << 141   AppendMenu(hMenu, MF_STRING, ID_ORIENTATION_OBLIQUE, "&Oblique");
142                                                   142 
143   hMenu = CreatePopupMenu();                      143   hMenu = CreatePopupMenu();
144   AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)hMe << 144   AppendMenu(menuBar, MF_POPUP, (UINT_PTR)hMenu, "&Zoom");
145   AddInteractor("Zoom", (G4Interactor)hMenu);     145   AddInteractor("Zoom", (G4Interactor)hMenu);
146                                                   146 
147   AppendMenuA(hMenu, MF_STRING, ID_ZOOM_IN, "Z << 147   AppendMenu(hMenu, MF_STRING, ID_ZOOM_IN, "Zoom &In");
148   AppendMenuA(hMenu, MF_STRING, ID_ZOOM_OUT, " << 148   AppendMenu(hMenu, MF_STRING, ID_ZOOM_OUT, "Zoom &Out");
149                                                   149 
150   tmpSession = this;                              150   tmpSession = this;
151   char winName[] = "Geant4";                   << 151   fHWndMainWindow = ::CreateWindowEx(WS_EX_CLIENTEDGE, mainClassName, "Geant4",
152   fHWndMainWindow = ::CreateWindowEx(WS_EX_CLI << 
153     WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_    152     WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
154     CW_USEDEFAULT, nullptr, menuBar, ::GetModu    153     CW_USEDEFAULT, nullptr, menuBar, ::GetModuleHandle(nullptr), nullptr);
155                                                   154 
156   if (fHWndMainWindow == nullptr) {               155   if (fHWndMainWindow == nullptr) {
157     MessageBoxA(nullptr, "Window Creation Fail << 156     MessageBox(nullptr, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
158     return;                                       157     return;
159   }                                               158   }
160   tmpSession = nullptr;                           159   tmpSession = nullptr;
161   ::SetWindowLongPtr(fHWndMainWindow, GWLP_USE    160   ::SetWindowLongPtr(fHWndMainWindow, GWLP_USERDATA, (LONG_PTR)this);
162                                                   161 
163   ::SetForegroundWindow(fHWndMainWindow);         162   ::SetForegroundWindow(fHWndMainWindow);
164   ::ShowWindow(fHWndMainWindow, SW_SHOWDEFAULT    163   ::ShowWindow(fHWndMainWindow, SW_SHOWDEFAULT);
165   ::UpdateWindow(fHWndMainWindow);                164   ::UpdateWindow(fHWndMainWindow);
166                                                   165 
167   if (UI != nullptr) UI->SetCoutDestination(th    166   if (UI != nullptr) UI->SetCoutDestination(this);
168                                                   167 
169   // TODO: Manage multithreaded output            168   // TODO: Manage multithreaded output
170   // #ifdef G4MULTITHREADED                       169   // #ifdef G4MULTITHREADED
171   // explicitly request that cout/cerr message    170   // explicitly request that cout/cerr messages from threads are ALSO propagated to the master.
172   // masterG4coutDestination = this;              171   // masterG4coutDestination = this;
173   // #endif                                       172   // #endif
174 }                                                 173 }
175 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    174 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
176 /*********************************************    175 /****************************************************************************************************/
177                                                   176 
178 /*********************************************    177 /****************************************************************************************************/
179 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    178 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
180 G4UIWin32::~G4UIWin32()                           179 G4UIWin32::~G4UIWin32()
181 {                                                 180 {
182   G4UImanager* UI = G4UImanager::GetUIpointer(    181   G4UImanager* UI = G4UImanager::GetUIpointer();
183   if (UI != nullptr) {                            182   if (UI != nullptr) {
184     UI->SetSession(nullptr);                      183     UI->SetSession(nullptr);
185     UI->SetG4UIWindow(nullptr);                   184     UI->SetG4UIWindow(nullptr);
186     UI->SetCoutDestination(nullptr);              185     UI->SetCoutDestination(nullptr);
187   }                                               186   }
188                                                   187 
189   // TODO: Manage multithreaded output            188   // TODO: Manage multithreaded output
190   // #ifdef G4MULTITHREADED                       189   // #ifdef G4MULTITHREADED
191   // masterG4coutDestination = 0; // set to co    190   // masterG4coutDestination = 0; // set to cout when UI is deleted
192   // #endif                                       191   // #endif
193                                                   192 
194   if (fHWndStatus != nullptr) ::SetWindowLongP    193   if (fHWndStatus != nullptr) ::SetWindowLongPtr(fHWndStatus, GWLP_USERDATA, LONG(NULL));
195   if (fHWndHelpTree != nullptr) ::SetWindowLon    194   if (fHWndHelpTree != nullptr) ::SetWindowLongPtr(fHWndHelpTree, GWLP_USERDATA, LONG(NULL));
196   if (fHWndComboBox != nullptr) ::SetWindowLon    195   if (fHWndComboBox != nullptr) ::SetWindowLongPtr(fHWndComboBox, GWLP_USERDATA, LONG(NULL));
197   if (fHWndToolBar != nullptr) ::SetWindowLong    196   if (fHWndToolBar != nullptr) ::SetWindowLongPtr(fHWndToolBar, GWLP_USERDATA, LONG(NULL));
198   if (fHWndEditor != nullptr) ::SetWindowLongP    197   if (fHWndEditor != nullptr) ::SetWindowLongPtr(fHWndEditor, GWLP_USERDATA, LONG(NULL));
199   if (fHWndMainWindow != nullptr) {               198   if (fHWndMainWindow != nullptr) {
200     ::SetWindowLongPtr(fHWndMainWindow, GWLP_U    199     ::SetWindowLongPtr(fHWndMainWindow, GWLP_USERDATA, LONG(NULL));
201     ::DestroyWindow(fHWndMainWindow);             200     ::DestroyWindow(fHWndMainWindow);
202   }                                               201   }
203 }                                                 202 }
204 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    203 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
205 /*********************************************    204 /****************************************************************************************************/
206                                                   205 
207 /*********************************************    206 /****************************************************************************************************/
208 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    207 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
209 G4UIsession* G4UIWin32::SessionStart()            208 G4UIsession* G4UIWin32::SessionStart()
210 {                                                 209 {
211   if (interactorManager != nullptr) {             210   if (interactorManager != nullptr) {
212     Prompt("session");                            211     Prompt("session");
213     exitSession = false;                          212     exitSession = false;
214                                                   213 
215     // TODO: Ensure that the list of commands     214     // TODO: Ensure that the list of commands is updated
216     // Load commands into Help Tree View          215     // Load commands into Help Tree View
217     InitHelpTreeItems();                          216     InitHelpTreeItems();
218                                                   217 
219     interactorManager->DisableSecondaryLoop();    218     interactorManager->DisableSecondaryLoop();
220     void* event;                                  219     void* event;
221     while ((event = interactorManager->GetEven    220     while ((event = interactorManager->GetEvent()) != nullptr) {
222       interactorManager->DispatchEvent(event);    221       interactorManager->DispatchEvent(event);
223       if (exitSession) break;                     222       if (exitSession) break;
224     }                                             223     }
225     interactorManager->EnableSecondaryLoop();     224     interactorManager->EnableSecondaryLoop();
226     return this;                                  225     return this;
227   }                                               226   }
228   else                                            227   else
229     return this;                                  228     return this;
230 }                                                 229 }
231 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    230 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
232 /*********************************************    231 /****************************************************************************************************/
233                                                   232 
234 /*********************************************    233 /****************************************************************************************************/
235 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    234 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
236 void G4UIWin32::Prompt(const G4String& a_promp    235 void G4UIWin32::Prompt(const G4String& a_prompt) {}
237 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    236 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
238 /*********************************************    237 /****************************************************************************************************/
239                                                   238 
240 /*********************************************    239 /****************************************************************************************************/
241 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    240 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
242 void G4UIWin32::SessionTerminate() {}             241 void G4UIWin32::SessionTerminate() {}
243 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    242 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
244 /*********************************************    243 /****************************************************************************************************/
245                                                   244 
246 /*********************************************    245 /****************************************************************************************************/
247 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    246 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
248 void G4UIWin32::PauseSessionStart(const G4Stri    247 void G4UIWin32::PauseSessionStart(const G4String& a_state)
249 {                                                 248 {
250   if (a_state == "G4_pause> ") {                  249   if (a_state == "G4_pause> ") {
251     SecondaryLoop("Pause, type continue to exi    250     SecondaryLoop("Pause, type continue to exit this state");
252   }                                               251   }
253                                                   252 
254   if (a_state == "EndOfEvent") {                  253   if (a_state == "EndOfEvent") {
255     // Picking with feed back in event data Do    254     // Picking with feed back in event data Done here !!!
256     SecondaryLoop("End of event, type continue    255     SecondaryLoop("End of event, type continue to exit this state");
257   }                                               256   }
258 }                                                 257 }
259 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    258 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
260 /*********************************************    259 /****************************************************************************************************/
261                                                   260 
262 /*********************************************    261 /****************************************************************************************************/
263 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    262 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
264 void G4UIWin32::SecondaryLoop(const G4String&     263 void G4UIWin32::SecondaryLoop(const G4String& a_prompt)
265 {                                                 264 {
266   if (interactorManager != nullptr) {             265   if (interactorManager != nullptr) {
267     Prompt(a_prompt);                             266     Prompt(a_prompt);
268     exitPause = false;                            267     exitPause = false;
269     void* event;                                  268     void* event;
270     while ((event = interactorManager->GetEven    269     while ((event = interactorManager->GetEvent()) != nullptr) {
271       interactorManager->DispatchEvent(event);    270       interactorManager->DispatchEvent(event);
272       if (exitPause) break;                       271       if (exitPause) break;
273     }                                             272     }
274     Prompt("session");                            273     Prompt("session");
275   }                                               274   }
276 }                                                 275 }
277 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    276 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
278 /*********************************************    277 /****************************************************************************************************/
279                                                   278 
280 /*********************************************    279 /****************************************************************************************************/
281 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    280 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
282 G4int G4UIWin32::ReceiveG4debug(const G4String    281 G4int G4UIWin32::ReceiveG4debug(const G4String& a_string)
283 {                                                 282 {
284   // Geant4 uses UNIX's style for new lines (\    283   // Geant4 uses UNIX's style for new lines (\n)
285   // we must convert them to Windows' style (\    284   // we must convert them to Windows' style (\r\n)
286   G4String str = ConvertNewLines(a_string);       285   G4String str = ConvertNewLines(a_string);
287                                                   286 
288   AddText((LPSTR)str.data());                     287   AddText((LPSTR)str.data());
289                                                   288 
290   return 0;                                       289   return 0;
291 }                                                 290 }
292 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    291 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
293 /*********************************************    292 /****************************************************************************************************/
294                                                   293 
295 /*********************************************    294 /****************************************************************************************************/
296 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    295 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
297 G4int G4UIWin32::ReceiveG4cout(const G4String&    296 G4int G4UIWin32::ReceiveG4cout(const G4String& a_string)
298 {                                                 297 {
299   // Geant4 uses UNIX's style for new lines (\    298   // Geant4 uses UNIX's style for new lines (\n)
300   // we must convert them to Windows' style (\    299   // we must convert them to Windows' style (\r\n)
301   G4String str = ConvertNewLines(a_string);       300   G4String str = ConvertNewLines(a_string);
302                                                   301 
303   AddText((LPSTR)str.data());                     302   AddText((LPSTR)str.data());
304                                                   303 
305   return 0;                                       304   return 0;
306 }                                                 305 }
307 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    306 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
308 /*********************************************    307 /****************************************************************************************************/
309                                                   308 
310 /*********************************************    309 /****************************************************************************************************/
311 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    310 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
312 G4int G4UIWin32::ReceiveG4cerr(const G4String&    311 G4int G4UIWin32::ReceiveG4cerr(const G4String& a_string)
313 {                                                 312 {
314   // Geant4 uses UNIX's style for new lines (\    313   // Geant4 uses UNIX's style for new lines (\n)
315   // we must convert them to Windows' style (\    314   // we must convert them to Windows' style (\r\n)
316   G4String str = ConvertNewLines(a_string);       315   G4String str = ConvertNewLines(a_string);
317                                                   316 
318   AddText((LPSTR)str.data());                     317   AddText((LPSTR)str.data());
319                                                   318 
320   return 0;                                       319   return 0;
321 }                                                 320 }
322 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    321 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
323 /*********************************************    322 /****************************************************************************************************/
324                                                   323 
325 /*********************************************    324 /****************************************************************************************************/
326 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    325 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
327 G4bool G4UIWin32::GetHelpChoice(G4int& aInt)      326 G4bool G4UIWin32::GetHelpChoice(G4int& aInt)
328 {                                                 327 {
329   fHelp = true;                                   328   fHelp = true;
330                                                   329 
331   if (interactorManager != nullptr) {             330   if (interactorManager != nullptr) {
332     Prompt("Help");                               331     Prompt("Help");
333     exitHelp = false;                             332     exitHelp = false;
334     void* event;                                  333     void* event;
335     while ((event = interactorManager->GetEven    334     while ((event = interactorManager->GetEvent()) != nullptr) {
336       interactorManager->DispatchEvent(event);    335       interactorManager->DispatchEvent(event);
337       if (exitHelp) break;                        336       if (exitHelp) break;
338     }                                             337     }
339     Prompt("session");                            338     Prompt("session");
340     //                                            339     //
341     if (! fHelp) return false;                    340     if (! fHelp) return false;
342     aInt = fHelpChoice;                           341     aInt = fHelpChoice;
343     fHelp = false;                                342     fHelp = false;
344     return true;                                  343     return true;
345   }                                               344   }
346   else                                            345   else
347     return false;                                 346     return false;
348 }                                                 347 }
349 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    348 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
350 /*********************************************    349 /****************************************************************************************************/
351                                                   350 
352 /*********************************************    351 /****************************************************************************************************/
353 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    352 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
354 void G4UIWin32::ExitHelp() const {}               353 void G4UIWin32::ExitHelp() const {}
355 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    354 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
356 /*********************************************    355 /****************************************************************************************************/
357                                                   356 
358 /*********************************************    357 /****************************************************************************************************/
359 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    358 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
360 void G4UIWin32::AddMenu(const char* a_name, co    359 void G4UIWin32::AddMenu(const char* a_name, const char* a_label)
361 {                                                 360 {
362   if (a_name != nullptr) {                        361   if (a_name != nullptr) {
363     HMENU hMenu = CreatePopupMenu();              362     HMENU hMenu = CreatePopupMenu();
364     AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)h << 363     AppendMenu(menuBar, MF_POPUP, (UINT_PTR)hMenu, a_label);
365     AddInteractor(a_name, (G4Interactor)hMenu)    364     AddInteractor(a_name, (G4Interactor)hMenu);
366     DrawMenuBar(fHWndMainWindow);                 365     DrawMenuBar(fHWndMainWindow);
367   }                                               366   }
368 }                                                 367 }
369 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    368 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
370 /*********************************************    369 /****************************************************************************************************/
371                                                   370 
372 /*********************************************    371 /****************************************************************************************************/
373 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    372 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
374 void G4UIWin32::AddButton(const char* a_menu,     373 void G4UIWin32::AddButton(const char* a_menu, const char* a_label, const char* a_command)
375 {                                                 374 {
376   if ((a_menu != nullptr) && (a_label != nullp    375   if ((a_menu != nullptr) && (a_label != nullptr) && (a_command != nullptr)) {
377     HMENU hMenu = (HMENU)GetInteractor(a_menu)    376     HMENU hMenu = (HMENU)GetInteractor(a_menu);
378     actionIdentifier++;                           377     actionIdentifier++;
379     commands[actionIdentifier] = a_command;       378     commands[actionIdentifier] = a_command;
380     AppendMenuA(hMenu, MF_STRING, actionIdenti << 379     AppendMenu(hMenu, MF_STRING, actionIdentifier, a_label);
381   }                                               380   }
382 }                                                 381 }
383 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    382 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
384 /*********************************************    383 /****************************************************************************************************/
385                                                   384 
386 /*********************************************    385 /****************************************************************************************************/
387 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    386 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
388 G4String G4UIWin32::GetCommand(G4int a_id) { r    387 G4String G4UIWin32::GetCommand(G4int a_id) { return commands[a_id]; }
389 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    388 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
390 /*********************************************    389 /****************************************************************************************************/
391                                                   390 
392 /*********************************************    391 /****************************************************************************************************/
393 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    392 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
394 LRESULT CALLBACK G4UIWin32::MainWindowProc(       393 LRESULT CALLBACK G4UIWin32::MainWindowProc(
395   HWND aWindow, UINT aMessage, WPARAM wParam,     394   HWND aWindow, UINT aMessage, WPARAM wParam, LPARAM lParam)
396 {                                                 395 {
397   switch (aMessage) {                             396   switch (aMessage) {
398     case WM_CREATE: {                             397     case WM_CREATE: {
399       auto* This = (G4UIWin32*)tmpSession;        398       auto* This = (G4UIWin32*)tmpSession;
400       if (This != nullptr) {                      399       if (This != nullptr) {
401         if (! This->CreateComponents(aWindow))    400         if (! This->CreateComponents(aWindow)) {
402           MessageBoxA(aWindow, "Could not crea << 401           MessageBox(aWindow, "Could not create components.", "Error", MB_OK | MB_ICONERROR);
403           return false;                           402           return false;
404         }                                         403         }
405       }                                           404       }
406     }                                             405     }
407       return 0;                                   406       return 0;
408                                                   407 
409     case WM_SIZE: {                               408     case WM_SIZE: {
410       auto* This = (G4UIWin32*)::GetWindowLong    409       auto* This = (G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
411       if (This != nullptr) {                      410       if (This != nullptr) {
412         if (! This->ResizeComponents(aWindow))    411         if (! This->ResizeComponents(aWindow)) {
413           MessageBoxA(aWindow, "Could not resi << 412           MessageBox(aWindow, "Could not resize components.", "Error", MB_OK | MB_ICONERROR);
414           return false;                           413           return false;
415         }                                         414         }
416       }                                           415       }
417     }                                             416     }
418       return 0;                                   417       return 0;
419                                                   418 
420     case WM_CLOSE:                                419     case WM_CLOSE:
421       DestroyWindow(aWindow);                     420       DestroyWindow(aWindow);
422       return 0;                                   421       return 0;
423                                                   422 
424     case WM_DESTROY:                              423     case WM_DESTROY:
425       PostQuitMessage(0);                         424       PostQuitMessage(0);
426       return 0;                                   425       return 0;
427                                                   426 
428     case WM_SETFOCUS: {                           427     case WM_SETFOCUS: {
429       auto* This = (G4UIWin32*)::GetWindowLong    428       auto* This = (G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
430       if (This != nullptr) SetFocus(This->fHWn    429       if (This != nullptr) SetFocus(This->fHWndComboBox);
431     }                                             430     }
432       return 0;                                   431       return 0;
433                                                   432 
434     case WM_NOTIFY: {                             433     case WM_NOTIFY: {
435       auto* This = (G4UIWin32*)::GetWindowLong    434       auto* This = (G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
436       if (This != nullptr) {                      435       if (This != nullptr) {
437         switch (((LPNMHDR)lParam)->code) {        436         switch (((LPNMHDR)lParam)->code) {
438           // Tooltip for Toolbar                  437           // Tooltip for Toolbar
439           case TTN_NEEDTEXT: {                    438           case TTN_NEEDTEXT: {
440             auto lpttt = (LPTOOLTIPTEXT)lParam    439             auto lpttt = (LPTOOLTIPTEXT)lParam;
441             lpttt->hinst = nullptr;               440             lpttt->hinst = nullptr;
442             UINT idButton = lpttt->hdr.idFrom;    441             UINT idButton = lpttt->hdr.idFrom;
443             lpttt->lpszText = (PTSTR)This->Get << 442             lpttt->lpszText = (LPSTR)This->GetToolTips(idButton).c_str();
444           } break;                                443           } break;
445                                                   444 
446           // Tooltip for TreeView                 445           // Tooltip for TreeView
447           case TVN_GETINFOTIP: {                  446           case TVN_GETINFOTIP: {
448             auto pTip = (LPNMTVGETINFOTIP)lPar    447             auto pTip = (LPNMTVGETINFOTIP)lParam;
449             pTip->pszText = (PTSTR)This->GetHe << 448             pTip->pszText = (LPSTR)This->GetHelpTreeToolTips(pTip->hItem).c_str();
450           } break;                                449           } break;
451                                                   450 
452           // Double click for TreeView            451           // Double click for TreeView
453           case NM_DBLCLK: {                       452           case NM_DBLCLK: {
454             auto lpnmh = (LPNMHDR)lParam;         453             auto lpnmh = (LPNMHDR)lParam;
455             auto item = TreeView_GetSelection(    454             auto item = TreeView_GetSelection(lpnmh->hwndFrom);
456             This->HelpTreeDoubleClick(item);      455             This->HelpTreeDoubleClick(item);
457           } break;                                456           } break;
458         }                                         457         }
459       }                                           458       }
460     }                                             459     }
461       return 0;                                   460       return 0;
462                                                   461 
463     case WM_COMMAND: {                            462     case WM_COMMAND: {
464       auto* This = (G4UIWin32*)::GetWindowLong    463       auto* This = (G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
465       if (This != nullptr)                        464       if (This != nullptr)
466         if (! This->ProcessDefaultCommands(LOW    465         if (! This->ProcessDefaultCommands(LOWORD(wParam)))
467           // If the command was not processed,    466           // If the command was not processed, do it now
468           switch (LOWORD(wParam)) {               467           switch (LOWORD(wParam)) {
469             case IDC_MAIN_EDIT: {                 468             case IDC_MAIN_EDIT: {
470               // We have to release some space    469               // We have to release some space when the buffer is full
471               if (HIWORD(wParam) == EN_ERRSPAC    470               if (HIWORD(wParam) == EN_ERRSPACE || HIWORD(wParam) == EN_MAXTEXT) {
472                 G4int bufferSize =                471                 G4int bufferSize =
473                   SendMessage(This->fHWndEdito    472                   SendMessage(This->fHWndEditor, EM_GETLIMITTEXT, (WPARAM)0, (LPARAM)0);
474                                                   473 
475                 // Select the first third of t    474                 // Select the first third of the text
476                 SendMessage(This->fHWndEditor,    475                 SendMessage(This->fHWndEditor, EM_SETSEL, (WPARAM)0, (LPARAM)bufferSize / 3);
477                 // Delete it                      476                 // Delete it
478                 SendMessage(This->fHWndEditor,    477                 SendMessage(This->fHWndEditor, EM_REPLACESEL, (WPARAM)0, (LPARAM) "");
479                 // Scroll to the bottom           478                 // Scroll to the bottom
480                 SendMessage(This->fHWndEditor,    479                 SendMessage(This->fHWndEditor, WM_VSCROLL, SB_BOTTOM, NULL);
481               }                                   480               }
482             } break;                              481             } break;
483             default:                              482             default:
484               if (! This->fHelp) {                483               if (! This->fHelp) {
485                 G4String command = This->GetCo    484                 G4String command = This->GetCommand(wParam);
486                 This->ApplyShellCommand(comman    485                 This->ApplyShellCommand(command, exitSession, exitPause);
487               }                                   486               }
488           }                                       487           }
489     }                                             488     }
490       return 0;                                   489       return 0;
491     default:                                      490     default:
492       //  For all the other cases, call the de    491       //  For all the other cases, call the default window procedure.
493       return DefWindowProc(aWindow, aMessage,     492       return DefWindowProc(aWindow, aMessage, wParam, lParam);
494   }                                               493   }
495 }                                                 494 }
496 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    495 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
497 /*********************************************    496 /****************************************************************************************************/
498                                                   497 
499 /*********************************************    498 /****************************************************************************************************/
500 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    499 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
501 LRESULT CALLBACK G4UIWin32::ComboEditorWindowP    500 LRESULT CALLBACK G4UIWin32::ComboEditorWindowProc(
502   HWND aWindow, UINT aMessage, WPARAM wParam,     501   HWND aWindow, UINT aMessage, WPARAM wParam, LPARAM lParam)
503 {                                                 502 {
504   // We need to go two steps up: Editor -> Com    503   // We need to go two steps up: Editor -> ComboBox -> Window
505   HWND parent = GetParent(GetParent(aWindow));    504   HWND parent = GetParent(GetParent(aWindow));
506   auto* This = (G4UIWin32*)::GetWindowLongPtr(    505   auto* This = (G4UIWin32*)::GetWindowLongPtr(parent, GWLP_USERDATA);
507                                                   506 
508   switch (aMessage) {                             507   switch (aMessage) {
509     case WM_KEYDOWN:                              508     case WM_KEYDOWN:
510       switch (wParam) {                           509       switch (wParam) {
511         case VK_TAB: {                            510         case VK_TAB: {
512           if (This != nullptr) {                  511           if (This != nullptr) {
513             if (This->fHelp) break;               512             if (This->fHelp) break;
514                                                   513 
515             This->ProcessTabKey();                514             This->ProcessTabKey();
516           }                                       515           }
517         }                                         516         }
518           return 0;  // Do not jump into origC    517           return 0;  // Do not jump into origComboEditorWindowProc.
519                                                   518 
520         case VK_ESCAPE: {                         519         case VK_ESCAPE: {
521           if (This != nullptr) This->ProcessEs    520           if (This != nullptr) This->ProcessEscKey();
522         }                                         521         }
523           return 0;  // Do not jump into origC    522           return 0;  // Do not jump into origComboEditorWindowProc.
524                                                   523 
525         case VK_RETURN: {                         524         case VK_RETURN: {
526           if (This != nullptr) This->ProcessEn    525           if (This != nullptr) This->ProcessEnterKey();
527         }                                         526         }
528           return 0;  // Do not jump into origC    527           return 0;  // Do not jump into origComboEditorWindowProc.
529                                                   528 
530         case VK_UP: {                             529         case VK_UP: {
531           if (This != nullptr) This->ProcessUp    530           if (This != nullptr) This->ProcessUpKey();
532         }                                         531         }
533           return 0;  // Do not jump into origC    532           return 0;  // Do not jump into origComboEditorWindowProc.
534                                                   533 
535         case VK_DOWN: {                           534         case VK_DOWN: {
536           if (This != nullptr) This->ProcessDo    535           if (This != nullptr) This->ProcessDownKey();
537         }                                         536         }
538           return 0;  // Do not jump into origC    537           return 0;  // Do not jump into origComboEditorWindowProc.
539       }                                           538       }
540       break;                                      539       break;
541                                                   540 
542     case WM_KEYUP:                                541     case WM_KEYUP:
543     case WM_CHAR:                                 542     case WM_CHAR:
544       switch (wParam) {                           543       switch (wParam) {
545         case VK_TAB:                              544         case VK_TAB:
546         case VK_ESCAPE:                           545         case VK_ESCAPE:
547         case VK_RETURN:                           546         case VK_RETURN:
548         case VK_UP:                               547         case VK_UP:
549         case VK_DOWN:                             548         case VK_DOWN:
550           return 0;  // Do not jump into origC    549           return 0;  // Do not jump into origComboEditorWindowProc.
551       }                                           550       }
552   }                                               551   }
553                                                   552 
554   //  Call the original window procedure for d    553   //  Call the original window procedure for default processing.
555   return CallWindowProc(origComboEditorWindowP    554   return CallWindowProc(origComboEditorWindowProc, aWindow, aMessage, wParam, lParam);
556 }                                                 555 }
557 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    556 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
558 /*********************************************    557 /****************************************************************************************************/
559                                                   558 
560 /*********************************************    559 /****************************************************************************************************/
561 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    560 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
562 G4bool G4UIWin32::CreateComponents(HWND aWindo    561 G4bool G4UIWin32::CreateComponents(HWND aWindow)
563 {                                                 562 {
564   HFONT hfDefault;                                563   HFONT hfDefault;
565   TBBUTTON tbb[NUM_BUTTONS];                      564   TBBUTTON tbb[NUM_BUTTONS];
566   TBADDBITMAP tbab;                               565   TBADDBITMAP tbab;
567   RECT rcClient;  // dimensions of client area    566   RECT rcClient;  // dimensions of client area
568                                                   567 
569   G4int statwidths[] = {100, -1};                 568   G4int statwidths[] = {100, -1};
570                                                   569 
571   // Create Edit Control                          570   // Create Edit Control
572   char winName[] = "EDIT";                     << 571   fHWndEditor = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
573   char winParam[] = "";                        << 
574   fHWndEditor = CreateWindowEx(WS_EX_CLIENTEDG << 
575     WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HS    572     WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL |
576       ES_AUTOHSCROLL | ES_READONLY,               573       ES_AUTOHSCROLL | ES_READONLY,
577     0, 0, 100, 100, aWindow, (HMENU)IDC_MAIN_E    574     0, 0, 100, 100, aWindow, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(nullptr), nullptr);
578   if (fHWndEditor == nullptr)                     575   if (fHWndEditor == nullptr)
579     MessageBoxA(aWindow, "Could not create edi << 576     MessageBox(aWindow, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
580                                                   577 
581   // Set editor font                              578   // Set editor font
582   // hfDefault = (HFONT) GetStockObject(DEFAUL    579   // hfDefault = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
583   hfDefault = CreateFontA(-10, -8, 0, 0, 0, fa << 580   hfDefault = CreateFont(-10, -8, 0, 0, 0, false, 0, 0, OEM_CHARSET, OUT_RASTER_PRECIS,
584     CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXE    581     CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, "System");
585   SendMessage(fHWndEditor, WM_SETFONT, (WPARAM    582   SendMessage(fHWndEditor, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(false, 0));
586                                                   583 
587   // Set editor's buffer size (the default val    584   // Set editor's buffer size (the default value is too small)
588   SendMessage(fHWndEditor, EM_SETLIMITTEXT, (W    585   SendMessage(fHWndEditor, EM_SETLIMITTEXT, (WPARAM)500000, (LPARAM)0);
589                                                   586 
590   // Create Toolbar                               587   // Create Toolbar
591   fHWndToolBar = CreateWindowEx(0, TOOLBARCLAS    588   fHWndToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, nullptr,
592     WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBS    589     WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, 0, 0, 0, 0, aWindow,
593     (HMENU)IDC_MAIN_TOOL, GetModuleHandle(null    590     (HMENU)IDC_MAIN_TOOL, GetModuleHandle(nullptr), nullptr);
594   if (fHWndToolBar == nullptr)                    591   if (fHWndToolBar == nullptr)
595     MessageBoxA(aWindow, "Could not create too << 592     MessageBox(aWindow, "Could not create tool bar.", "Error", MB_OK | MB_ICONERROR);
596                                                   593 
597   // Required for backward compatibility.         594   // Required for backward compatibility.
598   SendMessage(fHWndToolBar, TB_BUTTONSTRUCTSIZ    595   SendMessage(fHWndToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), (LPARAM)0);
599                                                   596 
600   // Load standard images                         597   // Load standard images
601   tbab.hInst = HINST_COMMCTRL;                    598   tbab.hInst = HINST_COMMCTRL;
602   tbab.nID = IDB_STD_SMALL_COLOR;                 599   tbab.nID = IDB_STD_SMALL_COLOR;
603   SendMessage(fHWndToolBar, TB_ADDBITMAP, (WPA    600   SendMessage(fHWndToolBar, TB_ADDBITMAP, (WPARAM)0, (LPARAM)&tbab);
604                                                   601 
605   // Load history images                          602   // Load history images
606   tbab.hInst = HINST_COMMCTRL;                    603   tbab.hInst = HINST_COMMCTRL;
607   tbab.nID = IDB_HIST_SMALL_COLOR;                604   tbab.nID = IDB_HIST_SMALL_COLOR;
608   SendMessage(fHWndToolBar, TB_ADDBITMAP, (WPA    605   SendMessage(fHWndToolBar, TB_ADDBITMAP, (WPARAM)0, (LPARAM)&tbab);
609                                                   606 
610   G4int btnBMP[NUM_BUTTONS] = {STD_FILEOPEN, S    607   G4int btnBMP[NUM_BUTTONS] = {STD_FILEOPEN, STD_FILESAVE, -1, STD_FIND, STD_FIND, -1,
611     15 + HIST_FORWARD, -1, STD_HELP, -1, STD_F    608     15 + HIST_FORWARD, -1, STD_HELP, -1, STD_FILENEW, STD_FILESAVE};
612   G4int btnSTL[NUM_BUTTONS] = {TBSTYLE_BUTTON,    609   G4int btnSTL[NUM_BUTTONS] = {TBSTYLE_BUTTON, TBSTYLE_BUTTON, TBSTYLE_SEP, TBSTYLE_BUTTON,
613     TBSTYLE_BUTTON, TBSTYLE_SEP, TBSTYLE_BUTTO    610     TBSTYLE_BUTTON, TBSTYLE_SEP, TBSTYLE_BUTTON, TBSTYLE_SEP, TBSTYLE_BUTTON, TBSTYLE_SEP,
614     TBSTYLE_BUTTON, TBSTYLE_BUTTON};              611     TBSTYLE_BUTTON, TBSTYLE_BUTTON};
615   G4int btnCMD[NUM_BUTTONS] = {ID_OPEN_MACRO,     612   G4int btnCMD[NUM_BUTTONS] = {ID_OPEN_MACRO, ID_SAVE_VIEWER_STATE, -1, ID_ZOOM_IN, ID_ZOOM_OUT, -1,
616     ID_RUN_BEAMON, -1, ID_HELP_ABOUT, -1, ID_L    613     ID_RUN_BEAMON, -1, ID_HELP_ABOUT, -1, ID_LOG_CLEAN, ID_LOG_SAVE};
617   ZeroMemory(tbb, sizeof(tbb));                   614   ZeroMemory(tbb, sizeof(tbb));
618   for (G4int i = 0; i < NUM_BUTTONS; i++) {       615   for (G4int i = 0; i < NUM_BUTTONS; i++) {
619     tbb[i].iBitmap = btnBMP[i];                   616     tbb[i].iBitmap = btnBMP[i];
620     tbb[i].fsState = TBSTATE_ENABLED;             617     tbb[i].fsState = TBSTATE_ENABLED;
621     tbb[i].fsStyle = btnSTL[i];                   618     tbb[i].fsStyle = btnSTL[i];
622     tbb[i].idCommand = btnCMD[i];                 619     tbb[i].idCommand = btnCMD[i];
623   }                                               620   }
624                                                   621 
625   SendMessage(fHWndToolBar, TB_ADDBUTTONS, siz    622   SendMessage(fHWndToolBar, TB_ADDBUTTONS, sizeof(tbb) / sizeof(TBBUTTON), (LPARAM)&tbb);
626                                                   623 
627   // Create the Combobox                          624   // Create the Combobox
628   fHWndComboBox = CreateWindowEx(0, WC_COMBOBO    625   fHWndComboBox = CreateWindowEx(0, WC_COMBOBOX, TEXT(""),
629     CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD |    626     CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, 150, 0, 200, 200,
630     aWindow, (HMENU)IDC_MAIN_COMBO, GetModuleH    627     aWindow, (HMENU)IDC_MAIN_COMBO, GetModuleHandle(nullptr), nullptr);
631                                                   628 
632   // Display an initial item in the selection     629   // Display an initial item in the selection field
633   SendMessage(fHWndComboBox, CB_SETCURSEL, (WP    630   SendMessage(fHWndComboBox, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
634                                                   631 
635   // Get aWindow of edit control in combobox c    632   // Get aWindow of edit control in combobox created earlier.
636   fHWndComboEditor = FindWindowEx(fHWndComboBo    633   fHWndComboEditor = FindWindowEx(fHWndComboBox, nullptr, WC_EDIT, nullptr);
637                                                   634 
638   //  Change the window procedure for the edit    635   //  Change the window procedure for the edit windows to the subclass procedure.
639   origComboEditorWindowProc =                     636   origComboEditorWindowProc =
640     (WNDPROC)SetWindowLongPtr(fHWndComboEditor    637     (WNDPROC)SetWindowLongPtr(fHWndComboEditor, GWLP_WNDPROC, (LONG_PTR)ComboEditorWindowProc);
641                                                   638 
642   // Create TreeView                              639   // Create TreeView
643                                                   640 
644   // Get the dimensions of the parent window's    641   // Get the dimensions of the parent window's client area, and create
645   // the tree-view control.                       642   // the tree-view control.
646   GetClientRect(aWindow, &rcClient);              643   GetClientRect(aWindow, &rcClient);
647   fHWndHelpTree = CreateWindowEx(0, WC_TREEVIE    644   fHWndHelpTree = CreateWindowEx(0, WC_TREEVIEW, TEXT("Tree View"),
648     WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_IN    645     WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_INFOTIP | TVS_HASBUTTONS | TVS_HASLINES |
649       TVS_LINESATROOT,                            646       TVS_LINESATROOT,
650     0, 0, rcClient.right, rcClient.bottom, aWi    647     0, 0, rcClient.right, rcClient.bottom, aWindow, (HMENU)IDC_MAIN_TREE_VIEW,
651     GetModuleHandle(nullptr), nullptr);           648     GetModuleHandle(nullptr), nullptr);
652                                                   649 
653   // Initialize the Help Tree View.               650   // Initialize the Help Tree View.
654   /*    if (!InitHelpTreeItems()) {               651   /*    if (!InitHelpTreeItems()) {
655           DestroyWindow(fHWndHelpTree);           652           DestroyWindow(fHWndHelpTree);
656           return false;                           653           return false;
657       }*/                                         654       }*/
658                                                   655 
659   // Create Status bar                            656   // Create Status bar
660   fHWndStatus = CreateWindowEx(0, STATUSCLASSN    657   fHWndStatus = CreateWindowEx(0, STATUSCLASSNAME, nullptr, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
661     100, 100, 200, 200, aWindow, (HMENU)IDC_MA    658     100, 100, 200, 200, aWindow, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(nullptr), nullptr);
662                                                   659 
663   SendMessage(fHWndStatus, SB_SETPARTS, sizeof    660   SendMessage(fHWndStatus, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM)statwidths);
664   // SendMessage(fHWndStatus, SB_SETTEXT, 0, (    661   // SendMessage(fHWndStatus, SB_SETTEXT, 0, (LPARAM) "Hi there :)");
665                                                   662 
666   return true;                                    663   return true;
667 }                                                 664 }
668 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    665 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
669 /*********************************************    666 /****************************************************************************************************/
670                                                   667 
671 /*********************************************    668 /****************************************************************************************************/
672 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    669 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
673 G4bool G4UIWin32::ResizeComponents(HWND aWindo    670 G4bool G4UIWin32::ResizeComponents(HWND aWindow)
674 {                                                 671 {
675   RECT rcTool;                                    672   RECT rcTool;
676   G4int iToolHeight, iToolWidth;                  673   G4int iToolHeight, iToolWidth;
677                                                   674 
678   RECT rcStatus;                                  675   RECT rcStatus;
679   G4int iStatusHeight;                            676   G4int iStatusHeight;
680                                                   677 
681   RECT rcComboBox;                                678   RECT rcComboBox;
682   G4int iComboBoxHeight;                          679   G4int iComboBoxHeight;
683                                                   680 
684   G4int iTreeViewHeight, iTreeViewWidth;          681   G4int iTreeViewHeight, iTreeViewWidth;
685   G4int iEditHeight, iEditWidth;                  682   G4int iEditHeight, iEditWidth;
686                                                   683 
687   RECT rcClient;                                  684   RECT rcClient;
688                                                   685 
689   // Size toolbar and get height and width        686   // Size toolbar and get height and width
690   SendMessage(fHWndToolBar, TB_AUTOSIZE, 0, 0)    687   SendMessage(fHWndToolBar, TB_AUTOSIZE, 0, 0);
691                                                   688 
692   GetWindowRect(fHWndToolBar, &rcTool);           689   GetWindowRect(fHWndToolBar, &rcTool);
693   iToolHeight = rcTool.bottom - rcTool.top;       690   iToolHeight = rcTool.bottom - rcTool.top;
694   iToolWidth = rcTool.right - rcTool.left;        691   iToolWidth = rcTool.right - rcTool.left;
695                                                   692 
696   // Size status bar and get height               693   // Size status bar and get height
697   SendMessage(fHWndStatus, WM_SIZE, 0, 0);        694   SendMessage(fHWndStatus, WM_SIZE, 0, 0);
698                                                   695 
699   GetWindowRect(fHWndStatus, &rcStatus);          696   GetWindowRect(fHWndStatus, &rcStatus);
700   iStatusHeight = rcStatus.bottom - rcStatus.t    697   iStatusHeight = rcStatus.bottom - rcStatus.top;
701                                                   698 
702   // Size status the Combo Box and get height     699   // Size status the Combo Box and get height
703   SendMessage(fHWndComboBox, WM_SIZE, 0, 0);      700   SendMessage(fHWndComboBox, WM_SIZE, 0, 0);
704                                                   701 
705   GetWindowRect(fHWndComboBox, &rcComboBox);      702   GetWindowRect(fHWndComboBox, &rcComboBox);
706   iComboBoxHeight = rcComboBox.bottom - rcComb    703   iComboBoxHeight = rcComboBox.bottom - rcComboBox.top;
707                                                   704 
708   // Calculate remaining height and size edit     705   // Calculate remaining height and size edit
709   GetClientRect(aWindow, &rcClient);              706   GetClientRect(aWindow, &rcClient);
710                                                   707 
711   iTreeViewHeight = rcClient.bottom - iToolHei    708   iTreeViewHeight = rcClient.bottom - iToolHeight - iStatusHeight;
712   iTreeViewWidth = iToolWidth / 4;                709   iTreeViewWidth = iToolWidth / 4;
713                                                   710 
714   iEditHeight = rcClient.bottom - iToolHeight     711   iEditHeight = rcClient.bottom - iToolHeight - iComboBoxHeight - iStatusHeight;
715   iEditWidth = iToolWidth - iTreeViewWidth;       712   iEditWidth = iToolWidth - iTreeViewWidth;
716                                                   713 
717   // TreeView location and size                   714   // TreeView location and size
718   SetWindowPos(                                   715   SetWindowPos(
719     fHWndHelpTree, nullptr, 0, iToolHeight, iT    716     fHWndHelpTree, nullptr, 0, iToolHeight, iTreeViewWidth, iTreeViewHeight, SWP_NOZORDER);
720                                                   717 
721   // Editor location and size                     718   // Editor location and size
722   SetWindowPos(                                   719   SetWindowPos(
723     fHWndEditor, nullptr, iTreeViewWidth, iToo    720     fHWndEditor, nullptr, iTreeViewWidth, iToolHeight, iEditWidth, iEditHeight, SWP_NOZORDER);
724                                                   721 
725   // ComboBox location and size                   722   // ComboBox location and size
726   SetWindowPos(                                   723   SetWindowPos(
727     fHWndComboBox, nullptr, iTreeViewWidth, iT    724     fHWndComboBox, nullptr, iTreeViewWidth, iToolHeight + iEditHeight, iEditWidth, 200, 0);
728                                                   725 
729   return true;                                    726   return true;
730 }                                                 727 }
731 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    728 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
732 /*********************************************    729 /****************************************************************************************************/
733                                                   730 
734 /*********************************************    731 /****************************************************************************************************/
735 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    732 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
736 void G4UIWin32::ProcessTabKey()                   733 void G4UIWin32::ProcessTabKey()
737 {                                                 734 {
738   char buffer[256];                               735   char buffer[256];
739                                                   736 
740   // Only process the command it the user has     737   // Only process the command it the user has written something
741   if (SendMessage(fHWndComboBox, WM_GETTEXT, (    738   if (SendMessage(fHWndComboBox, WM_GETTEXT, (WPARAM)sizeof(buffer), (LPARAM)buffer) != 0) {
742     G4String command(buffer);                     739     G4String command(buffer);
743                                                   740 
744     SetFocus(fHWndComboBox);                      741     SetFocus(fHWndComboBox);
745                                                   742 
746     G4String cmd = Complete(command);             743     G4String cmd = Complete(command);
747     const char* d = cmd.data();                   744     const char* d = cmd.data();
748     G4int l = strlen(d);                          745     G4int l = strlen(d);
749     Edit_SetText(fHWndComboEditor, (PTSTR)d);  << 746     Edit_SetText(fHWndComboEditor, d);
750     Edit_SetSel(fHWndComboEditor, l, l);          747     Edit_SetSel(fHWndComboEditor, l, l);
751   }                                               748   }
752   else {                                          749   else {
753     if (GetFocus() == fHWndComboEditor)           750     if (GetFocus() == fHWndComboEditor)
754       SetFocus(fHWndHelpTree);                    751       SetFocus(fHWndHelpTree);
755     else                                          752     else
756       SetFocus(fHWndComboBox);                    753       SetFocus(fHWndComboBox);
757   }                                               754   }
758 }                                                 755 }
759 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    756 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
760 /*********************************************    757 /****************************************************************************************************/
761                                                   758 
762 /*********************************************    759 /****************************************************************************************************/
763 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    760 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
764 void G4UIWin32::ProcessEscKey()                   761 void G4UIWin32::ProcessEscKey()
765 {                                                 762 {
766   // Clear the current selection.                 763   // Clear the current selection.
767   SendMessage(fHWndComboBox, CB_SETCURSEL, (WP    764   SendMessage(fHWndComboBox, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
768   // Set the focus to the Combo Box.              765   // Set the focus to the Combo Box.
769   SetFocus(fHWndComboBox);                        766   SetFocus(fHWndComboBox);
770 }                                                 767 }
771 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    768 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
772 /*********************************************    769 /****************************************************************************************************/
773                                                   770 
774 /*********************************************    771 /****************************************************************************************************/
775 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    772 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
776 void G4UIWin32::ProcessEnterKey()                 773 void G4UIWin32::ProcessEnterKey()
777 {                                                 774 {
778   char buffer[256];                               775   char buffer[256];
779   DWORD dwIndex, numItems;                        776   DWORD dwIndex, numItems;
780                                                   777 
781   // Only process the command it the user has     778   // Only process the command it the user has written something
782   if (SendMessage(fHWndComboBox, WM_GETTEXT, (    779   if (SendMessage(fHWndComboBox, WM_GETTEXT, (WPARAM)sizeof(buffer), (LPARAM)buffer) != 0) {
783     SetFocus(fHWndComboBox);                      780     SetFocus(fHWndComboBox);
784                                                   781 
785     // Read command                               782     // Read command
786     G4String command(buffer);                     783     G4String command(buffer);
787                                                   784 
788     // Now clear the current selection.           785     // Now clear the current selection.
789     SendMessage(fHWndComboBox, CB_SETCURSEL, (    786     SendMessage(fHWndComboBox, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0);
790                                                   787 
791     if (fHelp) {                                  788     if (fHelp) {
792       exitHelp = true;                            789       exitHelp = true;
793       fHelp = ConvertStringToInt(command.data(    790       fHelp = ConvertStringToInt(command.data(), fHelpChoice);
794     }                                             791     }
795     else {                                        792     else {
796       fHistory.push_back(command);                793       fHistory.push_back(command);
797       fHistoryPos = -1;                           794       fHistoryPos = -1;
798       ApplyShellCommand(command, exitSession,     795       ApplyShellCommand(command, exitSession, exitPause);
799                                                   796 
800       // Now update the history in the ComboBo    797       // Now update the history in the ComboBox
801                                                   798 
802       // Check if this command exists in the C    799       // Check if this command exists in the ComboBox
803       dwIndex = SendMessage(fHWndComboBox, CB_    800       dwIndex = SendMessage(fHWndComboBox, CB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)buffer);
804                                                   801 
805       //  Add the string, if necessary            802       //  Add the string, if necessary
806       if (dwIndex == CB_ERR)                      803       if (dwIndex == CB_ERR)
807         dwIndex = SendMessage(fHWndComboBox, C    804         dwIndex = SendMessage(fHWndComboBox, CB_INSERTSTRING, (WPARAM)0, (LPARAM)buffer);
808       // If the string exists, move it to the     805       // If the string exists, move it to the first position
809       if (dwIndex != CB_ERR) {                    806       if (dwIndex != CB_ERR) {
810         SendMessage(fHWndComboBox, CB_DELETEST    807         SendMessage(fHWndComboBox, CB_DELETESTRING, (WPARAM)dwIndex, (LPARAM)0);
811         dwIndex = SendMessage(fHWndComboBox, C    808         dwIndex = SendMessage(fHWndComboBox, CB_INSERTSTRING, (WPARAM)0, (LPARAM)buffer);
812       }                                           809       }
813                                                   810 
814       numItems = SendMessage(fHWndComboBox, CB    811       numItems = SendMessage(fHWndComboBox, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
815       while (numItems > MAX_HISTORY_ITEMS) {      812       while (numItems > MAX_HISTORY_ITEMS) {
816         SendMessage(fHWndComboBox, CB_DELETEST    813         SendMessage(fHWndComboBox, CB_DELETESTRING, (WPARAM)(numItems - 1), (LPARAM)0);
817         numItems = SendMessage(fHWndComboBox,     814         numItems = SendMessage(fHWndComboBox, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
818       }                                           815       }
819     }                                             816     }
820   }                                               817   }
821 }                                                 818 }
822 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    819 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
823 /*********************************************    820 /****************************************************************************************************/
824                                                   821 
825 /*********************************************    822 /****************************************************************************************************/
826 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    823 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
827 void G4UIWin32::ProcessUpKey()                    824 void G4UIWin32::ProcessUpKey()
828 {                                                 825 {
829   G4int pos = fHistoryPos == -1 ? fHistory.siz    826   G4int pos = fHistoryPos == -1 ? fHistory.size() - 1 : fHistoryPos - 1;
830   if ((pos >= 0) && (pos < (G4int)fHistory.siz    827   if ((pos >= 0) && (pos < (G4int)fHistory.size())) {
831     G4String command = fHistory[pos];             828     G4String command = fHistory[pos];
832     const char* d = command.data();               829     const char* d = command.data();
833     G4int l = strlen(d);                          830     G4int l = strlen(d);
834     Edit_SetText(fHWndComboEditor, (PTSTR)d);  << 831     Edit_SetText(fHWndComboEditor, d);
835     Edit_SetSel(fHWndComboEditor, l, l);          832     Edit_SetSel(fHWndComboEditor, l, l);
836                                                   833 
837     fHistoryPos = pos;                            834     fHistoryPos = pos;
838   }                                               835   }
839 }                                                 836 }
840 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    837 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
841 /*********************************************    838 /****************************************************************************************************/
842                                                   839 
843 /*********************************************    840 /****************************************************************************************************/
844 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    841 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
845 void G4UIWin32::ProcessDownKey()                  842 void G4UIWin32::ProcessDownKey()
846 {                                                 843 {
847   G4int pos = fHistoryPos + 1;                    844   G4int pos = fHistoryPos + 1;
848   if ((pos >= 0) && (pos < (G4int)fHistory.siz    845   if ((pos >= 0) && (pos < (G4int)fHistory.size())) {
849     G4String command = fHistory[pos];             846     G4String command = fHistory[pos];
850     const char* d = command.data();               847     const char* d = command.data();
851     G4int l = strlen(d);                          848     G4int l = strlen(d);
852     Edit_SetText(fHWndComboEditor, (PTSTR)d);  << 849     Edit_SetText(fHWndComboEditor, d);
853     Edit_SetSel(fHWndComboEditor, l, l);          850     Edit_SetSel(fHWndComboEditor, l, l);
854                                                   851 
855     fHistoryPos = pos;                            852     fHistoryPos = pos;
856   }                                               853   }
857   else if (pos >= (G4int)fHistory.size()) {       854   else if (pos >= (G4int)fHistory.size()) {
858   char eName[] = "";                           << 855     Edit_SetText(fHWndComboEditor, "");
859     Edit_SetText(fHWndComboEditor, (PTSTR)eNam << 
860     Edit_SetSel(fHWndComboEditor, 0, 0);          856     Edit_SetSel(fHWndComboEditor, 0, 0);
861                                                   857 
862     fHistoryPos = -1;                             858     fHistoryPos = -1;
863   }                                               859   }
864 }                                                 860 }
865 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    861 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
866 /*********************************************    862 /****************************************************************************************************/
867                                                   863 
868 /*********************************************    864 /****************************************************************************************************/
869 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    865 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
870 G4bool G4UIWin32::ProcessDefaultCommands(G4int    866 G4bool G4UIWin32::ProcessDefaultCommands(G4int idCommand)
871 {                                                 867 {
872   switch (idCommand) {                            868   switch (idCommand) {
873     case ID_EXIT_APP:                             869     case ID_EXIT_APP:
874       PostMessage(fHWndMainWindow, WM_CLOSE, 0    870       PostMessage(fHWndMainWindow, WM_CLOSE, 0, 0);
875       return true;                                871       return true;
876     case ID_OPEN_MACRO:                           872     case ID_OPEN_MACRO:
877       DoOpenMacro(fHWndMainWindow);               873       DoOpenMacro(fHWndMainWindow);
878       return true;                                874       return true;
879     case ID_SAVE_VIEWER_STATE:                    875     case ID_SAVE_VIEWER_STATE:
880       DoSaveViewer(fHWndMainWindow);              876       DoSaveViewer(fHWndMainWindow);
881       return true;                                877       return true;
882     case ID_RUN_BEAMON:                           878     case ID_RUN_BEAMON:
883       if (! fHelp) {                              879       if (! fHelp) {
884         G4String command = "/run/beamOn 1";       880         G4String command = "/run/beamOn 1";
885         ApplyShellCommand(command, exitSession    881         ApplyShellCommand(command, exitSession, exitPause);
886       }                                           882       }
887       return true;                                883       return true;
888     case ID_RUN_CMD:                              884     case ID_RUN_CMD:
889       return true;                                885       return true;
890     case ID_VIEW_SOLID:                           886     case ID_VIEW_SOLID:
891       if (! fHelp) {                              887       if (! fHelp) {
892         G4String command = "/vis/viewer/set/st    888         G4String command = "/vis/viewer/set/style s";
893         ApplyShellCommand(command, exitSession    889         ApplyShellCommand(command, exitSession, exitPause);
894       }                                           890       }
895       return true;                                891       return true;
896     case ID_VIEW_WIREFRAME:                       892     case ID_VIEW_WIREFRAME:
897       if (! fHelp) {                              893       if (! fHelp) {
898         G4String command = "/vis/viewer/set/st    894         G4String command = "/vis/viewer/set/style w";
899         ApplyShellCommand(command, exitSession    895         ApplyShellCommand(command, exitSession, exitPause);
900       }                                           896       }
901       return true;                                897       return true;
902     case ID_PROJ_ORTHOGRAPHIC:                    898     case ID_PROJ_ORTHOGRAPHIC:
903       if (! fHelp) {                              899       if (! fHelp) {
904         G4String command = "/vis/viewer/set/pr    900         G4String command = "/vis/viewer/set/projection o";
905         ApplyShellCommand(command, exitSession    901         ApplyShellCommand(command, exitSession, exitPause);
906       }                                           902       }
907       return true;                                903       return true;
908     case ID_PROJ_PERSPECTIVE:                     904     case ID_PROJ_PERSPECTIVE:
909       if (! fHelp) {                              905       if (! fHelp) {
910         G4String command = "/vis/viewer/set/pr    906         G4String command = "/vis/viewer/set/projection p";
911         ApplyShellCommand(command, exitSession    907         ApplyShellCommand(command, exitSession, exitPause);
912       }                                           908       }
913       return true;                                909       return true;
914     case ID_ZOOM_IN:                              910     case ID_ZOOM_IN:
915       if (! fHelp) {                              911       if (! fHelp) {
916         G4String command = "/vis/viewer/zoom 1    912         G4String command = "/vis/viewer/zoom 1.2";
917         ApplyShellCommand(command, exitSession    913         ApplyShellCommand(command, exitSession, exitPause);
918       }                                           914       }
919       return true;                                915       return true;
920     case ID_ZOOM_OUT:                             916     case ID_ZOOM_OUT:
921       if (! fHelp) {                              917       if (! fHelp) {
922         G4String command = "/vis/viewer/zoom 0    918         G4String command = "/vis/viewer/zoom 0.8";
923         ApplyShellCommand(command, exitSession    919         ApplyShellCommand(command, exitSession, exitPause);
924       }                                           920       }
925       return true;                                921       return true;
926     case ID_ORIENTATION_XY:                       922     case ID_ORIENTATION_XY:
927       if (! fHelp) {                              923       if (! fHelp) {
928         G4String command = "/vis/viewer/set/vi    924         G4String command = "/vis/viewer/set/viewpointThetaPhi 0. 0.";
929         ApplyShellCommand(command, exitSession    925         ApplyShellCommand(command, exitSession, exitPause);
930       }                                           926       }
931       return true;                                927       return true;
932     case ID_ORIENTATION_XZ:                       928     case ID_ORIENTATION_XZ:
933       if (! fHelp) {                              929       if (! fHelp) {
934         G4String command = "/vis/viewer/set/vi    930         G4String command = "/vis/viewer/set/viewpointThetaPhi 90. 0.";
935         ApplyShellCommand(command, exitSession    931         ApplyShellCommand(command, exitSession, exitPause);
936       }                                           932       }
937       return true;                                933       return true;
938     case ID_ORIENTATION_YZ:                       934     case ID_ORIENTATION_YZ:
939       if (! fHelp) {                              935       if (! fHelp) {
940         G4String command = "/vis/viewer/set/vi    936         G4String command = "/vis/viewer/set/viewpointThetaPhi 0. 90.";
941         ApplyShellCommand(command, exitSession    937         ApplyShellCommand(command, exitSession, exitPause);
942       }                                           938       }
943       return true;                                939       return true;
944     case ID_ORIENTATION_OBLIQUE:                  940     case ID_ORIENTATION_OBLIQUE:
945       if (! fHelp) {                              941       if (! fHelp) {
946         G4String command = "/vis/viewer/set/vi    942         G4String command = "/vis/viewer/set/viewpointThetaPhi 45. -45.";
947         ApplyShellCommand(command, exitSession    943         ApplyShellCommand(command, exitSession, exitPause);
948       }                                           944       }
949       return true;                                945       return true;
950     case ID_HELP_ABOUT:                           946     case ID_HELP_ABOUT:
951       return true;                                947       return true;
952     case ID_LOG_CLEAN:                            948     case ID_LOG_CLEAN:
953     {                                          << 949       SetDlgItemText(fHWndMainWindow, IDC_MAIN_EDIT, "");
954       char eName[] = "";                       << 
955         SetDlgItemText(fHWndMainWindow, IDC_MA << 
956     }                                          << 
957       return true;                                950       return true;
958     case ID_LOG_SAVE:                             951     case ID_LOG_SAVE:
959       DoSaveLog(fHWndMainWindow);                 952       DoSaveLog(fHWndMainWindow);
960       return true;                                953       return true;
961     default:                                      954     default:
962       return false;                               955       return false;
963   }                                               956   }
964 }                                                 957 }
965 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    958 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
966 /*********************************************    959 /****************************************************************************************************/
967                                                   960 
968 /*********************************************    961 /****************************************************************************************************/
969 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    962 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
970 G4String G4UIWin32::GetToolTips(G4int idButton    963 G4String G4UIWin32::GetToolTips(G4int idButton)
971 {                                                 964 {
972   switch (idButton) {                             965   switch (idButton) {
973     case ID_OPEN_MACRO:                           966     case ID_OPEN_MACRO:
974       return "Open and execute macro file";       967       return "Open and execute macro file";
975                                                   968 
976     case ID_SAVE_VIEWER_STATE:                    969     case ID_SAVE_VIEWER_STATE:
977       return "Save viewer state";                 970       return "Save viewer state";
978                                                   971 
979     case ID_ZOOM_IN:                              972     case ID_ZOOM_IN:
980       return "Zoom in";                           973       return "Zoom in";
981                                                   974 
982     case ID_ZOOM_OUT:                             975     case ID_ZOOM_OUT:
983       return "Zoom out";                          976       return "Zoom out";
984                                                   977 
985     case ID_RUN_BEAMON:                           978     case ID_RUN_BEAMON:
986       return "Beam on (one particle)";            979       return "Beam on (one particle)";
987                                                   980 
988     case ID_HELP_ABOUT:                           981     case ID_HELP_ABOUT:
989       return "About G4UIWin32";                   982       return "About G4UIWin32";
990                                                   983 
991     case ID_LOG_CLEAN:                            984     case ID_LOG_CLEAN:
992       return "Clean log";                         985       return "Clean log";
993                                                   986 
994     case ID_LOG_SAVE:                             987     case ID_LOG_SAVE:
995       return "Save log";                          988       return "Save log";
996                                                   989 
997     default:                                      990     default:
998       return "";                                  991       return "";
999   }                                               992   }
1000 }                                                993 }
1001 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    994 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1002 /********************************************    995 /****************************************************************************************************/
1003                                                  996 
1004 /********************************************    997 /****************************************************************************************************/
1005 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    998 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1006 G4String G4UIWin32::GetHelpTreeToolTips(HTREE    999 G4String G4UIWin32::GetHelpTreeToolTips(HTREEITEM item)
1007 {                                                1000 {
1008   // Tooltips for the help tree                  1001   // Tooltips for the help tree
1009   G4UImanager* UI = G4UImanager::GetUIpointer    1002   G4UImanager* UI = G4UImanager::GetUIpointer();
1010   if (UI == nullptr) return "";                  1003   if (UI == nullptr) return "";
1011   G4UIcommandTree* treeTop = UI->GetTree();      1004   G4UIcommandTree* treeTop = UI->GetTree();
1012                                                  1005 
1013   G4String itemText = GetItemPath(item);         1006   G4String itemText = GetItemPath(item);
1014                                                  1007 
1015   // Check if it is a command path               1008   // Check if it is a command path
1016   if (TreeView_GetChild(fHWndHelpTree, item)     1009   if (TreeView_GetChild(fHWndHelpTree, item) != nullptr) itemText += "/";
1017                                                  1010 
1018   G4UIcommand* command = treeTop->FindPath(it    1011   G4UIcommand* command = treeTop->FindPath(itemText.c_str());
1019                                                  1012 
1020   if (command) {                                 1013   if (command) {
1021     // This is a command, return the first li    1014     // This is a command, return the first line of help
1022     return command->GetGuidanceLine(0).data()    1015     return command->GetGuidanceLine(0).data();
1023   }                                              1016   }
1024   else {                                         1017   else {
1025     // This is not a command, but a sub direc    1018     // This is not a command, but a sub directory, return the title
1026     G4UIcommandTree* path = treeTop->FindComm    1019     G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
1027     if (path) return path->GetTitle().data();    1020     if (path) return path->GetTitle().data();
1028   }                                              1021   }
1029                                                  1022 
1030   return "";                                     1023   return "";
1031 }                                                1024 }
1032 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1025 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1033 /********************************************    1026 /****************************************************************************************************/
1034                                                  1027 
1035 /********************************************    1028 /****************************************************************************************************/
1036 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1029 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1037 G4String G4UIWin32::ConvertNewLines(const G4S << 1030 G4String G4UIWin32::ConvertNewLines(G4String a_string)
1038 {                                                1031 {
1039   // Geant4 uses UNIX's style for new lines (    1032   // Geant4 uses UNIX's style for new lines (\n)
1040   // we must convert them to Windows' style (    1033   // we must convert them to Windows' style (\r\n)
1041   G4String str = a_string;                    << 1034   G4String str = std::move(a_string);
1042   std::size_t index = str.find("\n", 0);      << 1035   size_t index = str.find("\n", 0);
1043   while (index < str.length()) {                 1036   while (index < str.length()) {
1044     str.replace(index, 1, "\r\n");            << 1037     str.replace(index, 2, "\r\n");
1045     // Advance index forward so the next iter    1038     // Advance index forward so the next iteration doesn't pick it up as well.
1046     index = str.find("\n", index + 2);           1039     index = str.find("\n", index + 2);
1047   }                                              1040   }
1048   return str;                                    1041   return str;
1049 }                                                1042 }
1050 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1043 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1051 /********************************************    1044 /****************************************************************************************************/
1052                                                  1045 
1053 /********************************************    1046 /****************************************************************************************************/
1054 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1047 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1055 void G4UIWin32::HelpTreeDoubleClick(HTREEITEM    1048 void G4UIWin32::HelpTreeDoubleClick(HTREEITEM item)
1056 {                                                1049 {
1057   const char* item_path = GetItemPath(item);     1050   const char* item_path = GetItemPath(item);
1058   G4int l = strlen(item_path);                   1051   G4int l = strlen(item_path);
1059   Edit_SetText(fHWndComboEditor, (PTSTR)item_ << 1052   Edit_SetText(fHWndComboEditor, item_path);
1060   Edit_SetSel(fHWndComboEditor, l, l);           1053   Edit_SetSel(fHWndComboEditor, l, l);
1061                                                  1054 
1062   SetFocus(fHWndComboEditor);                    1055   SetFocus(fHWndComboEditor);
1063 }                                                1056 }
1064 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1057 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1065 /********************************************    1058 /****************************************************************************************************/
1066                                                  1059 
1067 /********************************************    1060 /****************************************************************************************************/
1068 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1061 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1069 G4bool G4UIWin32::SaveLogFile(LPCTSTR fileNam    1062 G4bool G4UIWin32::SaveLogFile(LPCTSTR fileName)
1070 {                                                1063 {
1071   HANDLE hFile;                                  1064   HANDLE hFile;
1072   G4bool bSuccess = false;                       1065   G4bool bSuccess = false;
1073                                                  1066 
1074   hFile =                                        1067   hFile =
1075     CreateFile(fileName, GENERIC_WRITE, 0, nu    1068     CreateFile(fileName, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
1076   if (hFile != INVALID_HANDLE_VALUE) {           1069   if (hFile != INVALID_HANDLE_VALUE) {
1077     DWORD dwTextLength;                          1070     DWORD dwTextLength;
1078                                                  1071 
1079     dwTextLength = GetWindowTextLength(fHWndE    1072     dwTextLength = GetWindowTextLength(fHWndEditor);
1080     // No need to bother if there's no text.     1073     // No need to bother if there's no text.
1081     if (dwTextLength > 0) {                      1074     if (dwTextLength > 0) {
1082       LPSTR text;                                1075       LPSTR text;
1083       DWORD dwBufferSize = dwTextLength + 1;     1076       DWORD dwBufferSize = dwTextLength + 1;
1084                                                  1077 
1085       text = (LPSTR)GlobalAlloc(GPTR, dwBuffe    1078       text = (LPSTR)GlobalAlloc(GPTR, dwBufferSize);
1086       if (text != nullptr) {                     1079       if (text != nullptr) {
1087         if (GetWindowTextA(fHWndEditor, text, << 1080         if (GetWindowText(fHWndEditor, text, dwBufferSize)) {
1088           DWORD dwWritten;                       1081           DWORD dwWritten;
1089                                                  1082 
1090           if (WriteFile(hFile, text, dwTextLe    1083           if (WriteFile(hFile, text, dwTextLength, &dwWritten, nullptr)) bSuccess = true;
1091         }                                        1084         }
1092         GlobalFree(text);                        1085         GlobalFree(text);
1093       }                                          1086       }
1094     }                                            1087     }
1095     CloseHandle(hFile);                          1088     CloseHandle(hFile);
1096   }                                              1089   }
1097   return bSuccess;                               1090   return bSuccess;
1098 }                                                1091 }
1099 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1092 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1100 /********************************************    1093 /****************************************************************************************************/
1101                                                  1094 
1102 /********************************************    1095 /****************************************************************************************************/
1103 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1096 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1104 void G4UIWin32::AddText(LPSTR text)              1097 void G4UIWin32::AddText(LPSTR text)
1105 {                                                1098 {
1106   if ((fHWndEditor != nullptr) && (text != nu    1099   if ((fHWndEditor != nullptr) && (text != nullptr) && (text[0] != '\0')) {
1107     // Get current text length                   1100     // Get current text length
1108     G4int ndx = GetWindowTextLength(fHWndEdit    1101     G4int ndx = GetWindowTextLength(fHWndEditor);
1109                                                  1102 
1110     // Select the end of the text                1103     // Select the end of the text
1111     SendMessage(fHWndEditor, EM_SETSEL, (WPAR    1104     SendMessage(fHWndEditor, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
1112     // Add the new text                          1105     // Add the new text
1113     SendMessage(fHWndEditor, EM_REPLACESEL, (    1106     SendMessage(fHWndEditor, EM_REPLACESEL, (WPARAM)0, (LPARAM)text);
1114     // Scroll to the bottom                      1107     // Scroll to the bottom
1115     SendMessage(fHWndEditor, WM_VSCROLL, SB_B    1108     SendMessage(fHWndEditor, WM_VSCROLL, SB_BOTTOM, NULL);
1116   }                                              1109   }
1117 }                                                1110 }
1118 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1111 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1119 /********************************************    1112 /****************************************************************************************************/
1120                                                  1113 
1121 /********************************************    1114 /****************************************************************************************************/
1122 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1115 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1123 void G4UIWin32::DoOpenMacro(HWND aWindow)        1116 void G4UIWin32::DoOpenMacro(HWND aWindow)
1124 {                                                1117 {
1125   OPENFILENAME ofn;                              1118   OPENFILENAME ofn;
1126   char szFileName[MAX_PATH] = "";                1119   char szFileName[MAX_PATH] = "";
1127                                                  1120 
1128   ZeroMemory(&ofn, sizeof(ofn));                 1121   ZeroMemory(&ofn, sizeof(ofn));
1129                                                  1122 
1130   ofn.lStructSize = sizeof(ofn);                 1123   ofn.lStructSize = sizeof(ofn);
1131   ofn.hwndOwner = aWindow;                       1124   ofn.hwndOwner = aWindow;
1132   char fName[] = "Macro Files (*.mac)\0*.mac\ << 1125   ofn.lpstrFilter = "Macro Files (*.mac)\0*.mac\0All Files (*.*)\0*.*\0";
1133   ofn.lpstrFilter = (PTSTR)fName;             << 1126   ofn.lpstrFile = szFileName;
1134   ofn.lpstrFile = (PTSTR)szFileName;          << 
1135   ofn.nMaxFile = MAX_PATH;                       1127   ofn.nMaxFile = MAX_PATH;
1136   ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIS    1128   ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
1137   char dName[] = "mac";                       << 1129   ofn.lpstrDefExt = "mac";
1138   ofn.lpstrDefExt = (PTSTR)dName;             << 
1139                                                  1130 
1140   if (GetOpenFileName(&ofn)) {                   1131   if (GetOpenFileName(&ofn)) {
1141     G4String command = "/control/execute " +     1132     G4String command = "/control/execute " + G4String(szFileName);
1142     ApplyShellCommand(command, exitSession, e    1133     ApplyShellCommand(command, exitSession, exitPause);
1143                                                  1134 
1144     SendDlgItemMessage(aWindow, IDC_MAIN_STAT    1135     SendDlgItemMessage(aWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM) "Opened macro...");
1145     SendDlgItemMessage(aWindow, IDC_MAIN_STAT    1136     SendDlgItemMessage(aWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
1146   }                                              1137   }
1147 }                                                1138 }
1148 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1139 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1149 /********************************************    1140 /****************************************************************************************************/
1150                                                  1141 
1151 /********************************************    1142 /****************************************************************************************************/
1152 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1143 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1153 void G4UIWin32::DoSaveViewer(HWND aWindow)       1144 void G4UIWin32::DoSaveViewer(HWND aWindow)
1154 {                                                1145 {
1155   OPENFILENAME ofn;                              1146   OPENFILENAME ofn;
1156   char szFileName[MAX_PATH] = "";                1147   char szFileName[MAX_PATH] = "";
1157                                                  1148 
1158   ZeroMemory(&ofn, sizeof(ofn));                 1149   ZeroMemory(&ofn, sizeof(ofn));
1159                                                  1150 
1160   ofn.lStructSize = sizeof(ofn);                 1151   ofn.lStructSize = sizeof(ofn);
1161   ofn.hwndOwner = aWindow;                       1152   ofn.hwndOwner = aWindow;
1162   char fName[] = "Macro Files (*.mac)\0*.mac\ << 1153   ofn.lpstrFilter = "Macro Files (*.mac)\0*.mac\0All Files (*.*)\0*.*\0";
1163   ofn.lpstrFilter = (PTSTR)fName;             << 1154   ofn.lpstrFile = szFileName;
1164   ofn.lpstrFile = (PTSTR)szFileName;          << 
1165   ofn.nMaxFile = MAX_PATH;                       1155   ofn.nMaxFile = MAX_PATH;
1166   char dName[] = "mac";                       << 1156   ofn.lpstrDefExt = "mac";
1167   ofn.lpstrDefExt = (PTSTR)dName;             << 
1168   ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIS    1157   ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
1169                                                  1158 
1170   if (GetSaveFileName(&ofn)) {                   1159   if (GetSaveFileName(&ofn)) {
1171     G4String command = "/vis/viewer/save " +     1160     G4String command = "/vis/viewer/save " + G4String(szFileName);
1172     ApplyShellCommand(command, exitSession, e    1161     ApplyShellCommand(command, exitSession, exitPause);
1173                                                  1162 
1174     SendDlgItemMessage(aWindow, IDC_MAIN_STAT    1163     SendDlgItemMessage(aWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM) "State saved...");
1175     SendDlgItemMessage(aWindow, IDC_MAIN_STAT    1164     SendDlgItemMessage(aWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
1176   }                                              1165   }
1177 }                                                1166 }
1178 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1167 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1179 /********************************************    1168 /****************************************************************************************************/
1180                                                  1169 
1181 /********************************************    1170 /****************************************************************************************************/
1182 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1171 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1183 void G4UIWin32::DoSaveLog(HWND aWindow)          1172 void G4UIWin32::DoSaveLog(HWND aWindow)
1184 {                                                1173 {
1185   OPENFILENAME ofn;                              1174   OPENFILENAME ofn;
1186   char szFileName[MAX_PATH] = "";                1175   char szFileName[MAX_PATH] = "";
1187                                                  1176 
1188   ZeroMemory(&ofn, sizeof(ofn));                 1177   ZeroMemory(&ofn, sizeof(ofn));
1189                                                  1178 
1190   ofn.lStructSize = sizeof(ofn);                 1179   ofn.lStructSize = sizeof(ofn);
1191   ofn.hwndOwner = aWindow;                       1180   ofn.hwndOwner = aWindow;
1192   char fName[] = "Log Files (*.txt)\0*.txt\0A << 1181   ofn.lpstrFilter = "Log Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
1193   ofn.lpstrFilter = (PTSTR)fName;             << 1182   ofn.lpstrFile = szFileName;
1194   ofn.lpstrFile = (PTSTR)szFileName;          << 
1195   ofn.nMaxFile = MAX_PATH;                       1183   ofn.nMaxFile = MAX_PATH;
1196   char dName[] = "txt";                       << 1184   ofn.lpstrDefExt = "txt";
1197   ofn.lpstrDefExt = (PTSTR)dName;             << 
1198   ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIS    1185   ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
1199                                                  1186 
1200   if (GetSaveFileName(&ofn)) {                   1187   if (GetSaveFileName(&ofn)) {
1201     if (SaveLogFile((PTSTR)szFileName)) {     << 1188     if (SaveLogFile(szFileName)) {
1202       SendDlgItemMessage(aWindow, IDC_MAIN_ST    1189       SendDlgItemMessage(aWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM) "Saved log file...");
1203       SendDlgItemMessage(aWindow, IDC_MAIN_ST    1190       SendDlgItemMessage(aWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
1204     }                                            1191     }
1205   }                                              1192   }
1206 }                                                1193 }
1207 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1194 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1208 /********************************************    1195 /****************************************************************************************************/
1209                                                  1196 
1210 /********************************************    1197 /****************************************************************************************************/
1211 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1198 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1212 G4bool G4UIWin32::InitHelpTreeItems()            1199 G4bool G4UIWin32::InitHelpTreeItems()
1213 {                                                1200 {
1214   HTREEITEM newItem;                             1201   HTREEITEM newItem;
1215                                                  1202 
1216   G4UImanager* UI = G4UImanager::GetUIpointer    1203   G4UImanager* UI = G4UImanager::GetUIpointer();
1217   if (UI == nullptr) return false;               1204   if (UI == nullptr) return false;
1218   G4UIcommandTree* treeTop = UI->GetTree();      1205   G4UIcommandTree* treeTop = UI->GetTree();
1219                                                  1206 
1220   G4int treeSize = treeTop->GetTreeEntry();      1207   G4int treeSize = treeTop->GetTreeEntry();
1221   G4String commandText;                          1208   G4String commandText;
1222   for (G4int a = 0; a < treeSize; a++) {         1209   for (G4int a = 0; a < treeSize; a++) {
1223     // Creating new item                         1210     // Creating new item
1224     commandText = treeTop->GetTree(a + 1)->Ge    1211     commandText = treeTop->GetTree(a + 1)->GetPathName().data();
1225                                                  1212 
1226     // Add the item to the tree-view control.    1213     // Add the item to the tree-view control.
1227     newItem = AddItemToHelpTree((PTSTR)GetSho << 1214     newItem = AddItemToHelpTree(const_cast<LPTSTR>(GetShortCommandPath(commandText).c_str()));
1228                                                  1215 
1229     if (newItem == nullptr) return false;        1216     if (newItem == nullptr) return false;
1230                                                  1217 
1231     // Look for children                         1218     // Look for children
1232     CreateHelpTree(newItem, treeTop->GetTree(    1219     CreateHelpTree(newItem, treeTop->GetTree(a + 1));
1233   }                                              1220   }
1234                                                  1221 
1235   return true;                                   1222   return true;
1236 }                                                1223 }
1237 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1224 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1238 /********************************************    1225 /****************************************************************************************************/
1239                                                  1226 
1240 /********************************************    1227 /****************************************************************************************************/
1241 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1228 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1242 void G4UIWin32::CreateHelpTree(HTREEITEM aPar    1229 void G4UIWin32::CreateHelpTree(HTREEITEM aParent, G4UIcommandTree* aCommandTree)
1243 {                                                1230 {
1244   if ((aParent != nullptr) && (aCommandTree !    1231   if ((aParent != nullptr) && (aCommandTree != nullptr)) {
1245     // Creating new item                         1232     // Creating new item
1246     HTREEITEM newItem;                           1233     HTREEITEM newItem;
1247                                                  1234 
1248     G4String commandText;                        1235     G4String commandText;
1249     // Get the Sub directories                   1236     // Get the Sub directories
1250     for (G4int a = 0; a < aCommandTree->GetTr    1237     for (G4int a = 0; a < aCommandTree->GetTreeEntry(); a++) {
1251       commandText = aCommandTree->GetTree(a +    1238       commandText = aCommandTree->GetTree(a + 1)->GetPathName().data();
1252                                                  1239 
1253       // Add the item to the tree-view contro    1240       // Add the item to the tree-view control.
1254       newItem =                                  1241       newItem =
1255         AddItemToHelpTree((PTSTR)GetShortComm << 1242         AddItemToHelpTree(const_cast<LPTSTR>(GetShortCommandPath(commandText).c_str()), aParent);
1256                                                  1243 
1257       // Look for children                       1244       // Look for children
1258       CreateHelpTree(newItem, aCommandTree->G    1245       CreateHelpTree(newItem, aCommandTree->GetTree(a + 1));
1259     }                                            1246     }
1260                                                  1247 
1261     // Get the Commands                          1248     // Get the Commands
1262     for (G4int a = 0; a < aCommandTree->GetCo    1249     for (G4int a = 0; a < aCommandTree->GetCommandEntry(); a++) {
1263       commandText = aCommandTree->GetCommand(    1250       commandText = aCommandTree->GetCommand(a + 1)->GetCommandPath().data();
1264                                                  1251 
1265       // Add the item to the tree-view contro    1252       // Add the item to the tree-view control.
1266       AddItemToHelpTree((PTSTR)GetShortComman << 1253       AddItemToHelpTree(const_cast<LPTSTR>(GetShortCommandPath(commandText).c_str()), aParent);
1267     }                                            1254     }
1268   }                                              1255   }
1269 }                                                1256 }
1270 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1257 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1271 /********************************************    1258 /****************************************************************************************************/
1272                                                  1259 
1273 /********************************************    1260 /****************************************************************************************************/
1274 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1261 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1275 HTREEITEM G4UIWin32::AddItemToHelpTree(LPTSTR    1262 HTREEITEM G4UIWin32::AddItemToHelpTree(LPTSTR lpszItem, HTREEITEM aParent)
1276 {                                                1263 {
1277   TVITEM tvi;                                    1264   TVITEM tvi;
1278   TVINSERTSTRUCT tvins;                          1265   TVINSERTSTRUCT tvins;
1279   static auto hPrev = (HTREEITEM)TVI_FIRST;      1266   static auto hPrev = (HTREEITEM)TVI_FIRST;
1280                                                  1267 
1281   tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SE    1268   tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
1282                                                  1269 
1283   // Set the text of the item.                   1270   // Set the text of the item.
1284   tvi.pszText = lpszItem;                        1271   tvi.pszText = lpszItem;
1285   tvi.cchTextMax = sizeof(tvi.pszText) / size    1272   tvi.cchTextMax = sizeof(tvi.pszText) / sizeof(tvi.pszText[0]);
1286                                                  1273 
1287   // Save the heading level in the item's app    1274   // Save the heading level in the item's application-defined
1288   // data area.                                  1275   // data area.
1289   tvi.lParam = (LPARAM)aParent;                  1276   tvi.lParam = (LPARAM)aParent;
1290   tvins.item = tvi;                              1277   tvins.item = tvi;
1291   tvins.hInsertAfter = hPrev;                    1278   tvins.hInsertAfter = hPrev;
1292   // Set the parent item.                        1279   // Set the parent item.
1293   tvins.hParent = aParent;                       1280   tvins.hParent = aParent;
1294                                                  1281 
1295   // Add the item to the tree-view control.      1282   // Add the item to the tree-view control.
1296   hPrev = (HTREEITEM)SendMessage(                1283   hPrev = (HTREEITEM)SendMessage(
1297     fHWndHelpTree, TVM_INSERTITEM, (WPARAM)0,    1284     fHWndHelpTree, TVM_INSERTITEM, (WPARAM)0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
1298                                                  1285 
1299   if (hPrev == nullptr)                          1286   if (hPrev == nullptr)
1300     return nullptr;                              1287     return nullptr;
1301   else                                           1288   else
1302     return hPrev;                                1289     return hPrev;
1303 }                                                1290 }
1304 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1291 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1305 /********************************************    1292 /****************************************************************************************************/
1306                                                  1293 
1307 /********************************************    1294 /****************************************************************************************************/
1308 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1295 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1309 G4String G4UIWin32::GetShortCommandPath(const << 1296 G4String G4UIWin32::GetShortCommandPath(G4String commandPath)
1310 {                                                1297 {
1311   G4String str = commandPath;                 << 1298   G4String str = std::move(commandPath);
1312                                                  1299 
1313   if (str.find_last_of("/") == (str.size() -     1300   if (str.find_last_of("/") == (str.size() - 1)) str = str.erase(str.size() - 1, 1);
1314                                                  1301 
1315   str = str.erase(0, str.find_last_of("/") +     1302   str = str.erase(0, str.find_last_of("/") + 1);
1316                                                  1303 
1317   return str;                                    1304   return str;
1318 }                                                1305 }
1319 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1306 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1320 /********************************************    1307 /****************************************************************************************************/
1321                                                  1308 
1322 /********************************************    1309 /****************************************************************************************************/
1323 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1310 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1324 LPSTR G4UIWin32::GetItemPath(HTREEITEM item)     1311 LPSTR G4UIWin32::GetItemPath(HTREEITEM item)
1325 {                                                1312 {
1326   // Get the text for the item.                  1313   // Get the text for the item.
1327   TVITEM tvitem;                                 1314   TVITEM tvitem;
1328   tvitem.mask = TVIF_TEXT;                       1315   tvitem.mask = TVIF_TEXT;
1329   tvitem.hItem = item;                           1316   tvitem.hItem = item;
1330   TCHAR infoTipBuf[1024];                        1317   TCHAR infoTipBuf[1024];
1331   tvitem.pszText = infoTipBuf;                   1318   tvitem.pszText = infoTipBuf;
1332   tvitem.cchTextMax = sizeof(infoTipBuf) / si    1319   tvitem.cchTextMax = sizeof(infoTipBuf) / sizeof(TCHAR);
1333                                                  1320 
1334   std::string str = "";                          1321   std::string str = "";
1335   while  (item != nullptr) {                  << 1322   while (item != nullptr) {
1336     TreeView_GetItem(fHWndHelpTree, &tvitem);    1323     TreeView_GetItem(fHWndHelpTree, &tvitem);
1337     str = "/" + std::string((PSTR)tvitem.pszT << 1324     str = "/" + std::string(tvitem.pszText) + str;
1338                                                  1325 
1339     item = TreeView_GetParent(fHWndHelpTree,     1326     item = TreeView_GetParent(fHWndHelpTree, item);
1340     tvitem.hItem = item;                         1327     tvitem.hItem = item;
1341   }                                              1328   }
1342                                                  1329 
1343   auto* result = new TCHAR[str.size() + 1];      1330   auto* result = new TCHAR[str.size() + 1];
1344   result[str.size()] = 0;                        1331   result[str.size()] = 0;
1345   std::copy(str.begin(), str.end(), result);     1332   std::copy(str.begin(), str.end(), result);
1346                                                  1333 
1347   return (LPSTR)result;                       << 1334   return result;
1348 }                                                1335 }
1349 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1336 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1350 /********************************************    1337 /****************************************************************************************************/
1351                                                  1338 
1352 /********************************************    1339 /****************************************************************************************************/
1353 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1340 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1354 G4bool ConvertStringToInt(const char* aString    1341 G4bool ConvertStringToInt(const char* aString, G4int& aInt)
1355 {                                                1342 {
1356   aInt = 0;                                      1343   aInt = 0;
1357   if (aString == nullptr) return false;          1344   if (aString == nullptr) return false;
1358   char* s;                                       1345   char* s;
1359   G4long value = strtol(aString, &s, 10);        1346   G4long value = strtol(aString, &s, 10);
1360   if (s == aString) return false;                1347   if (s == aString) return false;
1361   aInt = value;                                  1348   aInt = value;
1362   return true;                                   1349   return true;
1363 }                                                1350 }
1364 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    1351 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
1365 /********************************************    1352 /****************************************************************************************************/
1366                                                  1353