Click here to Skip to main content
15,886,840 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to restore my application instead of running a new instance? Pin
julych2-Nov-03 20:03
julych2-Nov-03 20:03 
AnswerRe: How to restore my application instead of running a new instance? Pin
BlackRider2-Nov-03 20:33
BlackRider2-Nov-03 20:33 
AnswerRe: How to restore my application instead of running a new instance? Pin
Michael P Butler2-Nov-03 22:04
Michael P Butler2-Nov-03 22:04 
AnswerRe: How to restore my application instead of running a new instance? Pin
cmk2-Nov-03 22:30
cmk2-Nov-03 22:30 
GeneralPreCreateWindow Pin
Vancouver2-Nov-03 19:41
Vancouver2-Nov-03 19:41 
GeneralRe: PreCreateWindow Pin
Antti Keskinen2-Nov-03 22:36
Antti Keskinen2-Nov-03 22:36 
GeneralPreCreateWindow Pin
Vancouver3-Nov-03 6:50
Vancouver3-Nov-03 6:50 
GeneralRe: PreCreateWindow Pin
Antti Keskinen5-Nov-03 2:17
Antti Keskinen5-Nov-03 2:17 
Like I said, the PreCreateWindow allows you to fiddle with the create struct of the window. This structure contains info like the window class, window title, cursor, default brush, menu etc etc. This function is called before the Windows API call 'CreateEx' is called. This API call is responsible for actually creating the Windows window object. The framework will bind then this object (by it's handle) to the CWnd/CDialog object.

For example, in custom controls, it is common to make a check for class name in the PreCreateWindow -override. If this member is NULL, the control will register a new window class with AfxRegisterWndClass to make sure that it has a valid class (All top-level windows in MFC MUST have a valid class name). This way it doesn't bother the end user with this.

To get a complete idea of this, go check the Windows API reference on window objects. Look for things like WNDCLASS structure, RegisterWndClass function, CreateWindow and CreateWindowEx functions. These functions are called by the framework to actually create it's objects. You can, just as well, create them yourself and call the 'Attach' method of CWnd to bind your CWnd object to an existing window handle. Now, you can modify this window through the CWnd wrapper.

As for answers to your questions:

a) What you are trying to do is impossible, font-wise. After a Windows font object is created, you can't modify it. However, you _can_ modify a CFont object. It is just a wrapper for the underlying font.

To accomplish similar results, you can get the CFont-bound Windows font object's representation to a LOGFONT structure by calling the GetLogFont member method of CFont. This will fill the specified LOGFONT structure with the information about this specific font bound to this specific CFont.

Then, use the CFont's member function 'DestroyObject' to destroy the current font object, making sure that it is not selected to a device context, otherwise your program might crash/assert/throw an exception.

After you have destroyed the old object, modify the LOGFONT structure to meet your new demands. Then call 'CreateFontIndirect' of CFont and pass a pointer to the LOGFONT (use address-of) structure. This will create a new Windows font object with the specified parameters, and attach this font to the CFont object.

The general version of this routine (Get current params -> Destroy old -> Modify params -> Create new) is applicable to all GDI objects and their MFC wrappers (CPen, CBrush, CFont etc)


b) For some background info: each Windows window object (Window, dialog, control etc) has a default GDI object of each type bound to it. It has a default pen, a default brush... and a default font.

Now, the OnSetFont function of CDialog does precisely as it's description in MSDN says: it allows you to set a new default font for your dialog. This font is copied (passed) to all controls (statics, buttons etc) drawn by the dialog. So, yes, in a way. If you specify a new default font for your dialog, each control it draws will use this default font to draw it's texts. I am unsure whether the underlying framework routine will resize your controls depending on the font, but I believe that it will. The only way to make sure is to test it.

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralOnSetFont Pin
Vancouver7-Nov-03 13:34
Vancouver7-Nov-03 13:34 
GeneralRe: OnSetFont Pin
Antti Keskinen8-Nov-03 9:41
Antti Keskinen8-Nov-03 9:41 
GeneralOnSetFont Pin
Vancouver8-Nov-03 19:55
Vancouver8-Nov-03 19:55 
GeneralSharing MFC objects among threads... Pin
Suhail Yousaf2-Nov-03 19:16
Suhail Yousaf2-Nov-03 19:16 
GeneralFiles and folders Pin
Selevercin2-Nov-03 17:26
Selevercin2-Nov-03 17:26 
GeneralRe: Files and folders Pin
Michael Dunn2-Nov-03 20:04
sitebuilderMichael Dunn2-Nov-03 20:04 
Generaladding a cbutton to a custom control Pin
mindows2-Nov-03 17:11
mindows2-Nov-03 17:11 
GeneralRe: adding a cbutton to a custom control Pin
Antti Keskinen2-Nov-03 23:03
Antti Keskinen2-Nov-03 23:03 
GeneralRe: adding a cbutton to a custom control Pin
mindows3-Nov-03 11:54
mindows3-Nov-03 11:54 
GeneralRe: adding a cbutton to a custom control Pin
Antti Keskinen5-Nov-03 1:44
Antti Keskinen5-Nov-03 1:44 
QuestionHow to manage objects unknown at run-time Pin
Steve Messer2-Nov-03 16:42
Steve Messer2-Nov-03 16:42 
AnswerRe: How to manage objects unknown at run-time Pin
Christian Graus2-Nov-03 17:08
protectorChristian Graus2-Nov-03 17:08 
GeneralRe: How to manage objects unknown at run-time Pin
Steve Messer2-Nov-03 21:26
Steve Messer2-Nov-03 21:26 
GeneralRe: How to manage objects unknown at run-time Pin
Christian Graus3-Nov-03 9:07
protectorChristian Graus3-Nov-03 9:07 
GeneralRe: How to manage objects unknown at run-time Pin
Steve Messer3-Nov-03 10:23
Steve Messer3-Nov-03 10:23 
GeneralRe: How to manage objects unknown at run-time Pin
Steve S3-Nov-03 23:02
Steve S3-Nov-03 23:02 
GeneralFloat window in MDI application Pin
novachen2-Nov-03 16:35
novachen2-Nov-03 16:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.