|
For a technical drafting program, i need to draw truetype fonts with total control on their height : for example i want a text of exactly 10mm high.
The problem is in interpretation of height; for truetype fonts, this height is made of 3
parts : Descent (part under the baseline), Ascent (part over the baseline), InternalLeading (some space above the character). All these values are returned by
pDC->GetTextMetrics() when you have selected a font in the pDC.
In my case the height includes only the ascent part : when i say i want a font 10 mm high, it means a font whose characters above the baseline (such as digits) will be 10 mm high. This convention is used by programs such as Autocad, MicroStation, ...
For creating a CFont object, you have to fill a LOGFONT struct with the properties of the font, such as font name, height, weight, ... But as said before, the height here include descent + ascent + leading. Here is how i try to get what i want :
CFont *pOldFont, newfont;<br />
TEXTMETRIC Metrics;<br />
LOGFONT lf;<br />
memset(&lf, 0, sizeof(LOGFONT));<br />
strcpy(lf.lfFaceName, "Arial");<br />
lf.lfHeight = - (long)FontSizeInPixels;
<br />
...
newfont.CreateFontIndirect(&lf);<br />
pOldFont = pDC->SelectObject(&newfont);<br />
pDC->GetTextMetrics(&Metrics);
<br />
<br />
lf.lfHeight = -(long) FontSizeInPixels * (FontSizeInPixels / (Metrics.tmAscent - Metrics.tmInternalLeading));<br />
<br />
<br />
<br />
newfont.Detach();<br />
newfont.DeleteObject();<br />
newfont.CreateFontIndirect(&lf);
pDC->SelectObject(&newfont);<br />
pDC->GetTextMetrics(&Metrics);<br />
ASSERT(fabs(Metrics.tmAscent - Metrics.tmInternalLeading - FontSizeInPixels) < 2);<br />
Problem : although the ASSERT above is ok for all the fonts i tried, the resulting height on screen is near the required height but there is still an error up to 20 %; for a same specified height, some fonts are smaller, some are bigger.
JPG
|
|
|
|
|
Hi,
i have a MFC Dialog with a CPropertySheet in it. The CPropertySheet is made of 3 CPropertyPages, and one the these Pages holds a button, which, if pressed shall activate another CPropertyPage. Until now, i realized it in a very ugly way. I have stored the pointers of the CPropertySheet and the Page ,which should be activted, at OnInitDialog(). But there must be an easier way to do this. I need this pointers in a functionen which depends to that CPropertyPage, holding the Button. Does there a function extist, which can bring me the pointer of the CPropertySheet?
Thanks in advance!
|
|
|
|
|
CPropertySheet* pSheet = (CPropertySheet*)GetParent();
ASSERT_KINDOF(CPropertySheet, pSheet);
Then pSheet will be having the Ans for ur query
Thanx
TAKE CARE
|
|
|
|
|
Hi all,
Can anybody know how to restrict to type fixed number of characters in the CEdit control.
Thanks.
The Phantom.
|
|
|
|
|
open Class Wizard and assign a CString variable for your edit and you will see "Maximum characters" in the lower part of the Class Wizard. Set there how many characters your CString wants to have.(same for int, long...)
|
|
|
|
|
if u want to assign a CEdit ctrl as the data member to the Edit Ctrl then u can call the function-->>
EditCtrl.SetLimitText(VALUE_of_memeber_u_want );
i hope this solve ur query
Thanx
TAKE CARE
|
|
|
|
|
Hmmm.... is there an analgous way to restrict what is types? For example, suppose I only want to allow alphanumeric english letters in the editbox.... Or does that require subclassing?
|
|
|
|
|
Use the CEdit::SetLimitText() . You can use DDX for this but it's better to restrict the text length as you are typing rather than wait until the OK button has been clicked (i.e., validating in the OnOK() handler is too little too late).
|
|
|
|
|
Hi!
I am wondering how I can copy files in the current exe folder to a folder like C:\files\ which doesnt exist!
Thank you for your future answers!
Well... I am a beginner ...
|
|
|
|
|
You can use the CreateDirectory function to create your target directory, followed by CopyFile to copy the files.
|
|
|
|
|
Or you can use the SHFileOperation function (which also supports recursive copying) to copy. See the following MSDN page[^] for more detailed information.
|
|
|
|
|
Hello guys,
I want to generate Ctrl-Alt-Del key sequence programmatically.
I have searched a lot on net but don't get any solution.
I have tried to fill keyboard buffer with 'keybd_event()' function. But it is also not working. It seems that it fills application's key buffer.
Anyway......can anybody help me to solve this problem ?
Thanking You,
C.R.Naik
|
|
|
|
|
It's not an easy one to solve. That key combination is special. When you press the Ctrl+Alt+Del keys on the keyboard, the keyboard driver is detecting that and passing the instructions on to the OS, rather than any application(s). Trying to stuff the keyboard buffer does not get "low enough" in the hierarchy.
These two articles don't directly answer your question, but they might help you get started:
http://www.codeproject.com/useritems/preventclose.asp
http://www.codeproject.com/useritems/GINA_SPY.asp
|
|
|
|
|
Hi,
how are the big buttons done in the add/remove programs on XP?
they look great and i would like to use them.
any ideas how to do something like it or has anyone done it?
what would you call it? just buttons? listbar?
thx
|
|
|
|
|
According to Spy++, the buttons are part of the DirectUI window classes. I've not found any good information on this stuff sadly. (Probably more undocumented API's)
However you can easily simulate the effect using
http://www.codeproject.com/buttonctrl/cbuttonst.asp[^]
or
http://www.codeproject.com/buttonctrl/cxpstylebuttonst.asp
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
Hi,
can i use the new VS. Net IDE to write and compile my old mfc42 code without converting it to mfc7??
where and what do i have to setup?
and of course i still want to write mfc7 code as well... would there be a way to choose the settings on startup?
thanks guys
|
|
|
|
|
That's just my experience. Worked fine though:
1. Have parallel to .NET 2003 IDE -- VC6 installation;
2. Created simple MFC project (Dialog);
3. Project Settings/C/C++/Preprocessor/Ignore Standard Include Path - set to Yes;
4. Project Settings/C/C++/General/Additional Include Dirs - put the same that I have in VC6/Tools/Options/Directories/Include files and in the same order;
5. Project Settings/Linker/Additional Library Directories - put the same as I have in VC6 VC6/Tools/Options/Directories/Library Files and in the same order;
6. For Debug configuration: Disable Basic Runtime Check: Debug/Project Settings/C/C++/Code Generation/Basic Runtime Check/Set to Default;
7. For Release configuration: Disable Buffer Security Check: Release/Project Settings/C/C++/Code Generation/Buffer Security Check/Set to No;
8. If you are using CRT with floating point you may get:
LNK2001: unresolved external symbol __ftol2
To fix that add the following switch to C command line: /QIfist
9. If you are using C++ Exception Handling (/EHsc) you may get the following error at Link stage (usualy in Release):
LNK2019: unresolved external symbol __SEH_prolog referenced in function...
To fix that add sehprolg.obj at the link stage (Link/Additional Dependencies).
You can find it in latest MSDN Platform Microsoft SDK Lib subdir.
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
I'm trying to use a static const data member in a function from a different class as follows:
class A
{
public:
static const int m_iMaxClmTextSize;
};
const int CClmListCtrl::m_iMaxClmTextSize = 10000;
#include "A.h"
void B::MyFunc()
{
int MyArr[CClmListCtrl::m_iMaxClmTextSize];
}
And get these errors:
B.cpp(178) : error C2057: expected constant expression
B.cpp(178) : error C2466: cannot allocate an array of constant size 0
B.cpp(178) : error C2133: 'MyArr' : unknown size
According to Lipmann/Lajoie on Pg 645 this should be ok. Mind you there example uses a global C style function for my B::MyFunc() but I can't see that that should matter. Any thoughts?
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
I bet it's due to how C++ treats const s at file scope. IIRC (and this is a fine technical point that I may be misremembering) a const at file scope has internal (ie static) linkage and as such, can't be used as a template parameter, nor used in other translation units where a constant is required.
You can probably fix this by doing:
class A
{
public:
enum { m_iMaxClmTextSize = 10000 };
};
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Michael Dunn wrote:
I bet it's due to how C++ treats consts at file scope. IIRC (and this is a fine technical point that I may be misremembering) a const at file scope has internal (ie static) linkage and as such, can't be used as a template parameter, nor used in other translation units where a constant is required.
Yes you maybe right about file scope, but I couldn't see that mentioned in my ref. book. I did try adding: extern const int A:m_iMaxClmTextSize; in B.cpp but the compiler didn't like that either.
Thanks for enum idea. Sort of overkill, but should work fine.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
According to your example, the m_iMaxClmTextSize data member is declared in class A, therefore definition must be:
// In A.cpp
const int A::m_iMaxClmTextSize = 10000;
and the usage
// In B.cpp
#include "A.h"
void B::MyFunc()
{
int MyArr[A::m_iMaxClmTextSize]; // Will compile
}
Serge
|
|
|
|
|
My mistake in the code sample. Where you see CClmListCtrl, it should have been A, which agrees with your post. CClmListCtrl is the real name of the class.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
ActiveX keeps running after closing IE ?
Hi, all:
When browsing a web page which contains a CAB incluing DLLs and INF, the content within this CAB are downloaded and started to run. And it stops when IE is closed. How to keep the ActiveX running after closing IE?
My ActiveX is a DLL developed with VC ATL.
TIA
-gusd
|
|
|
|
|
Could somebody provide any idea ?
|
|
|
|
|
We are trying to add existing files from a project (C++ application) into a DLL. It gets to Generating code and produces about a hundred linker errors (LNK 2005 and LNK 2019). it says an object (or variable) is already defined in a libriry (the names of variables and libraries vary in errors).
When we tried to add those files to a new C++ application, that has an .exe file as an output, everything worked just fine.
any suggestions?
|
|
|
|