Hi guys,
I have found that Windows Tree View control macros are not defined to be used in Unicode.
For example, I used the macro TreeView_InsertItem and I noticed strange behavior. So i saw that it is defined in this way:
#define TreeView_InsertItem(hwnd,lpis) (HTREEITEM)SNDMSG((hwnd),TVM_INSERTITEM,0,(LPARAM)(LPTV_INSERTSTRUCT)(lpis))
To get around this, I have defined my own macro for unicode in this way:
#define TreeView_InsertItemW(hwnd,lpis) (HTREEITEM)SendMessageW((hwnd),TVM_INSERTITEMW,0,(LPARAM)(LPTVINSERTSTRUCTW)(lpis))
What is the cause of this lack?
Are you sure you added
#define UNICODE
#define _UNICODE
before your #includes
John Z
Go to https://docs.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-treeview_insertitem (https://docs.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-treeview_insertitem)
There are NO UNICODE MACROS for some controls in Windows!
Perhaps true but TreeView_InsertItem macro is defined in commctrl.h using SNDMSG
which then is defined windowsx.h
#define SNDMSG SendMessage
which then is defined in winuser.h
#ifdef UNICODE
#define SendMessage SendMessageW
#define SendMessageTimeout SendMessageTimeoutW
#define SendNotifyMessage SendNotifyMessageW
#define SendMessageCallback SendMessageCallbackW
#else /* !UNICODE */
so
#define TreeView_InsertItem(hwnd,lpis) (HTREEITEM)SNDMSG((hwnd),TVM_INSERTITEM,0,(LPARAM)(LPTV_INSERTSTRUCT)(lpis))
would automagically evolve to #define TreeView_InsertItemW(hwnd,lpis) (HTREEITEM)SendMessageW((hwnd),TVM_INSERTITEMW,0,(LPARAM)(LPTVINSERTSTRUCTW)(lpis))
if the UNICODE defines are done.
So I think they are missing from PaoloC13's code.... I could be wrong but worth checking :)
I have used Unicode treeviews albeit without the macros, but they do seem to exist in PellesC.
John Z
Oh yes, that's it!
indeed, the issue arose when I abandoned Windows support for both charsets (ASCII and Unicode), and I chose to work directly and explicitly on the Unicode versions of the Windows API.
Quote from: John Z on June 05, 2021, 04:49:29 PM
Perhaps true but TreeView_InsertItem macro is defined in commctrl.h using SNDMSG
which then is defined windowsx.h
#define SNDMSG SendMessage
which then is defined in winuser.h
#ifdef UNICODE
#define SendMessage SendMessageW
#define SendMessageTimeout SendMessageTimeoutW
#define SendNotifyMessage SendNotifyMessageW
#define SendMessageCallback SendMessageCallbackW
#else /* !UNICODE */
so
#define TreeView_InsertItem(hwnd,lpis) (HTREEITEM)SNDMSG((hwnd),TVM_INSERTITEM,0,(LPARAM)(LPTV_INSERTSTRUCT)(lpis))
would automagically evolve to #define TreeView_InsertItemW(hwnd,lpis) (HTREEITEM)SendMessageW((hwnd),TVM_INSERTITEMW,0,(LPARAM)(LPTVINSERTSTRUCTW)(lpis))
if the UNICODE defines are done.
So I think they are missing from PaoloC13's code.... I could be wrong but worth checking :)
I have used Unicode treeviews albeit without the macros, but they do seem to exist in PellesC.
John Z
Thank you John Z. I have been scratching my head about this for quite some time, using ListView and TreeView macros. This makes sense for compatibility!