[go: up one dir, main page]

Menu

[r4]: / trunk / gui.c  Maximize  Restore  History

Download this file

96 lines (85 with data), 2.9 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
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include "gui.h"
#include "resource.h"
extern HWND hWndMain;
extern char* ProgName;
#define NumTabChildWnds 6
extern HWND TabChildWnds[NumTabChildWnds];
#define HeaderWnd TabChildWnds[0]
#define TrimWnd TabChildWnds[1]
#define StripWnd TabChildWnds[2]
#define GD3Wnd TabChildWnds[3]
#define ConvertWnd TabChildWnds[4]
#define MiscWnd TabChildWnds[5]
void ShowError(char *format,...){
va_list args;
char buffer[1024];
va_start(args, format); // varargs start after format
_vsnprintf(buffer,1024,format,args);
va_end(args); // clean things up before leaving
MessageBox(hWndMain,buffer,ProgName,MB_ICONERROR+MB_OK);
}
void ShowMessage(char *format,...) {
va_list args;
char buffer[1024];
va_start(args, format); // varargs start after format
_vsnprintf(buffer,1024,format,args);
va_end(args); // clean things up before leaving
MessageBox(hWndMain,buffer,ProgName,0);
}
int ShowQuestion(char *format,...){
va_list args;
char buffer[1024];
va_start(args, format); // varargs start after format
_vsnprintf(buffer,1024,format,args);
va_end(args); // clean things up before leaving
return MessageBox(hWndMain,buffer,ProgName,MB_ICONQUESTION+MB_YESNO);
}
void ShowStatus(char *format,...) {
va_list args;
char buffer[1024];
va_start(args, format); // varargs start after format
_vsnprintf(buffer,1024,format,args);
va_end(args); // clean things up before leaving
SetDlgItemText(hWndMain,txtStatusBar,buffer);
}
// wnd, id specify a multi-line edit box
// format and subsequent printf-style parameters define a string to append to it
void AddConvertText(char *format,...) {
va_list args;
char buffer[1024];
int length;
va_start(args, format); // varargs start after format
_vsnprintf(buffer,1024,format,args);
va_end(args); // clean things up before leaving
length=SendDlgItemMessage(ConvertWnd,edtConvertResults,WM_GETTEXTLENGTH,0,0); // Get length
SendDlgItemMessage(ConvertWnd,edtConvertResults,EM_SETSEL,length,length); // move caret to end of text
SendDlgItemMessage(ConvertWnd,edtConvertResults,EM_REPLACESEL,FALSE,(LPARAM)buffer); // insert text there
}
BOOL GetInt(HWND hDlg,int item,int *result) {
BOOL b;
char c[3];
int i;
i=GetDlgItemInt(hDlg,item,&b,FALSE);
if(b || i) {
// b==TRUE -> no errors
// b==FALSE but i!=0 -> there were errors, but it managed to convert an integer
// This is the case when the text is something like "1234 (text)"
*result=i;
return TRUE;
}
// However, text like "0 (text)" looks like a total failure.
// But I can test for that.
if(
(GetDlgItemText(hDlg,item,c,3)==2) &&
(c[0]=='0') &&
!isdigit(c[1])
) {
// It looks like it was like that
*result=0;
return TRUE;
}
return FALSE;
}