Page 1 of 1

TextAlgin if style is Edit Field Only

Posted: 31 Dec 2010, 08:05
by Mex
Hi Timo!

Is it possible set TextAlign for combobox if style is set to Edit Field Only?
I'v tested with SetTextAlgin API, but this doesnt work


Alles gute;
Meelis

Re: TextAlgin if style is Edit Field Only

Posted: 31 Dec 2010, 12:12
by TiKu
It should work if you call GetWindowLong(GWL_STYLE) for the hWndEdit window, set/remove the ES_CENTER/ES_LEFT/ES_RIGHT styles and call SetWindowLong(GWL_STYLE) to apply the changes.

Re: TextAlgin if style is Edit Field Only

Posted: 18 Jan 2011, 15:40
by Mex
Hi again


Dim lngStyle As Long
lngStyle = GetWindowLong(ComboBox1.hWndEdit, GWL_STYLE)
SetWindowLong ComboBox1.hWndEdit, GWL_STYLE, lngStyle Or ES_RIGHT


Does not work. Am i doing something wrong?


BR;
Mex

Re: TextAlgin if style is Edit Field Only

Posted: 18 Jan 2011, 15:51
by Mex
Hmm i think if control is created i cant change style anymore at runtime :(?

Re: TextAlgin if style is Edit Field Only

Posted: 18 Jan 2011, 19:48
by TiKu
For a normal Edit control the alignment styles may be set and removed after window creation. The combo box uses a normal edit control, so it should work. But it might be that the combo box prevents such changes to the edit control. If this is the case, you are out of luck.

Re: TextAlgin if style is Edit Field Only

Posted: 18 Jan 2011, 19:59
by TiKu
Ha! I tried it myself. All you need is to force a redraw of the control after you changed the styles.

Re: TextAlgin if style is Edit Field Only

Posted: 20 Jan 2011, 07:55
by Mex
Hi

What you mean with "force redraw"?
SendMessage and WM_PAINT?



Mex

Re: TextAlgin if style is Edit Field Only

Posted: 20 Jan 2011, 07:59
by TiKu
Calling Refresh should be enough.

Re: TextAlgin if style is Edit Field Only

Posted: 20 Jan 2011, 08:01
by Mex
Refresh does not help

Is my code correct in first post?

Re: TextAlgin if style is Edit Field Only

Posted: 20 Jan 2011, 09:04
by TiKu
Assuming that you defined the constants and API functions correctly, it is correct, yes.

When I tried it myself on Tuesday, all I needed was to move another window over the control so that it will redraw. I thought that Refresh would be sufficient. Obviously it is not sufficient. Try this:

Code: Select all

Call SetWindowPos(ComboBox1.hWndEdit, 0, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOOWNERZORDER Or SWP_NOZORDER)
If this does not help, try this:

Code: Select all

Call SetWindowPos(ComboBox1.hWndEdit, 0, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOOWNERZORDER Or SWP_NOZORDER Or SWP_FRAMECHANGED)
If this also does not help, you could toggle the Visible property twice, but then the control will flicker.

Re: TextAlgin if style is Edit Field Only

Posted: 20 Jan 2011, 09:29
by Mex
Nope, nothing works :(

Re: TextAlgin if style is Edit Field Only

Posted: 20 Jan 2011, 10:55
by TiKu
Does your application have Windows skins enabled? I tried on Windows 7 x64 with skins enabled. Maybe it works only if skinning is enabled (Windows loads a newer version of comctl32.dll then).

Re: TextAlgin if style is Edit Field Only

Posted: 20 Jan 2011, 11:24
by Mex
OK
It works with Win 7 but not XP