Units of Measure in Edit Controls

Is there a good way for me to format data in an edit control by that
control's unit of measure?  For example:

CString data = foo;
FormatUnits(data, IDC_VALUE_CTL);
c_value.SetWindowText(data);

In FormatUnits(), of course, I have a basic problem: how do I determine
how to format "data" by knowing my control ID?  In the COM world, I'm
used to creating and storing a custom property that I can access later.
Is there a way to do this with MFC?

Or is there a "best practices" way of doing this and I'm barking up the
wrong tree?

0
dmccarty (45)
12/27/2004 9:50:04 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
454 Views

Similar Articles

[PageSpeed] 45

Seeing how no one has replied yet,* maybe I should be more specific
about my app.

I have an app that I'm moving to WinCE (4.2) with MFC and there are a
number of complicated dialogs--about 30--that each contain a number of
various fields.  In each dialog there are a lot of different units of
measure in use.  (e.g., 5.08 metres, 185 PSI, 1.8 in, 200 mm, 1.2 ms, 2
s, etc.).

Instead of maintaining a separate chunk of code in each dialog like
this...
value.Format("%d ms", m_value1)
c_value1.SetWindowText(value)
value.Format("%d ms", m_value2)
c_value2.SetWindowText(value)
....
....ad infinitum

....I thought that I might be able to come up with a custom property or
number for each field that defines its units of measure and store that
value along with the field.

Could I set the field's label's caption to something like "%d ms" and
store it as the format as the dialog init'd, then use that value to
format the field later?  Alternatively, could I use a global handler
and use the unique field ID (I will maintain nightly vigil over the
resource file to make sure they are unique) to retrieve the field's
formatting?  Alternatively, could I just shoot my foot off for coming
up with such silly ideas?  I don't know, are they silly?

I guess my real problem is that I'm not very familiar with MFC.  I'm
sure that this must be an easy problem, but I'm just not bright enough
to see the easy solution.  I've spent some time running Google and
Usenet searches but haven't come up with anything.  There are only n
types of units of measure, so there must be some way to store which
type of n belongs to each field, but I just don't see how to do it.

Thanks in advance for any help,
Dan.

* Whenever I post something and don't get any replies, I like to
convince myself that my question was just too specific and advanced for
everybody.  But it usually turns out that I was just so far off the
deep end that everyone ignored me.

0
dmccarty (45)
12/28/2004 8:07:55 PM
>Instead of maintaining a separate chunk of code in each dialog like
>this...
>value.Format("%d ms", m_value1)
>c_value1.SetWindowText(value)
>value.Format("%d ms", m_value2)
>c_value2.SetWindowText(value)
>...
>...ad infinitum
>
>...I thought that I might be able to come up with a custom property or
>number for each field that defines its units of measure and store that
>value along with the field.
>
>Could I set the field's label's caption to something like "%d ms" and
>store it as the format as the dialog init'd, then use that value to
>format the field later?

I guess you could.

This isn't something general that MFC will help you with - it's your
application design, you can solve it however you feel is most
appropriate.

>Alternatively, could I use a global handler
>and use the unique field ID (I will maintain nightly vigil over the
>resource file to make sure they are unique) to retrieve the field's
>formatting?

Since control IDs only need to be unique in a dialog this seems an
unnecessary constraint to apply. Why not have a table per-dialog?

>There are only n
>types of units of measure, so there must be some way to store which
>type of n belongs to each field, but I just don't see how to do it.

I'd probably define a structure that contains the control ID and an
enumerated value for the measurement type. In each dialog I'd have an
array of these and an array of values for each control so you can loop
through the array elements and tie the control ID to a measurement
type and a value.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
12/28/2004 8:26:50 PM
Reply:

Similar Artilces:

Windows Media Player Control 6.4.09.1130, VC7.0++ MFC, Unknow error when playing .asx file
Hello, I have a VC7.0 MFC application which was built using VS2003. In makes use of the Windows Media Player Control 6.4.09.1130, I give it a url to a .asx file which in turn has a reference to a MMS:// location on the same server. If I directly input the url containing the location to the .asx file into my web browser then media player 9.0 launches and is able to successfully play my media file. If however I try to launch the same url containing the .asx file from within my application which makes use of Windows Media Player Control 6.4.09.1130, I then get "An unknown error has...

Sorting the list control from callback function
8/28/2006 2:44 AM Hi, I am using a callback function for sorting the list control in report view. When user clicks on the header column then I call this function here is the code : void snip_CListCtrl_SortItems() { // The pointer to my list view control. extern CListCtrl* pmyListCtrl; // Sort the list view items using my callback procedure. pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl); } static int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { // lParamSort contains a pointer to the list view control. CListCtrl* pListCtrl = (CListCtrl*) lP...

turning off single click editing
Hi all Using Outlook 2002, I'm pretty sure there's a way to turn off single-click editing - in the Contacts window, say, but I'm darned if I can remember. Any ideas? strawberry wrote: > Hi all > > Using Outlook 2002, I'm pretty sure there's a way to turn off > single-click editing - in the Contacts window, say, but I'm darned if I > can remember. > > Any ideas? Well, in case anyone else ever needs to know: View --> Current View... --> Customize Current View --> Other Settings --> Rows --> allow in-cell editing Hooray! ...

need to edit/delete attendance trx in HR standalone
Clients who run HR as a standalone need to be able to edit or delete attendance transactions. With the new attendance funtionality, HR only users can't delete or edit a transactions, they have to enter another transaction if they need to make a correction. I have a ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader an...

teams and business units 02-21-06
I created a team in CRM 3 and would like to delete it, but cannot see how. Is this possible? Saira No, you cannot delete teams. -- Matt Parks MVP - Microsoft CRM "Saira" <Saira@Bayonet.com> wrote in message news:OipKOFwNGHA.208@tk2msftngp13.phx.gbl... I created a team in CRM 3 and would like to delete it, but cannot see how. Is this possible? Saira Thanks for the reply Matt So what do I do with teams that we create for ad-hoc projects? Do they have to hang around in perpetua, or is there a way that i can delete them out of the database directly? Saira "M...

Transaction is being edited
We get the message a lot in Great Plains (and we understand why) What I don't understand if if you search for the above message in TechKNowledge you get no responses. I have a PO that we get the above message on and no on is actually editing this PO. I need to somehow correct this so we can edit the PO. I have looked in the Dex_lock and Dex_session tables and do not see anything that refers to the purchase order. Does someone know how to correct a PO that is being edited but is not really being edited? -- Doug Doug, I remember getting this error a lot in previous versions o...

Subform Control
Hi, I have designed a database for members of our organisation with tables, queries, forms, subforms, graphs etc. Our members are independent and we have no say over their IT systems and so i need the database to work on Access 2000, 2003, 2007. I wrote the original in Access 2000 (lowest common denominator) and i am now testing it in 2007 and 2003 to get them to work. After a few issues, i now have it working fine in 2007 but have a really strange issue in 2003. I have a main form (frmCompany) with a subform (frmStaff), they link together and show the right staff with the right comp...

2007 Control Reply Format Style
This is a multi-part message in MIME format. ------=_NextPart_000_00EB_01C8E415.D28CFB40 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Is there any way to control reply format without having to select the = reply text and apply a quickstyle. I tried NormalEmail.dotm but it = changes Normal.dotm and the incoming email message. I have HTML turned = on. ------=_NextPart_000_00EB_01C8E415.D28CFB40 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//...

SQL Server Edition
Hi Experts I have serveral SQL Server and many instances under each server. I have problem in finding what are the editions of each instance. I know the following techs 1. SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition') (T-SQL and ADO) 2. select @@VERSION (T-SQL and ADO) 3. Using freeware MAP 4. reading registry 5. Looking at the \LOG\errolog file I have limitation is using this in our env. I am particularly expecting a way to read from WMI. Can anyone forward me the script to read server na...

Editing Lookup Formula Error
I've adapted the following formula from "How to lookup a value..." from Office Online: =IF(ISERROR(INDEX($A$2:$F$1007,SMALL(IF($B$2:$F$1007=G$1,ROW($A$2:$A$1007)),ROW(1:1)),1)),"",INDEX($A$2:$F$1007,SMALL(IF($B$2:$F$1007=G$1,ROW($A$2:$A$1007)),ROW(1:1)),1)) date no1 no2 no3 no4 no5 1 6/7/2008 2 4 11 15 28 6/24/08 6/10/2008 8 13 14 23 30 6/28/08 6/14/2008 5 13 24 35 45 6/17/2008 10 12 18 30 36 6/21/2008 1 2 5 23 45 6/24/2008 1 4 37 45 46 However, the date that is returned is from the row BELOW the I would like. In ...

Adding variables to control elements...HOW???
HI, I made MFC Application whitl user interface. There are somo combo boxes, check boxes, command buttons. I want to add variables to this ellements? but when I pressing right mouse button on some element (for example, command button) the item Add Variable is not accessible. What should I do??? Thanks in advance! Timur. I presume, you have created a dailog based application, and placed some controls on it. To add members corresponding to the controls, you placed, 1. Goto Class wizard ( Ctl +W ) 2. It will prompt you to create a new dialog class for the dialog resource you created. So cre...

Unit Accounts in POP
Customer wants to be able to enter unit accounts in Purchasing Distribution Entry window (Transactions >> Purchasing >> Receivings Transaction Entry >> enter or select a shipment or shipment/invoice receipt >> Distributions button). ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click &quo...

How to edit a message header on email received?
I would like to be able to edit an email message header that I receive in Outlook to make it more meaningful to me. Lobelia <Lobelia@discussions.microsoft.com> wrote: > I would like to be able to edit an email message header that I > receive in Outlook to make it more meaningful to me. What header do you wish to edit? -- Brian Tillman ...

Lebans tooltip control 10-25-07
I am trying to use the tooltip control on a form with a tab control, on which are the other controls I want to show information for. On controls that are outside the tab control, it works fine; on controls inside the tab control, the tooltip shows on text boxes only when they have the focus, and on check boxes not at all. I've tried every naming scheme for controls I can think of, without any luck. Anybody have any ideas about this??? Is it the same problem as using a subform???? -- Jack Walsh ...

Control Names and InStr
On a continuous form that sorts columns when user clicks the column headers. I also have some embedded gif icons next to each column header caption that display ascending and descending order and named them with the convention of icon_up_TheControlName and icon_down_TheControlName. I also have an embedded gif icon called "cmdRemove" on the form. If I run my sub in the "USAGE" section below, my sub FlipSortImages iterates through the form and correctly changes the icon_up_firstName control visible property to true and sets all of the other control's visible proper...

Loop through a Control
How do I loop in a specific control using For? The name of my Control is called "Result" I am trying the following with no luck, maybe because it is the end of the day? Dim counter As Integer counter = 0 Dim ctl As Control For Each ctl In Me!Result If IsNull(ctl) Then counter = counter + 1 Next ctl If counter > 0 Then MyText = MsgBox("Counters: " & counter, vbCritical, "Test") End If Thanks in advance Define "loop through a specific control".... it's not clear from your post what you want to achieve. -- Ken Snell <MS ACCE...

how to edit two powerpoint files in separate windows?
I have XP and Office Power Point 2003. The Window/Arrange All or Select Tools | Options, select the View tab and tick 'Windows in Taskbar' tricks are not exactly what i'm looking for. Best would be if I could open two Powerpoint applications at the same time in different windows. How to do it? Window, new window. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "rk" <rk@discussions.microsoft.com> wrote in message news:EF014883-1B3C-40C2-A776-724765C6BE1D@microsoft.com... >I have XP and Office Powe...

Hebrew Text on controls
Hello, I am using controls (VC 6.0), such as form. I want to change the caption of the form of something including Hebrew text. I see on design time that everything is OK (I have changed the form font to : david, which can be seen as Hebrew), and when I run the program, I see that Hebrew is not displayable (it display gurbish). Thanks :) This should have worked, if that font has Hebrew characters in positions 00..FF. When you say you changed the form font, do you mean at design time? Are you sure this is the font actually in effect at the time the control is running? Try this in your O...

Pull info from access to excel userfom and edit an existing record
Hi All, I have created a system which consists of a Userform in excell and database in Access. Rite now I have the following features in the form: - Users can insert data into the database through the userform by clicking a button "Enter" I want to add two more features: 1. I want users to pull info from the database into userform fields Eg: if user enters "User ID: " fields like "Name" "Phone" "Fax" should be pulled from access into respective userform fields. 2. Once the user pulls these data from access, the user sh...

Gain control over Microsoft RMS
TILE =96 The Item List Editor is a lightweight utility that helps the RMS users in many ways: - Single-click editing of RMS items - Edit an entire field-range - Hierarchical =91need-based=92 access - Resize and optimize images <b>TILE allows you to update hundreds of records in a few seconds</b> For further details on TILE, please visit: http://www.24sevencart.com/tile.= htm ...

What is the application control menu
...

Cant's Edit /or Delete Recurring Appts.
Since installing a new computer for one of our users, and loading all of the software just as it has always been done, any message with a .eml attachment has the attachment blocked. I do not recall seeing .eml in the Level 1 list (though perhaps it is now). Still, no other users at this location experience this problem. There were no changes made to the users profile, etc. Just logged on with a new computer that has a different name. The exchange email store is used vs. ..pst files. They are running Outlook XP on Exchange 2000. If you have suggestions they will be greatly apprecia...

Access 2000 Controls Wizard Not Working...
Hi all, I am currently trying to learn to use access 2000 to create simple databases. Unfortunately the Control Wizard has stopped working and I am unable to get it working again. I have clicked the Control Wizard button on the tool bar, but when I place a control (button, combo box, etc. etc.) it does not come up with the wizard screen. It just places the control object onto the form. I have tried uninstalling and reinstalling bu the problem persists. I am using Windows XP (SP3) and Office 2000. Hi Rob, > I am using Windows XP (SP3) and Office 2000. First, make su...

RICHEDIT / ActiveX control
I'm desparately trying to write an implementation of a Rich Text Box (RICHEDIT control) to use in an application but I think I will feel like I'm trying to cut down a forest with a pair of scissors if I write the whole application in C++, so I'm trying to create an MFC ActiveX control to use in ..NET, and when I do - it pops up a nice little dialog box entitled "Application settings" saying "What type of control do you want to base your new MFC ActiveX control on?" Aaaah!! nice!! methinks. But alas! I find that the RICHEDIT control isn't in the list! W...

password controlled files
Background - A colleague of mine died and his wife is trying to recover files in Excel for his Tax etc (in Switzerland) - she i saverage user capable - he password protected all his files and she does not know how to proceed. Request - any advice on procedures, contacts or services that would help her or a company representative in Switzerland to open these files and get data to a non protected version so probate can be processed. i am deliberately not asking for detailed answers for security reasons - if there is a simple procedure please post back to me to be followed up outside o...