C language > Windows questions

Tree View control macros for Unicode

(1/1)

PaoloC13:
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:


--- Code: ---#define TreeView_InsertItem(hwnd,lpis)  (HTREEITEM)SNDMSG((hwnd),TVM_INSERTITEM,0,(LPARAM)(LPTV_INSERTSTRUCT)(lpis))

--- End code ---

To get around this, I have defined my own macro for unicode in this way:


--- Code: ---#define TreeView_InsertItemW(hwnd,lpis)  (HTREEITEM)SendMessageW((hwnd),TVM_INSERTITEMW,0,(LPARAM)(LPTVINSERTSTRUCTW)(lpis))
--- End code ---

What is the cause of this lack?

John Z:
Are you sure you added
#define UNICODE
#define _UNICODE

before your #includes


John Z

Grincheux:
Go to https://docs.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-treeview_insertitem
There are NO UNICODE MACROS for some controls in Windows!

John Z:
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

--- Code: ---#define TreeView_InsertItem(hwnd,lpis)  (HTREEITEM)SNDMSG((hwnd),TVM_INSERTITEM,0,(LPARAM)(LPTV_INSERTSTRUCT)(lpis))
--- End code ---
would automagically evolve to
--- Code: ---#define TreeView_InsertItemW(hwnd,lpis)  (HTREEITEM)SendMessageW((hwnd),TVM_INSERTITEMW,0,(LPARAM)(LPTVINSERTSTRUCTW)(lpis))
--- End code ---
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

PaoloC13:
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.

Navigation

[0] Message Index

Go to full version