Solved

ws_ex_right in a text box (VC++ program)

Posted on 1998-11-10
4
624 Views
Last Modified: 2013-12-03
I am writing a program in VC++ that contains a text box. I wish to visually differentiate data entry in the box from data display by having data entry left justified and data display right justified.

I have tried to use the ModifyStyleEx() function with the WS_EX_LEFT and WS_EX_RIGHT values but all I get is a success status returned - the text is unaltered.

1) Is there something else I need to do?
2) Is there a better way to achieve this effect?

Thanks
0
Comment
Question by:mackayd
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1415966
Use ES_LEFT and ES_RIGHT instead. And note ES_RIGHT right-aligns text in a multiline edit control on Windows 95 and Windows NT 4.0.
 

0
 

Author Comment

by:mackayd
ID: 1415967
I believe that this is on the right track but...

I have tried this with ModifyStyle and ModifyStyleEx (which I know is probably the wrong one) but the effect is the same - I get a success status but no change in the display. It doesn't matter if the text box is set to single or multiline.

Any further ideas?

Thanks

Don
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 100 total points
ID: 1415968
Here is the article from MS knowledge base

SAMPLE: Changing Text Alignment in an Edit Control Dynamiclly

PSS ID Number: Q66942
-------------------------------------------------------------------------
The information in this article applies to:

 - Microsoft Windows Software Development Kit (SDK) versions 3.0 and 3.1

 - Microsoft Win32 Application Programming Interface (API) included with:

    - Microsoft Windows NT versions 3.5 and 3.51
    - Microsoft Windows 95 version 4.0
-------------------------------------------------------------------------

SUMMARY
=======


A Microsoft Windows edit control aligns its contents to the left or right
margins, or centers its contents, depending on the window style of the
control. The control styles ES_LEFT, ES_CENTER, and ES_RIGHT specify left-,
center-, and right-alignment, respectively.

Only multiline edit controls can be right-aligned or centered. Single-line
edit controls are always left-aligned, regardless of the control style
given.

Windows does not support altering the alignment style of a multiline edit

control after it has been created. However, there are two methods that you
can use to cause a multiline edit control in a dialog box to appear to
change alignment. Note that in each of these methods, the dialog box that
contains the control must be created with the DS_LOCALEDIT style.

MORE INFORMATION
================

The first method applies to all platforms. The second method does not apply
to Windows 95. Under Windows 95, EM_SETHANDlE and EM_GETHANDLE are not

supported. For more information, please see the following articles in the
Microsoft Knowledge Base:

   ARTICLE-ID: Q130759
   TITLE     : EM_SETHANDLE and EM_GETHANDLE Messages Not Supported

Method 1
--------

Create three controls: one left-aligned, one centered, and one right-
aligned. Each has the same dimensions and position in the dialog box, but
only one is initially made visible.

When the alignment is to change, call ShowWindow() to hide the visible

control and to make one of the other controls visible.

To keep the text identical in all three controls, use the EM_GETHANDLE and
EM_SETHANDLE messages to share the same memory among all three controls.

Method 2
--------

Initially create a single control. When the text alignment is to change,
retrieve location, size, and style bits for the existing edit control.
Create a new control with the same size and in the same location, but
change the style bits to reflect the new alignment.


Send the EM_GETHANDLE to each control to retrieve a handle to the memory
that stores the contents. Send an EM_SETHANDLE to each control to exchange
the memory used by each. Finally, destroy the original control.

There is a sample application named EDALIGN in the Microsoft Software
Library that demonstrates each of these methods. Note, however, that this
sample is a Windows 3.1 sample only.

Download EDALIGN.EXE, a self-extracting file, from the Microsoft Software

Library (MSL) on the following services:

 - Microsoft Download Service (MSDL)
      Dial (206) 936-6735 to connect to MSDL
      Download EDALIGN.EXE

 - Internet (anonymous FTP)
      ftp ftp.microsoft.com
      Change to the \SOFTLIB\MSLFILES directory
      Get EDALIGN.EXE

Additional reference words: 3.00 3.10 3.50 4.00 95 EDALIGN.EXE
KBCategory: kbui kbfile
KBSubcategory: UsrCtl


0
 

Author Comment

by:mackayd
ID: 1415969
Sigh - thanks for the information. I had searched the knowledgebase but I was looking for the WS_EX_RIGHT keyword so I missed this one.

Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now