NO

Author Topic: Tree View control macros for Unicode  (Read 1642 times)

Offline PaoloC13

  • Member
  • *
  • Posts: 44
Tree View control macros for Unicode
« 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?

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Tree View control macros for Unicode
« Reply #1 on: June 05, 2021, 03:13:38 PM »
Are you sure you added
#define UNICODE
#define _UNICODE

before your #includes


John Z

Grincheux

  • Guest
Re: Tree View control macros for Unicode
« Reply #2 on: June 05, 2021, 03:49:54 PM »
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!

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Tree View control macros for Unicode
« Reply #3 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

Offline PaoloC13

  • Member
  • *
  • Posts: 44
Re: Tree View control macros for Unicode
« Reply #4 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.