-
July 20th, 2015, 11:00 AM
#1
[RESOLVED] about fonts
on my label class:
Code:
private:
CHOOSEFONT chFont;
public:
CHOOSEFONT getFont()
{
return chFont;
}
void setFont(const CHOOSEFONT font)
{
chFont=font;
clrTextColor=chFont.rgbColors;
HFONT hFont=CreateFontIndirect(chFont.lpLogFont);
SendMessage(hwnd, WM_SETFONT,(WPARAM) hFont, TRUE);//setting the control font for resize the control
if(blnAutoSize==true)//the autosize is true
setAutoSize(true);
}
and see how i show the font dialog(using the label font):
Code:
CHOOSEFONT ShowSelectFont(const CHOOSEFONT cf1)
{
CHOOSEFONT cf = {sizeof(CHOOSEFONT)};
cf=cf1;
HWND hwnd=GetForegroundWindow();
cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
cf.hwndOwner = hwnd;
ChooseFont(&cf);
return cf;
}
the lpLogFont, CHOOSEFONT class member, it's a pointer. the problem is the font dialog isn't showed. what i belive is that i lose the pointer between the getFont() and ShowSelectFont(). what anyone can tell me?
-
July 20th, 2015, 11:33 AM
#2
Re: about fonts
1. CHOOSEFONT is a structure, NOT a pointer.
2. You need to check the return value from ChooseFont(&cf). If it is 0 (FALSE), you should call CommDlgExtendedError(); to see what was wrong.
3. You didn't show how you create CHOOSEFONT structure in the first place. Did you set its lStructSize member? To what?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 20th, 2015, 11:50 AM
#3
Re: about fonts
Originally Posted by VladimirF
1. CHOOSEFONT is a structure, NOT a pointer.
2. You need to check the return value from ChooseFont(&cf). If it is 0 (FALSE), you should call CommDlgExtendedError(); to see what was wrong.
3. You didn't show how you create CHOOSEFONT structure in the first place. Did you set its lStructSize member? To what?
1 - the CHOOSEFONT don't but the lpLogFont member is
3 - thanks. i didn't notice that :P
now the code works fine.
anotherthing: please see these function:
Code:
CHOOSEFONT ShowSelectFont()
{
HWND hwnd=GetForegroundWindow();
CHOOSEFONT cf = {sizeof(CHOOSEFONT)};
LOGFONT* lf = new LOGFONT;
HDC hdc=GetDC(hwnd);
HFONT hlf =(HFONT) GetCurrentObject(hdc,OBJ_FONT);
GetObject(hlf,sizeof(LOGFONT),lf);
cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
cf.hwndOwner = hwnd;
cf.lpLogFont = lf;
cf.rgbColors =GetTextColor(hdc);
ChooseFont(&cf);
ReleaseDC(hwnd,hdc);
cf.lpLogFont = lf;
return cf;
}
the lf use 'new', but i'm not using the 'delete'. so it's a memory leak. but honestly i can't use the 'delete', or i lose the lf data. can you correct me these?
Last edited by Cambalinho; July 20th, 2015 at 11:52 AM.
-
July 20th, 2015, 12:18 PM
#4
Re: about fonts
Originally Posted by Cambalinho
1 - the CHOOSEFONT don't but the lpLogFont member is
3 - thanks. i didn't notice that :P
now the code works fine.
anotherthing: please see these function:
Code:
CHOOSEFONT ShowSelectFont()
{
HWND hwnd=GetForegroundWindow();
CHOOSEFONT cf = {sizeof(CHOOSEFONT)};
LOGFONT* lf = new LOGFONT;
HDC hdc=GetDC(hwnd);
HFONT hlf =(HFONT) GetCurrentObject(hdc,OBJ_FONT);
GetObject(hlf,sizeof(LOGFONT),lf);
cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
cf.hwndOwner = hwnd;
cf.lpLogFont = lf;
cf.rgbColors =GetTextColor(hdc);
ChooseFont(&cf);
ReleaseDC(hwnd,hdc);
cf.lpLogFont = lf;
return cf;
}
the lf use 'new', but i'm not using the 'delete'. so it's a memory leak. but honestly i can't use the 'delete', or i lose the lf data. can you correct me these?
But why do you pass the CHOOSEFONT from a function as the return value?
Why not just pass it to the function as a parameter?
Like (reference)
Code:
BOOL ShowSelectFont(CHOOSEFONT& chooseFont )
or (pointer)
Code:
BOOL ShowSelectFont(CHOOSEFONT* chooseFont )
Victor Nijegorodov
-
July 20th, 2015, 12:24 PM
#5
Re: about fonts
Originally Posted by VictorN
But why do you pass the CHOOSEFONT from a function as the return value?
Why not just pass it to the function as a parameter?
Like (reference)
Code:
BOOL ShowSelectFont(CHOOSEFONT& chooseFont )
or (pointer)
Code:
BOOL ShowSelectFont(CHOOSEFONT* chooseFont )
honestly, by my experience, is more easy my way. but thinking more... i belive it's a opinion... it depends on programmer way
-
July 20th, 2015, 12:24 PM
#6
Re: about fonts
Think RAII
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 20th, 2015, 12:26 PM
#7
Re: about fonts
Originally Posted by 2kaud
Think RAII
i'm sorry... what means RAII?
-
July 20th, 2015, 12:33 PM
#8
Re: about fonts
Resource Acquisition Is Initialisation. See http://stackoverflow.com/questions/2...alization-raii and many other internet articles. If you program with c++ this is something with which you really should be familiar.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 20th, 2015, 12:37 PM
#9
Re: about fonts
Originally Posted by Cambalinho
i'm sorry... what means RAII?
A very fast search with Google shows you https://www.google.ch/search?q=RAII&..._sm=0&ie=UTF-8 where every from the first 10 items explains you what it is!
Victor Nijegorodov
-
July 20th, 2015, 12:42 PM
#10
Re: about fonts
i never ear about RAII, now i more or less understand it.
but i continue with my last question\confusion: why i can't use 'delete'?
the rule is: when we use the 'new' we must use the 'delete', when isn't needed. but i can't, in these case, delete the lf or i lose the data
-
July 20th, 2015, 12:52 PM
#11
Re: about fonts
Originally Posted by Cambalinho
i never ear about RAII, now i more or less understand it.
but i continue with my last question\confusion: why i can't use 'delete'?
the rule is: when we use the 'new' we must use the 'delete', when isn't needed. but i can't, in these case, delete the lf or i lose the data
So you don't understand RAII. The new and the corresponding delete go in a class - with delete in the destructor so memory is not 'lost'.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 20th, 2015, 12:55 PM
#12
Re: about fonts
Originally Posted by 2kaud
So you don't understand RAII. The new and the corresponding delete go in a class - with delete in the destructor so memory is not 'lost'.
understood... thanks for all
Last edited by Cambalinho; July 20th, 2015 at 12:58 PM.
-
July 20th, 2015, 02:33 PM
#13
Re: [RESOLVED] about fonts
correct me anotherthing about fonts color and control backcolor : when i put the child control transparent(regions in pixel way) a see 1 color arround the letters(not a backcolor)... why these happens?
-
July 22nd, 2015, 01:27 AM
#14
Re: [RESOLVED] about fonts
Last edited by Igor Vartanov; July 22nd, 2015 at 01:33 AM.
Best regards,
Igor
-
July 22nd, 2015, 02:58 AM
#15
Re: [RESOLVED] about fonts
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|