Pelles C forum

C language => Windows questions => Topic started by: PaoloC13 on June 05, 2021, 01:24:46 PM

Title: Tree View control macros for Unicode
Post by: PaoloC13 on June 05, 2021, 01:24:46 PM
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: [Select]
#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:

Code: [Select]
#define TreeView_InsertItemW(hwnd,lpis)  (HTREEITEM)SendMessageW((hwnd),TVM_INSERTITEMW,0,(LPARAM)(LPTVINSERTSTRUCTW)(lpis))
What is the cause of this lack?
Title: Re: Tree View control macros for Unicode
Post by: John Z on June 05, 2021, 03:13:38 PM
Are you sure you added
#define UNICODE
#define _UNICODE

before your #includes


John Z
Title: Re: Tree View control macros for Unicode
Post by: Grincheux on June 05, 2021, 03:49:54 PM
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!
Title: Re: Tree View control macros for Unicode
Post by: 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
Code: [Select]
#define TreeView_InsertItem(hwnd,lpis)  (HTREEITEM)SNDMSG((hwnd),TVM_INSERTITEM,0,(LPARAM)(LPTV_INSERTSTRUCT)(lpis))would automagically evolve to
Code: [Select]
#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
Title: Re: Tree View control macros for Unicode
Post by: PaoloC13 on June 06, 2021, 08:56:28 AM
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.