AB Bolim
AB Bolim

Reputation: 2105

How to change the Layout of the IFileSaveDialog - MFC

I want to change the Layout of my custom IFileSaveDialog in the mfc.

I want to change Right-to-left layout for the IFileSaveDialog for the Arabic Language.

Is their any properties to directly changed?

I dint find any way to do this, Please help me out.

Thanks in Advance.

Edit

Need little bit more help, How can I get CComptr IFileSaveDialog handle ?

Upvotes: 0

Views: 600

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

It seems that file dialogs do not inherit their layout from the parent window. I was a little surprised by this.

I think you may need to force the issue by adding the WS_EX_LAYOUTRTL to the dialog window. That's not totally easy to do since the file dialog interface does not provide you a window handle. You can work around that by using a CBT hook.

Here's an example which forces RTL for all dialogs (which have class name #32770). I've written the example in Delphi since that's what I am personally most familiar with. I'm sure you can translate it into your MFC environment.

First of all install the hook:

hook := SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId);

And when you need to uninstall it:

UnhookWindowsHookEx(hook);

And the hook procedure:

function CBTProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
  wnd: HWND;
  ClassName: array [0..63] of Char;
  Style: DWORD;
begin
  if nCode=HCBT_ACTIVATE then begin
    wnd := wParam;
    GetClassName(wnd, ClassName, Length(ClassName));
    if ClassName='#32770' then begin
      Style := GetWindowLongPtr(wnd, GWL_EXSTYLE);
      SetWindowLongPtr(wnd, GWL_EXSTYLE, Style or WS_EX_LAYOUTRTL);
    end;
  end;
  Result := CallNextHookEx(hook, nCode, wParam, lParam);
end;

And this is what it looks like on my very left-to-right English OS:

enter image description here

Upvotes: 1

Related Questions