Dynamically-created edit control wrong size

In an MFC dialog, I have a static control (CStatic), a checkbox (CButton), and an edit 
control (CEdit). I am dynamically creating additional controls identical to these, which 
must match in size. I have accomplished most of this by code like (shown just for the edit 
control; static and checkbox are almost identical)

CEdit newEdit,*pEdit; CRect oldRect,newRect;

// Get the size and position of the existing edit box
pEdit=(CEdit *)GetDlgItem(ID_OldEdit); pEdit->GetClientRect(&oldRect);
ScreenToClient(&oldRect); // adjust coords to relative to dialog, as rq for CreateEx

// Position the new edit box to be vSpacing below the old one
newRect=oldRect+CSize(0,vSpacing);
newEdit.CreateEx(WS_EX_CLIENTEDGE,"EDIT","",
   WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP, newRect, this, id);

The problem is that the new edit box is slightly smaller than the old one, by the size of 
the 3D border specified by WS_EX_CLIENTEDGE. The old edit box is 35 x 20 pixels, with a 
client area 31 x 16; the new one is 31 x 16 with a client area of 29 x 14. In other words, 
CreateEx has created a window smaller than the size argument it was given.

The static control and checkbox work correctly (give identically-sized controls). Anyone 
know why this code for duplicating an edit control does not work as expected?

sherNOwoodSPAM@computer.org (remove caps to get e-mail)

0
nospam4062 (39)
7/5/2004 9:46:26 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
976 Views

Similar Articles

[PageSpeed] 18

Anonymous wrote:
> In an MFC dialog, I have a static control (CStatic), a checkbox 
> (CButton), and an edit control (CEdit). I am dynamically creating 
> additional controls identical to these, which must match in size. I have 
> accomplished most of this by code like (shown just for the edit control; 
> static and checkbox are almost identical)
> 
> CEdit newEdit,*pEdit; CRect oldRect,newRect;
> 
> // Get the size and position of the existing edit box
> pEdit=(CEdit *)GetDlgItem(ID_OldEdit); pEdit->GetClientRect(&oldRect);
> ScreenToClient(&oldRect); // adjust coords to relative to dialog, as rq 
> for CreateEx
> 
> // Position the new edit box to be vSpacing below the old one
> newRect=oldRect+CSize(0,vSpacing);
> newEdit.CreateEx(WS_EX_CLIENTEDGE,"EDIT","",
>   WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP, newRect, this, id);
> 
> The problem is that the new edit box is slightly smaller than the old 
> one, by the size of the 3D border specified by WS_EX_CLIENTEDGE. The old 
> edit box is 35 x 20 pixels, with a client area 31 x 16; the new one is 
> 31 x 16 with a client area of 29 x 14. In other words, CreateEx has 
> created a window smaller than the size argument it was given.
> 
> The static control and checkbox work correctly (give identically-sized 
> controls). Anyone know why this code for duplicating an edit control 
> does not work as expected?
> 
> sherNOwoodSPAM@computer.org (remove caps to get e-mail)
> 

The size of the control should be obtained from GetWindowRect, not 
GetClientRect.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
7/5/2004 10:56:20 PM
Scott McPhillips [MVP] wrote:
 > The size of the control should be obtained from GetWindowRect, not
 > GetClientRect.

>> // Get the size and position of the existing edit box
>> pEdit=(CEdit *)GetDlgItem(ID_OldEdit); pEdit->GetClientRect(&oldRect);

Quite correct, and that's what I did--I just copied the wrong code. Using the window 
rectangle fails.

sherNOwoodSPAM@computer.org (remove caps to get e-mail)

0
nospam4062 (39)
7/6/2004 12:28:04 AM
Does the original window have the WS_EX_CLIENTEDGE style? This is assuming you have indeed
made the fix you indicated that you are not using GetClientRect, but GetWindowRect. There
is also no reason to ever use GetDlgItem in this context; create a control variable. Also,
avoid ever putting two lines of code on a single line of text., Think of semicolons as
begin valid only at the end of lines (except for possible comments).
				joe

On Mon, 05 Jul 2004 21:46:26 GMT, Anonymous <nospam@noISP.com> wrote:

>In an MFC dialog, I have a static control (CStatic), a checkbox (CButton), and an edit 
>control (CEdit). I am dynamically creating additional controls identical to these, which 
>must match in size. I have accomplished most of this by code like (shown just for the edit 
>control; static and checkbox are almost identical)
>
>CEdit newEdit,*pEdit; CRect oldRect,newRect;
>
>// Get the size and position of the existing edit box
>pEdit=(CEdit *)GetDlgItem(ID_OldEdit); pEdit->GetClientRect(&oldRect);
>ScreenToClient(&oldRect); // adjust coords to relative to dialog, as rq for CreateEx
>
>// Position the new edit box to be vSpacing below the old one
>newRect=oldRect+CSize(0,vSpacing);
>newEdit.CreateEx(WS_EX_CLIENTEDGE,"EDIT","",
>   WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP, newRect, this, id);
>
>The problem is that the new edit box is slightly smaller than the old one, by the size of 
>the 3D border specified by WS_EX_CLIENTEDGE. The old edit box is 35 x 20 pixels, with a 
>client area 31 x 16; the new one is 31 x 16 with a client area of 29 x 14. In other words, 
>CreateEx has created a window smaller than the size argument it was given.
>
>The static control and checkbox work correctly (give identically-sized controls). Anyone 
>know why this code for duplicating an edit control does not work as expected?
>
>sherNOwoodSPAM@computer.org (remove caps to get e-mail)

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
7/6/2004 3:00:50 AM
Joseph M. Newcomer wrote:

> Does the original window have the WS_EX_CLIENTEDGE style? This is assuming you have indeed
> made the fix you indicated that you are not using GetClientRect, but GetWindowRect. There
> is also no reason to ever use GetDlgItem in this context; create a control variable.

The original window was created by a dialog creation from a VS resource-editor dialog 
template, and it has the "3-D" appearance.

I did not create control variables in this instance for the original windows, because the 
dynamically-created windows are in an array, VS (ClassWizard) does not allow array-valued 
member variables, and I was too lazy to edit the code by hand. In many cases, GetDlgItem 
is cleaner, because it does not exchange all the member variables, a useful property when 
they are interdependent, so I have got in the habit of using it almost always.

My original code did use GetWindowRect; I used GetClientRect to calculate the border 
width, and copied the wrong piece of code.

> Also, avoid ever putting two lines of code on a single line of text., Think of semicolons as
> begin valid only at the end of lines (except for possible comments).

I do not agree with this often-cited coding standard, but I do not want to discuss it, as 
this is a religious issue.

sherNOwoodSPAM@computer.org (remove caps to get e-mail)

0
nospam4062 (39)
7/6/2004 5:11:47 AM
That isn't the question I asked. I asked if the control had the WS_EX_CLIENTEDGE style. If
you are creating a control, you must create it with the same styles as the one whose size
you are using as a reference.

I'm not sure what you mean by the comment "GetDlgItem is cleaner, because it does not
exchance all the member variables", since that statement is complete nonsense. Creating a
control member variable doesn't exchange anything with anything, so I see no reason this
is a concern at all. Certainly in all the years I have used control variables, I've never
encountered anything that exchanges the contents of control variables with anything else
in any way. "a useful property when they are interdependent" appears to also be a nonsense
phrase.

You should break the habit of using GetDlgItem. It is not clean, it is error-prone, and
serves very little purpose except when accessing array variables, and even then it is
dangerous.

Posting code which is nearly unreadable because of multiple-statements-per-line is not a
good way to get assistance; I had to read the code a couple times to see that this poor
style was what was being used.
					joe

On Tue, 06 Jul 2004 05:11:47 GMT, Anonymous <nospam@noISP.com> wrote:

>Joseph M. Newcomer wrote:
>
>> Does the original window have the WS_EX_CLIENTEDGE style? This is assuming you have indeed
>> made the fix you indicated that you are not using GetClientRect, but GetWindowRect. There
>> is also no reason to ever use GetDlgItem in this context; create a control variable.
>
>The original window was created by a dialog creation from a VS resource-editor dialog 
>template, and it has the "3-D" appearance.
>
>I did not create control variables in this instance for the original windows, because the 
>dynamically-created windows are in an array, VS (ClassWizard) does not allow array-valued 
>member variables, and I was too lazy to edit the code by hand. In many cases, GetDlgItem 
>is cleaner, because it does not exchange all the member variables, a useful property when 
>they are interdependent, so I have got in the habit of using it almost always.
>
>My original code did use GetWindowRect; I used GetClientRect to calculate the border 
>width, and copied the wrong piece of code.
>
>> Also, avoid ever putting two lines of code on a single line of text., Think of semicolons as
>> begin valid only at the end of lines (except for possible comments).
>
>I do not agree with this often-cited coding standard, but I do not want to discuss it, as 
>this is a religious issue.
>
>sherNOwoodSPAM@computer.org (remove caps to get e-mail)

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
7/6/2004 5:27:50 AM
Joseph M. Newcomer wrote:
>I asked if the control had the WS_EX_CLIENTEDGE style.

According to Spy++, the control created from the dialog template (the original I'm trying 
to replicate) has the following styles:

WS_TABSTOP, ES_LEFT, ES_AUTOHSCROLL
WS_EX_LEFT, WS_EX_LTRREADING, WS_EX_NOPARENTNOTIFY, WS_EX_CLIENTEDGE

sherNOwoodSPAM@computer.org (remove caps to get e-mail)

0
nospam4062 (39)
7/7/2004 6:49:56 PM
Reply:

Similar Artilces:

service calendar in MS Dynamics 4.0
Does anyone knows how we can achieve the following requirement with MSCRM 4.0 In the service calendar in MS Dynamics 4.0 you are able to create new appointments and service activities. Appointments and Service Activities which are created will be present in the Service Calendar. To see all details of such a record[Subject(default Value)] you must open it. But by moving your mouse on the concerning appointment or service activity, a text-box-view appears with primary information. With appointments the content of the following fields is displayed: 'show time as', 'subject...

dynamic resource
Hi, Anybody know how to load e.g. bitmap into resource dynamicaly? The bitmap file will be downloaded by application itself , so it has to be somehow inserted into resource and displayed. thanks What do you mean by "into resoure dynamically"? Do you want to load a ..bmp file and display it? If yes, take a look at GDI+, which is by far the easiest way to achieve this. ---------- Ajay Kalra ajaykalra@yahoo.com I misspelled this, yes I'd like to load new bitmap on the fly. But resource file looks like is static. I use ATL/MFC applicatation. "Ajay Kalra" <aja...

Dynamic sum in Chart
Hello: So I've got this pivot chart that I've created, and it's great, EXCEPT when I select different categories to show up, I want to show a SUM of the categories, not the values of each category. I would appreciate any help/advice you may have. Thank you! Michelle In the pivot table you can select different thing like count and SUM etc. If you right click in the upper left vacant square and chose field settings, then select what you want to see in your data section. Misha wrote: > Hello: > > So I've got this pivot chart that I've created, and it's great...

GP 2010 - Fabrikam
I just installed GP 2010 and the Fabrikam TWO company. When I first went to Tools>Setup>Payroll>Payroll-Additional>Prompt Print Edit Reports I was able to see and check the on/off buttons for the report option. I was expecting to then be able to (somehow) set a flag for which reports print and which report to not print. I turned on the reports and then went into Tools>Setup>Posting>Posting expecting to see some on/off checkboxes for the Prompt Print Edit Reports but there was nothing there. So I went back to the Prompt Print Edit Report window and c...

online Excel file edit
Hello, I need to enable user to edit Excel file online and save changes for the file back to server(IIS60.0) directly, could you tell me how to do it? Thanks a lot. ...

Tab seq dynamically...
I have a button which added dynamically to a property sheet. Now for setting the tab sequence with this new button, Am using SetWindowPos() method. Now tab sequence is proper. THE PROBLEM IS Through the arrow keys, I could not navigate to the last button for which I called SetWindowPos. where as through tab keys I could go to the last control. I will appreciate ur help in this. DETAILED DESCRIPTION I have three buttons (OK,Cancel, Help)on the property sheet. I added a button "Default" to the property sheet and positioned between Cancel and Help. I set the tab sequence as ...

Problems opening a Workbook created by Excel 2002
hi everyone can someone explain to me why i have problems opening an excel workboo created in excel 2002 with excel 2003? aren't the latest version b able to open files created by any lower version? also, i aske previously can i have 2 version of excel running and a kind sou answered my question but i already have my 2003 installed an running... how can i install the 2002 now? does that i have t uninstall 2003 first, then install 2002, then 2003...? because the sol given to me was to install them in chronological order... is there an other way out because by uninstalling 2003 first, i wou...

Can't edit document
My wife and I both have Windows 7 and Office 2007. We each use it to make labels on occassions. We can no longer edit our label templates. The cursor always jumps to the beginning of a doc as soon as we try to move it elsewhere. Can't highlight, can't do a thing. Both docs are in in .docx. I've tried saving in other formats, as well. If I can't find a solution, I suppose I can create the label template again, but it seems a waste of time. I'd rather have a solution and a reason for this happening to both of us at the same time on two separate machines....

Create a report showing investment commissions?
Is it possible in MS Money Premium 2006 to create a report that shows the amount of commissions charged in an investment account? My broker is indicating that commissions = X and I want to see if it's accurate. Thanks, Miles In microsoft.public.money, Miles wrote: >Is it possible in MS Money Premium 2006 to create a report that shows the >amount of commissions charged in an investment account? My broker is >indicating that commissions = X and I want to see if it's accurate. Go to the Investment Transactions report. Customize for the dates and accounts you want. Right-...

Database Size Limit for Small Business Edition
Is Exchange 2003 RTM (including SBS2003) the same as Standard Edition of 16GB limit? Or does it have a different databse limit? Yes, with SBS 2003 Exchange 2003 Service Pack 2 you can increase the limit to 75GB. See, http://www.msexchange.org/tutorials/Explaining-Database-size-limit-changes-Exchange-2003-Service-Pack-2.html -- John Oliver, Jr MCSE, MCT, CCNA Exchange MVP 2006 Microsoft Certified Partner "Tone Przyszlak" <Tone Przyszlak@discussions.microsoft.com> wrote in message news:82074267-D992-4710-80F8-EF323D78AE8C@microsoft.com... > Is Exchange 2003 RTM (inclu...

Tab Control Issue
Hi-- Can anyone help with why this code causes the subform inside of a tab control page to disappear? Forms!frmPurchaseOrder!pgCurrent.Visible = True Forms!frmPurchaseOrder.Section(acFooter).Visible = True Forms!frmPurchaseOrder!pgCurrent.SetFocus Forms!frmPurchaseOrder!pgAddEdit.Visible = False At first, I had 2 subforms inside of a main form. When a button was clicked, one form was hidden and the other visible. That was causing the subform to turn completely white and become useless. I decided to try tabs thinking this might solve the probl...

SharePoint Alternate Access Mapping to my Dynamics GP BP site
Hello, If I have posted this question in the wrong forum please let me know! I’m looking for some guidance on changing the Alternate Access Mapping for my Dynamics Business Portal site. So I can implement Single Sign On via ISA Server which is supported on one web listener. Present configuration: Default Zone: http://geneva:222 I would like to add: Internet Zone: http://dynamicsbp.proclub.com I presently have another SharePoint Collection (The Main Portal) http://geneva configured which listens on Port: 80. I tried to add the Alternate Access Mapping http://dynamicsbp.proclub.com...

dynamic charting #2
Hi I have to update a weekly spreadsheet With week numbers in column B x series and three y series percentages in G,H,I columns. Could someone please help I need these to update automatically. If someone can explain in detail I would appreciate 39 2097 2165 68 1770.7 97 96.86 118.43 40 2443.15 2201 -242.15 1548.93 97 111.00 157.73 41 2162.83 2259 96.17 1600.78 97 95.74 135.11 42 2163.08 2241 77.92 1545.1 97 96.52 140.00 43 2137.5 2271 133.5 1664.6 97 94.12 128.41 44 2160.67 2298 137.33 1455 97 94.02 148.50 Ta Brian ...

Mail Merge
Hi I am the admin on the crm 4.0 environment here. Whenever i do a mail merge through outlook or through the web client i dont get the create activites dialog box. Instead i always get a pop up saying "Opening this document will run a SQL command and data from the database will be placed into your document" When i click yes to continue , I get a pop saying mail merge can not find the data source... and then two options to remove all merge info or remove data header source.. any ideas what i could do to fix this? regards Snow White ...

Advice for creating search?
Hi I am trying to plan the best way to handle the following scenario: Table tblStories has 2 fields, StoryIDNumber and StoryNarration. E.g. 234, "Once upon a time Joe was travelling to town when he saw a poodle. He then kept walking till he reached the bakery." 235, "Many years ago, Fred found a wild elephant in his back yard. The elephant was very heavy." 288, "Mary had a Doberman dog. It chased a creature with a big gray trunk." .... ... Table tblAnimals has 4 fields. Title, Description, DangerLevel and Keywords. "Elephant", &q...

Need a method to Dynamicly change the X axis Scale on a chart. #2
I dynamically change the amount of data on a chart. This causes the X axis Scale to either to either show too few values or too many values ( a solid black line if too many). I would like a method to dynamically change the scale values in relation to the data span. Joe - Do you want to limit the number of points displayed? http://peltiertech.com/Excel/Charts/Dynamics.html http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=246 Or do you want to link the axis scales to something you calculate in the sheet? http://peltiertech.com/Excel/Zips/SwitchXYAxes.zip - Jon ----...

How do I create a double sided postcard
I am creating a graduation announcement. One side has all the details. On the other side I wanted to be able to type in my return address, so all I would have to do is address them and stamp them. How can I do this? Open the file; now do an Insert, Page. You now have a second page which is the back side of your postcard. -- Don Vancouver, USA "Meghan" <Meghan@discussions.microsoft.com> wrote in message news:EF24C43E-487B-4932-B1BD-74B7EAECF87D@microsoft.com... >I am creating a graduation announcement. One side has all the details. On > the other side I want...

Dynamically populate a drop down list
Hi, I'm trying to dynamically populate a drop down list in MS CRM (1.2) based on certain parameters. I suppose I could do it using a SQL stored procedure, but I would prefer to use standard/supported CRM customizations. Any assistance in this would be greatly appreciated. Thanks! -Dave- Dave, You can do it in 3.0 pretty easily based upon an example in the SDK... Here are some pretty pictures... http://blogs.msdn.com/midatlanticcrm/archive/2005/12/04/499868.aspx I have not tried it with 1.2, but it could probably work... Thanks Ben "Dave" <renor321@yahoo.com> wrot...

How do create a basic line chart using Excel?
I am trying to create a basic 2 dimensional line chart using the following data: X-axis Y-axis DATA DATA "Rating" "Time" "Rating" "Time" 5 02:00.0 5 02:00.0 4 02:04.7 5 02:08.6 3 02:09.5 4 02:17.2 2 02:14.2 4 02:19.1 1 02:18.9 4 02:28.0 02:23.7 4 02:28.2 02:28.4 4 02:29.2 02:33.2 4 02:33.1 02:37.9 3 02:36.9 02:42.6 3 02:41.2 02:47.4 3 02:42.1 02:52.1 3 02:44.2 02:56.8 3 02:48.8 03:01.6 3 02:48.9 03:06.3 3 02:50.6 03:11.1 3 03:00.2 03:15.8 3 03:02.9 03:20.5 3 03:04.9 03:25.3 3 03:05.7 03:30.0 ...

Create an SMTP connector that uses authentication to 'smart host'
Let me just say this right out of the box; there's a lot of things in 2003 that seem to really suck compared to 2000. I just spent hours trying to delete all messages in the outbound smtp queue because there is no longer an option to just click on the 'queue' folder and select 'delete all', you have to go domain by domain searching for files and deleting them individually etc. LAME. I finally figured out a way to make them all end up in the same location so that if someone sends another 3 meg email to a thousand people, I can get them all in one shot, but I can't use it...

CRM Integration with MBS/Dynamics products
Hi, Anyone know anything about the integration between CRM 3.0 and ...say.... Dynamix AX/Axapta? I'm thinking sharing of customer data and such.... Jeppe Jespersen Denmark There is nothing available yet. You would need to build it. -- Matt Parks MVP - Microsoft CRM "Jeppe Jespersen" <jdj curly jdj dot dk> wrote in message news:OAfVImWLGHA.3276@TK2MSFTNGP09.phx.gbl... Hi, Anyone know anything about the integration between CRM 3.0 and ...say.... Dynamix AX/Axapta? I'm thinking sharing of customer data and such.... Jeppe Jespersen Denmark ...

Limits to file size for Excel 2000
Hi All Is there a limit size to a file that Excel 2000 can open and save as we have several clients that are having issues with a file that is over 300MB. Thanks Hi Von! Take a look at: Charles Williams: http://www.decisionmodels.com/memlimitsc.htm -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. ...

Office beta 2011 installer wizard in 10.5.7 shows "Wrong OS version. This software needs Mac OS X 10.4.9 or later"
Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Office beta 2011 installer wizard in 10.5.7 shows &quot;Wrong OS version. This software needs Mac OS X 10.4.9 or later&quot; <br> Hi everyone. As the title says the installer wizard shows: <br> &nbsp;&quot;Wrong OS version. This software needs Mac OS X 10.4.9 or later&quot; <br> <a href="http://img163.imageshack.us/img163/3857/errorinstalaroffice2011.jpg">http://img163.imageshack.us/img163/3857/errorinstalaroffice2011.jpg</a> <br><br>My computer has hardwar...

Dynamics GP 10 and Dynamics AX 4.0
just a half year ago, our company has started to work with Dynamics AX 4.0. Now i am doing some programming in X++ and almost customizing reports. Accidently, i stumpled on Dynamics GP 10.0 and i am wondering what s the difference between AX and GP? What stands GP for? Maybe GP is to replace AX, and our company backs to wrong horse? Does GP 10 contains AX 4.0? I have learnt lot of X++ programming, would it be possible to using X++ in the GT 10 field, too? Great Plains (GP) is another ERP system that Microsoft acquired a few years ago when it acquired the company of the same name. GP ...

Can't open XLS file I created
Window XP Sp2 - MS Ofc 2000 / Excel I created a list in Excel by doing a copy/past from a web site. (List of name, address, phone, website) I did a save when done and then tried to disable all the hyperlinks on the page. Followed directions I got off the web, F11/Macro to remove hyperlinks. I closed and saved and then when I tried to re-open it but got the following error msg: 'The workbook contains a type of Macro (MS Excel ver. 4 macro) that cannot be disabled nor signed. Therefore, this workbook cannot be opened under High Security Level.' This is all Greek to me, please help s...