|
afx_msg int CChildWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CClientDC dc(this);
CFont font;
font.CreateFont(charHeight, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");
//charheight is any number (usually 12)
dc.SelectObject(&font);
m_MyEdit.SetFont(&font);
...
}
This works fine on Win98, but on WinNT and Win2000 it seems like nothing happens. The default font (FixedSys) is being used instead. Why? And it's not only MyEdit, but all other childwindows: CStatic, CListCtrl, CEdit, CStatusBarCtrl, anything!
Please help me
|
|
|
|
|
You need to allocate the CFont object with the new operator (on the heap) and you need to maintain it for as long as you plan on using that font for those controls. Actually, I am surprised it works on Win98. Usually, I allocate fonts in my OnCreate or OnInitialize and destroy them in the OnDestroy or destructor.
|
|
|
|
|
You would not need to allocate the CFont object on the heap -- you could do on the stack as a class member variable. One less thing to worry about during cleanup. However, you still have to remember to call DeleteObject() in OnDestroy.
CodeGuy
http://groups.yahoo.com/group/wtl
|
|
|
|
|
You are absolutely right, it just needs to be persisted as long as it is being used.
I just like to have definitive control over all resource related functionality.
|
|
|
|
|
A global CFont object could do the job as well I guess then, but is that "good programming"?
Sprudling
|
|
|
|
|
No. Resources such as fonts should be tied to the lifetime of their windows. Also, you would not want to let other windows have the potential of fighting over the same global font variable.
CodeGuy
The WTL newsgroup: 860 members and growing ... http://groups.yahoo.com/group/wtl
|
|
|
|
|
The scenario is that I have a file xyz.ini and I want to make a backup of it called xyz.ini2 and then rewrite to xyz. I have tried CFile::Rename and CFile::Duplicate and I am getting "a sharing violation occured while accessing an unnamed file".
CFile temporiginifile;
temporiginifile.Open(m_sFileFullPathName,CFile::modeReadWrite|CFile::shareDenyNone);
temporiginifile.Rename(m_sFileFullPathName,m_sFileFullPathName+"2");
temporiginifile.Close();
Paradise is where I am.
Voltaire
|
|
|
|
|
Just use CopyFile API function. All you need to do is to pass the filenames.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks.
Paradise is where I am.
Voltaire
|
|
|
|
|
|
I'm adding dynamically several pages in a Propertysheet, but when the tabscontrols are on more than one line the sheet doesn't inflate automatically.
What can I do?
Natacha
|
|
|
|
|
Does anyone know if there is any way to easily format the contents of a messagebox? Or maybe just format a CString to be a specified number of columns wide.
Now I first have to create a CString and use the Format method on it to fill it with text, values and new lines. But since I'm never sure about how much space the values take it's hard to format the text to look good in the messagebox. What I'm looking for is a way to insert newlines automatically at runtime. Is there any simple way to do this?
Thanks!
|
|
|
|
|
Hi..
Use, the tab "\t" and "\n" with CString to solve this problem. See the sample given below.
CString str;
str.Format("Rejeesh\tRamesh\tRanjit\nRejeesh\tRamesh\tRanjit\nRejeesh\tRamesh\tRanjit");
AfxMessageBox(str);
|
|
|
|
|
I don't think it's worth the trouble - the font displayed in the msgbox can be different on different machines; the maximum width of msgbox depends on screen resolution, etc.
You'd have to get the font metrics and compute widths 'manually'. And it's plain impossible to get pixel-perfect columns this way - inserting spaces doesn't give you this level of control.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for your answers. I'm afraid I was a bit unclear though. What I would like is to specify the desired width of my messagebox and then the program should take care of word-wrapping for me.
I guess you thought I wanted to line up data in columns. When I read my first post again I can see that I was a bit vague about what I was looking for.
So, let's say I have a string like this:
"This is a long string that's supposed to be in a messagebox. It contains some values of unspecified length, for example 1.23456789 and John Doe"
Then it would be nice to just tell my messagebox that this string should be divided over several lines where no line would be more than say 40 characters, or 400 pixels, or something like that.
Is there any support for this in MFC, or would I have to write my own messagebox class? Or a new string class? It probably wouldn't be very difficult, but I'm not sure it would be worth it. Well except for the fun of it.
|
|
|
|
|
Then it would be nice to just tell my messagebox that this string should be divided over several lines where no line would be more than say 40 characters
So you just need to scan the string and insert newlines at appropriate positions - probably replacing spaces between words. You don't need new class for that - a function will be enough.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
You're right, I don't need a class for that. A function should be able to handle it.
Thanks for your help!
|
|
|
|
|
Can someone enlighten me as the significance of the Const keyword, when used in terms on const char * or LPCSTR etc. I have never understood what it does...
Regards
Ray
"Je Suis Mort De Rire"
|
|
|
|
|
it means that a variable is constant. ie unchanging.
|
|
|
|
|
The "const" keyword is a compiler directive which tells the compiler that the variable following const will not be changed by the code which executes against it. It can improve performance because the compiler can make better decisions about how to handle data passing, etc. The most signifigant benefit (that I am aware of) to using const is in parameter passing.
void SomeFunction(int iValue, char* pszValue);
This function declaration just tells the comiler that it needs an integer and a pointer to a char. If this function is called from anywhere in the app, the compiler must insure that the iValue is a copy from the calling function and that char* pszValue is a changeable value.
void SomeFunction(const int iValue, const char* pszValue);
With this version of the function declaration, the compiler assumes that it can just pass the parameters in the most effecient manner possible and does not need to deal with determining if the calling procedures version on iValue of pszValue where const or not, nor does it have to allocate a new int for the iValue paramater.
I should include here that the const keyword is a hint to the compiler, but it is possible (although very dangerous) to cast a const to a non const.
char* pszTemp = (char*)pszValue);
|
|
|
|
|
if you have a function like:
void foo(LPCSTR s)
{
}
unlike
void foo(LPSTR s)
{
}
In the first function the caller knows that you dont change the value of the pointer within the function, in the second function you never know, unless you have the source for the function...
Also if you do embedded programming a const value can stay in ROM where a non-const value have to be moved to RAM.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Cool,
Thanks for the explaination, funny I have gone all this time without knowing that.
I had a look at CESoftware.dk, you seem to devote most of your CE Programming Skill to developing games. I do alot embedded development myself (I am the King of Unaligned Data Access Exceptions) and I spend most of my time developing Form to Database applications.
I have often felt what CE and other Mobile Platforms lack is a Interface to Database Scripting Language. Something really high level (even higher than embedded VB and faster). That would parse a script from which it would generate a user interface and read/write a datasource. A rough idea only ...
For Example it could look something like this:
FORM FORM1(0,0,240,160, \\Storage Card\\DataSource.cdb)
TREEVIEW TREEVIEW1(10,10, 200, 150, SELECT * FROM CUSTOMERS)
BUTTON BUTTON1(210, 130, 230, 150, "Ok")
FORM_INITALISE
END FORM_INITALISE
FORM_ONBUTTON1CLICK
SQL DELETE * FROM CUSTOMERS
CLOSE FORM1
END ONBUTTON1CLICK
END FORM
Regards
Ray
"Je Suis Mort De Rire"
|
|
|
|
|
The database_interface_thing you describe would be a cool application IMHO.
I just think it would take a lot of time to develop.
Do you think people would by it?
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
It would be a great RAD tool, not very useful perhaps for serious development but if you needs a small app or a demo app it would be excellant. I estimate development time for this at about 4 months.
Petty my time is booked up for this forseeable future
Regards
Ray
"Je Suis Mort De Rire"
|
|
|
|
|
First of all, apologises for my english.
An important point in declaring a const data type is that its placed in the .rdata section (for only reading data) wich is much better than using an object because it'd be stored in .bss section, in the swapping file (at least partially). This is true for integral data types and structures declared as const data types.
So if you think you'll need a value that will remain unchanged it's more efficient to use a const data type.
That's all!
|
|
|
|