2 * Undocumented functions from COMCTL32.DLL
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
24 * Do NOT rely on names or contents of undocumented structures and types!!!
25 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
26 * COMCTL32.DLL (internally).
32 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
34 static const WCHAR strMRUList
[] = { 'M','R','U','L','i','s','t',0 };
36 /**************************************************************************
39 * Allocates memory block from the dll's private heap
42 * dwSize [I] size of the allocated memory block
45 * Success: pointer to allocated memory block
48 LPVOID WINAPI
Alloc (DWORD dwSize
)
50 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
54 /**************************************************************************
55 * ReAlloc [COMCTL32.72]
57 * Changes the size of an allocated memory block or allocates a memory
58 * block using the dll's private heap.
61 * lpSrc [I] pointer to memory block which will be resized
62 * dwSize [I] new size of the memory block.
65 * Success: pointer to the resized memory block
69 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
72 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
75 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
| LMEM_MOVEABLE
);
77 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
81 /**************************************************************************
84 * Frees an allocated memory block from the dll's private heap.
87 * lpMem [I] pointer to memory block which will be freed
93 BOOL WINAPI
Free (LPVOID lpMem
)
95 return !LocalFree( lpMem
);
99 /**************************************************************************
100 * GetSize [COMCTL32.74]
102 * Retrieves the size of the specified memory block from the dll's
106 * lpMem [I] pointer to an allocated memory block
109 * Success: size of the specified memory block
112 DWORD WINAPI
GetSize (LPVOID lpMem
)
114 return LocalSize( lpMem
);
118 /**************************************************************************
119 * MRU-Functions {COMCTL32}
122 * The MRU-API is a set of functions to manipulate lists of M.R.U. (Most Recently
123 * Used) items. It is an undocumented API that is used (at least) by the shell
124 * and explorer to implement their recent documents feature.
126 * Since these functions are undocumented, they are unsupported by MS and
127 * may change at any time.
129 * Internally, the list is implemented as a last in, last out list of items
130 * persisted into the system registry under a caller chosen key. Each list
131 * item is given a one character identifier in the Ascii range from 'a' to
132 * '}'. A list of the identifiers in order from newest to oldest is stored
133 * under the same key in a value named "MRUList".
135 * Items are re-ordered by changing the order of the values in the MRUList
136 * value. When a new item is added, it becomes the new value of the oldest
137 * identifier, and that identifier is moved to the front of the MRUList value.
139 * Wine stores MRU-lists in the same registry format as Windows, so when
140 * switching between the builtin and native comctl32.dll no problems or
141 * incompatibilities should occur.
143 * The following undocumented structure is used to create an MRU-list:
144 *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
145 *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
147 *|typedef struct tagMRUINFO
153 *| LPTSTR lpszSubKey;
155 *|} MRUINFO, *LPMRUINFO;
158 * cbSize [I] The size of the MRUINFO structure. This must be set
159 * to sizeof(MRUINFO) by the caller.
160 * uMax [I] The maximum number of items allowed in the list. Because
161 * of the limited number of identifiers, this should be set to
162 * a value from 1 to 30 by the caller.
163 * fFlags [I] If bit 0 is set, the list will be used to store binary
164 * data, otherwise it is assumed to store strings. If bit 1
165 * is set, every change made to the list will be reflected in
166 * the registry immediately, otherwise changes will only be
167 * written when the list is closed.
168 * hKey [I] The registry key that the list should be written under.
169 * This must be supplied by the caller.
170 * lpszSubKey [I] A caller supplied name of a subkey under hKey to write
171 * the list to. This may not be blank.
172 * lpfnCompare [I] A caller supplied comparison function, which may be either
173 * an MRUStringCmpFn if dwFlags does not have bit 0 set, or a
174 * MRUBinaryCmpFn otherwise.
177 * - Create an MRU-list with CreateMRUList() or CreateMRUListLazy().
178 * - Add items to an MRU-list with AddMRUString() or AddMRUData().
179 * - Remove items from an MRU-list with DelMRUString().
180 * - Find data in an MRU-list with FindMRUString() or FindMRUData().
181 * - Iterate through an MRU-list with EnumMRUList().
182 * - Free an MRU-list with FreeMRUList().
185 typedef INT (CALLBACK
*MRUStringCmpFnA
)(LPCSTR lhs
, LPCSTR rhs
);
186 typedef INT (CALLBACK
*MRUStringCmpFnW
)(LPCWSTR lhs
, LPCWSTR rhs
);
187 typedef INT (CALLBACK
*MRUBinaryCmpFn
)(LPCVOID lhs
, LPCVOID rhs
, DWORD length
);
189 typedef struct tagMRUINFOA
198 MRUStringCmpFnA string_cmpfn
;
199 MRUBinaryCmpFn binary_cmpfn
;
201 } MRUINFOA
, *LPMRUINFOA
;
203 typedef struct tagMRUINFOW
212 MRUStringCmpFnW string_cmpfn
;
213 MRUBinaryCmpFn binary_cmpfn
;
215 } MRUINFOW
, *LPMRUINFOW
;
218 #define MRU_STRING 0 /* list will contain strings */
219 #define MRU_BINARY 1 /* list will contain binary data */
220 #define MRU_CACHEWRITE 2 /* only save list order to reg. is FreeMRUList */
222 /* If list is a string list lpfnCompare has the following prototype
223 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
224 * for binary lists the prototype is
225 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
226 * where cbData is the no. of bytes to compare.
227 * Need to check what return value means identical - 0?
230 typedef struct tagWINEMRUITEM
232 DWORD size
; /* size of data stored */
233 DWORD itemFlag
; /* flags */
235 } WINEMRUITEM
, *LPWINEMRUITEM
;
238 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
240 typedef struct tagWINEMRULIST
242 MRUINFOW extview
; /* original create information */
243 BOOL isUnicode
; /* is compare fn Unicode */
244 DWORD wineFlags
; /* internal flags */
245 DWORD cursize
; /* current size of realMRU */
246 LPWSTR realMRU
; /* pointer to string of index names */
247 LPWINEMRUITEM
*array
; /* array of pointers to data */
248 /* in 'a' to 'z' order */
249 } WINEMRULIST
, *LPWINEMRULIST
;
252 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
254 /**************************************************************************
255 * MRU_SaveChanged (internal)
257 * Local MRU saving code
259 static void MRU_SaveChanged ( LPWINEMRULIST mp
)
266 /* or should we do the following instead of RegOpenKeyEx:
269 /* open the sub key */
270 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
271 0, KEY_WRITE
, &newkey
))) {
272 /* not present - what to do ??? */
273 ERR("Could not open key, error=%d, attempting to create\n",
275 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
278 REG_OPTION_NON_VOLATILE
,
279 KEY_READ
| KEY_WRITE
,
283 ERR("failed to create key /%s/, err=%d\n",
284 debugstr_w(mp
->extview
.lpszSubKey
), err
);
288 if (mp
->wineFlags
& WMRUF_CHANGED
) {
289 mp
->wineFlags
&= ~WMRUF_CHANGED
;
290 err
= RegSetValueExW(newkey
, strMRUList
, 0, REG_SZ
, (LPBYTE
)mp
->realMRU
,
291 (strlenW(mp
->realMRU
) + 1)*sizeof(WCHAR
));
293 ERR("error saving MRUList, err=%d\n", err
);
295 TRACE("saving MRUList=/%s/\n", debugstr_w(mp
->realMRU
));
298 for(i
=0; i
<mp
->cursize
; i
++) {
299 witem
= mp
->array
[i
];
300 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
301 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
302 realname
[0] = 'a' + i
;
303 err
= RegSetValueExW(newkey
, realname
, 0,
304 (mp
->extview
.fFlags
& MRU_BINARY
) ?
306 &witem
->datastart
, witem
->size
);
308 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
310 TRACE("saving value for name /%s/ size=%d\n",
311 debugstr_w(realname
), witem
->size
);
314 RegCloseKey( newkey
);
317 /**************************************************************************
318 * FreeMRUList [COMCTL32.152]
320 * Frees a most-recently-used items list.
323 * hMRUList [I] Handle to list.
328 void WINAPI
FreeMRUList (HANDLE hMRUList
)
330 LPWINEMRULIST mp
= hMRUList
;
333 TRACE("(%p)\n", hMRUList
);
337 if (mp
->wineFlags
& WMRUF_CHANGED
) {
338 /* need to open key and then save the info */
339 MRU_SaveChanged( mp
);
342 for(i
=0; i
<mp
->extview
.uMax
; i
++)
347 Free(mp
->extview
.lpszSubKey
);
352 /**************************************************************************
353 * FindMRUData [COMCTL32.169]
355 * Searches binary list for item that matches lpData of length cbData.
356 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
357 * corresponding to item's reg. name will be stored in it ('a' -> 0).
360 * hList [I] list handle
361 * lpData [I] data to find
362 * cbData [I] length of data
363 * lpRegNum [O] position in registry (maybe NULL)
366 * Position in list 0 -> MRU. -1 if item not found.
368 INT WINAPI
FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
,
371 const WINEMRULIST
*mp
= hList
;
376 if (!mp
|| !mp
->extview
.u
.string_cmpfn
)
379 if(!(mp
->extview
.fFlags
& MRU_BINARY
) && !mp
->isUnicode
) {
380 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
381 NULL
, 0, NULL
, NULL
);
383 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
386 for(i
=0; i
<mp
->cursize
; i
++) {
387 if (mp
->extview
.fFlags
& MRU_BINARY
) {
388 if (!mp
->extview
.u
.binary_cmpfn(lpData
, &mp
->array
[i
]->datastart
, cbData
))
393 if (!mp
->extview
.u
.string_cmpfn(lpData
, (LPWSTR
)&mp
->array
[i
]->datastart
))
396 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
397 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
398 NULL
, 0, NULL
, NULL
);
399 LPSTR itemA
= Alloc(len
);
401 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
402 itemA
, len
, NULL
, NULL
);
404 cmp
= mp
->extview
.u
.string_cmpfn((LPWSTR
)dataA
, (LPWSTR
)itemA
);
416 if (lpRegNum
&& (ret
!= -1))
419 TRACE("(%p, %p, %d, %p) returning %d\n",
420 hList
, lpData
, cbData
, lpRegNum
, ret
);
426 /**************************************************************************
427 * AddMRUData [COMCTL32.167]
429 * Add item to MRU binary list. If item already exists in list then it is
430 * simply moved up to the top of the list and not added again. If list is
431 * full then the least recently used item is removed to make room.
434 * hList [I] Handle to list.
435 * lpData [I] ptr to data to add.
436 * cbData [I] no. of bytes of data.
439 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
442 INT WINAPI
AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
444 LPWINEMRULIST mp
= hList
;
448 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) >= 0) {
449 /* Item exists, just move it to the front */
450 LPWSTR pos
= strchrW(mp
->realMRU
, replace
+ 'a');
451 while (pos
> mp
->realMRU
)
458 /* either add a new entry or replace oldest */
459 if (mp
->cursize
< mp
->extview
.uMax
) {
460 /* Add in a new item */
461 replace
= mp
->cursize
;
465 /* get the oldest entry and replace data */
466 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
467 Free(mp
->array
[replace
]);
470 /* Allocate space for new item and move in the data */
471 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
472 witem
->itemFlag
|= WMRUIF_CHANGED
;
473 witem
->size
= cbData
;
474 memcpy( &witem
->datastart
, lpData
, cbData
);
476 /* now rotate MRU list */
477 for(i
=mp
->cursize
-1; i
>=1; i
--)
478 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
481 /* The new item gets the front spot */
482 mp
->wineFlags
|= WMRUF_CHANGED
;
483 mp
->realMRU
[0] = replace
+ 'a';
485 TRACE("(%p, %p, %d) adding data, /%c/ now most current\n",
486 hList
, lpData
, cbData
, replace
+'a');
488 if (!(mp
->extview
.fFlags
& MRU_CACHEWRITE
)) {
489 /* save changed stuff right now */
490 MRU_SaveChanged( mp
);
496 /**************************************************************************
497 * AddMRUStringW [COMCTL32.401]
499 * Add an item to an MRU string list.
502 * hList [I] Handle to list.
503 * lpszString [I] The string to add.
506 * Success: The number corresponding to the registry name where the string
507 * has been stored (0 maps to 'a', 1 to 'b' and so on).
508 * Failure: -1, if hList is NULL or memory allocation fails. If lpszString
509 * is invalid, the function returns 0, and GetLastError() returns
510 * ERROR_INVALID_PARAMETER. The last error value is set only in
514 * -If lpszString exists in the list already, it is moved to the top of the
515 * MRU list (it is not duplicated).
516 * -If the list is full the least recently used list entry is replaced with
518 * -If this function returns 0 you should check the last error value to
519 * ensure the call really succeeded.
521 INT WINAPI
AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
523 TRACE("(%p,%s)\n", hList
, debugstr_w(lpszString
));
528 if (!lpszString
|| IsBadStringPtrW(lpszString
, -1))
530 SetLastError(ERROR_INVALID_PARAMETER
);
534 return AddMRUData(hList
, lpszString
,
535 (strlenW(lpszString
) + 1) * sizeof(WCHAR
));
538 /**************************************************************************
539 * AddMRUStringA [COMCTL32.153]
543 INT WINAPI
AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
549 TRACE("(%p,%s)\n", hList
, debugstr_a(lpszString
));
554 if (IsBadStringPtrA(lpszString
, -1))
556 SetLastError(ERROR_INVALID_PARAMETER
);
560 len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0) * sizeof(WCHAR
);
561 stringW
= Alloc(len
);
565 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
/sizeof(WCHAR
));
566 ret
= AddMRUData(hList
, stringW
, len
);
571 /**************************************************************************
572 * DelMRUString [COMCTL32.156]
574 * Removes item from either string or binary list (despite its name)
577 * hList [I] list handle
578 * nItemPos [I] item position to remove 0 -> MRU
581 * TRUE if successful, FALSE if nItemPos is out of range.
583 BOOL WINAPI
DelMRUString(HANDLE hList
, INT nItemPos
)
585 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
589 /**************************************************************************
590 * FindMRUStringW [COMCTL32.402]
592 * See FindMRUStringA.
594 INT WINAPI
FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
596 return FindMRUData(hList
, lpszString
,
597 (lstrlenW(lpszString
) + 1) * sizeof(WCHAR
), lpRegNum
);
600 /**************************************************************************
601 * FindMRUStringA [COMCTL32.155]
603 * Searches string list for item that matches lpszString.
604 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
605 * corresponding to item's reg. name will be stored in it ('a' -> 0).
608 * hList [I] list handle
609 * lpszString [I] string to find
610 * lpRegNum [O] position in registry (maybe NULL)
613 * Position in list 0 -> MRU. -1 if item not found.
615 INT WINAPI
FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
617 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
618 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
621 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
622 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
627 /*************************************************************************
628 * create_mru_list (internal)
630 static HANDLE
create_mru_list(LPWINEMRULIST mp
)
634 DWORD datasize
, dwdisp
;
639 /* get space to save indices that will turn into names
640 * but in order of most to least recently used
642 mp
->realMRU
= Alloc((mp
->extview
.uMax
+ 2) * sizeof(WCHAR
));
644 /* get space to save pointers to actual data in order of
645 * 'a' to 'z' (0 to n).
647 mp
->array
= Alloc(mp
->extview
.uMax
* sizeof(LPVOID
));
649 /* open the sub key */
650 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
653 REG_OPTION_NON_VOLATILE
,
654 KEY_READ
| KEY_WRITE
,
658 /* error - what to do ??? */
659 ERR("(%u %u %x %p %s %p): Could not open key, error=%d\n",
660 mp
->extview
.cbSize
, mp
->extview
.uMax
, mp
->extview
.fFlags
,
661 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
662 mp
->extview
.u
.string_cmpfn
, err
);
666 /* get values from key 'MRUList' */
668 datasize
= (mp
->extview
.uMax
+ 1) * sizeof(WCHAR
);
669 if (RegQueryValueExW( newkey
, strMRUList
, 0, &type
,
670 (LPBYTE
)mp
->realMRU
, &datasize
)) {
671 /* not present - set size to 1 (will become 0 later) */
676 datasize
/= sizeof(WCHAR
);
678 TRACE("MRU list = %s, datasize = %d\n", debugstr_w(mp
->realMRU
), datasize
);
680 mp
->cursize
= datasize
- 1;
681 /* datasize now has number of items in the MRUList */
683 /* get actual values for each entry */
685 for(i
=0; i
<mp
->cursize
; i
++) {
686 realname
[0] = 'a' + i
;
687 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
688 /* not present - what to do ??? */
689 ERR("Key %s not found 1\n", debugstr_w(realname
));
691 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
692 witem
->size
= datasize
;
693 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
694 &witem
->datastart
, &datasize
)) {
695 /* not present - what to do ??? */
696 ERR("Key %s not found 2\n", debugstr_w(realname
));
699 RegCloseKey( newkey
);
704 TRACE("(%u %u %x %p %s %p): Current Size = %d\n",
705 mp
->extview
.cbSize
, mp
->extview
.uMax
, mp
->extview
.fFlags
,
706 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
707 mp
->extview
.u
.string_cmpfn
, mp
->cursize
);
711 /**************************************************************************
712 * CreateMRUListLazyW [COMCTL32.404]
714 * See CreateMRUListLazyA.
716 HANDLE WINAPI
CreateMRUListLazyW (const MRUINFOW
*infoW
, DWORD dwParam2
,
717 DWORD dwParam3
, DWORD dwParam4
)
721 /* Native does not check for a NULL lpcml */
722 if (!infoW
->hKey
|| IsBadStringPtrW(infoW
->lpszSubKey
, -1))
725 mp
= Alloc(sizeof(WINEMRULIST
));
726 memcpy(&mp
->extview
, infoW
, sizeof(MRUINFOW
));
727 mp
->extview
.lpszSubKey
= Alloc((strlenW(infoW
->lpszSubKey
) + 1) * sizeof(WCHAR
));
728 strcpyW(mp
->extview
.lpszSubKey
, infoW
->lpszSubKey
);
729 mp
->isUnicode
= TRUE
;
731 return create_mru_list(mp
);
734 /**************************************************************************
735 * CreateMRUListLazyA [COMCTL32.157]
737 * Creates a most-recently-used list.
740 * lpcml [I] ptr to CREATEMRULIST structure.
741 * dwParam2 [I] Unknown
742 * dwParam3 [I] Unknown
743 * dwParam4 [I] Unknown
746 * Handle to MRU list.
748 HANDLE WINAPI
CreateMRUListLazyA (const MRUINFOA
*lpcml
, DWORD dwParam2
,
749 DWORD dwParam3
, DWORD dwParam4
)
754 /* Native does not check for a NULL lpcml */
756 if (!lpcml
->hKey
|| IsBadStringPtrA(lpcml
->lpszSubKey
, -1))
759 mp
= Alloc(sizeof(WINEMRULIST
));
760 memcpy(&mp
->extview
, lpcml
, sizeof(MRUINFOA
));
761 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
762 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
763 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
764 mp
->extview
.lpszSubKey
, len
);
765 mp
->isUnicode
= FALSE
;
766 return create_mru_list(mp
);
769 /**************************************************************************
770 * CreateMRUListW [COMCTL32.400]
772 * See CreateMRUListA.
774 HANDLE WINAPI
CreateMRUListW (const MRUINFOW
*infoW
)
776 return CreateMRUListLazyW(infoW
, 0, 0, 0);
779 /**************************************************************************
780 * CreateMRUListA [COMCTL32.151]
782 * Creates a most-recently-used list.
785 * lpcml [I] ptr to CREATEMRULIST structure.
788 * Handle to MRU list.
790 HANDLE WINAPI
CreateMRUListA (const MRUINFOA
*lpcml
)
792 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
796 /**************************************************************************
797 * EnumMRUListW [COMCTL32.403]
799 * Enumerate item in a most-recently-used list
802 * hList [I] list handle
803 * nItemPos [I] item position to enumerate
804 * lpBuffer [O] buffer to receive item
805 * nBufferSize [I] size of buffer
808 * For binary lists specifies how many bytes were copied to buffer, for
809 * string lists specifies full length of string. Enumerating past the end
810 * of list returns -1.
811 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
814 INT WINAPI
EnumMRUListW (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
817 const WINEMRULIST
*mp
= hList
;
818 const WINEMRUITEM
*witem
;
819 INT desired
, datasize
;
822 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
823 if (nItemPos
>= mp
->cursize
) return -1;
824 desired
= mp
->realMRU
[nItemPos
];
826 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
827 witem
= mp
->array
[desired
];
828 datasize
= min( witem
->size
, nBufferSize
);
829 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
830 TRACE("(%p, %d, %p, %d): returning len=%d\n",
831 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
835 /**************************************************************************
836 * EnumMRUListA [COMCTL32.154]
840 INT WINAPI
EnumMRUListA (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
843 const WINEMRULIST
*mp
= hList
;
845 INT desired
, datasize
;
849 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
850 if (nItemPos
>= mp
->cursize
) return -1;
851 desired
= mp
->realMRU
[nItemPos
];
853 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
854 witem
= mp
->array
[desired
];
855 if(mp
->extview
.fFlags
& MRU_BINARY
) {
856 datasize
= min( witem
->size
, nBufferSize
);
857 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
859 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
860 NULL
, 0, NULL
, NULL
);
861 datasize
= min( lenA
, nBufferSize
);
862 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
863 lpBuffer
, datasize
, NULL
, NULL
);
864 ((char *)lpBuffer
)[ datasize
- 1 ] = '\0';
867 TRACE("(%p, %d, %p, %d): returning len=%d\n",
868 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
872 /**************************************************************************
873 * Str_GetPtrWtoA [internal]
875 * Converts a unicode string into a multi byte string
878 * lpSrc [I] Pointer to the unicode source string
879 * lpDest [O] Pointer to caller supplied storage for the multi byte string
880 * nMaxLen [I] Size, in bytes, of the destination buffer
883 * Length, in bytes, of the converted string.
886 INT
Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
890 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
892 if (!lpDest
&& lpSrc
)
893 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
903 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
907 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
913 /**************************************************************************
914 * Str_GetPtrAtoW [internal]
916 * Converts a multibyte string into a unicode string
919 * lpSrc [I] Pointer to the multibyte source string
920 * lpDest [O] Pointer to caller supplied storage for the unicode string
921 * nMaxLen [I] Size, in characters, of the destination buffer
924 * Length, in characters, of the converted string.
927 INT
Str_GetPtrAtoW (LPCSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
931 TRACE("(%s %p %d)\n", debugstr_a(lpSrc
), lpDest
, nMaxLen
);
933 if (!lpDest
&& lpSrc
)
934 return MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, 0, 0);
944 len
= MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, 0, 0);
948 MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
);
955 /**************************************************************************
956 * Str_SetPtrAtoW [internal]
958 * Converts a multi byte string to a unicode string.
959 * If the pointer to the destination buffer is NULL a buffer is allocated.
960 * If the destination buffer is too small to keep the converted multi byte
961 * string the destination buffer is reallocated. If the source pointer is
962 * NULL, the destination buffer is freed.
965 * lppDest [I/O] pointer to a pointer to the destination buffer
966 * lpSrc [I] pointer to a multi byte string
969 * TRUE: conversion successful
972 BOOL
Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
974 TRACE("(%p %s)\n", lppDest
, lpSrc
);
977 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
978 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
982 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
993 /**************************************************************************
994 * Str_SetPtrWtoA [internal]
996 * Converts a unicode string to a multi byte string.
997 * If the pointer to the destination buffer is NULL a buffer is allocated.
998 * If the destination buffer is too small to keep the converted wide
999 * string the destination buffer is reallocated. If the source pointer is
1000 * NULL, the destination buffer is freed.
1003 * lppDest [I/O] pointer to a pointer to the destination buffer
1004 * lpSrc [I] pointer to a wide string
1007 * TRUE: conversion successful
1010 BOOL
Str_SetPtrWtoA (LPSTR
*lppDest
, LPCWSTR lpSrc
)
1012 TRACE("(%p %s)\n", lppDest
, debugstr_w(lpSrc
));
1015 INT len
= WideCharToMultiByte(CP_ACP
,0,lpSrc
,-1,NULL
,0,NULL
,FALSE
);
1016 LPSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(CHAR
));
1020 WideCharToMultiByte(CP_ACP
,0,lpSrc
,-1,ptr
,len
,NULL
,FALSE
);
1032 /**************************************************************************
1033 * Notification functions
1036 typedef struct tagNOTIFYDATA
1044 } NOTIFYDATA
, *LPNOTIFYDATA
;
1047 /**************************************************************************
1048 * DoNotify [Internal]
1051 static LRESULT
DoNotify (const NOTIFYDATA
*lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
1054 LPNMHDR lpNmh
= NULL
;
1057 TRACE("(%p %p %d %p 0x%08x)\n",
1058 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
1059 lpNotify
->dwParam5
);
1061 if (!lpNotify
->hwndTo
)
1064 if (lpNotify
->hwndFrom
== (HWND
)-1) {
1066 idFrom
= lpHdr
->idFrom
;
1069 if (lpNotify
->hwndFrom
)
1070 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
1072 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
1074 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
1075 lpNmh
->idFrom
= idFrom
;
1076 lpNmh
->code
= uCode
;
1079 return SendMessageW (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
1083 /**************************************************************************
1084 * SendNotify [COMCTL32.341]
1086 * Sends a WM_NOTIFY message to the specified window.
1089 * hwndTo [I] Window to receive the message
1090 * hwndFrom [I] Window that the message is from (see notes)
1091 * uCode [I] Notification code
1092 * lpHdr [I] The NMHDR and any additional information to send or NULL
1095 * Success: return value from notification
1099 * If hwndFrom is -1 then the identifier of the control sending the
1100 * message is taken from the NMHDR structure.
1101 * If hwndFrom is not -1 then lpHdr can be NULL.
1103 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
1107 TRACE("(%p %p %d %p)\n",
1108 hwndTo
, hwndFrom
, uCode
, lpHdr
);
1110 notify
.hwndFrom
= hwndFrom
;
1111 notify
.hwndTo
= hwndTo
;
1112 notify
.dwParam5
= 0;
1113 notify
.dwParam6
= 0;
1115 return DoNotify (¬ify
, uCode
, lpHdr
);
1119 /**************************************************************************
1120 * SendNotifyEx [COMCTL32.342]
1122 * Sends a WM_NOTIFY message to the specified window.
1125 * hwndFrom [I] Window to receive the message
1126 * hwndTo [I] Window that the message is from
1127 * uCode [I] Notification code
1128 * lpHdr [I] The NMHDR and any additional information to send or NULL
1129 * dwParam5 [I] Unknown
1132 * Success: return value from notification
1136 * If hwndFrom is -1 then the identifier of the control sending the
1137 * message is taken from the NMHDR structure.
1138 * If hwndFrom is not -1 then lpHdr can be NULL.
1140 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
1141 LPNMHDR lpHdr
, DWORD dwParam5
)
1146 TRACE("(%p %p %d %p 0x%08x)\n",
1147 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
1149 hwndNotify
= hwndTo
;
1151 if (IsWindow (hwndFrom
)) {
1152 hwndNotify
= GetParent (hwndFrom
);
1158 notify
.hwndFrom
= hwndFrom
;
1159 notify
.hwndTo
= hwndNotify
;
1160 notify
.dwParam5
= dwParam5
;
1161 notify
.dwParam6
= 0;
1163 return DoNotify (¬ify
, uCode
, lpHdr
);