1
[DllImport("kernel32")]
2
private static extern long WritePrivateProfileString(string section,string key, string val, string filePath);
3
[DllImport("kernel32")]
4
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
5

2

3

4

5

读取ini
1
try
2
{
3
if (!File.Exists(System.Windows.Forms.Application.StartupPath + "\\tif.ini"))
4
{
5
IniWriteValue("Config", "Lastworkfolder", "tmp", System.Windows.Forms.Application.StartupPath + "\\tif.ini");
6
IniWriteValue("Config", "Lastimgindex", "-1", System.Windows.Forms.Application.StartupPath + "\\tif.ini");
7
WriteLog("config file is not Exists,Create config file.");
8
}
9
//load ini
10
Lastworkfolder = IniReadValue("Config", "Lastworkfolder", System.Windows.Forms.Application.StartupPath + "\\tif.ini");
11
Lastimgindex = Convert.ToInt32(IniReadValue("Config", "Lastimgindex", System.Windows.Forms.Application.StartupPath + "\\tif.ini"));
12
Firsttime = IniReadValue("Config", "Firsttime", System.Windows.Forms.Application.StartupPath + "\\tif.ini");
13
//Lastimgcount = Convert.ToInt32(IniReadValue("Config", "Lastimgcount", System.Windows.Forms.Application.StartupPath + "\\tif.INI"));
14
//load ini
15
WriteLog("Read the config file.");
16
if (Lastworkfolder == "tmp")
17
{
18
//DateTime.Now.ToString();
19
WriteLog("Start a new work.");
20
}
21
else
22
{
23
fileNames = Directory.GetFiles(workpath);
24
foreach (string file in fileNames)
25
{
26
strImageName = strImageName + file + ",";
27
}
28
fileNames = (strImageName.Remove(strImageName.Length - 1, 1)).Split(',');
29
30
strImageName = null;
31
for (int i = 0; i < fileNames.Length; i++)
32
{
33
//textBox1.AppendText(ImageNames[i].ToString() + "\n");
34
35
36
if (fileNames[i].Substring(fileNames[i].Length - 3) == "tif")
37
{
38
ImageCount = ImageCount + 1;
39
strImageName = strImageName + fileNames[i] + ",";
40
41
}
42
if (fileNames[i].Substring(fileNames[i].Length - 3) == "xml")
43
{
44
xmlfile = fileNames[i];
45
}
46
}
47
ImageNames = (strImageName.Remove(strImageName.Length - 1, 1)).Split(',');
48
SetImage(ImageNames[imgcnt]);
49
AllControlsQ(xmlfile);
50
editsaveToolStripMenuItem.Enabled = false;
51
toolStripStatusLabel2.Text = workpath;
52
WriteLog("Open the last work.");
53
}
54
}
55
catch (Exception) { }

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

对ini文件进行操作
1
write read ini

写日志函数
1
write log
