by Michael S. Kaplan, published on 2006/12/08 14:19 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/12/08/1241746.aspx
Some questions, I get more than once, but not often enough for it to occur to me that maybe I should blog about it.
One of those questions came to me from Dr. International just the other day, but the first time the question was asked almost two years ago was by Benjamin, it went something like this:
I have used your Unicode MessageBox code from VBA and tried both passing the Bidi flags and prepending two RLMs, and neither worked in Access. The code I used:
Private Declare Function MessageBoxW _
Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByVal lpText As Long, _
ByVal lpCaption As Long, _
ByVal wType As Long) As LongPrivate Const MB_RIGHT As Long = &H80000
Private Const MB_RTLREADING As Long = &H100000Public Sub Test()
MessageBoxW 0&, _
StrPtr(ChrW(&H5D0) & ChrW(&H5D1) & ChrW(&H5D2) & ChrW(&H5D3)), _
StrPtr("test"), _
MB_RIGHT Or MB_RTLREADINGMessageBoxW 0&, _
StrPtr(ChrW(&H200F) & ChrW(&H200F) & ChrW(&H5D0) & ChrW(&H5D1) & ChrW(&H5D2) & ChrW(&H5D3)), _
StrPtr("test"), _
0
End Sub
At first I thought my code was broken, but when I put it in Excel or Word, it works just fine.
So why is Access broken here?
Benjamin is correct here; this code works fine in every Office application I tried, except for Access where nothing could make the MessageBox RTL or right-aligned. It even happens woth the VBA MsgBox.
I tried installing a CBT hook and looking at the EXSTYLE of the MessageBox, which was
WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT
in Access but
WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_LAYOUTRTL
everywhere else, which implies that Access is itself installing a CBT hook after mine (easy enough for it to do since it gets to run code after I do but before VBA calls the function), and removing the WS_EX_LAYOUTRTL exstyle bit.
There is a happy ending to the story -- if you install a CBT hook you can actually put the style bit back, if you want to (the benefot to having your CBT hook running second is that you can fix whatever they may have broken!). A little heavy handed, to be sure. But desperate times can call for desperate measures!
As to why they do it, who knows? Maybe someone from the Access development team can chime in on this one? :-)
UPDATE 12:28 PM: This problem only applies to Access 2003 -- Access 2007 properly respects the passed-in flags....
This post brought to you by U+200f, a.k.a. RIGHT-TO-LEFT MARK)