Hey guys. I'm creating these CEdits, placing them within their parent dialog. I do this by adding offsets from the parent dialog's rect. The only problem is the CEdits end up being offset by a much larger amount than I set them to be. For example, this->GetWindowRect(&rect) sets rect as rect = {top=275 bottom=654 left=393 right=869}. But further down when I test the value of the first CEdit's (at_edit) rect, it's rect = {top=576 bottom=588 left=794 right=834}, which is not correct.
You're mixing up window coordinates and client coordinates I believe. GetWindowRect returns the rect relative to the screen. The rect you pass into create is relative to the parent's client area. So when you say, rect.left + 8, you're specifying the left coordinate to be 401 pixels to the right of the left side of the parent dialog. If you want the edit to be offset by 8, just specify 8, not rect.left+ 8.
Last edited by GCDEF; February 17th, 2009 at 09:13 PM.
One other question... apart from left justification, how would I make the CEdit up the top look like the editor-placed one below it? I gave the manually created on these styles:
One other question... apart from left justification, how would I make the CEdit up the top look like the editor-placed one below it? I gave the manually created on these styles:
I continue to faill understanding why you are creating controls instead letting OS use dialog template to do it for you.
If you want to resize controls at the run time it would be less difficult than your approach.
If you insert edit controls using dialog editor, client edge is implied.
When you attach window handle to any MFC control using Create member, passing WS_BORDER style, control will be created with this style, not WS_EX_CLIENTEDGE.
Create control without WS_BORDER and modify extended style adding WS_EX_CLIENTEDGE or use CreateWindowEx.
Furthermore: your homemade control is using system font (default). Template controls use font used by template (the same font dialog is using).
In order to display the same font you will have to assign one using SetFont and passing a pointer to a dialog font or creating control’s own font.
As for using DoDataExchange for validation, you can still do it, providing homemade control has the same ID and you either replace variable name inserted by wizard, with a name you are using to call Create.
I still fail understanding why you are creating controls instead letting OS use dialog template to do it for you.
Is it an exercise?
There are only 10 types of people in the world: Those who understand binary and those who do not.
I continue to faill understanding why you are creating controls instead letting OS use dialog template to do it for you.
If you want to resize controls at the run time it would be less difficult than your approach.
If you insert edit controls using dialog editor, client edge is implied.
When you attach window handle to any MFC control using Create member, passing WS_BORDER style, control will be created with this style, not WS_EX_CLIENTEDGE.
Create control without WS_BORDER and modify extended style adding WS_EX_CLIENTEDGE or use CreateWindowEx.
Furthermore: your homemade control is using system font (default). Template controls use font used by template (the same font dialog is using).
In order to display the same font you will have to assign one using SetFont and passing a pointer to a dialog font or creating control’s own font.
As for using DoDataExchange for validation, you can still do it, providing homemade control has the same ID and you either replace variable name inserted by wizard, with a name you are using to call Create.
I still fail understanding why you are creating controls instead letting OS use dialog template to do it for you.
Is it an exercise?
I'm creating them myself because otherwise I don't know how to change the type to my derived edit class.
Hmmmm, why you did not mention it in your first post?
In VS 6.0 after deriving class from CEdit (or any other window control) use class wizard to insert variable. Pick your class from the "Variable Type" drop box.
In later versions of the VS, or if you want to change type of variable after inserting it, simply replace class inserted by wizard with your derived class. Make sure appropriate headers are available.
That is it.
Last edited by JohnCz; February 18th, 2009 at 09:26 PM.
Reason: Typo
There are only 10 types of people in the world: Those who understand binary and those who do not.
But if you add a variable via the add variable wizard, it isn't placed onto the visual editor. I've already got the CEdits working fine though, so it doesn't matter. Cheers for the font advice as well.
I'm creating them myself because otherwise I don't know how to change the type to my derived edit class.
I told you days ago. In the header file change the control variable type from CEdit to your CEdit derived class. That's all you have to do.
If that's the reason, I would strongly and I mean strongly recommend throwing away this code and doing it properly. It'll be easier for you to maintain, whoever works on it after you will be happier, it's really easy to do, and you can't jump through all these hoops every time you need to use a control class you've created yourself.
One thing about being a good programmer is knowing when you're headed down the wrong path and not creating a convoluted workaround because you're stuck on a simple problem.
Last edited by GCDEF; February 18th, 2009 at 08:21 AM.
But if you add a variable via the add variable wizard, it isn't placed onto the visual editor. I've already got the CEdits working fine though, so it doesn't matter. Cheers for the font advice as well.
Pick CEdit and change it manually. There's nothing to id.
Guys... I know how to change the type of a variable. My problem has always been what I said above. That if I add the controls via the visual editor, they aren't created as instances and so I didn't know how to change their type. John, you said it yourself:
Once dialog resource is saved, all information is written to a resource file as ASCII script.
I told you days ago. In the header file change the control variable type from CEdit to your CEdit derived class. That's all you have to do.
If that's the reason, I would strongly and I mean strongly recommend throwing away this code and doing it properly. It'll be easier for you to maintain, whoever works on it after you will be happier, it's really easy to do, and you can't jump through all these hoops every time you need to use a control class you've created yourself.
One thing about being a good programmer is knowing when you're headed down the wrong path and not creating a convoluted workaround because you're stuck on a simple problem.
That's not what I meant at all. I meant:
I'm creating them myself because otherwise, if I place them visually, I don't know how to change the type to my derived edit class.
I don't know how to change their type if they were placed visually with the editor. When I place them with the editor, there are no instances created that I can edit:
As you realize now, once control is placed in a dialog template you do not have to create it.
So, I have two options. 1) Add them via the add variable wizard. They're created as instances and I can change their type (I always understood how do to that). But if I do it that way, then I have to position them manually... which is harder.
2) Create them with the visual editor by placing them on the dialog. Easier to do but there is no way to change their type as there are no instances created and I have not yet found a way to change their type via properties or anything else like that.
Last edited by Mybowlcut; February 19th, 2009 at 12:15 AM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.