i.e. what is the difference between the following:
SendMessage(h, BFFM_SETSELECTION, ...
SendMessageA(h, BFFM_SETSELECTIONA, ...
SendMessageW(h, BFFM_SETSELECTIONW, ...
... and what happens if you mix your A's and W's e.g.
SendMessage(h, BFFM_SETSELECTIONW, ...
SendMessageA(h, BFFM_SETSELECTIONW, ...
I ask this for a practical reason. I am using the Windows Shell
BrowseForFolder dialog, and I find that it has different behaviour on
different Windows platforms. The Windows SDK documentation says that to set
the dialog selection you should use:
SendMessage(h, BFFM_SETSELECTION, 1, integer(PWideChar(UnicodeString));
But on Windows2k and WindowsXP this does not work. Instead I have to use:
SendMessage(h, BFFM_SETSELECTION, 1, integer(PChar(AnsiString));
However this in turn does not work on WindowsNT v4. The closest that I can
get to a solution which works on both WinXP, Win2k and WinNT is the
following:
SendMessageW(h, BFFM_SETSELECTIONW, 1, integer(PWideChar(UnicodeString));
However I don't really understand why this works; and I am not sure if it
would also work on Win9x and WinMe (not to mention future OS's)
{ PS all above are compiled with D7 on XP and the resulting EXE is tested on
XP, NT, 2K }
Regards,
AndrewFG
>What are the significance of the Windows API calls SendMessageA and
>SendMessageW? I believe that they have something to do with whether the
>arguments contain Ansi or Unicode strings.
That's correct. Each window can be created as a Unicode or ANSI
window. This is determined by the version of
CreateWindow/CreateWindowEx function used to create the window -
Unicode windows are created by the W version, while ANSI windows are
created by the A version.
>However I have also seen that
>Windows implements A and W versions of windows messages (e.g.
>BFFM_SETSELECTIONA and BFFM_SETSELECTIONW) which also differentiate between
>Ansi and Unicode arguments. Is this not overkill?
Certain messages contain pointers to strings. In these cases, the
message record definition changes based on the character set
definition.
> SendMessage(h, BFFM_SETSELECTION, ...
> SendMessageA(h, BFFM_SETSELECTIONA, ...
> SendMessageW(h, BFFM_SETSELECTIONW, ...
The first version is simply an easier name for one of the two other
versions. In current Delphi versions, the simple name always
translates to the ANSI version. In C/C++, you can define which
mappings to use.
>... and what happens if you mix your A's and W's e.g.
If you're lucky, you'll get an error code. If you're not so lucky,
you'll get an access violation. If you're really unlucky, you'll pass
invalid data and get a bunch of unexpected errors, sometimes without
even knowing it. The type declarations are separate for a reason.
> SendMessage(h, BFFM_SETSELECTIONW, ...
> SendMessageA(h, BFFM_SETSELECTIONW, ...
Don't do that.
>I ask this for a practical reason. I am using the Windows Shell
>BrowseForFolder dialog
Use the SelectDirectory function. If you want to call the function
directly, search the newsgroups - plenty of examples have been posted
in the past.
---
Yorai Aminov (TeamB)
http://develop.shorterpath.com/yorai
(TeamB cannot answer questions received via email.)
Thanks for you very informative response.
>> Use the SelectDirectory function.
---
Actually the code that I am using is built on the source code of the
SelectDirectory function provided in Delphi (D7). From what you say in your
message, I think that there must be a bug in that code since it does not
seem to function on WindowsNT v4.
The SelectDirectory function uses a callback procedure. Essentially, the
callback procedure contains the following call to initialise the browser
tree selection:
SendMessage(Wnd, BFFM_SETSELECTION, integer(true), integer(PChar(aPath)));
The Windows SDK states that the path parameter must be a Unicode string.
When I use the above code on Win2k and WinXP it works correctly, so it seems
that although a PChar(aPathname) is passed, the function call is properly
marshalling the PChar(aPath) to a PWideChar(aUnicodePath) and passing it on
to the browser tree.
However, the above (Delphi) code does NOT function on Windows NT v4, so I
fear that the above function call is not properly marshalling on this
platform. I have not fully tested it, but I think that the following
explicit Unicode call might solve the problem:
SendMessageW(Wnd, BFFM_SETSELECTIONW, integer(true),
integer(PWideChar(aUnicodePath)));
This is a wild guess, but a reason for not working on WinNT but working on
WinXP, Win2k might be the existence of deficiencies in earlier versions of
OS or Shell library, that Microsoft has subsequently fixed. Some ideas are
as follows:
- perhaps the Windows Unicode marshalling was not perfect on early versions
of the OS?
- perhaps in earlier versions of the Shell library (i.e. Shell v4 for NT),
the target window (i.e. the browser tree control) did not have the Unicode
attribute set on it?
This is getting rather heavy, so I would appreciate if others can throw any
light on the matter.
PS Can anyone say what happens on Win9x or on WinMe?
Regards,
AndrewFG
"Yorai Aminov (TeamB)" <yaminov@delete_shorterpath.com> wrote in message
news:tm3ogvs3ddd6982si...@4ax.com...
procedure 9xSendMsg(...);
begin
SendMessageA(...)
end;
procedure NTSendMsg(...);
begin
SendMessageW(...)
end;
procedure SendMsg(...);
begin
If WinNT then
NTSendMsg(...)
else
9xSendMsg(...);
end;
Regards
Des Norton
>Actually the code that I am using is built on the source code of the
>SelectDirectory function provided in Delphi (D7). From what you say in your
>message, I think that there must be a bug in that code since it does not
>seem to function on WindowsNT v4.
Unfortunately, I can't test that - I no longer have NT 4 installed.
Perhaps someone else can test this.
SendMessage(Wnd, BFFM_SETSELECTION, integer(false), integer(aPathPIDL));
I will try it tomorrow...
Regards,
AndrewFG
"Andrew Fiddian-Green" <andrewfg at zugernet dot ch> wrote in message news:3f0c...@newsgroups.borland.com...
SendMessage(Wnd, BFFM_SETSELECTION, integer(false), integer(aPathPIDL))
Whereas the following works on WinMe, Win2k and WinXP but does NOT work on
Windows NT.
SendMessage(Wnd, BFFM_SETSELECTION, integer(true),
integer(PChar(aPathString))
=> Advice: It's safer to use a PIDL...
>=> Advice: It's safer to use a PIDL...
Good to know.