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).
30 #include "wine/port.h"
38 #define NONAMELESSUNION
39 #define NONAMELESSSTRUCT
51 #include "wine/unicode.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
58 static const WCHAR strMRUList
[] = { 'M','R','U','L','i','s','t',0 };
60 /**************************************************************************
63 * Allocates memory block from the dll's private heap
66 * dwSize [I] size of the allocated memory block
69 * Success: pointer to allocated memory block
72 LPVOID WINAPI
Alloc (DWORD dwSize
)
74 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
78 /**************************************************************************
79 * ReAlloc [COMCTL32.72]
81 * Changes the size of an allocated memory block or allocates a memory
82 * block using the dll's private heap.
85 * lpSrc [I] pointer to memory block which will be resized
86 * dwSize [I] new size of the memory block.
89 * Success: pointer to the resized memory block
93 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
96 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
99 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
| LMEM_MOVEABLE
);
101 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
105 /**************************************************************************
108 * Frees an allocated memory block from the dll's private heap.
111 * lpMem [I] pointer to memory block which will be freed
117 BOOL WINAPI
Free (LPVOID lpMem
)
119 return !LocalFree( lpMem
);
123 /**************************************************************************
124 * GetSize [COMCTL32.74]
126 * Retrieves the size of the specified memory block from the dll's
130 * lpMem [I] pointer to an allocated memory block
133 * Success: size of the specified memory block
136 DWORD WINAPI
GetSize (LPVOID lpMem
)
138 return LocalSize( lpMem
);
142 /**************************************************************************
143 * MRU-Functions {COMCTL32}
146 * The MRU-Api is a set of functions to manipulate lists of M.R.U. (Most Recently
147 * Used) items. It is an undocumented Api that is used (at least) by the shell
148 * and explorer to implement their recent documents feature.
150 * Since these functions are undocumented, they are unsupported by MS and
151 * may change at any time.
153 * Internally, the list is implemented as a last in, last out list of items
154 * persisted into the system registry under a caller chosen key. Each list
155 * item is given a one character identifier in the Ascii range from 'a' to
156 * '}'. A list of the identifiers in order from newest to oldest is stored
157 * under the same key in a value named "MRUList".
159 * Items are re-ordered by changing the order of the values in the MRUList
160 * value. When a new item is added, it becomes the new value of the oldest
161 * identifier, and that identifier is moved to the front of the MRUList value.
163 * Wine stores MRU-lists in the same registry format as Windows, so when
164 * switching between the builtin and native comctl32.dll no problems or
165 * incompatibilities should occur.
167 * The following undocumented structure is used to create an MRU-list:
168 *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
169 *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
171 *|typedef struct tagCREATEMRULIST
177 *| LPTSTR lpszSubKey;
179 *|} CREATEMRULIST, *LPCREATEMRULIST;
182 * cbSize [I] The size of the CREATEMRULIST structure. This must be set
183 * to sizeof(CREATEMRULIST) by the caller.
184 * nMaxItems [I] The maximum number of items allowed in the list. Because
185 * of the limited number of identifiers, this should be set to
186 * a value from 1 to 30 by the caller.
187 * dwFlags [I] If bit 0 is set, the list will be used to store binary
188 * data, otherwise it is assumed to store strings. If bit 1
189 * is set, every change made to the list will be reflected in
190 * the registry immediately, otherwise changes will only be
191 * written when the list is closed.
192 * hKey [I] The registry key that the list should be written under.
193 * This must be supplied by the caller.
194 * lpszSubKey [I] A caller supplied name of a subkey under hKey to write
195 * the list to. This may not be blank.
196 * lpfnCompare [I] A caller supplied comparison function, which may be either
197 * an MRUStringCmpFn if dwFlags does not have bit 0 set, or a
198 * MRUBinaryCmpFn otherwise.
201 * - Create an MRU-list with CreateMRUList() or CreateMRUListLazy().
202 * - Add items to an MRU-list with AddMRUString() or AddMRUData().
203 * - Remove items from an MRU-list with DelMRUString().
204 * - Find data in an MRU-list with FindMRUString() or FindMRUData().
205 * - Iterate through an MRU-list with EnumMRUList().
206 * - Free an MRU-list with FreeMRUList().
209 typedef INT (CALLBACK
*MRUStringCmpFnA
)(LPCSTR lhs
, LPCSTR rhs
);
210 typedef INT (CALLBACK
*MRUStringCmpFnW
)(LPCWSTR lhs
, LPCWSTR rhs
);
211 typedef INT (CALLBACK
*MRUBinaryCmpFn
)(LPCVOID lhs
, LPCVOID rhs
, DWORD length
);
213 typedef struct tagCREATEMRULISTA
222 MRUStringCmpFnA string_cmpfn
;
223 MRUBinaryCmpFn binary_cmpfn
;
225 } CREATEMRULISTA
, *LPCREATEMRULISTA
;
227 typedef struct tagCREATEMRULISTW
236 MRUStringCmpFnW string_cmpfn
;
237 MRUBinaryCmpFn binary_cmpfn
;
239 } CREATEMRULISTW
, *LPCREATEMRULISTW
;
242 #define MRUF_STRING_LIST 0 /* list will contain strings */
243 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
244 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
246 /* If list is a string list lpfnCompare has the following prototype
247 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
248 * for binary lists the prototype is
249 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
250 * where cbData is the no. of bytes to compare.
251 * Need to check what return value means identical - 0?
254 typedef struct tagWINEMRUITEM
256 DWORD size
; /* size of data stored */
257 DWORD itemFlag
; /* flags */
259 } WINEMRUITEM
, *LPWINEMRUITEM
;
262 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
264 typedef struct tagWINEMRULIST
266 CREATEMRULISTW extview
; /* original create information */
267 BOOL isUnicode
; /* is compare fn Unicode */
268 DWORD wineFlags
; /* internal flags */
269 DWORD cursize
; /* current size of realMRU */
270 LPWSTR realMRU
; /* pointer to string of index names */
271 LPWINEMRUITEM
*array
; /* array of pointers to data */
272 /* in 'a' to 'z' order */
273 } WINEMRULIST
, *LPWINEMRULIST
;
276 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
278 /**************************************************************************
279 * MRU_SaveChanged (internal)
281 * Local MRU saving code
283 static void MRU_SaveChanged ( LPWINEMRULIST mp
)
290 /* or should we do the following instead of RegOpenKeyEx:
293 /* open the sub key */
294 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
295 0, KEY_WRITE
, &newkey
))) {
296 /* not present - what to do ??? */
297 ERR("Could not open key, error=%d, attempting to create\n",
299 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
302 REG_OPTION_NON_VOLATILE
,
303 KEY_READ
| KEY_WRITE
,
307 ERR("failed to create key /%s/, err=%d\n",
308 debugstr_w(mp
->extview
.lpszSubKey
), err
);
312 if (mp
->wineFlags
& WMRUF_CHANGED
) {
313 mp
->wineFlags
&= ~WMRUF_CHANGED
;
314 err
= RegSetValueExW(newkey
, strMRUList
, 0, REG_SZ
, (LPBYTE
)mp
->realMRU
,
315 (strlenW(mp
->realMRU
) + 1)*sizeof(WCHAR
));
317 ERR("error saving MRUList, err=%d\n", err
);
319 TRACE("saving MRUList=/%s/\n", debugstr_w(mp
->realMRU
));
322 for(i
=0; i
<mp
->cursize
; i
++) {
323 witem
= mp
->array
[i
];
324 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
325 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
326 realname
[0] = 'a' + i
;
327 err
= RegSetValueExW(newkey
, realname
, 0,
328 (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) ?
330 &witem
->datastart
, witem
->size
);
332 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
334 TRACE("saving value for name /%s/ size=%d\n",
335 debugstr_w(realname
), witem
->size
);
338 RegCloseKey( newkey
);
341 /**************************************************************************
342 * FreeMRUList [COMCTL32.152]
344 * Frees a most-recently-used items list.
347 * hMRUList [I] Handle to list.
352 void WINAPI
FreeMRUList (HANDLE hMRUList
)
354 LPWINEMRULIST mp
= hMRUList
;
357 TRACE("(%p)\n", hMRUList
);
361 if (mp
->wineFlags
& WMRUF_CHANGED
) {
362 /* need to open key and then save the info */
363 MRU_SaveChanged( mp
);
366 for(i
=0; i
<mp
->extview
.nMaxItems
; i
++)
371 Free(mp
->extview
.lpszSubKey
);
376 /**************************************************************************
377 * FindMRUData [COMCTL32.169]
379 * Searches binary list for item that matches lpData of length cbData.
380 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
381 * corresponding to item's reg. name will be stored in it ('a' -> 0).
384 * hList [I] list handle
385 * lpData [I] data to find
386 * cbData [I] length of data
387 * lpRegNum [O] position in registry (maybe NULL)
390 * Position in list 0 -> MRU. -1 if item not found.
392 INT WINAPI
FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
,
395 const WINEMRULIST
*mp
= hList
;
400 if (!mp
|| !mp
->extview
.u
.string_cmpfn
)
403 if(!(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) && !mp
->isUnicode
) {
404 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
405 NULL
, 0, NULL
, NULL
);
407 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
410 for(i
=0; i
<mp
->cursize
; i
++) {
411 if (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
412 if (!mp
->extview
.u
.binary_cmpfn(lpData
, &mp
->array
[i
]->datastart
, cbData
))
417 if (!mp
->extview
.u
.string_cmpfn(lpData
, (LPWSTR
)&mp
->array
[i
]->datastart
))
420 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
421 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
422 NULL
, 0, NULL
, NULL
);
423 LPSTR itemA
= Alloc(len
);
425 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
426 itemA
, len
, NULL
, NULL
);
428 cmp
= mp
->extview
.u
.string_cmpfn((LPWSTR
)dataA
, (LPWSTR
)itemA
);
440 if (lpRegNum
&& (ret
!= -1))
443 TRACE("(%p, %p, %d, %p) returning %d\n",
444 hList
, lpData
, cbData
, lpRegNum
, ret
);
450 /**************************************************************************
451 * AddMRUData [COMCTL32.167]
453 * Add item to MRU binary list. If item already exists in list then it is
454 * simply moved up to the top of the list and not added again. If list is
455 * full then the least recently used item is removed to make room.
458 * hList [I] Handle to list.
459 * lpData [I] ptr to data to add.
460 * cbData [I] no. of bytes of data.
463 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
466 INT WINAPI
AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
468 LPWINEMRULIST mp
= hList
;
472 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) >= 0) {
473 /* Item exists, just move it to the front */
474 LPWSTR pos
= strchrW(mp
->realMRU
, replace
+ 'a');
475 while (pos
> mp
->realMRU
)
482 /* either add a new entry or replace oldest */
483 if (mp
->cursize
< mp
->extview
.nMaxItems
) {
484 /* Add in a new item */
485 replace
= mp
->cursize
;
489 /* get the oldest entry and replace data */
490 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
491 Free(mp
->array
[replace
]);
494 /* Allocate space for new item and move in the data */
495 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
496 witem
->itemFlag
|= WMRUIF_CHANGED
;
497 witem
->size
= cbData
;
498 memcpy( &witem
->datastart
, lpData
, cbData
);
500 /* now rotate MRU list */
501 for(i
=mp
->cursize
-1; i
>=1; i
--)
502 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
505 /* The new item gets the front spot */
506 mp
->wineFlags
|= WMRUF_CHANGED
;
507 mp
->realMRU
[0] = replace
+ 'a';
509 TRACE("(%p, %p, %d) adding data, /%c/ now most current\n",
510 hList
, lpData
, cbData
, replace
+'a');
512 if (!(mp
->extview
.dwFlags
& MRUF_DELAYED_SAVE
)) {
513 /* save changed stuff right now */
514 MRU_SaveChanged( mp
);
520 /**************************************************************************
521 * AddMRUStringW [COMCTL32.401]
523 * Add an item to an MRU string list.
526 * hList [I] Handle to list.
527 * lpszString [I] The string to add.
530 * Success: The number corresponding to the registry name where the string
531 * has been stored (0 maps to 'a', 1 to 'b' and so on).
532 * Failure: -1, if hList is NULL or memory allocation fails. If lpszString
533 * is invalid, the function returns 0, and GetLastError() returns
534 * ERROR_INVALID_PARAMETER. The last error value is set only in
538 * -If lpszString exists in the list already, it is moved to the top of the
539 * MRU list (it is not duplicated).
540 * -If the list is full the least recently used list entry is replaced with
542 * -If this function returns 0 you should check the last error value to
543 * ensure the call really succeeded.
545 INT WINAPI
AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
547 TRACE("(%p,%s)\n", hList
, debugstr_w(lpszString
));
552 if (!lpszString
|| IsBadStringPtrW(lpszString
, -1))
554 SetLastError(ERROR_INVALID_PARAMETER
);
558 return AddMRUData(hList
, lpszString
,
559 (strlenW(lpszString
) + 1) * sizeof(WCHAR
));
562 /**************************************************************************
563 * AddMRUStringA [COMCTL32.153]
567 INT WINAPI
AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
573 TRACE("(%p,%s)\n", hList
, debugstr_a(lpszString
));
578 if (IsBadStringPtrA(lpszString
, -1))
580 SetLastError(ERROR_INVALID_PARAMETER
);
584 len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0) * sizeof(WCHAR
);
585 stringW
= Alloc(len
);
589 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
/sizeof(WCHAR
));
590 ret
= AddMRUData(hList
, stringW
, len
);
595 /**************************************************************************
596 * DelMRUString [COMCTL32.156]
598 * Removes item from either string or binary list (despite its name)
601 * hList [I] list handle
602 * nItemPos [I] item position to remove 0 -> MRU
605 * TRUE if successful, FALSE if nItemPos is out of range.
607 BOOL WINAPI
DelMRUString(HANDLE hList
, INT nItemPos
)
609 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
613 /**************************************************************************
614 * FindMRUStringW [COMCTL32.402]
616 * See FindMRUStringA.
618 INT WINAPI
FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
620 return FindMRUData(hList
, lpszString
,
621 (lstrlenW(lpszString
) + 1) * sizeof(WCHAR
), lpRegNum
);
624 /**************************************************************************
625 * FindMRUStringA [COMCTL32.155]
627 * Searches string list for item that matches lpszString.
628 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
629 * corresponding to item's reg. name will be stored in it ('a' -> 0).
632 * hList [I] list handle
633 * lpszString [I] string to find
634 * lpRegNum [O] position in registry (maybe NULL)
637 * Position in list 0 -> MRU. -1 if item not found.
639 INT WINAPI
FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
641 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
642 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
645 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
646 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
651 /*************************************************************************
652 * CreateMRUListLazy_common (internal)
654 static HANDLE
CreateMRUListLazy_common(LPWINEMRULIST mp
)
658 DWORD datasize
, dwdisp
;
663 /* get space to save indices that will turn into names
664 * but in order of most to least recently used
666 mp
->realMRU
= Alloc((mp
->extview
.nMaxItems
+ 2) * sizeof(WCHAR
));
668 /* get space to save pointers to actual data in order of
669 * 'a' to 'z' (0 to n).
671 mp
->array
= Alloc(mp
->extview
.nMaxItems
* sizeof(LPVOID
));
673 /* open the sub key */
674 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
677 REG_OPTION_NON_VOLATILE
,
678 KEY_READ
| KEY_WRITE
,
682 /* error - what to do ??? */
683 ERR("(%u %u %x %p %s %p): Could not open key, error=%d\n",
684 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
685 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
686 mp
->extview
.u
.string_cmpfn
, err
);
690 /* get values from key 'MRUList' */
692 datasize
= (mp
->extview
.nMaxItems
+ 1) * sizeof(WCHAR
);
693 if((err
=RegQueryValueExW( newkey
, strMRUList
, 0, &type
,
694 (LPBYTE
)mp
->realMRU
, &datasize
))) {
695 /* not present - set size to 1 (will become 0 later) */
700 datasize
/= sizeof(WCHAR
);
702 TRACE("MRU list = %s, datasize = %d\n", debugstr_w(mp
->realMRU
), datasize
);
704 mp
->cursize
= datasize
- 1;
705 /* datasize now has number of items in the MRUList */
707 /* get actual values for each entry */
709 for(i
=0; i
<mp
->cursize
; i
++) {
710 realname
[0] = 'a' + i
;
711 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
712 /* not present - what to do ??? */
713 ERR("Key %s not found 1\n", debugstr_w(realname
));
715 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
716 witem
->size
= datasize
;
717 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
718 &witem
->datastart
, &datasize
)) {
719 /* not present - what to do ??? */
720 ERR("Key %s not found 2\n", debugstr_w(realname
));
723 RegCloseKey( newkey
);
728 TRACE("(%u %u %x %p %s %p): Current Size = %d\n",
729 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
730 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
731 mp
->extview
.u
.string_cmpfn
, mp
->cursize
);
735 /**************************************************************************
736 * CreateMRUListLazyW [COMCTL32.404]
738 * See CreateMRUListLazyA.
740 HANDLE WINAPI
CreateMRUListLazyW (const CREATEMRULISTW
*lpcml
, DWORD dwParam2
,
741 DWORD dwParam3
, DWORD dwParam4
)
745 /* Native does not check for a NULL lpcml */
747 if (lpcml
->cbSize
!= sizeof(CREATEMRULISTW
) || !lpcml
->hKey
||
748 IsBadStringPtrW(lpcml
->lpszSubKey
, -1))
751 mp
= Alloc(sizeof(WINEMRULIST
));
752 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
753 mp
->extview
.lpszSubKey
= Alloc((strlenW(lpcml
->lpszSubKey
) + 1) * sizeof(WCHAR
));
754 strcpyW(mp
->extview
.lpszSubKey
, lpcml
->lpszSubKey
);
755 mp
->isUnicode
= TRUE
;
757 return CreateMRUListLazy_common(mp
);
760 /**************************************************************************
761 * CreateMRUListLazyA [COMCTL32.157]
763 * Creates a most-recently-used list.
766 * lpcml [I] ptr to CREATEMRULIST structure.
767 * dwParam2 [I] Unknown
768 * dwParam3 [I] Unknown
769 * dwParam4 [I] Unknown
772 * Handle to MRU list.
774 HANDLE WINAPI
CreateMRUListLazyA (const CREATEMRULISTA
*lpcml
, DWORD dwParam2
,
775 DWORD dwParam3
, DWORD dwParam4
)
780 /* Native does not check for a NULL lpcml */
782 if (lpcml
->cbSize
!= sizeof(CREATEMRULISTA
) || !lpcml
->hKey
||
783 IsBadStringPtrA(lpcml
->lpszSubKey
, -1))
786 mp
= Alloc(sizeof(WINEMRULIST
));
787 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
788 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
789 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
790 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
791 mp
->extview
.lpszSubKey
, len
);
792 mp
->isUnicode
= FALSE
;
793 return CreateMRUListLazy_common(mp
);
796 /**************************************************************************
797 * CreateMRUListW [COMCTL32.400]
799 * See CreateMRUListA.
801 HANDLE WINAPI
CreateMRUListW (const CREATEMRULISTW
*lpcml
)
803 return CreateMRUListLazyW(lpcml
, 0, 0, 0);
806 /**************************************************************************
807 * CreateMRUListA [COMCTL32.151]
809 * Creates a most-recently-used list.
812 * lpcml [I] ptr to CREATEMRULIST structure.
815 * Handle to MRU list.
817 HANDLE WINAPI
CreateMRUListA (const CREATEMRULISTA
*lpcml
)
819 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
823 /**************************************************************************
824 * EnumMRUListW [COMCTL32.403]
826 * Enumerate item in a most-recently-used list
829 * hList [I] list handle
830 * nItemPos [I] item position to enumerate
831 * lpBuffer [O] buffer to receive item
832 * nBufferSize [I] size of buffer
835 * For binary lists specifies how many bytes were copied to buffer, for
836 * string lists specifies full length of string. Enumerating past the end
837 * of list returns -1.
838 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
841 INT WINAPI
EnumMRUListW (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
844 const WINEMRULIST
*mp
= hList
;
845 const WINEMRUITEM
*witem
;
846 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 datasize
= min( witem
->size
, nBufferSize
);
856 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
857 TRACE("(%p, %d, %p, %d): returning len=%d\n",
858 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
862 /**************************************************************************
863 * EnumMRUListA [COMCTL32.154]
867 INT WINAPI
EnumMRUListA (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
870 const WINEMRULIST
*mp
= hList
;
872 INT desired
, datasize
;
876 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
877 if (nItemPos
>= mp
->cursize
) return -1;
878 desired
= mp
->realMRU
[nItemPos
];
880 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
881 witem
= mp
->array
[desired
];
882 if(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
883 datasize
= min( witem
->size
, nBufferSize
);
884 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
886 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
887 NULL
, 0, NULL
, NULL
);
888 datasize
= min( witem
->size
, nBufferSize
);
889 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
890 lpBuffer
, datasize
, NULL
, NULL
);
892 TRACE("(%p, %d, %p, %d): returning len=%d\n",
893 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
897 /**************************************************************************
898 * Str_GetPtrWtoA [internal]
900 * Converts a unicode string into a multi byte string
903 * lpSrc [I] Pointer to the unicode source string
904 * lpDest [O] Pointer to caller supplied storage for the multi byte string
905 * nMaxLen [I] Size, in bytes, of the destination buffer
908 * Length, in bytes, of the converted string.
911 INT
Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
915 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
917 if (!lpDest
&& lpSrc
)
918 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
928 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
932 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
938 /**************************************************************************
939 * Str_GetPtrAtoW [internal]
941 * Converts a multibyte string into a unicode string
944 * lpSrc [I] Pointer to the multibyte source string
945 * lpDest [O] Pointer to caller supplied storage for the unicode string
946 * nMaxLen [I] Size, in characters, of the destination buffer
949 * Length, in characters, of the converted string.
952 INT
Str_GetPtrAtoW (LPCSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
956 TRACE("(%s %p %d)\n", debugstr_a(lpSrc
), lpDest
, nMaxLen
);
958 if (!lpDest
&& lpSrc
)
959 return MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, 0, 0);
969 len
= MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, 0, 0);
973 MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
);
980 /**************************************************************************
981 * Str_SetPtrAtoW [internal]
983 * Converts a multi byte string to a unicode string.
984 * If the pointer to the destination buffer is NULL a buffer is allocated.
985 * If the destination buffer is too small to keep the converted multi byte
986 * string the destination buffer is reallocated. If the source pointer is
987 * NULL, the destination buffer is freed.
990 * lppDest [I/O] pointer to a pointer to the destination buffer
991 * lpSrc [I] pointer to a multi byte string
994 * TRUE: conversion successful
997 BOOL
Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
999 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1002 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1003 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1007 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1018 /**************************************************************************
1019 * Str_SetPtrWtoA [internal]
1021 * Converts a unicode string to a multi byte string.
1022 * If the pointer to the destination buffer is NULL a buffer is allocated.
1023 * If the destination buffer is too small to keep the converted wide
1024 * string the destination buffer is reallocated. If the source pointer is
1025 * NULL, the destination buffer is freed.
1028 * lppDest [I/O] pointer to a pointer to the destination buffer
1029 * lpSrc [I] pointer to a wide string
1032 * TRUE: conversion successful
1035 BOOL
Str_SetPtrWtoA (LPSTR
*lppDest
, LPCWSTR lpSrc
)
1037 TRACE("(%p %s)\n", lppDest
, debugstr_w(lpSrc
));
1040 INT len
= WideCharToMultiByte(CP_ACP
,0,lpSrc
,-1,NULL
,0,NULL
,FALSE
);
1041 LPSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(CHAR
));
1045 WideCharToMultiByte(CP_ACP
,0,lpSrc
,-1,ptr
,len
,NULL
,FALSE
);
1057 /**************************************************************************
1058 * Notification functions
1061 typedef struct tagNOTIFYDATA
1069 } NOTIFYDATA
, *LPNOTIFYDATA
;
1072 /**************************************************************************
1073 * DoNotify [Internal]
1076 static LRESULT
DoNotify (const NOTIFYDATA
*lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
1079 LPNMHDR lpNmh
= NULL
;
1082 TRACE("(%p %p %d %p 0x%08x)\n",
1083 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
1084 lpNotify
->dwParam5
);
1086 if (!lpNotify
->hwndTo
)
1089 if (lpNotify
->hwndFrom
== (HWND
)-1) {
1091 idFrom
= lpHdr
->idFrom
;
1094 if (lpNotify
->hwndFrom
)
1095 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
1097 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
1099 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
1100 lpNmh
->idFrom
= idFrom
;
1101 lpNmh
->code
= uCode
;
1104 return SendMessageW (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
1108 /**************************************************************************
1109 * SendNotify [COMCTL32.341]
1111 * Sends a WM_NOTIFY message to the specified window.
1114 * hwndTo [I] Window to receive the message
1115 * hwndFrom [I] Window that the message is from (see notes)
1116 * uCode [I] Notification code
1117 * lpHdr [I] The NMHDR and any additional information to send or NULL
1120 * Success: return value from notification
1124 * If hwndFrom is -1 then the identifier of the control sending the
1125 * message is taken from the NMHDR structure.
1126 * If hwndFrom is not -1 then lpHdr can be NULL.
1128 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
1132 TRACE("(%p %p %d %p)\n",
1133 hwndTo
, hwndFrom
, uCode
, lpHdr
);
1135 notify
.hwndFrom
= hwndFrom
;
1136 notify
.hwndTo
= hwndTo
;
1137 notify
.dwParam5
= 0;
1138 notify
.dwParam6
= 0;
1140 return DoNotify (¬ify
, uCode
, lpHdr
);
1144 /**************************************************************************
1145 * SendNotifyEx [COMCTL32.342]
1147 * Sends a WM_NOTIFY message to the specified window.
1150 * hwndFrom [I] Window to receive the message
1151 * hwndTo [I] Window that the message is from
1152 * uCode [I] Notification code
1153 * lpHdr [I] The NMHDR and any additional information to send or NULL
1154 * dwParam5 [I] Unknown
1157 * Success: return value from notification
1161 * If hwndFrom is -1 then the identifier of the control sending the
1162 * message is taken from the NMHDR structure.
1163 * If hwndFrom is not -1 then lpHdr can be NULL.
1165 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
1166 LPNMHDR lpHdr
, DWORD dwParam5
)
1171 TRACE("(%p %p %d %p 0x%08x)\n",
1172 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
1174 hwndNotify
= hwndTo
;
1176 if (IsWindow (hwndFrom
)) {
1177 hwndNotify
= GetParent (hwndFrom
);
1183 notify
.hwndFrom
= hwndFrom
;
1184 notify
.hwndTo
= hwndNotify
;
1185 notify
.dwParam5
= dwParam5
;
1186 notify
.dwParam6
= 0;
1188 return DoNotify (¬ify
, uCode
, lpHdr
);