File: INTERNLS\M_MAIN.CPP
1 // m_main.cpp
2 // (C) 1993,95 by Heiko Damerow MPG AG "Roentgenbeugung"
3 // (C) 1996 by Heiko Damerow DLR/DFD
4 #include <direct.h>
5
6 #include "internls\evrythng.h" // GermanVersion
7 #include "winresrc\rc_def.h" // Ressourcen-IDs
8 #include "winresrc\rc_prtow.h" // Ressourcen-IDs (! neu: klier Protokollbuch)
9 #include "help\help_def.h" // Help-IDs
10 #include <shellapi.h>
11 //!neu ini-Datei klier
12 // Bibliotheken zum Zugriff auf das Dateisystem (16/32bit)
13 // damit koennen die Dateiattribute der Hardware-ini-Datei
14 // geaendert werden
15 #include <winbase.h>
16 #include <Commctrl.h>
17 #pragma hdrstop
18
19 #include "utils\u_window.h"
20 //#include "datavisa\datavisa.h"
21 #include "workflow\workflow.h"
22 #include "detecuse\detecuse.h"
23 #include "motrstrg\motrstrg.h"
24
25 // Diffraktometrie
26 #include "difrkmty\a_extern.h" // TAreaScanWindow
27 #include "difrkmty\s_extern.h" // TScanWindow
28
29 //! neu: klier Allgemeine Einstellungen
30 #include "mespara\mespara.h"
31 #include "mespara\mesparaw.h"
32
33 //! neu: klier Protokollbuch
34 #include "protocol\protocol.h"
35
36 //! neu: Automatische Justage
37 #include "autojust\autojust.h"
38
39 // ANFANG 29.11.2002 Kullmann, Reinecker : getrennte Manuelle Justage, Topographie und neue Manuelle Justage
40 #include "manjust\mj_gui.h" // neue Manuelle Justage
41 #include "manjust\mj_ogui.h" // getrennte Manuelle Justage
42 #include "manjust\mj_old.h" // alte ungetrennte Manuelle Justage
43 #include "topogrfy\tp_gui.h" // getrennte Topographie
44 #include "topogrfy\topogrfy.h" // alte Topographie
45 // ENDE 29.11.2002
46
47 #include "internls\l_layer.h"
48
49 #include "utils\CheckMemory.h" // CHECKMEM
50
51 //--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--
52
53 TModelessDlg *MacroExecDlg= 0; //! neu Kullmann+Reinecker: TheModeless ersetzt durch MacroExecDlg; extern entfernt
54 HACCEL TMain::hAccellerator= 0;
55
56 const int WindowMenuPos= 4; // Index des 'Fenster'-Hauptmenüpunktes
57 static BOOL bEnvInstalled= FALSE;
58 static EWorkPlace WorkPlace= RTK;
59 static BOOL nStartupReport= 0;
60 static BOOL bShutdown= FALSE;
61 static char buf[MaxString];
62
63 //!neu klier Allgemeine Einstellungen
64 TMeasurementParameter MeasurementParameter;
65
66 TMain Main;
67
68 extern TSteering Steering;
69 extern TTopographyOld TopographyOld;
70
71 //Prototypen
72 //17.11.2002 LPDataBase WINAPI GetDataBasePtr( void );
73
74 //!neu ini-Datei klier
75 BOOL bNoHardwareFile= TRUE; // Pruefvariable ist TRUE, wenn Hardware-ini-Datei nicht existiert
76 BOOL bNoConfigurationFile= TRUE; // Pruefvariable ist TRUE, wenn Programm-ini-Datei nicht existiert
77
78 BOOL bManualMovesCorrected= FALSE;
79
80 static char mainVersion[]= "V 1.52 ("__DATE__")";
81
82 #ifdef GermanVersion
83 static const char strFailure[]= "Fehler";
84 static const char strMessage[]= "Meldung";
85 static const char strMessage01[]= "Messung wird abgebrochen";
86 static const char strMessage02[]= "MDI-Fenster kann nicht erzeugt werden! Zu viele Fenster?";
87 static const char strMessage03[]= "Daten wurden noch nicht gesichert.\nSichern ?";
88 static const char strMessage4[]= "kont. &PSD-Anzeige ausschalten";
89 static const char strMessage04[]= "Messung &weiterführen";
90 static const char strMessage05[]= "Messung &unterbrechen";
91 static const char strMessage5[]= "Makro &unterbrechen";
92 static const char strMessage06[]= "Das Motorsteuer-Modul ist noch anderweitig in Benutzung !";
93 static const char strMessage07[]= "Neustart";
94 static const char strMessage08[]= "Endlage von Motor %d angesprochen.";
95 static const char strMessage09[]= "Motor-Steuerung";
96 static const char strMessage10[]= "Programm wurde erfolgreich gestartet.";
97 static const char strMessage11[]= "Probleme beim Starten des Programms";
98 static const char strMessage12[]= "Bitte ein Darstellungs-Fenster öffnen !";
99 static const char strMessage13[]= "Die Messung wurde abgeschlossen !";
100 static const char strMessage15[]= "Fehler beim Starten einer Meß-Funktion.";
101 static const char strMessage16[]= "Fehler beim Starten eines MDI-Fensters.";
121 #endif
122
123 //******************************************************************************
124 //******************************************************************************
125 //******************************************************************************
126
127 int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR, int cmdShow)
128 {
129 // ACHTUNG bis nach dem Aufruf von Methode InitializeFileLocations() dürfen die Methoden zum Auslesen von FileLocations nicht verwendet werden
130 CreateMutex(NULL,true,"XCTL_32_INSTANCE"); //hp Mutexobjekt anlegen
131 if ( GetLastError() == ERROR_ALREADY_EXISTS ) //hp prüfen ob es schon existiert
132 { // only single instance allowed
133 // SetActivWindow(hPrevInst);
134 exit(0);
135 } //hp Änderung nötig, da hPrevInst unter Win32 immer 0
136
137 // Teile von TBasicMain
138 InitBasicMain( (TBasicMain*)(&Main) );
139 char _arg[_MAX_PATH];
140 GetModuleFileName(hInstance, _arg, _MAX_PATH);
141 Main.SetExeFilename( _arg );
142
143 Main.SetMainInstance( hInstance );
144 Main.SetWakeUpMsg( RegisterWindowMessage("WakeUpSteering") );
145
146
147 // Test ob die Programm-ini-Datei existiert (benötigt TBasicMain)
148 OFSTRUCT of;
149 if (OpenFile(GetCFile(), &of, OF_EXIST) == -1)
150 {
151 #ifdef GermanVersion
152 MessageBox(GetFocus(), "Kein Konfigurationsfile !", "Fehler", MBSTOP);
155 #endif
156 exit(4);
157 }
158 else
159 bNoConfigurationFile= FALSE; // Datei ist vorhanden
160
161 // Test ob die Hardware-ini-Datei existiert (benötigt FileLocations)
162 if (OpenFile(GetHWFile(), &of, OF_EXIST) == -1)
163 {
164 #ifdef GermanVersion
165 MessageBox(GetFocus(), "Kein Hardwarekonfigurationsfile !", "Fehler", MBSTOP);
168 #endif
169 exit(4);
170 }
171 else
172 bNoHardwareFile= FALSE; // Datei ist vorhanden
173
174 // Größe der Messagequeue auf 100 Einträge setzen (in Win32 eigentlich obsolete)
175 int cnt= 100;
176 while (!SetMessageQueue(cnt--))
177 /* increase messagequeue-size*/;
178
179 // Hauptprogramm, incl. Fenstern initialisieren
180 if ( !Main.Init(hInstance, cmdShow) ) nStartupReport += 1;
181
182 // Testen ob Timer verfügbar sind (benoetigt das Hauptfenster)
183 cnt= SetTimer(GetFrameHandle(), 2000, 30000, NULL);
184 if (cnt)
185 KillTimer(GetFrameHandle(), 2000);
186 else
187 #ifdef GermanVersion
188 MessageBox(GetFocus(), "Keine Timer verfügbar !", "System-Fehler", MBSTOP);
191 #endif
192
193 // initialize DLLs, Hardware und Fenster (benötigt Hauptfenster)
194 Main.InitHardware();
195
196 return TMain::MessageLoop();
197 };
198 //-----------------------------------------------------------------------------
199
200 void ShowProgramStatus(HWND hwnd)
201 {
202 char buf[MaxString];
203 char fn[MaxString];
204 char info[3*MaxString];
205
206 GetModuleFileName(mlGetInstance(), fn, MaxString);
207 sprintf(buf, "Drive : %s [%s]\n\n", mlGetVersion(), fn);
208 strcpy(info, buf);
209 GetModuleFileName(dlGetInstance(), fn, MaxString);
210 sprintf(buf, "Detector : %s [%s]\n\n", dlGetVersion(), fn);
211 strcat(info, buf);
212 GetModuleFileName(spGetInstance(), fn, MaxString);
213 sprintf(buf, "Library : %s [%s]\n\n", spGetVersion(), fn);
214 strcat(info, buf);
215 sprintf(buf, "Main : %s\n", mainVersion);
216 strcat(info, buf);
217 MessageBox(hwnd, info, "Versionskontrolle", MBINFO);
218 };
219
220 //#############################################################################
221 // TMain
222 //#############################################################################
223
224 LPCSTR TMain::GetTarget( void ) {
225 return MeasurementParameter.GetTarget();
226 }
227
228 LPSTR TMain::GetReflection( LPSTR sRef ) {
229 return MeasurementParameter.GetReflection(sRef);
230 }
231
232 TMain::TMain(void): m_EventHandler(true, true, false), ScanWindow(0), AreaScanWindow(0), hTheMenu(0), hwndClient(NULL) // 16.06.2004 , bmpStatusLine
233 {
234 // ! neu Kullmann+Reinecker: Es ist immer ratsam ALLE Attribute zu initialisieren !!!
235 //Datum 16.05.2003: AdjustmentWindow= NULL;
236 //Datum 16.05.2003: CCDLineScanWindow= NULL;
237 //Datum 16.05.2003: AreaScanCCDWindow= NULL;
238 //Datum 16.05.2003: hCCDLineScanWindow= 0;
239 //Datum 16.05.2003: hAreaScanCCDWindow= 0;
240 //Datum 16.05.2003: hActualWindow= 0;
241 //24.04.2004 CurrentID= 0;
242 //24.04.2004 CurrentPopup= 0;
243 // Laden der Einstellungen ausgelagert in WinMain()
244 InitializeDelay();
245 PRE; //hp
246 };
247 //-----------------------------------------------------------------------------
248
249 TMain::~TMain(void)
250 { // Mdi-Fenster (u.a. ScanWindow, AreaScanWindow,) sind bereits freigegeben
251 // ANFANG 23.01.2003 Kullmann, Reinecker : getrennte Topographie und Manuelle Justage
252 IniWriteBool( GetCFile(), "Environment", "NEW-MANUALADJUSTMENT", m_NewManJustage );
253 // ENDE 23.01.2003
254 if (!bNoHardwareFile && !bNoConfigurationFile)
255 SavePos();
256 UnInitializeMotorsSimulation();
257 MeasurementParameter.Save(GetCFile());
258 //!neu ini-Datei klier
259 /*
260 #ifndef _WIN32
261 _rtl_chmod(GetHWFile(),1,FA_HIDDEN + FA_ARCH + FA_RDONLY); // Schreibschutzattribut der Hardware-
262 #else // ini-Datei wird gesetzt
263 SetFileAttributes(GetHWFile(),FILE_ATTRIBUTE_HIDDEN + FILE_ATTRIBUTE_ARCHIVE
264 + FILE_ATTRIBUTE_READONLY);
265 #endif
266 */
267
268 // ANFANG: neu Kullmann+Reinecker (31.01.2004) anderen Klassen gestatten auf Ereignisse zur reagieren
269 TIndex i= 0;
270 while ( i<m_EventHandler.GetCount() ) {
271 IMainEvents *act= (IMainEvents *)m_EventHandler[i];
272 if ( act ) act->OnLeave(); // benachrichtigen
273 if ( i<m_EventHandler.GetCount() && m_EventHandler[i]==act ) i++; // diese Bedingung ist nicht erfüllt, wenn sich <act> in OnLeave mit RemoveFromEventList aus der Liste entfernt hat; dann i nicht weitersetzen!!!
274 }
275 // abschließend die Liste freigeben
276 while ( m_EventHandler.GetCount() ) {
277 IMainEvents *act= (IMainEvents *)m_EventHandler.Remove(0);
278 if ( act ) _FREEOBJ(act);
279 }
280 // ENDE: neu Kullmann+Reinecker (31.01.2004)
281
282 POST;
283 DUMPDIFF("TMAIN"); //hp
284 CHECKMEM("TMAIN");
285 };
286 //-----------------------------------------------------------------------------
287
288 BOOL TMain::Init( HINSTANCE hInstance, int cmdShow )
289 {
290 //!neu klier Allgemeine Einstellungen
291 MeasurementParameter.Load(GetCFile());
292
293 bManualMovesCorrected= GetPrivateProfileInt("ManualMoves", "Correction",
294 FALSE, GetCFile());
295
296 // ANFANG 23.01.2003 Kullmann, Reinecker : getrennte Topographie und Manuelle Justage
297 m_NewManJustage= IniReadBool( GetCFile(), "Environment", "NEW-MANUALADJUSTMENT", TRUE );
298 // ENDE 23.01.2003
299
300 //welche Art Arbeitsplatz
301 GetPrivateProfileString("Steuerprogramm", "Environment", "RTK", buf, MaxString, GetCFile());
302 if ( !strcmp(buf, "HRM") )
303 WorkPlace= HRM;
304 else if ( !strcmp(buf, "Expert") )
305 WorkPlace= Expert;
306 else if ( !strcmp(buf, "ScanTable") )
307 WorkPlace= ScanTable;
308 else if ( !strcmp(buf, "PDI-Diffractometer") )
309 WorkPlace= PDI_Diffractometer;
310 else if ( !strcmp(buf, "Diff2") )
311 WorkPlace= Diff2;
312 else if ( !strcmp(buf, "Diff3") )
313 WorkPlace= Diff3;
314 else
315 WorkPlace= RTK; // DEFAULT "RTK"
316
317 //welche Features freischalten (benoetigt Art des Arbeitsplatzes)
318 AreaScanExtention= ScanExtention= MacroExtention= TopographyExtention= FALSE;
319 switch (WorkPlace)
320 {
321 case HRM:
322 AreaScanExtention= ScanExtention= TRUE;
323 break;
324
325 case RTK:
326 ScanExtention= TopographyExtention= TRUE;
327 break;
328
329 case PDI_Diffractometer:
330 AreaScanExtention= ScanExtention= TopographyExtention= TRUE;
331 break;
332
333 case Diff2:
334 AreaScanExtention= ScanExtention= TopographyExtention= TRUE;
335 break;
336
337 case Diff3:
338 AreaScanExtention= ScanExtention= TopographyExtention= TRUE;
339 break;
340
341 case Expert:
342 MacroExtention= AreaScanExtention= ScanExtention= TopographyExtention= TRUE;
343 break;
344
345 default:
346 ScanExtention= TopographyExtention= TRUE;
347 }
348
349 // Hauptfenster mit Menü
350 WNDCLASS wndClass;
351 GetClassInfo(NULL, APPLICATIONTITLE, &wndClass);
352 wndClass.style= CS_HREDRAW | CS_VREDRAW;
353 wndClass.cbClsExtra= 0;
354 wndClass.cbWndExtra= 0;
355 wndClass.hInstance= hInstance;
356 wndClass.hIcon= (HICON)LoadImage( hInstance, MAKEINTRESOURCE(icon_XControl),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
357 wndClass.hCursor= (HCURSOR)LoadImage(NULL, IDC_ARROW,IMAGE_CURSOR,0,0,LR_DEFAULTCOLOR);
358 wndClass.hbrBackground= (HBRUSH)COLOR_APPWORKSPACE + 1;
359 wndClass.lpszMenuName= NULL;
360 wndClass.lpszClassName= APPLICATIONTITLE;
361 wndClass.lpfnWndProc= TMain::EventHandler;
362 RegisterClass(&wndClass);
363 HWND WndFrame= CreateWindow(APPLICATIONTITLE, APPLICATIONTITLE, MainWindow_Style,
364 5, 5, 500, 500, NULL, NULL, hInstance, NULL); // sendet WM_CREATE an TMain::EventHandler
365
366 // Clientbereich (wo die MDI-Fenster rein kommen)
367 CLIENTCREATESTRUCT ClientCreate;
368 ClientCreate.hWindowMenu= GetSubMenu(hTheMenu, 1);
369 ClientCreate.idFirstChild= 2000;
370 ClientCreate.hWindowMenu= GetSubMenu(hTheMenu, WindowMenuPos);
371 hwndClient= CreateWindow( (LPSTR)"MdiClient", 0, ClientWindow_Style,
372 0, 0, 0, 0, WndFrame, (HMENU)NULL, hInstance, (LPSTR) &ClientCreate);
373 ShowWindow(hwndClient, SW_SHOW);
374 TBasicMain::SetClientHandle(hwndClient);
375
376 // Statuszeile
377 CreateStatusBar(hInstance, WndFrame);
378
379 // Hauptfenster anzeigen; Tastenkombinationen laden
380 ShowWindow(WndFrame, cmdShow);
381 UpdateWindow(WndFrame);
382 TMain::hAccellerator= LoadAccelerators(hInstance, MAKEINTRESOURCE(ACC_Main)); // Tastenkombinationen laden
383 TBasicMain::SetFrameHandle(WndFrame);
384
385 // die gemeinsam genutzen Attribute in TMainParameters verwalten (die bereits oben registrierten Meldungen verwenden, nicht neu registrieren)
386 BOOL createDefs= IniReadBool(GetCFile(), "Steuerprogramm", "CreateIniDefaults", TRUE);
387 TBasicMain::SetCreateIniDefaults(createDefs);
388
389 //benötigt TBasicMain
390 CreateMenuBar();
391 LoadPos();
392
393 // jetzt erst den neuen Hintergrund zeigen
394 DefMdiClientProc= (WNDPROC) SetWindowLong(hwndClient, GWL_WNDPROC, (LONG) TMain::EventHandlerMdiClient);
395 return TRUE;
396 }
397 //-----------------------------------------------------------------------------
398
399 void TMain::InitHardware() {
400 //MOTORS.DLL
401 InitializeMotorsSimulation(GetHWFile());
402
403 if (!mlInitializeMotorsDLL())
404 nStartupReport += 2;
405 mlSetAxis(0);
406
407 //COUNTERS.DLL
408 HINSTANCE CountersDLLInstance= GetModuleHandle("counters.dll");
409 if (!CountersDLLInstance)
410 MessageBox(GetFocus(), "Bibliothek counters.dll nicht geladen !", "Fehler", MBSTOP);
411
412 //PROTOCOL.DLL
413 InitializeProtocol(GetFrameHandle(), &MeasurementParameter);
414
415 //Steering
416 //!
417 if (! Steering.Initialize( GetFrameHandle(), mlGetAxis(), TDetectorManager::DetectorManager().GetDetector() ))
418 {
419 exit(0);
420 }
421
422 //Topography
423 TopographyOld.Initialize();
424
425 bEnvInstalled= TRUE;
426
427 //Autokalibierung?
428 BOOL bAutoCalibration= GetPrivateProfileInt("Steuerprogramm", "AutoCalibration",
429 FALSE, GetCFile());
430 if (bAutoCalibration)
431 mlInquireReferencePointDlg(99);
432
433 //zeige gewünschte Fenster an
434 int nStartup= 0;
435 GetPrivateProfileString("Steuerprogramm", "Startup", "Scan", buf, MaxString, GetCFile());
436 if ( !strcmp(buf, "AreaScan") )
437 nStartup= 0;
438 else if ( !strcmp(buf, "Detector") )
439 nStartup= 1;
440 else if ( !strcmp(buf, "ManualAdjustment") )
441 nStartup= 3;
442 else if ( !strcmp(buf, "ScanPlace") )
443 nStartup= 4;
444 else if ( !strcmp(buf, "ExecuteMacro") )
445 nStartup= 5;
446 else if ( !strcmp(buf, "Nothing") )
447 nStartup= 6;
448 else if ( !strcmp(buf, "AreaScanCCD") )
449 nStartup= 7;
450 else
451 nStartup= 2; // DEFAULT "Scan"
452 switch (nStartup)
453 {
454 case 0:
455 if (AreaScanExtention && !AreaScanWindow)
456 (new TAreaScanWindow(GetMainInstance()))->Show(); // bei TAreaScanWindow.Create() wird auch AreaScanWindow auf dieses Fenster gesetzt
457 (new TCounterWindow(GetMainInstance()))->Show();
458 break;
459
460 case 1:
461 (new TCounterWindow(GetMainInstance()))->Show();
462 break;
463
464 case 2:
465 if (ScanExtention && !ScanWindow )
466 (new TScanWindow(GetMainInstance()))->Show(); // bei TScanWindow.Create() wird auch ScanWindow auf dieses Fenster gesetzt
467 (new TCounterWindow(GetMainInstance()))->Show();
468 break;
469
470 case 3:
471 (new TCounterWindow(GetMainInstance()))->Show();
472 PostMessage(GetFrameHandle(), WM_COMMAND, cm_AngleControl, 0);
473 break;
474
475 case 5:
476 if (MacroExtention)
477 PostMessage(GetFrameHandle(), WM_COMMAND, cm_CallExecuteMacro, 0);
478 break;
479
480 case 6:
481 /* do not execute default-path */;
482 break;
483
484 default:
485 (new TCounterWindow(GetMainInstance()))->Show();
486 }
487 if (nStartupReport)
488 sprintf(buf, "%s (%d)", strMessage11, nStartupReport);
489 else
490 sprintf(buf, "%s", strMessage10);
491 SetInfo(buf);
492 }
493 //-----------------------------------------------------------------------------
494
495 void TMain::CreateStatusBar( HINSTANCE hInstance, HWND hWnd )
496 { // GetMainInstance und GetFrameHandle dürfen noch nicht verwendet werden,
497 // weil InitializeMainParameters noch nicht aufgerufen wurde - deshalb
498 // werden HINSTANCE und HWND übergeben
499
500 INITCOMMONCONTROLSEX InitCtrls;
501 int PartArray[6]= { 0, 15, 105, 155, 255, -1 }; // Breiten der StatusBar-Teile
502
503 // CommonControl DLL laden
504 InitCtrls.dwSize= sizeof(INITCOMMONCONTROLSEX);
505 InitCtrls.dwICC= ICC_BAR_CLASSES;
506 if (!InitCommonControlsEx(&InitCtrls)) return;
507
508 // StatusBar erzeugen
509 HWND hwndStatusBar= CreateWindowEx(
510 0, // no extended styles
511 STATUSCLASSNAME, // name of status bar class
512 (LPCTSTR) NULL, // no text when first created
513 SBARS_SIZEGRIP | // includes a sizing grip
514 WS_CHILD | WS_VISIBLE, // creates a child window
515 0, 0, 0, 0, // ignores size and position
516 hWnd, // handle to parent window
517 (HMENU) id_STATUS_BAR, // child window identifier
518 hInstance, // handle to application instance
519 NULL); // no window creation data
520
521 // Nachricht an StatusBar, wie die Unterteilungen aussehen sollen
522 SendMessage(hwndStatusBar, SB_SETPARTS, (WPARAM) 6, (LPARAM) PartArray);
523 TBasicMain::SetStatusBarHandle( hwndStatusBar );
524 }
525 //-----------------------------------------------------------------------------
526 //ph
527
528 HMENU TMain::CreateMenuBar ( void )
529 {
530 hTheMenu= LoadMenu(GetMainInstance(), MAKEINTRESOURCE(menu_Main));
531
532 if ( !ScanExtention )
533 RemoveMenu(hTheMenu, cm_CallExecuteScan, MF_BYCOMMAND);
534 if ( !AreaScanExtention )
535 RemoveMenu(hTheMenu, cm_CallExecuteAreaScan, MF_BYCOMMAND);
536 if ( !TopographyExtention )
537 RemoveMenu(hTheMenu, cm_CallExecuteTopograpy, MF_BYCOMMAND);
538
539 if ( !TopographyExtention )
540 RemoveMenu(hTheMenu, cm_CallTopographyExec, MF_BYCOMMAND); // 03.01.2003 Kullmann, Reinecker : neue Topografie
541
542 if ( !MacroExtention )
543 RemoveMenu(hTheMenu, cm_CallExecuteMacro, MF_BYCOMMAND);
544 if ( !TopographyExtention )
545 RemoveMenu(hTheMenu, cm_TopograpyParam, MF_BYCOMMAND);
546
547 if ( !TopographyExtention )
548 RemoveMenu(hTheMenu, cm_TopographyAdjust, MF_BYCOMMAND); // 03.01.2003 Kullmann, Reinecker : neue Topografie
549
550
551 SetMenu(GetFrameHandle(), hTheMenu);
552 return NULL;
553 };
554 //-----------------------------------------------------------------------------
555
556 void TMain::LoadPos(void)
557 {
558 RECT rc;
559
560 rc.left= GetPrivateProfileInt("Steuerprogramm", "xo", 500, GetCFile());
561 rc.top= GetPrivateProfileInt("Steuerprogramm", "yo", 400, GetCFile());
562 rc.right= GetPrivateProfileInt("Steuerprogramm", "x1", 670, GetCFile());
563 rc.bottom= GetPrivateProfileInt("Steuerprogramm", "y1", 450, GetCFile());
564 SetWindowPos(GetFrameHandle(), NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
565 };
566 //-----------------------------------------------------------------------------
567
568 void TMain::SavePos(void)
569 {
570 char buf[MaxString];
571 RECT rc;
572
573 GetWindowRect(GetFrameHandle(), &rc);
574 sprintf(buf, "%ld", min(max(0l, (long)rc.left), 900l));
575 WritePrivateProfileString("Steuerprogramm", "xo", buf, GetCFile());
576 sprintf(buf, "%ld", min(max(0l, (long)rc.top), 600l));
577 WritePrivateProfileString("Steuerprogramm", "yo", buf, GetCFile());
578 sprintf(buf, "%ld", min(max((long)rc.left + 100l, (long)rc.right), 1000l));
579 WritePrivateProfileString("Steuerprogramm", "x1", buf, GetCFile());
580 sprintf(buf, "%ld", min(max((long)rc.top + 70l, (long)rc.bottom), 750l));
581 WritePrivateProfileString("Steuerprogramm", "y1", buf, GetCFile());
582 };
583 //-----------------------------------------------------------------------------
584
585 // ANFANG: neu Kullmann+Reinecker (31.01.2004) anderen Klassen gestatten auf Ereignisse zur reagieren
586 bool TMain::AddToEventList(IMainEvents *toAdd)
587 { // zur Liste hinzufügen
588 return m_EventHandler.Append(toAdd);
589 }
590 //-----------------------------------------------------------------------------
591
592 bool TMain::RemoveFromEventList(IMainEvents *toRemove)
593 { // aus der Liste entfernen
594 return ( m_EventHandler.RemoveData(toRemove)!=0 );
595 }
596 //-----------------------------------------------------------------------------
597 // ENDE: neu Kullmann+Reinecker (31.01.2004)
598
599 void TMain::OnSize(HWND hWindow)
600 {
601 RECT rect, stat_rect;
602 LONG stat_heigth;
603
604 GetClientRect(hWindow, &rect);
605 GetWindowRect( GetStatusBarHandle(), &stat_rect );
606 stat_heigth= stat_rect.bottom - stat_rect.top;
607 MoveWindow( GetClientHandle(), 0, 0, rect.right, rect.bottom - stat_heigth, 1 );
608 SendMessage( GetStatusBarHandle(), WM_SIZE, 0, 0 );
609 };
610 //-----------------------------------------------------------------------------
611
612 void TMain::OnPaint(HWND hWindow)
613 {
614 if (bShutdown)
615 return;
616
617 SetStatusBarText();
618 SetWatchIndicator(3);
619 SendMessage(GetStatusBarHandle(), WM_PAINT, 0, 0);
620 };
621 //-----------------------------------------------------------------------------
622
623 void TMain::OnMenuInit( void )
624 { // wird nach dem Öffnen, aber vor dem Anzeigen des Hauptmenüs aufgerufen
625 BOOL bNew= FALSE, bOpen= FALSE, bSave= FALSE, bScanning= FALSE, bShowPsdContinuous= FALSE, bInterrupted= FALSE;
626 HWND hwnd= (HWND)SendMessage(GetClientHandle(), WM_MDIGETACTIVE, 0, 0l);
627 // Ermitteln des des Fenster-Struktur-Zeigers
628 TMDIWindow *window= (TMDIWindow *)GetWindowLong(hwnd, 1);
629 if ( window && hwnd) {
630 bNew= window->CanNew();
631 bOpen= window->CanOpenFile();
632 bSave= window->CanSave();
633 bScanning= window->IsScanning(bShowPsdContinuous);
634 bInterrupted= window->IsInterrupted();
635 }
636 EnableMenuItem(hTheMenu, cm_New, (bNew) ? MF_ENABLED : MF_GRAYED);
637 EnableMenuItem(hTheMenu, cm_Open, (bOpen) ? MF_ENABLED : MF_GRAYED);
638 EnableMenuItem(hTheMenu, cm_Save, (bSave) ? MF_ENABLED : MF_GRAYED);
639 EnableMenuItem(hTheMenu, cm_SaveAs, (bSave) ? MF_ENABLED : MF_GRAYED);
640 // Beschriftung von Menüpunkt cm_InterruptAction aktualisieren
641 if ( bShowPsdContinuous )
642 ModifyMenu( hTheMenu, cm_InterruptAction, MF_BYCOMMAND, cm_InterruptAction, strMessage4);
643 else if ( bScanning && bInterrupted )
644 ModifyMenu( hTheMenu, cm_InterruptAction, MF_BYCOMMAND, cm_InterruptAction, strMessage04);
645 else if ( bScanning && !bInterrupted )
646 ModifyMenu( hTheMenu, cm_InterruptAction, MF_BYCOMMAND, cm_InterruptAction, strMessage05);
647 else
648 ModifyMenu( hTheMenu, cm_InterruptAction, MF_BYCOMMAND, cm_InterruptAction, strMessage5);
649 EnableMenuItem(hTheMenu, cm_InterruptAction, (Steering.IsActive() || bScanning || bShowPsdContinuous) ? MF_ENABLED : MF_GRAYED);
650 DrawMenuBar(GetFrameHandle());
651 }
652 //-----------------------------------------------------------------------------
653
654 void TMain::OnMenuSelect(HWND hWindow, WPARAM wParam, LPARAM lParam)
655 { // Beschreibung für Menüpunkte in der Statuszeile anzeigen, wenn ein Menüpunkt ausgewählt wird
656 char *MsgString= 0;
657 UINT menuResId= GET_WM_COMMAND_ID(wParam, lParam);
658 if ( menuResId!=NULL && menuResId>20/*Summe der Hauptmenüs und Menüs mit Untermenüs*/ && menuResId!=0xFFFFFFFF ) {
659 int actLen= 50;
660 while (1) {
661 MsgString= new char[actLen+1];
662 int len= ::LoadString( GetMainInstance(), menuResId, MsgString, actLen );
663 if ( len>=actLen-1 && actLen<512 ) { // in jedem Durchlauf 10 Zeichen mehr Platz gewähren
664 _FREELIST(MsgString);
665 actLen+= 10;
666 continue;
667 }
668 if ( !len ) { // Eintrag ist nicht vorhanden
669 _FREELIST(MsgString);
670 const char prae[]= "RESID-FEHLER!!! Für RessourcenId %d ist kein StringTable-Eintrag verfügbar.";
671 char *buf= new char[ strlen(prae)+_MAXLENDOUBLE+1 ];
672 sprintf(buf, prae, menuResId);
673 TraceErr(buf);
674 _FREEOBJ(buf);
675
676 MsgString= new char[ 1+1 ]; // Leerzeichen + Nullterminierung
677 strcpy(MsgString, " ");
678 }
679 break;
680 }
681 } else { // für Separator, Menüs mit Untermenüs und Verlassen des Menüs
682 MsgString= new char[ 1+1 ]; // Leerzeichen + Nullterminierung
683 strcpy(MsgString, " ");
684 }
685 if ( !MsgString ) return;
686 SetInfo( MsgString );
687 _FREELIST(MsgString);
688 };
689 //-----------------------------------------------------------------------------
690
691 void TMain::SetWatchIndicator(long st)
692 {
693 char chr[2];
694
695 chr[0]= 0;
696 chr[1]= 0;
697 switch (st % 4)
698 {
699 case 0:
700 chr[0]= '\\';
701 break;
702
703 case 1:
704 chr[0]= '|';
705 break;
706
707 case 2:
708 chr[0]= '/';
709 break;
710
711 case 3:
712 chr[0]= '-';
713 break;
714 }
715
716 SetStatusBarText( piIndicator, chr );
717 };
718 //-----------------------------------------------------------------------------
719
720 /*BOOL TMain::GetDataDlg(LPSTR text, int *val)
721 {
722 int dref;
723 TModalDlg *dlg= 0;
724
725 dref= *val;
726 dlg= new TGetDataDlg(text, &dref);
727 if ( dlg ) dlg->ExecuteDialog(GetFrameHandle());
728 *val= dref;
729 _FREEOBJ(dlg);
730 return TRUE;
731 };*/
732 //-----------------------------------------------------------------------------
733
734 LRESULT TMain::OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
735 {
736 TModalDlg *dlg= 0;
737
738 switch (GET_WM_COMMAND_ID(wParam, lParam))
739 {
740 case cm_Exit:
741 // Iterate through all child windows. If still can close then
742 FORWARD_WM_DESTROY(hwnd, PostMessage);
743 return TRUE;
744
745 case cm_PosControl:
746 mlPositionControlDlg();
747 return TRUE;
748
749 case cm_Calibrate:
750 mlInquireReferencePointDlg(0);
751 return TRUE;
752
753 case cm_CallExecuteMacro:
754 if ( !MacroExtention )
755 return TRUE;
756
757 //! neu Kullmann+Reinecker: TheModeless ersetzt durch MacroExecDlg; extern entfernt
758 if ( (!MacroExecDlg) || (!MacroExecDlg->GetHandle()) )
759 { // !GetHandle() ist wichtig für den Fall, dass sich das Dialogfenster selbst zerstört hat !!!
760 MacroExecDlg= new TMacroExecuteDlg(&MacroExecDlg);
761 if ( MacroExecDlg ) MacroExecDlg->Initialize( GetMainInstance(), GetFrameHandle() );
762 }
763 else
764 { // sonst verbergen
765 _FREEOBJ(MacroExecDlg);
766 }
767 return TRUE;
768
769 case cm_CallExecuteCounter:
770 (new TCounterWindow(GetMainInstance()))->Show();
771 return TRUE;
772
773 //! neu: klier Allgemeine Einstellungen
774 case cm_MeasurementParameterDlg:
775 dlg= new TMeasurementParameterDlg("MeasurementParameterDlg");
776 if ( dlg ) dlg->ExecuteDialog(hwnd);
777 _FREEOBJ(dlg);
778 SetInfo("");
779 return TRUE;
780
781 //! neu: klier Protokollbuch
782 case cm_ProtocolTopographyDlg:
783 ViewProtocolTopographyDlg();
784 SetInfo("");
785 return TRUE;
786
787 //! neu: klier Protokollbuch
788 case cm_ProtocolDiffractometryDlg:
789 ViewProtocolDiffractometryDlg();
790 SetInfo("");
791 return TRUE;
792
793 case cm_AngleControl:
794 // ANFANG 29.11.2002 Kullmann, Reinecker : getrennte Manuelle Justage
795 if ( HasNewManJustage() )
796 dlg= new TAngleCtlDlg(); // Funktionalität und Oberfläche getrennt
797 else
798 dlg= new TAngleControlDlg(); //ALT
799 // ENDE 29.11.2002
800 if ( dlg ) dlg->ExecuteDialog(hwnd);
801 _FREEOBJ(dlg);
802 return TRUE;
803
804 // ANFANG 29.11.2002 Kullmann, Reinecker : neue Manuelle Justage
805 case cm_ManualJustage:
806 dlg= new TManJustageDlg;
807 if ( dlg ) dlg->ExecuteDialog(hwnd);
808 _FREEOBJ(dlg);
809 return TRUE;
810 // ENDE 29.11.2002
811
812
813 //! neu: Automatische Justage (S.Freund, D.Hepp)
814 case cm_AutomaticAngleControl:
815 dlg= (TAutomaticAngleControlDlg *)new TAutomaticAngleControlDlg();
816 if ( dlg ) dlg->ExecuteDialog(hwnd);
817 _FREEOBJ(dlg);
818 return TRUE;
819
820 case cm_SetWatchIndicator:
821 SetWatchIndicator(lParam);
822 return TRUE;
823
824 case cm_LimitHitOccure:
825 char buf[MaxString];
826
827 sprintf(buf, strMessage08, (int)lParam);
828 MessageBox(hwnd, buf, strMessage09, MBINFO);
829 return TRUE;
830
831 // ANFANG 23.01.2003 Kullmann, Reinecker : die alte und neue getrennte Topografie
832 case cm_TopograpyParam:
833 dlg= new TTopographySetParamDlg(FALSE); // die ALTE
834 if ( dlg ) dlg->ExecuteDialog(hwnd);
835 _FREEOBJ(dlg);
836 return TRUE;
837
838 case cm_TopographyAdjust:
839 dlg= new TTopographyAdjustDlg(FALSE); // die NEUE : Funktionalität und Oberfläche getrennt
840 if ( dlg ) dlg->ExecuteDialog(hwnd);
841 _FREEOBJ(dlg);
842 return TRUE;
843 // ENDE 23.01.2003
844
845 case cm_MotorParam:
846 mlSetParametersDlg();
847 return TRUE;
848
849 case cm_SensorParam:
850 TDetectorGUI::RunCommonDevParamDialog(hwnd);
851 return TRUE;
852
853 case cm_OptimizeDC:
854 // operates the actual motor
855 mlOptimizingDlg();
856 return TRUE;
857
858 case cm_SetAngleDefault:
859 mlSetAngleDefault();
860 return TRUE;
861
862 //! neu: Ausgabe der verwendeten Compiler-Version und des Compile-Datums
863 case cm_Version:
864 {
865 char buf[MaxString];
866 #ifdef GermanVersion
867 sprintf(buf, "Microsoft Visual C++ Compiler Version %x\n"
868 "\nerstellt am: %s um %s Uhr",
869 _MSC_VER, __DATE__, __TIME__);
870
871 MessageBox(GetFocus(), buf, "Info über erstellte Version", MBINFO);
877 #endif
878 return TRUE;
879 }
880
881 case cm_About:
882 AboutTheMaker();
883 return TRUE;
884
885 case cm_AllVersions:
886 ShowProgramStatus(hwnd);
887 return TRUE;
888
889 case cm_Directories:
890 dlg= new TModalDlg("Directories", GetMainInstance());
891 if ( dlg ) dlg->ExecuteDialog(hwnd);
892 _FREEOBJ(dlg);
893 return TRUE;
894
895 // ANFANG 23.01.2003 Kullmann, Reinecker : die alte und neue getrennte Topografie
896 case cm_CallExecuteTopograpy:
897 dlg= new TTopographyExecuteDlg(); // die ALTE
898 if ( dlg ) dlg->ExecuteDialog(hwnd);
899 _FREEOBJ(dlg);
900 return TRUE;
901
902 case cm_CallTopographyExec:
903 dlg= new TTopographyExecDlg(); // die NEUE : Funktionalität und Oberfläche getrennt
904 if ( dlg ) dlg->ExecuteDialog(hwnd);
905 _FREEOBJ(dlg);
906 return TRUE;
907 // ENDE 23.01.2003
908
909 case cm_CallExecuteCmd:
910 dlg= (TExecuteCmdDlg*)new TExecuteCmdDlg();
911 if ( dlg ) dlg->ExecuteDialog(hwnd);
912 _FREEOBJ(dlg);
913 return TRUE;
914
915 case cm_CallExecuteScan:
916 if (ScanExtention)
917 if ( ScanWindow ) ScanWindow->Show(); // in den Vordergrund und markieren
918 else (new TScanWindow(GetMainInstance()))->Show(); // bei TScanWindow.Create() wird auch ScanWindow auf dieses Fenster gesetzt
919 return TRUE;
920
921 case cm_CallExecuteAreaScan:
922 if (AreaScanExtention)
923 if ( AreaScanWindow ) AreaScanWindow->Show(); // in den Vordergrund und markieren
924 else (new TAreaScanWindow(GetMainInstance()))->Show(); // bei TAreaScanWindow.Create() wird auch Main.AreaScanWindow auf dieses Fenster gesetzt
925 return TRUE;
926
927 case cm_Tile:
928 SendMessage(GetClientHandle(), WM_MDITILE, 0, 0L);
929 return TRUE;
930
931 case cm_Cascade:
932 SendMessage(GetClientHandle(), WM_MDICASCADE, 0, 0L);
933 return TRUE;
934
935 case cm_ArrangeIcons:
936 SendMessage(GetClientHandle(), WM_MDIICONARRANGE, 0, 0L);
937 return TRUE;
938
939 case cm_H_Index:
940 WinHelp(hwnd, GetHelpFile(), HELP_CONTEXT, Help_Contents);
941 break;
942
943 default:
944 HWND hChildWnd= (HWND)(SendMessage(GetClientHandle(), WM_MDIGETACTIVE, 0, NULL));
945 if (IsWindow(hChildWnd))
946 SendMessage(hChildWnd, WM_COMMAND, wParam, lParam);
947 break;
948 }
949 return FALSE;
950 }
951
952 ///////////////////////////////////////////////////////////////////////////////
953 // STATIC
954 ///////////////////////////////////////////////////////////////////////////////
955
956 int TMain::MessageLoop(void)
957 {
958 MSG msg;
959 //! BOOL fQuit= FALSE;
960
961 while (GetMessage(&msg, NULL, 0, 0))
962 {
963 if ( !TranslateMDISysAccel(::GetClientHandle(), &msg) &&
964 !TranslateAccelerator(::GetFrameHandle(), TMain::hAccellerator, &msg))
965 {
966 TranslateMessage(&msg);
967 DispatchMessage(&msg);
968 }
969 }
970
971 return 0;
972 };
973 //-----------------------------------------------------------------------------
974
975 void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart,
976 short yStart)
977 {
978 BITMAP bm;
979 COLORREF cColor;
980 HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
981 HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
982 HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
983 POINT ptSize;
984
985 hdcTemp = CreateCompatibleDC(hdc);
986 SelectObject(hdcTemp, hBitmap); // Select the bitmap
987
988 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
989 ptSize.x = bm.bmWidth; // Get width of bitmap
990 ptSize.y = bm.bmHeight; // Get height of bitmap
991 DPtoLP(hdcTemp, &ptSize, 1); // Convert from device
992
993 // to logical points
994
995 // choose this color as transparent, that is most often in the corners
996 COLORREF corners[4];
997 corners[0]= GetPixel(hdcTemp, 0, 0);
998 corners[1]= GetPixel(hdcTemp, bm.bmWidth-1, 0);
999 corners[2]= GetPixel(hdcTemp, bm.bmWidth-1, bm.bmHeight-1);
1000 corners[3]= GetPixel(hdcTemp, 0, bm.bmHeight-1);
1001 COLORREF cTransparentColor= corners[0];
1002 int bestCount= 0;
1003 for (int i=0; i<4; i++) {
1004 int iCount= 0;
1005 for (int j=0; j<4; j++) if ( corners[i]==corners[j] ) iCount++;
1006 if ( iCount>bestCount ) {
1007 bestCount= iCount;
1008 cTransparentColor= corners[i];
1009 }
1010 }
1011
1012 // Create some DCs to hold temporary data.
1013 hdcBack = CreateCompatibleDC(hdc);
1014 hdcObject = CreateCompatibleDC(hdc);
1015 hdcMem = CreateCompatibleDC(hdc);
1016 hdcSave = CreateCompatibleDC(hdc);
1017
1018 // Create a bitmap for each DC. DCs are required for a number of
1019 // GDI functions.
1020
1021 // Monochrome DC
1022 bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
1023
1024 // Monochrome DC
1025 bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
1026
1027 bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
1028 bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
1029
1030 // Each DC must select a bitmap object to store pixel data.
1031 bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
1032 bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
1033 bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
1034 bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);
1035
1036 // Set proper mapping mode.
1037 SetMapMode(hdcTemp, GetMapMode(hdc));
1038
1039 // Save the bitmap sent here, because it will be overwritten.
1040 BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
1041
1042 // Set the background color of the source DC to the color.
1043 // contained in the parts of the bitmap that should be transparent
1044 cColor = SetBkColor(hdcTemp, cTransparentColor);
1045
1046 // Create the object mask for the bitmap by performing a BitBlt
1047 // from the source bitmap to a monochrome bitmap.
1048 BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
1049 SRCCOPY);
1050
1051 // Set the background color of the source DC back to the original
1052 // color.
1053 SetBkColor(hdcTemp, cColor);
1054
1055 // Create the inverse of the object mask.
1056 BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
1057 NOTSRCCOPY);
1058
1059 // Copy the background of the main DC to the destination.
1060 BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
1061 SRCCOPY);
1062
1063 // Mask out the places where the bitmap will be placed.
1064 BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
1065
1066 // Mask out the transparent colored pixels on the bitmap.
1067 BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
1068
1069 // XOR the bitmap with the background on the destination DC.
1070 BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
1071
1072 // Copy the destination to the screen.
1073 BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
1074 SRCCOPY);
1075
1076 // Place the original bitmap back into the bitmap sent here.
1077 BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
1078
1079 // Delete the memory bitmaps.
1080 DeleteObject(SelectObject(hdcBack, bmBackOld));
1081 DeleteObject(SelectObject(hdcObject, bmObjectOld));
1082 DeleteObject(SelectObject(hdcMem, bmMemOld));
1083 DeleteObject(SelectObject(hdcSave, bmSaveOld));
1084
1085 // Delete the memory DCs.
1086 DeleteDC(hdcMem);
1087 DeleteDC(hdcBack);
1088 DeleteDC(hdcObject);
1089 DeleteDC(hdcSave);
1090 DeleteDC(hdcTemp);
1091 }
1092
1093 LRESULT CALLBACK TMain::EventHandlerMdiClient(HWND hWindow, UINT message, WPARAM wParam, LPARAM lParam) {
1094 switch ( message ) {
1095 case WM_ERASEBKGND:
1096 return 00;
1097
1098 case WM_PAINT:
1099 // DoubleBuffered-Ausgabe vorbereiten
1100 RECT rect;
1101 PAINTSTRUCT ps;
1102 GetClientRect(hWindow, (LPRECT)&rect);
1103 HDC hdc= BeginPaint(hWindow, &ps);
1104 HBITMAP hMemBmp= CreateCompatibleBitmap(hdc, rect.right-rect.left, rect.bottom-rect.top);
1105 HDC hMemDC= CreateCompatibleDC(hdc);
1106 HGDIOBJ hOldMemBmp= SelectObject(hMemDC, hMemBmp);
1107
1108 // Hintergrund flächig ausfüllen
1109 BITMAP bmInfo;
1110 HBITMAP hBitmap= LoadBitmap( ::GetMainInstance(), MAKEINTRESOURCE(bmp_Background) );
1111 GetObject(hBitmap, sizeof(bmInfo), &bmInfo);
1112 HDC hBmpDC= CreateCompatibleDC(hdc);
1113 HGDIOBJ hOldBitmap= SelectObject(hBmpDC, hBitmap);
1114 for (int y= 0; y<rect.bottom-rect.top+bmInfo.bmHeight; y+= bmInfo.bmHeight)
1115 for (int x= 0; x<rect.right-rect.left+bmInfo.bmWidth; x+= bmInfo.bmWidth)
1116 BitBlt(hMemDC, x, y, bmInfo.bmWidth, bmInfo.bmHeight,
1117 hBmpDC, 0, 0, SRCCOPY);
1118 SelectObject(hBmpDC, hOldBitmap);
1119 DeleteObject(hBitmap);
1120 DeleteDC(hBmpDC);
1121
1122 // zentriert und transparent eine Bitmap
1123 hBitmap= LoadBitmap( ::GetMainInstance(), MAKEINTRESOURCE(bmp_CenterBack) );
1124 GetObject(hBitmap, sizeof(bmInfo), &bmInfo);
1125 DrawTransparentBitmap(hMemDC, hBitmap, (rect.right-rect.left)/2 - bmInfo.bmWidth/2, (rect.bottom-rect.top)/2 - bmInfo.bmHeight/2);
1126 DeleteObject(hBitmap);
1127
1128 // Trennungslinie zum Menu
1129 HPEN hPen= CreatePen( PS_SOLID, 1, RGB(0,0,0) );
1130 HGDIOBJ hOldPen= SelectObject(hMemDC, hPen);
1131 POINT p;
1132 MoveToEx(hMemDC, 0, 0, &p);
1133 LineTo(hMemDC, rect.right-rect.left, 0);
1134 SelectObject(hMemDC, hOldPen);
1135 DeleteObject(hPen);
1136
1137 // auf den Bildschirm und aufräumen
1138 BitBlt(hdc, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1139 hMemDC, 0, 0, SRCCOPY);
1140 SelectObject(hMemDC, hOldMemBmp);
1141 DeleteObject(hMemBmp);
1142 DeleteDC(hMemDC);
1143 EndPaint(hWindow, &ps);
1144 return 01;
1145 }
1146 return CallWindowProc(Main.DefMdiClientProc, hWindow, message, wParam, lParam);
1147 }
1148 //-----------------------------------------------------------------------------
1149
1150 LRESULT CALLBACK TMain::EventHandler(HWND hWindow, UINT message, WPARAM wParam, LPARAM lParam)
1151 {
1152 // main window handler, called first
1153 TDetector *detector= 0;
1154 int nDetector;
1155 HWND hwnd;
1156 TMDIWindow *window;
1157
1158 switch (message)
1159 {
1160 case WM_TIMER:
1161 nDetector= GET_WM_COMMAND_ID(wParam, lParam) - DetectorTimerIdStart;
1162 if (TDetectorManager::DetectorManager().IsValidId(nDetector))
1163 {
1164 detector= TDetectorManager::DetectorManager().GetDetector(nDetector);
1165 if (detector->PollDetector() == R_Failure)
1166 {
1167 detector->MeasureStop();
1168 SetStatus(strMessage07);
1169 MessageBeep(0);
1170 detector->MeasureStart();
1171 }
1172 }
1173 break;
1174
1175 case WM_SIZE:
1176 Main.OnSize(hWindow);
1177 // immediately return, otherhand case no write of status line.
1178 return 0l;
1179
1180 case WM_PAINT:
1181 Main.OnPaint(hWindow);
1182 break;
1183
1184 case WM_COMMAND:
1185 Main.OnCommand(hWindow, wParam, lParam);
1186 break;
1187
1188 case WM_SYSCOMMAND:
1189 if (wParam == SC_CLOSE)
1190 {
1191 do
1192 { // Es sind eventuell Daten noch nicht gespeichert worden
1193 hwnd= (HWND)SendMessage(::GetClientHandle(), WM_MDIGETACTIVE, 0, 0l);
1194 // Ermitteln des des Fenster-Strucktur-Zeigers
1195 window= (TMDIWindow *)GetWindowLong(hwnd, 1);
1196 if ( window && hwnd)
1197 {
1198 if (window->CanClose())
1199 {
1200 SendMessage(::GetClientHandle(), WM_MDIDESTROY, (WPARAM)(HWND)hwnd, 0l);
1201 continue;
1202 }
1203 else
1204 {
1205 bShutdown= FALSE;
1206 return 1l;
1207 }
1208 }
1209 break;
1210 } while (1);
1211 bShutdown= TRUE;
1212 PostMessage(::GetFrameHandle(), WM_DESTROY, 0, 0l);
1213 return 1;
1214 } //if
1215 break;
1216
1217 case WM_DESTROY:
1218 bShutdown= TRUE;
1219 do
1220 {
1221 hwnd= (HWND)SendMessage(::GetClientHandle(), WM_MDIGETACTIVE, 0, 0l);
1222 // Ermitteln des des Fenster-Struktur-Zeigers
1223 window= (TMDIWindow *)GetWindowLong(hwnd, 1);
1224 if ( window && hwnd)
1225 {
1226 if (window->CanClose())
1227 SendMessage(::GetClientHandle(), WM_MDIDESTROY, (WPARAM)(HWND)hwnd, 0l);
1228 continue;
1229 }
1230 break;
1231 } while (1);
1232
1233 if (bEnvInstalled)
1234 {
1235 /* 16.06.2004 if (Main.bmpStatusLine)
1236 {
1237 DeleteObject(Main.bmpStatusLine);
1238 Main.bmpStatusLine= 0;
1239 }*/
1240 //! Ctl3dUnregister((const HINSTANCE__ near*)GetFrameHandle());
1241 mlSaveModuleSettings();
1242 bEnvInstalled= FALSE;
1243 }
1244 Main.SavePos();
1245 PostQuitMessage(0);
1246 return 0l;
1247
1248 case WM_INITMENU:
1249 Main.OnMenuInit();
1250 break;
1251
1252 case WM_MENUSELECT:
1253 Main.OnMenuSelect(hWindow, wParam, lParam);
1254 break;
1255
1256 default:
1257 // die folgenden Varianten sind keine Konstanten (deshalb nicht als case realisierbar)
1258 if (message == ::GetWakeUpMsg())
1259 Steering.WakeUp();
1260 } // end switch
1261 return DefFrameProc(hWindow, Main.hwndClient, message, wParam, lParam);
1262 };
1263
1264 //#############################################################################
1265 // TMDIWindow
1266 //#############################################################################
1267
1268 int TMDIWindow::s_WindowCount= 0;
1269
1270 TMDIWindow::TMDIWindow(HINSTANCE aInstance) : TBasicMDIWindow( aInstance ), hHoleMenu(0), TheMenu(0)
1271 {
1272 bUserPaint= false;
1273 s_WindowCount++;
1274 bInterrupted= FALSE;
1275 bPaintPoint= FALSE;
1276 };
1277 //-----------------------------------------------------------------------------
1278
1279 TMDIWindow::~TMDIWindow()
1280 {
1281 s_WindowCount--;
1282 if (hHoleMenu) {
1283 DestroyMenu(hHoleMenu);
1284 hHoleMenu= 0;
1285 TheMenu= 0; // ist Untermenü von hHoleMenu
1286 }
1287 if (TheMenu) {
1288 DestroyMenu(TheMenu);
1289 TheMenu= 0;
1290 }
1291 };
1292 //-----------------------------------------------------------------------------
1293
1294 LRESULT TMDIWindow::Show( void )
1295 {
1296 if ( !strcmp(m_Title, "") )
1297 strcpy(m_Title, ClassName());
1298 return TBasicMDIWindow::Show( GetClientHandle() );
1299 };
1300 //-----------------------------------------------------------------------------
1301
1302 BOOL TMDIWindow::CanOpen(void)
1303 {
1304 return ( s_WindowCount <= 5 );
1305 };
1306 //-----------------------------------------------------------------------------
1307
1308 BOOL TMDIWindow::CanClose(void)
1309 {
1310 BOOL temp= FALSE;
1311 if ( IsScanning(temp) && !bInterrupted)
1312 Interrupt();
1313 return TRUE;
1314 };
1315 //-----------------------------------------------------------------------------
1316
1317 HICON TMDIWindow::GetIcon ( void ) const
1318 {
1319 return (HICON)LoadImage( GetMainInstance(), MAKEINTRESOURCE(icon_MdiWindow),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
1320 };
1321 //-----------------------------------------------------------------------------
1322
1323 void TMDIWindow::UpdateWnd(EPaintType act)
1324 {
1325 bUserPaint= true;
1326 switch (act)
1327 {
1328 case ptPaintPoint:
1329 bPaintPoint= TRUE;
1330 SetTitle();
1331 InvalidateRect(GetHandle(), NULL, !bPaintPoint);
1332 break;
1333
1334 case ptFlush: {
1335 PAINTSTRUCT ps;
1336 HDC hdc= BeginPaint(GetHandle(), &ps);
1337 DoPaint(hdc, &ps);
1338 EndPaint(GetHandle(), &ps);
1339 break;
1340 }
1341
1342 default: // ptEntire
1343 SetTitle();
1344 InvalidateRect(GetHandle(), NULL, !bPaintPoint);
1345 }
1346 };
1347 //-----------------------------------------------------------------------------
1348
1349 BOOL TMDIWindow::WholeWnd(void)
1350 {
1351 int b= bPaintPoint;
1352 bPaintPoint= FALSE;
1353 return !b;
1354 };
1355 //-----------------------------------------------------------------------------
1356
1357 void TMDIWindow::OnRButtonDown ( WPARAM, LPARAM lParam)
1358 {
1359 if ( !TheMenu ) return;
1360
1361 Show(); // zuerst Fenster fokussieren
1362 //! darstellen des Menues an der Mausposition
1363 POINT pp;
1364 pp.x= LOWORD( lParam );
1365 pp.y= HIWORD( lParam );
1366 ClientToScreen( GetHandle(), &pp );
1367 TrackPopupMenu( TheMenu, 0, pp.x, pp.y, 0, GetHandle(), NULL );
1368 };
1369 //-----------------------------------------------------------------------------
1370
1371 void TMDIWindow::OnMenuSelect ( WPARAM wParam, LPARAM )
1372 { // Beschreibung für Menüpunkte in der Statuszeile anzeigen, wenn ein Menüpunkt ausgewählt wird
1373 char *MsgString= 0;
1374 UINT menuResId= GET_WM_COMMAND_ID(wParam, lParam);
1375 if ( menuResId!=NULL && menuResId>10/*Summe der Hauptmenüs und Menüs mit Untermenüs*/ && menuResId!=0xFFFFFFFF )
1376 MsgString= LoadString(menuResId);
1377
1378 if ( !MsgString || strlen(MsgString)==0 ) {
1379 if ( MsgString ) _FREELIST(MsgString);
1380 MsgString= new char[1+1]; // Leerzeichen + Nullterminierung
1381 strcpy(MsgString, " "); // Leerstring würde keine Änderung in Statuszeile zur Folge haben
1382 }
1383 SetInfo( MsgString );
1384 _FREELIST(MsgString);
1385 };
1386 //-----------------------------------------------------------------------------
1387
1388 void TMDIWindow::Interrupt()
1389 {
1390 BOOL temp= FALSE;
1391 if ( !IsScanning(temp) ) { // vielleicht Makroverarbeitung aktiv?
1392 if ( Steering.IsActive() ) Steering.ToggleInterrupt();
1393 } else {
1394 bInterrupted= !bInterrupted;
1395 }
1396 };
1397
1398 ///////////////////////////////////////////////////////////////////////////////
1399 // Botschaften
1400 ///////////////////////////////////////////////////////////////////////////////
1401
1402 void TMDIWindow::OnTimer ( WPARAM wParam, LPARAM lParam )
1403 {
1404 if ( GET_WM_COMMAND_ID(wParam, lParam) == TimerIdSteering )
1405 TimerRequest(GET_WM_COMMAND_ID(wParam, lParam));
1406 }
1407 //-----------------------------------------------------------------------------
1408
1409 void TMDIWindow::OnNotCreated ( void )
1410 {
1411 MessageBox(strMessage02, strFailure, MBFAILURE);
1412 }
1413 //-----------------------------------------------------------------------------
1414
1415 LRESULT TMDIWindow::OnCommand(WPARAM wParam, LPARAM lParam)
1416 {
1417 WPARAM Cmd;
1418 Cmd= GET_WM_COMMAND_ID(wParam, lParam);
1419 switch (Cmd)
1420 {
1421 case cm_Copy: // alle MDI
1422 DoCopy();
1423 return 0l;
1424
1425 /* Datum 16.05.2003: case cm_PSD_Scan: case cm_PSD_AreaScan: case cm_InquireCCDLine: case cm_ShowHistogram:
1426 InitializeTask(wParam, lParam);
1427 return 0l;*/
1428
1429 /* Datum 16.05.2003: case cm_SetupCCDLineScan: case cm_ImageSaveOptions:
1430 InitializeDlg(wParam, lParam);
1431 return 0l;*/
1432
1433 case cm_InterruptAction: // Makroverarbeitung oder Area-/ StepScan beenden/ fortsetzen
1434 MessageBeep(0);
1435 Interrupt();
1436 return 0l;
1437
1438 case cm_StopAll: // alle MDI
1439 int id;
1440 id= 0;
1441 while (mlSetAxis(id++))
1442 mStopDrive(0);
1443 MessageBox("Trial to stop all drives !", "Message", MBINFO);
1444 return 0l;
1445
1446 /* 16.05.2003 case cm_GrabPicture: // Dialogfenster CCDParameter
1447 return 0l;*/
1448
1449 //Datum 16.05.2003: case cm_GetHistogram: case cm_AccuPicture: case cm_EventCounting: return 0l;
1450
1451 case cm_SensorParam:
1452 // TDetectorGUI::RunCommonDevParamDialog(GetHandle()); führte zum Absturz, wenn das Fenster geschlossen wurde.
1453 // Dort wurde das TCounterWindow freigegeben, diese Objektmethode (OnCommand) existiert dann nicht mehr! --> Prozessorfehler!
1454 // Deshalb POSTMessage (zeitversetzt verarbeiten) zum Hauptfenster und dort verarbeiten lassen (dort war die Behandlung bereits für den gleichnamigen Menüeintrag impl.).
1455 PostMessage(GetFrameHandle(), WM_COMMAND, (WPARAM)cm_SensorParam, 0);
1456 return TRUE;
1457
1458 //*** Ablauf-Steuerung *************************
1459 case cm_SteeringReady:
1460 SteeringReady(lParam);
1461 return 0l;
1462
1463 case cm_SteeringReset:
1464 SteeringReset(lParam);
1465 return 01;
1466
1467 //Datum 05.06.2004
1468 /*case cm_DistanceSet:
1469 DistanceSetRequest(lParam);
1470 return 0l;*/
1471
1472 // *** Detektor
1473 case cm_CounterSet:
1474 CounterSetRequest(lParam);
1475 return 0l;
1476
1477 //Datum 16.05.2003
1478 /*case cm_PlotCurve:
1479 PickUpData(lParam);
1480 SendMessage(GetHandle(),WM_SETFOCUS,0,0l);
1481 return 0l;*/
1482
1483 //Datum 16.05.2003
1484 /*case cm_SetProperties:
1485 SetKSProperties((TKSProperties*)lParam);
1486 return 0l;*/
1487
1488 //Datum 16.05.2003
1489 /*case cm_SetRanges:
1490 SetRanges();
1491 if (lParam) UpdateWnd();
1492 return 0l;*/
1493 }
1494 return 100000l;
1495 };
1496
1497 //#############################################################################
1498 // TFileWindow
1499 //#############################################################################
1500
1501 TFileWindow::TFileWindow( HINSTANCE aInstance ) : TMDIWindow(aInstance) {
1502 strcpy(FileName, "*.*");
1503 strcpy(szFilter, "Alle Dateien (*.*)|*.*||");
1504 strcpy(szExtension, "*");
1505 strcpy(szDataPath, "");
1506 bOldDataLoaded= FALSE;
1507 bIsNewFile= TRUE;
1508 bFileChanged= FALSE;
1509 }
1510 //-----------------------------------------------------------------------------
1511
1512 BOOL TFileWindow::CanClose( void ) {
1513 if ( !TMDIWindow::CanClose() ) return FALSE;
1514
1515 if ( bFileChanged ) {
1516 int res= MessageBox(strMessage03, strMessage, MB_YESNOCANCEL | MB_ICONQUESTION);
1517 if ( res==IDCANCEL ) return FALSE;
1518 if ( res==IDYES ) SaveFile();
1519 if ( res==IDNO ) bFileChanged= FALSE; // nicht erneut fragen, ob gespeichert werden
1520 }
1521 return TRUE;
1522 }
1523 //-----------------------------------------------------------------------------
1524
1525 BOOL TFileWindow::New(void)
1526 {
1527 bFileChanged= FALSE;
1528 bInterrupted= FALSE;
1529 bPaintPoint= FALSE;
1530 bOldDataLoaded= FALSE;
1531 UpdateWnd();
1532 return TRUE;
1533 };
1534 //-----------------------------------------------------------------------------
1535
1536 BOOL TFileWindow::LoadOldData() {
1537 bFileChanged= FALSE;
1538 bPaintPoint= FALSE;
1539 bOldDataLoaded= TRUE;
1540 UpdateWnd();
1541 return FALSE;
1542 };
1543 //-----------------------------------------------------------------------------
1544
1545 BOOL TFileWindow::SaveFile(EAskType) {
1546 bFileChanged= FALSE;
1547 return FALSE;
1548 };
1549 //-----------------------------------------------------------------------------
1550
1551 BOOL TFileWindow::SaveFileAs(void)
1552 {
1553 char Old_FileName[_MAX_PATH];
1554 //! BOOL Old_bFileChanged= bFileChanged;
1555 BOOL Old_bIsNewFile= bIsNewFile;
1556
1557 strcpy(Old_FileName, FileName);
1558 bFileChanged= TRUE;
1559 bIsNewFile= TRUE;
1560 strcpy(FileName, "");
1561 if ( SaveFile(atNewName) )
1562 return TRUE;
1563 strcpy(FileName, Old_FileName);
1564 bIsNewFile= Old_bIsNewFile;
1565 return FALSE;
1566 };
1567 //-----------------------------------------------------------------------------
1568
1569 BOOL TFileWindow::SetFileName(LPSTR fn)
1570 {
1571 if (strstr("\\", fn))
1572 sprintf(FileName, "%s", fn);
1573 else
1574 sprintf(FileName, "%s%s", szDataPath, fn);
1575 bIsNewFile= (0 == strlen(FileName));
1576 return TRUE;
1577 };
1578 //-----------------------------------------------------------------------------
1579
1580 LRESULT TFileWindow::OnCommand(WPARAM wParam, LPARAM lParam)
1581 {
1582 WPARAM Cmd;
1583 Cmd= GET_WM_COMMAND_ID(wParam, lParam);
1584 switch (Cmd)
1585 {
1586 case cm_New:
1587 Interrupt(); // zuerst aktive Messung oder Spektrenanzeige beenden
1588 SetFileName("");
1589 New(); // Interrupt und SetFileName dürfen nicht in New() verschoben werden = NUR HIER wenn Menüpunkt geklickt wurde
1590 return 0l;
1591
1592 case cm_Open:
1593 Interrupt(); // zuerst aktive Messung oder Spektrenanzeige beenden
1594 LoadOldData(); // Interrupt darf nicht in New() verschoben werden = NUR HIER wenn Menüpunkt geklickt wurde
1595 return 0l;
1596
1597 case cm_Save:
1598 SaveFile();
1599 return 0l;
1600
1601 case cm_SaveAs:
1602 SaveFileAs();
1603 return 0l;
1604
1605 case cm_UpdateFile:
1606 UpdateFile();
1607 return 0l;
1608
1609 }
1610 return TMDIWindow::OnCommand(wParam, lParam);
1611 }
1612
1613 //******************************************************************************
1614 // __LastLine__
1615
1616
1617