File: INTERNLS\L_LAYER.CPP
1 // l_layer.cpp
2 // (C) 1993,1994 by Heiko Damerow MPG AG "Roentgenbeugung"
3 // Allgemeine Funktionen
4 #include <direct.h>
5
6 #include "internls\evrythng.h" // GermanVersion
7 #include "winresrc\rc_def.h" // Ressourcen-IDs
8 #include <commdlg.h> // OPENFILENAME
9 #include <commctrl.h> // für SB_SETTEXT
10 #pragma hdrstop
11
12 #include "internls\l_layer.h"
13 #include "datavisa\datavisa.h" // lpDBase
14
15 #include "utils\CheckMemory.h" // CHECKMEM
16
17 //--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--
18
19 //Datum: 02.07.2003 int bModulLoaded= FALSE;
20 HINSTANCE hModuleInstance;
21 LPDataBase _CURVECLASS lpDBase= 0; // 17.11.2002
22 TBasicMain *BasicMain= 0; // wird mit InitBasicMain initialisiert; nicht freigeben!
23
24 static char spVersion[]= "V 1.51 ("__DATE__")";
25
26 //#############################################################################
27 // sprachspezifische Konstanten
28 //#############################################################################
29
30 #ifdef GermanVersion
31 const char _TITLE[]= "Über \"%s\""; // Titelleistenbeschriftung
34 #endif
35
36 //##############################################################################
37 // TAboutDlg
38 //##############################################################################
39
40 class _CURVECLASS TAboutDlg : public TModalDlg
41 {
42 public:
43 TAboutDlg ( void ) : TModalDlg( "ABOUT", hModuleInstance )
44 {};
45
46 private:
47 BOOL Dlg_OnInit ( HWND, HWND, LPARAM )
48 {
49 char *buf= new char[ strlen(_TITLE) + strlen(APPLICATIONTITLE) ];
50 sprintf(buf, _TITLE, APPLICATIONTITLE);
51 SetWindowText(GetHandle(), buf);
52 _FREELIST(buf);
53 return TRUE;
54 };
55 };
56
57 void _CURVECLASS WINAPI AboutTheMaker ( void )
58 {
59 TAboutDlg *dlg= new TAboutDlg();
60 if ( dlg ) dlg->ExecuteDialog(GetFrameHandle());
61 _FREEOBJ(dlg);
62 };
63
64 BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwFunction, LPVOID)
65 {
66 switch (dwFunction)
67 {
68 case DLL_PROCESS_ATTACH:
69 //Datum: 02.07.2003 bModulLoaded= FALSE;
70 hModuleInstance= hModule;
71 lpDBase= new TDataBase();
72 break;
73
74 case DLL_PROCESS_DETACH:
75 _FREEOBJ(lpDBase);
76
77 //CHECKMEM("SPLIB.DLL"); //hp
78 break;
79 }
80
81 return TRUE;
82 }
83
84 LPCSTR _CURVECLASS WINAPI spGetVersion(void)
85 {
86 return (LPCSTR)spVersion;
87 }
88
89 HINSTANCE _CURVECLASS WINAPI spGetInstance(void)
90 {
91 return hModuleInstance;
92 }
93
94 //#############################################################################
95 // TBasicMain
96 //#############################################################################
97
98 TBasicMain::TBasicMain() {
99 strcpy(szDirectory, "");
100 strcpy(szName, "");
101 strcpy(szDrive, "");
102 strcpy(szCFileName, "");
103 strcpy(szHelpFile, "");
104 strcpy(szPTopoDirectory, "");
105 strcpy(szPDiffDirectory, "");
106 strcpy(szPTopoBackupDirectory, "");
107 strcpy(szPDiffBackupDirectory, "");
108 strcpy(szPTopoName, "");
109 strcpy(szPDiffName, "");
110 strcpy(szPTopoFileName, "");
111 strcpy(szPDiffFileName, "");
112 strcpy(szHWFile, "");
113 strcpy(szTestDevFile, "");
114 strcpy(szMacroFileName, "");
115 strcpy(Drive, "");
116 strcpy(Dir, "");
117 strcpy(Name, "");
118 strcpy(Ext, "");
119 strcpy(Path, "");
120
121 m_MainInstance= 0;
122 m_WndFrame= 0;
123 m_WndClient= 0;
124 m_WndScan= 0;
125 m_WakeUpMsg= 0;
126 m_CreateIniDefaults= FALSE;
127
128 m_WndStatusBar= 0;
129 };
130
131 //******************************************************************************
132 // Verwaltung von absoluten Dateinamen für alle benutzen Dateien
133 //******************************************************************************
134
135 //klier 25.02.2003 überarbeitet
136 void TBasicMain::SetExeFilename(char* FileName) {
137 SplitFileName(FileName);
138 strcpy(szDirectory, Path);
139 strcpy(szName, Name);
140 strcpy(szDrive, Drive);
141 strupr(szDrive);
142 sprintf(szCFileName, "%s%s%s", szDirectory, szName, ".INI" );
143 sprintf(szPTopoFileName, "%s%s", szDirectory, "PROTOCOL\\TOPOGRFY\\PROTTOPO.CSV");
144 GetPrivateProfileString("ProtocolTopography", "ProtocolFile", szPTopoFileName, szPTopoFileName, _MAX_PATH, szCFileName);
145 if (!SetPTopoFile(szPTopoFileName))
146 {
147 sprintf(szPTopoFileName, "%s%s", szDirectory, "PROTOCOL\\TOPOGRFY\\PROTTOPO.CSV");
148 SetPTopoFile(szPTopoFileName);
149 }
150 sprintf(szPDiffFileName, "%s%s", szDirectory, "PROTOCOL\\DIFRKMTY\\PROTDIFF.CSV");
151 GetPrivateProfileString("ProtocolDiffractometry", "ProtocolFile", szPDiffFileName, szPDiffFileName, _MAX_PATH, szCFileName);
152 if (!SetPDiffFile(szPDiffFileName))
153 {
154 sprintf(szPDiffFileName, "%s%s", szDirectory, "PROTOCOL\\DIFRKMTY\\PROTDIFF.CSV");
155 SetPDiffFile(szPDiffFileName);
156 }
157 strcpy(szPTopoBackupDirectory, szPTopoDirectory);
158 GetPrivateProfileString("ProtocolTopography", "BackupPath", szPTopoBackupDirectory, szPTopoBackupDirectory, _MAX_PATH, szCFileName);
159 if (!CreatePDirectory(szPTopoBackupDirectory))
160 SetPTopoBackupDirectory(szPTopoDirectory);
161 strcpy(szPDiffBackupDirectory, szPDiffDirectory);
162 GetPrivateProfileString("ProtocolDiffractometry", "BackupPath", szPDiffBackupDirectory, szPDiffBackupDirectory, _MAX_PATH, szCFileName);
163 if (!CreatePDirectory(szPDiffBackupDirectory))
164 SetPDiffBackupDirectory(szPDiffDirectory);
165 strcpy(Path, szDirectory);
166 GetPrivateProfileString("Steuerprogramm", "HardwareINIFilePath", Path, Path, _MAX_PATH, szCFileName);
167 if (Path[strlen(Path) - 1] == '\\')
168 sprintf( szHWFile, "%s%s", Path, "HARDWARE.INI" );
169 else
170 sprintf( szHWFile, "%s%s", Path, "\\HARDWARE.INI" );
171 sprintf( szTestDevFile, "%s%s", szDirectory, "TESTDEV.DAT" );
172 sprintf( szHelpFile, "%s%s", szDirectory, "SPHELP.HLP" );
173 }
174
175 //klier 16.03.2003
176 //verändern von szPTopoBackupDirectory
177 BOOL TBasicMain::SetPTopoBackupDirectory ( LPCSTR lDir )
178 {
179 strcpy(szPTopoBackupDirectory, lDir);
180 WritePrivateProfileString("ProtocolTopography", "BackupPath", szPTopoBackupDirectory, szCFileName);
181 return CreatePDirectory(szPTopoBackupDirectory);
182 }
183
184 //klier 16.03.2003
185 //verändern von szPDiffBackupDirectory
186 BOOL TBasicMain::SetPDiffBackupDirectory ( LPCSTR lDir )
187 {
188 strcpy(szPDiffBackupDirectory, lDir);
189 WritePrivateProfileString("ProtocolDiffractometry", "BackupPath", szPDiffBackupDirectory, szCFileName);
190 return CreatePDirectory(szPDiffBackupDirectory);
191 }
192
193 //klier 16.03.2003 überarbeitet
194 //verändert Name der Protokoll-Topographie-Datei
195 BOOL TBasicMain::SetPTopoFile ( LPCSTR FileName )
196 {
197 SplitFileName(FileName);
198 sprintf(szPTopoFileName, "%s%s.CSV", Path, Name);
199 if (strcmp(strupr(Ext), ".CSV") != 0)
200 WritePrivateProfileString("ProtocolTopography", "ProtocolFile", szPTopoFileName, szCFileName);
201 strcpy(szPTopoDirectory, Path);
202 strcpy(szPTopoName, Name);
203 return CreatePDirectory(szPTopoDirectory);
204 }
205
206 //klier 16.03.2003 überarbeitet
207 //verändert Name der Protokoll-Diffraktometrie-Datei
208 BOOL TBasicMain::SetPDiffFile ( LPCSTR FileName )
209 {
210 SplitFileName(FileName);
211 sprintf(szPDiffFileName, "%s%s.CSV", Path, Name);
212 if (strcmp(strupr(Ext), ".CSV") != 0)
213 WritePrivateProfileString("ProtocolDiffractometry", "ProtocolFile", szPDiffFileName, szCFileName);
214 strcpy(szPDiffDirectory, Path);
215 strcpy(szPDiffName, Name);
216 return CreatePDirectory(szPDiffDirectory);
217 }
218
219 //vollst. Name der <macroname>; <macroname> sollte auf ".mak" enden (z.B. "scan.mak" oder "standard.mak")
220 LPCSTR TBasicMain::GetMacroFile ( LPCSTR macroname )
221 {
222 sprintf( szMacroFileName, "%s%s", szDirectory, macroname );
223 return szMacroFileName;
224 }
225
226 //klier 16.03.2003
227 //Testet ob die Protokollverzeichnisse existieren, wenn nicht werden sie erstellt
228 BOOL TBasicMain::CreatePDirectory( LPSTR PDirectory )
229 {
230 char buf[_MAX_DIR], *token;
231
232 if (PDirectory[strlen(PDirectory) - 1] != '\\')
233 strcat( PDirectory, "\\");
234 SplitFileName(PDirectory);
235 strupr(Drive);
236 _chdrive(Drive[0] - 'A' + 1);
237 _chdir("\\");
238 strcpy(buf, PDirectory);
239 strcat(buf, "\\SKIZZEN");
240 token= strtok(buf, "\\");
241 while ((token= strtok(NULL, "\\")) != NULL)
242 if ( _chdir(token) == -1)
243 {
244 if (mkdir(token) == -1)
245 {
246 MessageBox(GetFocus(), token,
247 "Verzeichniss kann nicht erstellt werden!", MBFAILURE);
248 return FALSE;
249 }
250 if (_chdir(token) == -1)
251 {
252 MessageBox(GetFocus(), token,
253 "Verzeichniss kann nicht geändert werden!", MBFAILURE);
254 return FALSE;
255 }
256 }
257 _chdrive(szDrive[0] - 'A' + 1);
258 _chdir("\\");
259 strcpy(buf, szDirectory);
260 token= strtok(buf, "\\");
261 while ((token= strtok(NULL, "\\")) != NULL)
262 _chdir(token);
263 return TRUE;
264 }
265
266 //zerlegt den kompletten Dateinamen in seine Bestandteile
267 void TBasicMain::SplitFileName ( LPCSTR DirFileName)
268 {
269 _splitpath( DirFileName, Drive, Dir, Name, Ext );
270 sprintf( Path, "%s%s", Drive, Dir );
271 }
272
273 void TBasicMain::SetStatusBarText( UINT aPart, LPCSTR aText ) {
274 char buf[MaxString], buf2[20];
275 if ( aPart==piIndicator ) { // Ausgabe von "|", "/", "-", "\"
276 SendMessage(m_WndStatusBar, SB_SETTEXT, (WPARAM) 1, (LPARAM) aText);
277 }
278
279 if ( aPart==piStaticInfo || aPart==piAll ) { // Ausgabe der aktuellen Probe und des untersuchten Reflex
280 sprintf(buf, "%s", GetTarget());
281 SendMessage(m_WndStatusBar, SB_SETTEXT, (WPARAM) 2, (LPARAM) buf);
282
283 GetReflection(buf2);
284 sprintf(buf, "%s", buf2);
285 SendMessage(m_WndStatusBar, SB_SETTEXT, (WPARAM) 3, (LPARAM) buf);
286 }
287
288 static char s_AdditionalInfo[MaxString];
289 if ( aPart==piStatus || aPart==piAll ) { // Ausgabe der Zustands-Information
290 if ( aPart==piStatus ) strcpy( s_AdditionalInfo, aText ); // bei DRAWSTATUSALL letzte Meldung anzeigen
291 SendMessage(m_WndStatusBar, SB_SETTEXT, (WPARAM) 4, (LPARAM)s_AdditionalInfo);
292 }
293
294 static char s_StatusInfo[MaxString];
295 if ( aPart==piInfo || aPart==piAll ) {
296 if ( aPart==piInfo ) strcpy( s_StatusInfo, aText ); // bei DRAWSTATUSALL letzte Meldung anzeigen
297 SendMessage(m_WndStatusBar, SB_SETTEXT, (WPARAM) 5, (LPARAM)s_StatusInfo);
298 }
299 };
300 //******************************************************************************
301
302 void _CURVECLASS WINAPI InitBasicMain(TBasicMain *aBasicMain) {
303 BasicMain= aBasicMain;
304 }
305
306 //******************************************************************************
307 // Verwaltung von absoluten Dateinamen für alle benutzen Dateien
308 //******************************************************************************
309
310 LPCSTR _CURVECLASS WINAPI GetDirectory( void )
311 {
312 if ( BasicMain ) return BasicMain->GetDirectory();
313 else return "";
314 }
315
316 LPCSTR _CURVECLASS WINAPI GetName( void )
317 {
318 if ( BasicMain ) return BasicMain->GetName();
319 else return "";
320 }
321
322 LPCSTR _CURVECLASS WINAPI GetHWFile( void )
323 {
324 if ( BasicMain ) return BasicMain->GetHWFile();
325 else return "";
326 }
327
328 LPCSTR _CURVECLASS WINAPI GetCFile( void )
329 {
330 if ( BasicMain ) return BasicMain->GetCFile();
331 else return "";
332 }
333
334 LPCSTR _CURVECLASS WINAPI GetHelpFile( void )
335 {
336 if ( BasicMain ) return BasicMain->GetHelpFile();
337 else return "";
338 }
339
340 LPCSTR _CURVECLASS WINAPI GetPTopoName( void )
341 {
342 if ( BasicMain ) return BasicMain->GetPTopoName();
343 else return "";
344 }
345
346 LPCSTR _CURVECLASS WINAPI GetPDiffName( void )
347 {
348 if ( BasicMain ) return BasicMain->GetPDiffName();
349 else return "";
350 }
351
352 LPCSTR _CURVECLASS WINAPI GetPTopoFile( void )
353 {
354 if ( BasicMain ) return BasicMain->GetPTopoFile();
355 else return "";
356 }
357
358 LPCSTR _CURVECLASS WINAPI GetPDiffFile( void )
359 {
360 if ( BasicMain ) return BasicMain->GetPDiffFile();
361 else return "";
362 }
363
364 LPCSTR _CURVECLASS WINAPI GetPTopoDirectory( void )
365 {
366 if ( BasicMain ) return BasicMain->GetPTopoDirectory();
367 else return "";
368 }
369
370 LPCSTR _CURVECLASS WINAPI GetPDiffDirectory( void )
371 {
372 if ( BasicMain ) return BasicMain->GetPDiffDirectory();
373 else return "";
374 }
375
376 //klier 25.02.2003
377 LPCSTR _CURVECLASS WINAPI GetPTopoBackupDirectory( void )
378 {
379 if ( BasicMain ) return BasicMain->GetPTopoBackupDirectory();
380 else return "";
381 }
382
383 //klier 25.02.2003
384 LPCSTR _CURVECLASS WINAPI GetPDiffBackupDirectory( void )
385 {
386 if ( BasicMain ) return BasicMain->GetPDiffBackupDirectory();
387 else return "";
388 }
389
390 //klier 16.03.2003
391 BOOL _CURVECLASS WINAPI SetPTopoBackupDirectory( LPCSTR lDir)
392 {
393 if ( BasicMain ) return BasicMain->SetPTopoBackupDirectory(lDir);
394 else return FALSE;
395 }
396
397 //klier 16.03.2003
398 BOOL _CURVECLASS WINAPI SetPDiffBackupDirectory( LPCSTR lDir)
399 {
400 if ( BasicMain ) return BasicMain->SetPDiffBackupDirectory(lDir);
401 else return FALSE;
402 }
403
404 //klier 16.03.2003
405 BOOL _CURVECLASS WINAPI SetPTopoFile( LPCSTR FileName )
406 {
407 if ( BasicMain ) return BasicMain->SetPTopoFile(FileName);
408 else return FALSE;
409 }
410
411 //klier 16.03.2003
412 BOOL _CURVECLASS WINAPI SetPDiffFile( LPCSTR FileName )
413 {
414 if ( BasicMain ) return BasicMain->SetPDiffFile(FileName);
415 else return FALSE;
416 }
417
418 LPCSTR _CURVECLASS WINAPI GetTestDevFile( void )
419 {
420 if ( BasicMain ) return BasicMain->GetTestDevFile();
421 else return "";
422 }
423
424 LPCSTR _CURVECLASS WINAPI GetMacroFile( LPCSTR macroname )
425 {
426 if ( BasicMain ) return BasicMain->GetMacroFile( macroname );
427 else return "";
428 }
429
430 //******************************************************************************
431 // Verwaltung weiterer gemeinsam genutzer Teile
432 //******************************************************************************
433
434 HINSTANCE _CURVECLASS WINAPI GetMainInstance(void)
435 {
436 if ( BasicMain ) return BasicMain->GetMainInstance();
437 else return 0;
438 };
439
440 HWND _CURVECLASS WINAPI GetFrameHandle(void)
441 {
442 if ( BasicMain ) return BasicMain->GetFrameHandle();
443 else return 0;
444 };
445
446 HWND _CURVECLASS WINAPI GetScanHandle(void)
447 {
448 if ( BasicMain ) return BasicMain->GetScanHandle();
449 else return 0;
450 };
451
452 HWND _CURVECLASS WINAPI GetClientHandle(void)
453 {
454 if ( BasicMain ) return BasicMain->GetClientHandle();
455 else return 0;
456 };
457
458 UINT _CURVECLASS WINAPI GetWakeUpMsg(void)
459 {
460 if ( BasicMain ) return BasicMain->GetWakeUpMsg();
461 else return 0;
462 };
463
464 BOOL _CURVECLASS WINAPI CreateIniDefaults(void)
465 {
466 if ( BasicMain ) return BasicMain->CreateIniDefaults();
467 else return TRUE;
468 };
469
470 //17.11.2002
471 /*LPDataBase _CURVECLASS WINAPI GetDataBasePtr ( void ) {
472 if (!bModulLoaded) return NULL;
473 return (LPDataBase)lpDBase;
474 };*/
475
476 //******************************************************************************
477 // Info's in Statuszeile ausgeben
478 //******************************************************************************
479
480 HWND _CURVECLASS WINAPI GetStatusBarHandle( void ) {
481 if ( BasicMain ) return BasicMain->GetStatusBarHandle();
482 else return 0;
483 }
484
485 void _CURVECLASS WINAPI SetStatusBarText( UINT aPart, LPCSTR aText ) {
486 if ( BasicMain ) BasicMain->SetStatusBarText( aPart, aText );
487 }
488
489 void _CURVECLASS WINAPI SetInfo(LPCSTR status_txt)
490 {
491 SetStatusBarText( piInfo, status_txt );
492 };
493
494 void _CURVECLASS WINAPI SetStaticInfo(LPCSTR status_txt)
495 {
496 SetStatusBarText( piStaticInfo, status_txt );
497 };
498
499 void _CURVECLASS WINAPI SetStatus(LPCSTR status_txt)
500 {
501 SetStatusBarText( piStatus, status_txt );
502 };
503
504 //##############################################################################
505 // Rest
506 //##############################################################################
507
508 BOOL _CURVECLASS WINAPI FileOpenDialog(LPCSTR HeadLine, LPSTR szFilter, LPSTR szFileName, LPCSTR StartupPath ) {
509 DWORD Filter= 1;
510 return FileOpenDialog( HeadLine, szFilter, szFileName, StartupPath, Filter );
511 }
512
513 BOOL _CURVECLASS WINAPI FileOpenDialog(LPCSTR HeadLine, LPSTR szFilter, LPSTR szFileName, LPCSTR StartupPath, DWORD &aFilterIndex)
514 {
515 OPENFILENAME ofnTemp;
516 DWORD Errval; // Error value
517 char buf[5]; // Error buffer
518 char Errstr[50]= "GetOpenFileName returned Error #";
519 char chSeperator= '|';
520 int i;
521
522 ofnTemp.lStructSize= sizeof(OPENFILENAME);
523 ofnTemp.hwndOwner= GetFrameHandle(); // An invalid hWnd causes non-modality
524 ofnTemp.hInstance= 0;
525 ofnTemp.lpstrFilter= (LPSTR)szFilter; // See previous note concerning string
526 ofnTemp.lpstrCustomFilter= 0;
527 ofnTemp.nMaxCustFilter= 0;
528 ofnTemp.nFilterIndex= aFilterIndex;
529 ofnTemp.lpstrFile= (LPSTR)szFileName; // Stores the result in this variable
530 ofnTemp.nMaxFile= _MAX_PATH;
531 ofnTemp.lpstrFileTitle= NULL;
532 ofnTemp.nMaxFileTitle= 0;
533 ofnTemp.lpstrInitialDir= StartupPath;
534 ofnTemp.lpstrTitle= HeadLine;
535 ofnTemp.Flags= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
536 ofnTemp.nFileOffset= 0;
537 ofnTemp.nFileExtension= 0;
538 ofnTemp.lpstrDefExt= NULL;
539 ofnTemp.lCustData= NULL;
540 ofnTemp.lpfnHook= NULL;
541 ofnTemp.lpTemplateName= NULL;
542
543 for (i= 0;szFilter[i] != '\0';i++)
544 if (szFilter[i] == chSeperator)
545 szFilter[i]= '\0';
546 if ( !GetOpenFileName(&ofnTemp) )
547 {
548 Errval= CommDlgExtendedError();
549 if (Errval)
550 { // 0 value means user selected Cancel
551 sprintf(buf, "%ld", Errval);
552 strcat(Errstr, buf);
553 MessageBox(GetFrameHandle(), Errstr, "WARNING", MBSTOP);
554 }
555 return FALSE;
556 } else aFilterIndex= ofnTemp.nFilterIndex;
557 InvalidateRect(GetFrameHandle(), NULL, TRUE ); // Repaint to display the new name
558 return TRUE;
559 };
560
561 BOOL _CURVECLASS WINAPI FileSaveDialog(LPCSTR HeadLine, LPSTR szFilter, LPSTR szFileName, LPCSTR StartupPath ) {
562 DWORD Filter= 1;
563 return FileSaveDialog( HeadLine, szFilter, szFileName, StartupPath, Filter );
564 }
565
566 BOOL _CURVECLASS WINAPI FileSaveDialog(LPCSTR HeadLine, LPSTR szFilter, LPSTR szFileName, LPCSTR StartupPath, DWORD &aFilterIndex)
567 {
568 OPENFILENAME ofnTemp;
569 DWORD Errval; // Error value
570 char buf[5]; // Error buffer
571 char Errstr[50]= "GetSaveFileName returned Error #";
572 char chSeperator= '|';
573 int i;
574
575 ofnTemp.lStructSize= sizeof(OPENFILENAME);
576 ofnTemp.hwndOwner= GetFrameHandle(); // An invalid hWnd causes non-modality
577 ofnTemp.hInstance= 0;
578 ofnTemp.lpstrFilter= szFilter; // See previous note concerning string
579 ofnTemp.lpstrCustomFilter= 0;
580 ofnTemp.nMaxCustFilter= 0;
581 ofnTemp.nFilterIndex= aFilterIndex;
582 ofnTemp.lpstrFile= (LPSTR)szFileName; // Stores the result in this variable
583 ofnTemp.nMaxFile= _MAX_PATH;
584 ofnTemp.lpstrFileTitle= NULL;
585 ofnTemp.nMaxFileTitle= 0;
586 ofnTemp.lpstrInitialDir= StartupPath;
587 ofnTemp.lpstrTitle= HeadLine;
588 ofnTemp.Flags= OFN_HIDEREADONLY | OFN_READONLY | OFN_OVERWRITEPROMPT;
589 ofnTemp.nFileOffset= 0;
590 ofnTemp.nFileExtension= 0;
591 ofnTemp.lpstrDefExt= NULL;
592 ofnTemp.lCustData= NULL;
593 ofnTemp.lpfnHook= NULL;
594 ofnTemp.lpTemplateName= NULL;
595
596 for (i= 0;szFilter[i] != '\0';i++)
597 if (szFilter[i] == chSeperator)
598 szFilter[i]= '\0';
599 if ( !GetSaveFileName(&ofnTemp) )
600 {
601 Errval= CommDlgExtendedError();
602 if (Errval)
603 { // 0 value means user selected Cancel
604 sprintf(buf, "%ld", Errval);
605 strcat(Errstr, buf);
606 MessageBox(GetFrameHandle(), Errstr, "WARNING", MBSTOP);
607 }
608 return FALSE;
609 } else aFilterIndex= ofnTemp.nFilterIndex;
610 InvalidateRect(GetFrameHandle(), NULL, TRUE); // Repaint to display the new name
611 return TRUE;
612 };
613
614 BOOL _CURVECLASS WINAPI PathCanWrite(LPSTR szPath)
615 {
616 OFSTRUCT of;
617 char TestFile[ _MAX_PATH ], p[ _MAX_PATH ], drv[ _MAX_DRIVE+1 ], dir[ _MAX_DIR+1 ], name[ _MAX_FNAME+1 ], ext[ _MAX_EXT+1 ];
618 strcpy(p, szPath);
619 if ( p[ max(0, strlen(p)-1) ] != '\\' )
620 strcat( p, "\\" );
621 _splitpath( p, drv, dir, name, ext );
622
623 _makepath( TestFile, drv, dir, "check", "tmp" );
624 HFILE hfile= OpenFile( TestFile, &of, OF_CREATE );
625 if ( hfile!=HFILE_ERROR ) {
626 _lclose( hfile );
627 remove( TestFile );
628 _makepath( szPath, drv, dir, "", "" );
629 }
630 return ( hfile!=HFILE_ERROR );
631 }
632
633 BOOL _CURVECLASS WINAPI SetFPOnData(HFILE hfile)
634 {
635 char data;
636 char *buf;
637 //! BOOL EoH= FALSE;
638 int cnt, cntfp;
639
640 // the file pointer will be set on the first character after
641 // the key [Data] and any whitespaces (\r \n \t _)
642 buf= new char[21];
643 _llseek(hfile, 0, FILE_BEGIN);
644 cntfp= 0;
645 while (_lread(hfile, &data, 1))
646 {
647 cntfp++;
648 if (data == '[')
649 {
650 cnt= 0;
651 while (_lread(hfile, &data, 1))
652 {
653 cntfp++;
654 if ( data == ']' || cnt>5 )
655 {
656 buf[cnt++]= 0;
657 if (strstr(buf, "Data"))
658 goto Finish;
659 else
660 goto SearchAgain;
661 }
662 buf[cnt++]= data;
663 } // after break
664 _FREELIST(buf);
665 return FALSE;
666 }
667 SearchAgain:
668 /*nur eine leere Anweisung, wegen SearchAgain-Label*/;
669 }
670 _FREELIST(buf);
671 return FALSE;
672 Finish:
673 while (_lread(hfile, &data, 1))
674 {
675 if (data == ' ')
676 continue;
677 if (data == '\r')
678 continue;
679 if (data == '\n')
680 continue;
681 if (data == '\t')
682 continue;
683 _llseek(hfile, -1, SEEK_CUR);
684
685 _FREELIST(buf);
686 return TRUE;
687 }
688 _FREELIST(buf);
689 return FALSE;
690 }
691
692 //Datum: 03.02.2003
693 /*int _CURVECLASS WINAPI GetBufferLine(LPSTR src,LPSTR dst,int dstsize) {
694 static LPSTR Source= NULL;
695 static WORD cnt_s;
696 BOOL EoL= FALSE;
697 char data;
698 int cnt_d= 0;
699
700 if (src != NULL)
701 {
702 Source= src;
703 cnt_s= 0;
704 }
705 if (!Source) return FALSE;
706 if (Source[cnt_s] == '\0') return FALSE;
707 do {
708 data= Source[cnt_s++];
709 switch(data) {
710 case '\n':
711 case '\r':
712 data= Source[cnt_s++];
713 if(EoL) goto Ready;
714 EoL= TRUE;
715 continue;
716
717 case '\0':
718 dst[cnt_d]= '\0';
719 return R_EndOfFile;
720
721 default:
722 dst[cnt_d++]= data;
723 }
724 } while(cnt_d < dstsize);
725 Ready:
726 dst[cnt_d]= '\0';
727 return TRUE;
728 };
729 */
730
731 int _CURVECLASS WINAPI GetFileLine(int hFile, LPSTR dst, int dstsize)
732 {
733 char data;
734 BOOL EoL= FALSE;
735 int cnt= 0;
736 int rdl;
737
738 dst[cnt]= '\0';
739 if (hFile == -1)
740 return FALSE;
741 do
742 {
743 rdl= _lread(hFile, &data, 1);
744 switch (data)
745 {
746 case '\n':
747 case '\r':
748 rdl= _lread(hFile, &data, 1);
749 if (EoL)
750 goto Ready;
751 EoL= TRUE;
752 continue;
753
754 case '\0':
755 dst[cnt]= '\0';
756 return R_EndOfFile;
757
758 default:
759 if (EoL)
760 goto Ready;
761 dst[cnt++]= data;
762 }
763 } while (cnt < dstsize);
764 Ready:
765 _llseek(hFile, -1, SEEK_CUR);
766 dst[cnt]= '\0';
767 if (cnt == dstsize)
768 {
769 // overflow dst
770 return R_Overflow;
771 };
772 if (!rdl)
773 return R_EndOfFile;
774 return TRUE;
775 }
776
777 EUnitType _CURVECLASS WINAPI UnitEnum(LPSTR sz_unit)
778 {
779 char buf[MaxString];
780 strcpy(buf, sz_unit);
781 strupr(buf);
782 if (strstr((LPSTR)buf, "GRAD"))
783 return utGrad;
784 if (strstr((LPSTR)buf, "SEKUNDEN"))
785 return utSekunden;
786 if (strstr((LPSTR)buf, "MINUTEN"))
787 return utMinuten;
788 if (strstr((LPSTR)buf, "MINUTS"))
789 return utMinuten;
790 if (strstr((LPSTR)buf, "MILLIMETER"))
791 return utMillimeter;
792 if (strstr((LPSTR)buf, "MIKROMETER"))
793 return utMikrometer;
794 if (strstr((LPSTR)buf, "MIKCOMETER"))
795 return utMikrometer;
796 if (strstr((LPSTR)buf, "CHANNEL"))
797 return utChannel;
798 return utNone;
799 }
800
801 float _CURVECLASS WINAPI CalcValueInUnit(EUnitType aUnit, float fValParam)
802 {
803 switch (aUnit)
804 {
805 case utGrad:
806 return ( fValParam / 3600.0 );
807
808 case utMinuten:
809 return ( fValParam / 60.0 );
810 }
811 return fValParam;
812 }
813
814 float _CURVECLASS WINAPI CalcValueFromUnit(EUnitType aUnit, float fValParam)
815 {
816 switch ( aUnit )
817 {
818 case utGrad:
819 return ( fValParam * 3600 );
820
821 case utMinuten:
822 return ( fValParam * 60 );
823 }
824 return fValParam;
825 }
826
827 //Datum: 03.02.2003
828 /*LPSTR _CURVECLASS WINAPI UnitStr(TUnitType n_unit) {
829 switch(n_unit) {
830 case Grad:
831 return "Grad";
832
833 case Minuten:
834 return "Minuten";
835
836 case Sekunden:
837 return "Sekunden";
838
839 case Millimeter:
840 return "Millimeter";
841
842 case Mikrometer:
843 return "Mikrometer";
844
845 case Channel:
846 return "Channel";
847
848 default:
849 return "None";
850
851 }
852 };*/
853
854 //hp
855 static double dCountFreq= 0;
856 const double dDelayMin= 100; // Faktor für Delay()
857 void _CURVECLASS WINAPI InitializeDelay()
858 {
859 LARGE_INTEGER freq;
860
861 if(QueryPerformanceFrequency(&freq))
862 {
863 dCountFreq= freq.QuadPart; // Counts je 1Sekunde
864 dCountFreq= dCountFreq / 1000000; // Counts je 1µs
865 dCountFreq= dCountFreq * dDelayMin;// unsere Basis, dauer von Delay(1);
866 }
867 else
868 MessageBox(0,"Das System besitzt eine minimale Zeitauflösung von 1 Millisekunde. Dieser ungünstige Wert kann zu Fehlfunktionen führen.","XCTL",MB_ICONINFORMATION | MB_OK);
869 }
870
871 void _CURVECLASS WINAPI Delay(long count)
872 {
873 LARGE_INTEGER liStartCount, liStopCount;
874 //double dPerfCount= liPerfCount.QuadPart
875 double dFinishCount= 0;
876
877 if (dCountFreq)
878 {
879 QueryPerformanceCounter(&liStartCount); // Startwert holen
880 liStopCount.QuadPart= liStartCount.QuadPart;
881 dFinishCount= dCountFreq * count + liStartCount.QuadPart;
882 while (dFinishCount > liStopCount.QuadPart)
883 QueryPerformanceCounter(&liStopCount);
884 }
885 else
886 {
887 if (count == 0)
888 return;
889 count= count / 100;
890 if(!count) // leider gibt es auf diesem System keine höherauflösende Funktion als Sleep mit 1ms auflösung
891 count= 1; // daher ist alles unter count 100 gleich 1ms
892 Sleep( (DWORD) count );
893 }
894 }
895
896 void _CURVECLASS WINAPI ProcessMessages(UINT32 Ticks) {
897 UINT start= ::GetTickCount();
898 do {
899 MSG msg;
900 if ( PeekMessage(&msg,NULL,0,0,PM_REMOVE) ) {
901 TranslateMessage(&msg);
902 DispatchMessage(&msg);
903 }
904 } while ( ::GetTickCount()-start<Ticks );
905 }
906 /*
907 void _CURVECLASS WINAPI Delay(long count)
908 {
909 if (count == 0)
910 return;
911 count= count / 100; //bei ca 30 Takten/Addition, Bsp: (5000 * 11 + 920) * 30 / 33Mhz => ~ 0,05s= 50ms => faktor 100
912 if(!count) //leider gibt es keine höherauflösende Funktion als Sleep mit 1ms auflösung
913 count= 1; // daher ist alles unter count 100 gleich 1ms
914 Sleep( (DWORD) count );
915 //hp
916 }*/
917 /*
918 void _CURVECLASS WINAPI Delay(long count)
919 {
920
921 long d1, corr=920*14, m=0;
922 if(count == 0) return;
923 if(count>0)
924 count--;
925 for(d1=0;d1<(count*11+corr);d1++)
926 m=m+1;
927
928 }*/
929 void _CURVECLASS WINAPI DelayTime(int MilliSec)
930 {
931 if (MilliSec == 0)
932 return;
933 Sleep( (DWORD) MilliSec );
934
935 }
936
937 //Datum: 16.08.2002 maxi, maxl, maxf, maxd, mini, minl, minf, mind verschoben nach U_VALUES.CPP
938
939 // __LastLine__
940