2 * Windows Properties Functions
4 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
18 typedef struct tagPROPENTRY
{
22 struct tagPROPENTRY
*lpPrevProp
;
23 struct tagPROPENTRY
*lpNextProp
;
25 typedef PROPENTRY
*LPPROPENTRY
;
28 /*************************************************************************
29 * RemoveProp [USER.24]
31 HANDLE
RemoveProp(HWND hWnd
, LPSTR lpStr
)
37 if (((DWORD
)lpStr
& 0xFFFF0000) == 0L)
38 printf("RemoveProp(%04X, Atom %04X)\n", hWnd
, LOWORD((DWORD
)lpStr
));
40 printf("RemoveProp(%04X, '%s')\n", hWnd
, lpStr
);
42 wndPtr
= WIN_FindWndPtr(hWnd
);
44 printf("RemoveProp // Bad Window handle !\n");
47 lpProp
= (LPPROPENTRY
) GlobalLock(wndPtr
->hProp
);
50 printf("Property List Empty !\n");
55 if ((((DWORD
)lpStr
& 0xFFFF0000) == 0L &&
56 lpProp
->Atom
== LOWORD((DWORD
)lpStr
)) ||
57 (((DWORD
)lpStr
& 0xFFFF0000) != 0L &&
58 lpProp
->PropName
!= NULL
&&
59 strcmp(lpProp
->PropName
, lpStr
) == 0)) {
61 printf("RemoveProp // Property found ! hData=%04X\n", lpProp
->hData
);
63 hOldData
= lpProp
->hData
;
64 if (lpProp
->lpPrevProp
!= NULL
)
65 lpProp
->lpPrevProp
->lpNextProp
= lpProp
->lpNextProp
;
66 if (lpProp
->lpNextProp
!= NULL
)
67 lpProp
->lpNextProp
->lpPrevProp
= lpProp
->lpPrevProp
;
68 if (lpProp
->PropName
!= NULL
) free(lpProp
->PropName
);
70 GlobalUnlock(wndPtr
->hProp
);
73 if (lpProp
->lpNextProp
== NULL
) break;
74 lpProp
= lpProp
->lpNextProp
;
76 GlobalUnlock(wndPtr
->hProp
);
78 printf("RemoveProp // Property not found !\n");
84 /*************************************************************************
87 HANDLE
GetProp(HWND hWnd
, LPSTR lpStr
)
92 if (((DWORD
)lpStr
& 0xFFFF0000) == 0L)
93 printf("GetProp(%04X, Atom %04X)\n", hWnd
, LOWORD((DWORD
)lpStr
));
95 printf("GetProp(%04X, '%s')\n", hWnd
, lpStr
);
97 wndPtr
= WIN_FindWndPtr(hWnd
);
99 printf("GetProp // Bad Window handle !\n");
102 lpProp
= (LPPROPENTRY
) GlobalLock(wndPtr
->hProp
);
103 if (lpProp
== NULL
) {
105 printf("Property List Empty !\n");
110 if ((((DWORD
)lpStr
& 0xFFFF0000) == 0L &&
111 lpProp
->Atom
== LOWORD((DWORD
)lpStr
)) ||
112 (((DWORD
)lpStr
& 0xFFFF0000) != 0L &&
113 lpProp
->PropName
!= NULL
&&
114 strcmp(lpProp
->PropName
, lpStr
) == 0)) {
116 printf("GetProp // Property found ! hData=%04X\n", lpProp
->hData
);
118 GlobalUnlock(wndPtr
->hProp
);
119 return lpProp
->hData
;
121 if (lpProp
->lpNextProp
== NULL
) break;
122 lpProp
= lpProp
->lpNextProp
;
125 printf("GetProp // Property not found !\n");
127 GlobalUnlock(wndPtr
->hProp
);
132 /*************************************************************************
135 BOOL
SetProp(HWND hWnd
, LPSTR lpStr
, HANDLE hData
)
139 LPPROPENTRY lpNewProp
;
142 if (((DWORD
)lpStr
& 0xFFFF0000) == 0L)
143 printf("SetProp(%04X, Atom %04X, %04X)\n",
144 hWnd
, LOWORD((DWORD
)lpStr
), hData
);
146 printf("SetProp(%04X, '%s', %04X)\n", hWnd
, lpStr
, hData
);
148 wndPtr
= WIN_FindWndPtr(hWnd
);
149 if (wndPtr
== NULL
) {
150 printf("SetProp // Bad Window handle !\n");
153 lpProp
= (LPPROPENTRY
) GlobalLock(wndPtr
->hProp
);
154 if (lpProp
!= NULL
) {
156 if ((((DWORD
)lpStr
& 0xFFFF0000) == 0L &&
157 lpProp
->Atom
== LOWORD((DWORD
)lpStr
)) ||
158 (((DWORD
)lpStr
& 0xFFFF0000) != 0L &&
159 lpProp
->PropName
!= NULL
&&
160 strcmp(lpProp
->PropName
, lpStr
) == 0)) {
162 printf("SetProp // change already exinsting property !\n");
164 lpProp
->hData
= hData
;
165 GlobalUnlock(wndPtr
->hProp
);
168 if (lpProp
->lpNextProp
== NULL
) break;
169 lpProp
= lpProp
->lpNextProp
;
172 hNewProp
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(PROPENTRY
));
173 lpNewProp
= (LPPROPENTRY
) GlobalLock(hNewProp
);
174 if (lpNewProp
== NULL
) {
175 printf("SetProp // Can't allocate Property entry !\n");
176 GlobalUnlock(wndPtr
->hProp
);
180 printf("SetProp // entry allocated %08X\n", lpNewProp
);
182 if (lpProp
== NULL
) {
183 wndPtr
->hProp
= hNewProp
;
184 lpNewProp
->lpPrevProp
= NULL
;
186 printf("SetProp // first entry \n");
190 lpProp
->lpNextProp
= lpNewProp
;
191 lpNewProp
->lpPrevProp
= lpProp
;
193 lpNewProp
->lpNextProp
= NULL
;
194 lpNewProp
->hData
= hData
;
195 if (((DWORD
)lpStr
& 0xFFFF0000) == 0L) {
196 lpNewProp
->PropName
= NULL
;
197 lpNewProp
->Atom
= LOWORD((DWORD
)lpStr
);
201 lpNewProp
->PropName
= malloc(strlen(lpStr
) + 1);
202 if (lpNewProp
->PropName
== NULL
) {
203 printf("SetProp // Can't allocate memory for Property Name !\n");
204 GlobalUnlock(wndPtr
->hProp
);
207 strcpy(lpNewProp
->PropName
, lpStr
);
209 GlobalUnlock(hNewProp
);
210 GlobalUnlock(wndPtr
->hProp
);
215 /*************************************************************************
216 * EnumProps [USER.27]
218 int EnumProps(HWND hWnd
, FARPROC lpEnumFunc
)
224 printf("EnumProps(%04X, %08X)\n", hWnd
, lpEnumFunc
);
225 wndPtr
= WIN_FindWndPtr(hWnd
);
226 if (wndPtr
== NULL
) {
227 printf("EnumProps // Bad Window handle !\n");
230 lpProp
= (LPPROPENTRY
) GlobalLock(wndPtr
->hProp
);
231 if (lpProp
== NULL
) {
232 printf("Property List Empty !\n");
235 if (lpEnumFunc
!= NULL
) return 0;
237 printf("EnumProps // lpProp->Atom=%04X !\n", lpProp
->Atom
);
238 str
= (LPSTR
)MAKELONG(lpProp
->Atom
, 0);
239 if (lpProp
->PropName
!= NULL
) {
240 printf("EnumProps // lpProp->PropName='%s' !\n", lpProp
->PropName
);
241 str
= lpProp
->PropName
;
244 nRet
= (*lpEnumFunc
)((HWND
)hWnd
, (WORD
)0,
245 (LPSTR
)str
, (HANDLE
)lpProp
->hData
);
247 nRet
= CallBack16(lpEnumFunc
, 4, (HANDLE
)lpProp
->hData
,
248 (LPSTR
)str
, (WORD
)0, (HWND
)hWnd
);
250 if (nRet
== 0) break;
251 if (lpProp
->lpNextProp
== NULL
) break;
252 lpProp
= lpProp
->lpNextProp
;
254 GlobalUnlock(wndPtr
->hProp
);