1 | /*
|
---|
2 | * This file is (C) Chris Wohlgemuth 2001-2005
|
---|
3 | */
|
---|
4 | #define INCL_WIN
|
---|
5 |
|
---|
6 | #include <os2.h>
|
---|
7 |
|
---|
8 | /*!**************************************************/
|
---|
9 | /* */
|
---|
10 | /* @@MODULE */
|
---|
11 | /* */
|
---|
12 | /* Profile functions */
|
---|
13 | /* */
|
---|
14 | /* @@DESC */
|
---|
15 | /* */
|
---|
16 | /* This funktion stores a window position in an INI */
|
---|
17 | /* file. */
|
---|
18 | /* */
|
---|
19 | /* @@REMARKS */
|
---|
20 | /* */
|
---|
21 | /* If hini is NULL the given file name will be used */
|
---|
22 | /* for opening the INI file. If hini is not NULL */
|
---|
23 | /* the file name is ignored. */
|
---|
24 | /* */
|
---|
25 | /* @@RETURNS */
|
---|
26 | /* */
|
---|
27 | /* BOOL fSuccess */
|
---|
28 | /* */
|
---|
29 | /* TRUE: Function succeeded. */
|
---|
30 | /* FALSE: Error occurred */
|
---|
31 | /* */
|
---|
32 | /*!!*************************************************/
|
---|
33 | BOOL PrfSaveWindowPos(HINI hini, char* iniFile, char* chrApp, char* chrKey, HWND hwnd)
|
---|
34 | {
|
---|
35 | BOOL bError=FALSE;
|
---|
36 | SWP swp;
|
---|
37 | HINI hiniPriv=hini;
|
---|
38 |
|
---|
39 | if(!hini && !iniFile)
|
---|
40 | return FALSE;
|
---|
41 |
|
---|
42 | do{
|
---|
43 |
|
---|
44 | if(!hiniPriv) {
|
---|
45 | /* Open ini-file */
|
---|
46 | if((hiniPriv=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile))
|
---|
47 | ==NULLHANDLE)
|
---|
48 | break;
|
---|
49 | }/* end of if(!hiniPriv) */
|
---|
50 |
|
---|
51 | WinQueryWindowPos(hwnd, &swp);
|
---|
52 | if(!PrfWriteProfileData(hiniPriv, chrApp, chrKey, &swp, sizeof(swp)))
|
---|
53 | bError=TRUE;
|
---|
54 |
|
---|
55 | if(hiniPriv && !hini)
|
---|
56 | PrfCloseProfile(hiniPriv);
|
---|
57 |
|
---|
58 | if(bError)
|
---|
59 | break;
|
---|
60 | return TRUE;
|
---|
61 | } while(TRUE);
|
---|
62 | return FALSE;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /*!**************************************************/
|
---|
66 | /* */
|
---|
67 | /* @@MODULE */
|
---|
68 | /* */
|
---|
69 | /* Profile functions */
|
---|
70 | /* */
|
---|
71 | /* @@DESC */
|
---|
72 | /* */
|
---|
73 | /* This funktion gets a saved window position from */
|
---|
74 | /* an INI file and resizes and moves the window */
|
---|
75 | /* accordingly. */
|
---|
76 | /* */
|
---|
77 | /* @@REMARKS */
|
---|
78 | /* */
|
---|
79 | /* If hini is NULL the given file name will be used */
|
---|
80 | /* for opening the INI file. If hini is not NULL */
|
---|
81 | /* the file name is ignored. */
|
---|
82 | /* */
|
---|
83 | /* @@RETURNS */
|
---|
84 | /* */
|
---|
85 | /* BOOL fSuccess */
|
---|
86 | /* */
|
---|
87 | /* TRUE: Function succeeded. */
|
---|
88 | /* FALSE: Error occurred */
|
---|
89 | /* */
|
---|
90 | /*!!*************************************************/
|
---|
91 | BOOL PrfRestoreWindowPos(HINI hini, char * iniFile, char* chrApp, char *chrKey, HWND hwnd, ULONG fSize)
|
---|
92 | {
|
---|
93 | HINI hiniPriv=hini;
|
---|
94 | ULONG ulSize;
|
---|
95 | BOOL bError=FALSE;
|
---|
96 | SWP swp;
|
---|
97 |
|
---|
98 | do{
|
---|
99 | if(!hiniPriv) {
|
---|
100 | if((hiniPriv=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile))
|
---|
101 | ==NULLHANDLE)
|
---|
102 | break;
|
---|
103 | }/* end of if(!hini) */
|
---|
104 |
|
---|
105 | ulSize=sizeof(swp);
|
---|
106 | if(!PrfQueryProfileData(hiniPriv, chrApp, chrKey, &swp, &ulSize))
|
---|
107 | bError=TRUE;
|
---|
108 |
|
---|
109 | if(hiniPriv && !hini)
|
---|
110 | PrfCloseProfile(hiniPriv);
|
---|
111 |
|
---|
112 | if(bError)
|
---|
113 | break;
|
---|
114 | WinSetWindowPos(hwnd, NULLHANDLE, swp.x, swp.y, swp.cx, swp.cy, SWP_MOVE | fSize);
|
---|
115 | return TRUE;
|
---|
116 | } while(TRUE);
|
---|
117 |
|
---|
118 | return FALSE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /*!**************************************************/
|
---|
122 | /* */
|
---|
123 | /* @@MODULE */
|
---|
124 | /* */
|
---|
125 | /* Profile functions */
|
---|
126 | /* */
|
---|
127 | /* @@DESC */
|
---|
128 | /* */
|
---|
129 | /* Save a string in an INI file. */
|
---|
130 | /* */
|
---|
131 | /* . */
|
---|
132 | /* */
|
---|
133 | /* @@REMARKS */
|
---|
134 | /* */
|
---|
135 | /* If hini is NULL the given file name will be used */
|
---|
136 | /* for opening the INI file. If hini is not NULL */
|
---|
137 | /* the file name is ignored. */
|
---|
138 | /* */
|
---|
139 | /* @@RETURNS */
|
---|
140 | /* */
|
---|
141 | /* BOOL fSuccess */
|
---|
142 | /* */
|
---|
143 | /* TRUE: Function succeeded. */
|
---|
144 | /* FALSE: Error occurred */
|
---|
145 | /* */
|
---|
146 | /*!!*************************************************/
|
---|
147 | BOOL PrfWriteString(HINI hini, char * iniFile, char* chrApp, char *chrKey, char* chrString)
|
---|
148 | {
|
---|
149 | BOOL bError=FALSE;
|
---|
150 | HINI hiniPriv=hini;
|
---|
151 |
|
---|
152 | if(!hini && !iniFile)
|
---|
153 | return FALSE;
|
---|
154 |
|
---|
155 | do {
|
---|
156 | if(!hiniPriv) {
|
---|
157 | /* Open ini-file */
|
---|
158 | if((hiniPriv=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile))
|
---|
159 | ==NULLHANDLE)
|
---|
160 | break;
|
---|
161 | }/* end of if(!hiniPriv) */
|
---|
162 |
|
---|
163 | if(!PrfWriteProfileString(hiniPriv, chrApp, chrKey, chrString))
|
---|
164 | bError=TRUE;
|
---|
165 |
|
---|
166 | if(hiniPriv && !hini)
|
---|
167 | PrfCloseProfile(hiniPriv);
|
---|
168 |
|
---|
169 | if(bError)
|
---|
170 | break;
|
---|
171 | return TRUE;
|
---|
172 | } while(TRUE);
|
---|
173 | return FALSE;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /*!**************************************************/
|
---|
177 | /* */
|
---|
178 | /* @@MODULE */
|
---|
179 | /* */
|
---|
180 | /* Profile functions */
|
---|
181 | /* */
|
---|
182 | /* @@DESC */
|
---|
183 | /* */
|
---|
184 | /* Get a string from an INI file. */
|
---|
185 | /* */
|
---|
186 | /* . */
|
---|
187 | /* */
|
---|
188 | /* @@REMARKS */
|
---|
189 | /* */
|
---|
190 | /* If hini is NULL the given file name will be used */
|
---|
191 | /* for opening the INI file. If hini is not NULL */
|
---|
192 | /* the file name is ignored. */
|
---|
193 | /* */
|
---|
194 | /* @@RETURNS */
|
---|
195 | /* */
|
---|
196 | /* ULONG ulLength */
|
---|
197 | /* */
|
---|
198 | /* TRUE: Function succeeded. */
|
---|
199 | /* FALSE: Error occurred */
|
---|
200 | /* */
|
---|
201 | /*!!*************************************************/
|
---|
202 | BOOL PrfQueryString(HINI hini, char * iniFile, char* chrApp, char *chrKey, char* chrDefault, char* chrBuffer, ULONG ulSize)
|
---|
203 | {
|
---|
204 | HINI hiniPriv=hini;
|
---|
205 | ULONG ulRC=0;
|
---|
206 |
|
---|
207 | do{
|
---|
208 | if(!hiniPriv) {
|
---|
209 | if((hiniPriv=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile))
|
---|
210 | ==NULLHANDLE)
|
---|
211 | break;
|
---|
212 | }/* end of if(!hini) */
|
---|
213 |
|
---|
214 | ulRC=PrfQueryProfileString(hiniPriv, chrApp, chrKey, chrDefault, chrBuffer, ulSize);
|
---|
215 |
|
---|
216 | if(hiniPriv && !hini) {
|
---|
217 | PrfCloseProfile(hiniPriv);
|
---|
218 | }
|
---|
219 | break;
|
---|
220 | } while(TRUE);
|
---|
221 | return ulRC;
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|