[65ba95]: sys_win.c Maximize Restore History

Download this file

sys_win.c    930 lines (730 with data), 20.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
/* Panorama_Tools - Generate, Edit and Convert Panoramic Images
Copyright (C) 1998,1999 - Helmut Dersch der@fh-furtwangen.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/*
Modifications by Max Lyons (maxlyons@erols.com):
March 4, 2002. Changes made to mymalloc and myfree functions to
work around a problem allocating more than 256MB of RAM from heap.
See Microsoft Knowledge Base article Q198959 for more information.
"PRB: Windows 95/98 Heaps Have A 255.9 MB Allocation Ceiling".
This problem was causing "out of memory" errors when trying to stitch
images that require more than 256MB of RAM (i.e. 64 megapixels)
to be requested using the mymalloc function.
March 6, 2002. Added memory monitoring feature...
This feature reports on memory allocation requests (i.e. chunks of memory
that Pano Tools request from the operating system), and total memory
usage (the sum of all currently allocated memory).
This information is displayed on the progress dialog.
*/
/*------------------------------------------------------------*/
/* modified by Fulvio Senore June.2004
Added a call to disable warnings from the TIFF library: some tiff files (probably created by Photoshop)
caused annoying warnings about unknown tags while loading each tiff source image
*/
// FS+
// needed for TIFFSetWarningHandler()
#include "tiffio.h"
// FS-
#include "sys_win.h"
#define CG_IDD_PROGRESS 101
#define CG_IDS_PROGRESS_CAPTION 102
#define CG_IDC_PROGDLG_PROGRESS 1003
#define CG_IDC_PROGDLG_PERCENT 1004
#define CG_IDC_PROGDLG_MEM_REQUEST 1005
#define CG_IDC_PROGDLG_MEM_USAGE 1006
#define ID_PRG 100
#define ID_MM 100
#define ID_SM 101
HINSTANCE hDllInstance = NULL;
HWND wndOwner = NULL;
int dialogDone;
int infoDone;
//Used to keep track of memory statistics
int kBytesAlloced =0;
int maxKBytesAlloced =0;
int maxKBytesUsage =0;
//------------------ Public functions required by filter.h -------------------------------
void SetWindowOwner( HWND Owner )
{
wndOwner = Owner;
}
void filter_main( TrformStr *TrPtr, struct size_Prefs *spref)
{
dispatch ( TrPtr, spref);
}
// Error reporting
void PrintError(char* fmt, ...){
va_list ap;
char message[257];
va_start(ap, fmt);
vsprintf(message, fmt, ap);
va_end(ap);
if( JavaUI )
JPrintError( message );
else
// MessageBox(GetFocus(), (LPSTR)message, (LPSTR)"", MB_OK | MB_ICONHAND) ;
MessageBox((HWND)NULL, (LPSTR)message, (LPSTR)"", MB_OK | MB_ICONHAND) ;
}
// Progress report; return false if canceled
int Progress( int command, char* argument ){
static HWND hwDlg = NULL;
MSG msg;
long percent;
switch( command ){
case _initProgress:
if( hwDlg != NULL ){ // Update text and reset bar
SetWindowText(hwDlg, argument);
SendMessage( hwDlg, WM_COMMAND, ID_PRG, 0 );
while( PeekMessage(&msg, 0,0,0, PM_REMOVE)){
if( !IsDialogMessage( hwDlg, &msg ) ){
TranslateMessage(&msg); DispatchMessage(&msg);
}
}
return TRUE;
}
hwDlg = CreateDialogParam( hDllInstance,
MAKEINTRESOURCE( 101 ), 0, DispPrg, (LPARAM)&dialogDone);
if( hwDlg == NULL )
PrintError( "Could not create Window" );
else{
dialogDone = FALSE;
SetWindowText(hwDlg, argument);
CenterDialog(hwDlg);
ShowWindow(hwDlg, SW_SHOWNORMAL);
}
return TRUE;
case _setProgress:
if( (hwDlg != NULL) && !dialogDone){
ShowWindow(hwDlg, SW_SHOWNORMAL);
sscanf(argument,"%ld", &percent);
if(percent>100) percent = 100;
if(percent<0 ) percent = 0;
SendMessage( hwDlg, WM_COMMAND, ID_PRG, percent );
while( PeekMessage(&msg, 0,0,0, PM_REMOVE)){
if( !IsDialogMessage( hwDlg, &msg ) ){
TranslateMessage(&msg); DispatchMessage(&msg);
}
}
}
if(dialogDone){
if( hwDlg != NULL ){
DestroyWindow (hwDlg);
hwDlg = NULL;
}
return FALSE; // User clicked cancel
}
return TRUE;
break;
case _disposeProgress:
if( hwDlg != NULL )
{
DestroyWindow (hwDlg);
hwDlg = NULL;
}
return TRUE;
case _idleProgress:
return TRUE;
}
return TRUE;
}
int infoDlg ( int command, char* argument ) // Display info: same argumenmts as progress
{
char text[256];
static char mainMessage[256];
static HWND hwDlg;
MSG msg;
switch( command )
{
case _initProgress:
hwDlg = CreateDialogParam( hDllInstance,
MAKEINTRESOURCE( 105 ), 0, InfoPrg, (LPARAM)&infoDone);
if( hwDlg == NULL )
PrintError( "Could not create Window" );
else
{
infoDone = FALSE;
SetWindowText(hwDlg, argument);
CenterDialog(hwDlg);
ShowWindow(hwDlg, SW_SHOWNORMAL);
SendMessage( hwDlg, WM_COMMAND, ID_MM, (LPARAM)argument );
}
return TRUE;
case _setProgress:
if( (hwDlg != NULL) && !infoDone)
{
if( *argument != 0 )
{
if( *argument != '+' )
{
strcpy( mainMessage, argument );
strcpy( text, argument );
}
else
{
sprintf( text,"%s%s", mainMessage, &(argument[1]) );
}
SendMessage( hwDlg, WM_COMMAND, ID_SM, (LPARAM)text );
while( PeekMessage(&msg, 0,0,0, PM_REMOVE))
{
if( !IsDialogMessage( hwDlg, &msg ) )
{
TranslateMessage(&msg); DispatchMessage(&msg);
}
}
}
}
if(infoDone)
{
if( hwDlg != NULL )
{
DestroyWindow (hwDlg);
}
return FALSE; // User clicked cancel
}
return TRUE;
break;
case _disposeProgress:
if( hwDlg != NULL )
{
DestroyWindow (hwDlg);
}
return TRUE;
case _idleProgress:
return TRUE;
}
return TRUE;
}
int readPrefs( char* pref, int selector )
{
struct {
char v[sizeof(VERSION)];
struct correct_Prefs c;
struct remap_Prefs r;
struct perspective_Prefs p;
struct adjust_Prefs a;
struct size_Prefs s;
panControls pc;
} prf;
char prefname[256], *c;
long size;
FILE *prfile;
int result = 0;
GetModuleFileName( NULL, prefname, 256 );
c = strrchr( prefname, '\\' );
if( c!= NULL )
{
c++;
strcpy( c,"pano12.prf" );
}
else
{
strcpy( prefname,".\\pano12.prf" );
}
if( (prfile = fopen( prefname, "rb" )) != NULL )
{
size = fread( &prf, 1, sizeof(prf), prfile);
fclose( prfile );
if( size != sizeof(prf) )
{
result = -1;
}
else
{
switch( selector)
{
case _version:
memcpy( pref, &prf.v, sizeof( VERSION ) );
break;
case _correct:
if( prf.c.magic != 20 )
result = -1;
else
memcpy( pref, &prf.c, sizeof(struct correct_Prefs));
break;
case _remap:
if( prf.r.magic != 30 )
result = -1;
else
memcpy( pref, &prf.r , sizeof(struct remap_Prefs));
break;
case _perspective:
if( prf.p.magic != 40 )
result = -1;
else
memcpy( pref, &prf.p , sizeof(struct perspective_Prefs));
break;
case _adjust:
if( prf.a.magic != 50 )
result = -1;
else
memcpy( pref, &prf.a , sizeof(struct adjust_Prefs));
break;
case _sizep:
if( prf.s.magic != 70 )
result = -1;
else
memcpy( pref, &prf.s , sizeof(struct size_Prefs));
break;
case _panright:
case _panleft:
case _panup:
case _pandown:
case _zoomin:
case _zoomout:
case _apply:
case _getPano:
case _increment:
memcpy( pref, &prf.pc , sizeof(panControls));
break;
}// switch
} // sizes match
}
else
result = -1;
return result;
}
void writePrefs( char* prefs, int selector )
{
struct {
char v[sizeof(VERSION)];
struct correct_Prefs c;
struct remap_Prefs r;
struct perspective_Prefs p;
struct adjust_Prefs a;
struct size_Prefs s;
panControls pc;
} prf;
FILE *prfile;
char prefname[256], *c;
GetModuleFileName( NULL, prefname, 256 );
c = strrchr( prefname, '\\' );
if( c!= NULL )
{
c++;
strcpy( c,"pano12.prf" );
}
else
{
strcpy( prefname,".\\pano12.prf" );
}
if( (prfile = fopen( prefname, "rb" )) != NULL )
{
fread( &prf, sizeof(prf), 1 , prfile);
fclose( prfile );
}
switch( selector)
{
case _version:
memcpy( &prf.v, prefs, sizeof( VERSION ) );
break;
case _correct:
memcpy( &prf.c , prefs, sizeof(struct correct_Prefs));
break;
case _remap:
memcpy( &prf.r , prefs, sizeof(struct remap_Prefs));
break;
case _perspective:
memcpy( &prf.p , prefs, sizeof(struct perspective_Prefs));
break;
case _adjust:
memcpy( &prf.a , prefs, sizeof(struct adjust_Prefs));
break;
case _sizep:
memcpy( &prf.s , prefs, sizeof(struct size_Prefs));
break;
case _panright:
case _panleft:
case _panup:
case _pandown:
case _zoomin:
case _zoomout:
case _apply:
case _getPano:
case _increment:
memcpy( &prf.pc , prefs, sizeof(panControls));
break;
}
if( (prfile = fopen( prefname, "wb" )) != NULL )
{
fwrite( &prf, sizeof(prf), 1 , prfile);
fclose(prfile);
}
}
/**
*
* Function counts the amount of memory that has been virtualAlloc'd by this process
*/
DWORD countMemUsage()
{
MEMORY_BASIC_INFORMATION mbi;
DWORD dwMemUsed = 0;
PVOID pvAddress = 0;
CHAR szBuf[512];
memset(&mbi, 0, sizeof(MEMORY_BASIC_INFORMATION));
while(pvAddress < (PVOID)0x80000000 && VirtualQuery(pvAddress, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == sizeof(MEMORY_BASIC_INFORMATION))
{
if(mbi.State == MEM_COMMIT && mbi.Type == MEM_PRIVATE && (!GetModuleFileNameA((HINSTANCE)mbi.AllocationBase, szBuf, 512)))
dwMemUsed += mbi.RegionSize;
pvAddress = ((BYTE*)mbi.BaseAddress) + mbi.RegionSize;
}
return dwMemUsed/1024;
}
#define signatureSize 4
void** mymalloc( long numBytes ) // Memory allocation, use Handles
{
LPSTR *mHand;
char *p;
static char cSig[signatureSize] = {'O', 'T', 'O', 'F'};
mHand = (LPSTR *) GlobalAllocPtr (GHND, (sizeof (LPSTR *) + signatureSize));
if (mHand)
//*mHand = (LPSTR) GlobalAllocPtr (GHND, numBytes);
//Use VirtualAlloc to work around Win 95/98/ME memory allocation problems
//See Microsoft KB article Q198959
*mHand = (LPSTR) VirtualAlloc (NULL, numBytes, MEM_COMMIT, PAGE_READWRITE);
if (!mHand || !(*mHand))
{
PrintError("Error allocating %ld KB of memory", numBytes/1024);
return NULL;
}
kBytesAlloced = numBytes/1024;
if (kBytesAlloced>maxKBytesAlloced) maxKBytesAlloced = kBytesAlloced;
// put the signature after the pointer
p = (char *) mHand;
p += sizeof (Handle);
memcpy (p,cSig, signatureSize);
GlobalLock(mHand);
return (void**)mHand;
}
void myfree( void** Hdl ) // free Memory, use Handles
{
if (Hdl)
{
LPSTR p;
GlobalUnlock((LPSTR *) Hdl);
p = *((LPSTR*) Hdl);
//Use VirtualFree because of Win 95/98/ME memory allocation problems
//See Microsfot KB article Q198959
if (p)
VirtualFree(p, 0, MEM_RELEASE);
GlobalFreePtr ((LPSTR) Hdl);
}
}
// Display Scriptfile using plain text editor
void showScript( fullPath* scriptFile )
{
char cmd[ MAX_PATH_LENGTH + 32 ];
sprintf( cmd, "Notepad \"%s\"", scriptFile->name );
WinExec( cmd , SW_SHOWNORMAL );
}
void CenterDialog(HWND hDlg)
{
HWND hParent;
int nHeight;
int nWidth;
int nTitleBits;
RECT rcDialog;
RECT rcParent;
int xOrigin;
int yOrigin;
int xScreen;
int yScreen;
if ( ! (hParent = GetParent(hDlg)))
hParent = GetDesktopWindow();
GetClientRect(hParent, &rcParent);
ClientToScreen(hParent, (LPPOINT)&rcParent.left); // point(left, top)
ClientToScreen(hParent, (LPPOINT)&rcParent.right); // point(right, bottom)
// Center on Title: title bar has system menu, minimize, maximize bitmaps
// Width of title bar bitmaps - assumes 3 of them and dialog has a sysmenu
nTitleBits = GetSystemMetrics(SM_CXSIZE);
// If dialog has no sys menu compensate for odd# bitmaps by sub 1 bitwidth
if ( ! (GetWindowLong(hDlg, GWL_STYLE) & WS_SYSMENU))
nTitleBits -= nTitleBits / 3;
GetWindowRect(hDlg, &rcDialog);
nWidth = rcDialog.right - rcDialog.left;
nHeight = rcDialog.bottom - rcDialog.top;
xOrigin = max(rcParent.right - rcParent.left - nWidth, 0) / 2
+ rcParent.left - nTitleBits;
xScreen = GetSystemMetrics(SM_CXSCREEN);
if (xOrigin + nWidth > xScreen)
xOrigin = max (0, xScreen - nWidth);
yOrigin = max(rcParent.bottom - rcParent.top - nHeight, 0) / 3
+ rcParent.top;
yScreen = GetSystemMetrics(SM_CYSCREEN);
if (yOrigin + nHeight > yScreen)
yOrigin = max(0 , yScreen - nHeight);
SetWindowPos(hDlg, NULL, xOrigin, yOrigin, nWidth, nHeight, SWP_NOZORDER);
}
int getConfirmation(HWND hWnd, char *message)
{
return (MessageBox(hWnd, (LPSTR)message, (LPSTR)"Panorama Tools", MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_APPLMODAL));
}
BOOL WINAPI DispPrg(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) // Win32 Change
{
int item, cmd;
short numberErr = 0;
char message[128];
char bar[128];
long percent;
int i;
int memUsage;
static int *dDone;
switch (wMsg)
{
case WM_INITDIALOG:
dDone = (int*)lParam;
/* drop into PAINT */
case WM_PAINT:
return FALSE;
break;
case WM_COMMAND:
item = LOWORD(wParam); // WIN32 Change
cmd = HIWORD (wParam);
switch (item)
{
case IDCANCEL:
if (cmd == BN_CLICKED)
{
if (getConfirmation(hDlg, "Are you sure you want to cancel?")==IDYES)
{
*dDone = TRUE;
return TRUE;
}
}
break;
case ID_PRG:
sprintf(message,"Progress: %ld %%",(long)lParam);
SetDlgItemText( hDlg, CG_IDC_PROGDLG_PERCENT, message); // stuff string
//Show some statistics on memory allocation requests
sprintf(message,"Memory Requests (Last/Max): %.1lf / %.1lf MB", (double)kBytesAlloced/1024.0, (double)maxKBytesAlloced/1024.0);
SetDlgItemText( hDlg, CG_IDC_PROGDLG_MEM_REQUEST, message); // stuff string
//Show some statistics on current/peak memory usage
memUsage = countMemUsage();
if (memUsage > maxKBytesUsage) maxKBytesUsage = memUsage;
sprintf(message,"Memory Usage (Current/Max): %.1lf / %.1lf MB", (double)memUsage/1024.0, (double)maxKBytesUsage/1024.0);
SetDlgItemText( hDlg, CG_IDC_PROGDLG_MEM_USAGE, message); // stuff string
percent = (long)lParam;
if( percent > 100 )
percent = 100;
for(i=0; i<percent; i++)
bar[i] = '|';
bar[percent] = 0;
SetDlgItemText( hDlg, CG_IDC_PROGDLG_PROGRESS, bar); // stuff string
break;
default:
break;
}
break; // case WM_COMMAND
default:
return FALSE;
break;
} // switch
return TRUE;
}
BOOL WINAPI InfoPrg(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) // Win32 Change
{
int item, cmd;
short numberErr = 0;
static int *dDone;
switch (wMsg)
{
case WM_INITDIALOG:
dDone = (int*)lParam;
/* drop into PAINT */
case WM_PAINT:
return FALSE;
break;
case WM_COMMAND:
item = LOWORD(wParam); // WIN32 Change
cmd = HIWORD (wParam);
switch (item)
{
case IDCANCEL:
if (cmd == BN_CLICKED)
{
if (getConfirmation(hDlg, "Are you sure you want to cancel?")==IDYES)
{
*dDone = TRUE;
return TRUE;
}
}
break;
case ID_MM:
SetDlgItemText( hDlg, 10, (char*)lParam); // stuff string
break;
case ID_SM:
SetDlgItemText( hDlg, 11, (char*)lParam); // stuff string
break;
default:
break;
}
break; // case WM_COMMAND
default:
return FALSE;
break;
} // switch
return TRUE;
}
// Every 32-Bit DLL has an entry point DLLInit
BOOL APIENTRY DLLInit(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
hDllInstance = hInstance;
return TRUE; // Indicate that the DLL was initialized successfully.
}
int FindFile( fullPath *fname )
{
OPENFILENAME f;
char fName[256];
char zTitle[64];
int nresult;
memset(&f, 0, sizeof(f)); // initialize structure to 0/NULL
fName[0] = '\0';
zTitle[0] = '\0';
f.lStructSize = sizeof(f);
f.lpstrFile = fName;
f.nMaxFile = 256;
f.lpstrDefExt = "";
f.lpstrFileTitle = (LPTSTR)zTitle;
f.nMaxFileTitle = 256;//64;
f.hInstance = hDllInstance;
f.hwndOwner = wndOwner;
nresult = GetOpenFileName(&f);
if( nresult )
{
strcpy( fname->name, fName );
return 0;
}
else
return -1;
}
int SaveFileAs ( fullPath *fname, char *prompt, char *name )
{
OPENFILENAME f;
char fName[sizeof(fname->name)];
int nresult;
memset(&f, 0, sizeof(f)); // initialize structure to 0/NULL
strcpy(fName, name );
f.lStructSize = sizeof(f);
f.lpstrFile = fName;
f.nMaxFile = 256;
f.lpstrDefExt = "";//prompt;
f.lpstrTitle = prompt;
f.hInstance = hDllInstance;
f.hwndOwner = wndOwner;
nresult = GetSaveFileName(&f);
if( nresult )
{
strcpy( fname->name, fName );
return 0;
}
else
return -1;
}
void makePathForResult ( fullPath *path )
{
strcpy( path->name, "C:\\ptool_result" );
}
int makePathToHost ( fullPath *path )
{
GetModuleFileName( NULL, path->name, MAX_PATH_LENGTH );
return 0;
}
// Fname is appended to host-directory path
void MakeTempName( fullPath *destPath, char *fname )
{
char path[MAX_PATH_LENGTH];
char sname[256];
sprintf( sname, "pano12.%s", fname );
path[0] = 0;
GetModuleFileName( NULL, path, 256 );
GetShortPathName( path, destPath->name, 256 );
if( strrchr( destPath->name, '\\' ) != NULL )
sprintf( strrchr( destPath->name, '\\' )+1, "%s", sname );
else
sprintf( destPath->name, "C:\\%s", sname );
}
void ConvFileName( fullPath *fspec,char *string)
{
strcpy( string, fspec->name );
}
int FullPathtoString (fullPath *path, char *filename)
{
if( strlen( path->name ) < 256 )
{
strcpy( filename, path->name );
return 0;
}
else
{
return -1;
}
}
int IsTextFile( char* fname )
{
if( strrchr( fname, '.' ) != NULL &&
(strcmp( strrchr( fname, '.' ), ".txt") == 0 ||
strcmp( strrchr( fname, '.' ), ".TXT") == 0) )
return TRUE;
return FALSE;
}
int LaunchAndSendScript(char* application, char* script){
char *cmd;
cmd = (char*) malloc( strlen(application) + strlen(script) + 16 );
if( cmd == NULL )
{
PrintError("Not enough memory");
return -1;
}
sprintf( cmd , "%s %s", application, script );
if(strlen(cmd)<256){
WinExec( cmd , SW_SHOWNORMAL );
return 0;
}else{
PrintError("Command to long for WinExec");
free( cmd );
return -1;
}
}
int StringtoFullPath (fullPath *path, char *filename){
if( strlen( filename ) < 256 ){
strcpy( path->name, filename );
return 0;
}else{
return -1;
}
}
BOOL WINAPI
DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
hDllInstance = hDll;
// Code to run when the DLL is loaded
// FS+
// disable warnings for unknown tags
TIFFSetWarningHandler( 0 );
// FS-
break;
case DLL_PROCESS_DETACH:
// Code to run when the DLL is freed
break;
case DLL_THREAD_ATTACH:
// Code to run when a thread is created during the DLL's lifetime
break;
case DLL_THREAD_DETACH:
// Code to run when a thread ends normally.
break;
}
return TRUE;
}