| View previous topic :: View next topic |
| Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Jul 20, 2008 10:54 pm Post subject: [C++] HFONT issue |
|
|
I'm following theForger's Win32API tutorial, attempting to make a basic text editor.
As you can see hfDefault has been assigned as type HFONT.
However, when I compile it, I receive an error on this line:
| Code: | | hfDefault = GetStockObject(DEFAULT_GUI_FONT); |
The error is: The error I receive is: invalid conversion from `void*' to `HFONT__*'
This is the part of the code where the error arises:
| Code: | case WM_CREATE:
{
HFONT hfDefault;
HWND hEdit;
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE |
ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL),
NULL);
if(hEdit == NULL)
MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK |
MB_ICONERROR);
hfDefault = GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
}
break; |
_________________
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sun Jul 20, 2008 11:08 pm Post subject: |
|
|
Have you even tried type casting? o.o
| Code: | | hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT); |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jul 20, 2008 11:10 pm Post subject: |
|
|
If you look at the GetStockObject documentation, it shows that the API returns an HGDIOBJ type.
| Quote: |
HGDIOBJ GetStockObject(
int fnObject // stock object type
);
|
So typecast it so that it returns an HFONT.
| Code: |
HFONT hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
|
EDIT:
Beaten to it by Symbol. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Jul 20, 2008 11:27 pm Post subject: |
|
|
Using the line provided by Symbol I get weird linker errors:
| Quote: | In function `Z7WndProcP6HWND__jjl':
[Linker error] undefined reference to `GetStockObject@4
ld returned 1 exit status |
Using the line provided by oib111 I get multiple declaration errors:
| Quote: | redeclaration of `HFONT__*hfDefault'
`HFONT__*hfDefault' previously declared here |
 _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jul 20, 2008 11:31 pm Post subject: |
|
|
Go download VC++. Dev-C++ is horrible; only should be used as a backup. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Jul 20, 2008 11:35 pm Post subject: |
|
|
lol, I have Microsoft Visual Studios 2008, like, the whole goddam thing. But I never know what kind of file to open. As in File->New->(What the fuck do i do now, theres like 50 options).  _________________
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sun Jul 20, 2008 11:36 pm Post subject: |
|
|
| Win32 Console or any other Win32 project. |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jul 20, 2008 11:37 pm Post subject: |
|
|
Open up VC++. Hit Ctrl+Shift+N. Go to Win32 and choose Win32 Project. Name it, click next, next, fill in options, finish. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Sun Jul 20, 2008 11:40 pm Post subject: |
|
|
| Code: | | HFONT hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT); |
Put that line above your function, so that it becomes a global. |
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Jul 20, 2008 11:49 pm Post subject: |
|
|
Hmm Thanks, I think I've got the hang of it. + Whats the hotkey to compile? _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jul 20, 2008 11:50 pm Post subject: |
|
|
F5. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Jul 20, 2008 11:52 pm Post subject: |
|
|
Omg. DevC++ returned 3 lines of errors. Look at what VC++ returns
| Quote: | Compiling...
VCSOUrce.cpp
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(1 : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(21) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [27]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(6 : error C2440: '=' : cannot convert from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(73) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(83) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(87) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
| Christ...
@Zand, tried it. More linker errors. _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jul 20, 2008 11:54 pm Post subject: |
|
|
It's because your coding with MBCS (multi-byte character set) and the default character set for VC++ is Unicode. Go to View>Property Pages, and go to Configuration Properties>General>Character Set>Multi-byte Character set _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Mon Jul 21, 2008 12:00 am Post subject: |
|
|
Thanks oib! LIFESAVER! (Its working now ) _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jul 21, 2008 12:10 am Post subject: |
|
|
No problem. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|