 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Wed Apr 30, 2008 9:00 pm Post subject: muldiv() explanation |
|
|
I was wondering if anyone could explain these lines of code to me.
| Code: |
lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
|
I sort of understand the MulDiv API, but not a lot. And I don't understand why he's putting the -MulDiv() instead of just MulDiv(), and what the 72 is for, and how he knew how to put it. Also...
| Code: |
f(hf)
{
DeleteObject(g_hfFont);
g_hfFont = hf;
}
|
I get the if statement itself, but not the code in it. I mean, where does g_hFont come into play, I mean is it like a default font, and a pre-defined variable in Win32 or something? _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Wed Apr 30, 2008 10:13 pm Post subject: |
|
|
you really should link to the whole code, you gave me nothing, but i found it and figured it out
| Code: | | arf = CreateFont(lfHeight,0,0,0,0,TRUE,0,0,0,0,0,0,0,"Times New Roman"); |
he was using lfHeight to find a percent of space on the screen, to set his font's height (which he divided to his liking)
that must of slipped your eyes, he already declared it
and also
| Code: | if(hf) {
g_hfFont = hf;
} |
you added the other bit, wasn't in the code _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu May 01, 2008 8:45 am Post subject: |
|
|
Nah....And still, why was he doing -MulDiv() instead of just MulDiv(), and how did he know to use 72. Or does it not matter?
http://www.winprog.org/tutorial/fonts.html
| Code: |
HFONT hf;
HDC hdc;
long lfHeight;
hdc = GetDC(NULL);
lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
ReleaseDC(NULL, hdc);
hf = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");
if(hf)
{
DeleteObject(g_hfFont);
g_hfFont = hf;
}
else
{
MessageBox(hwnd, "Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu May 01, 2008 2:59 pm Post subject: |
|
|
I'm not sure why, but
| Code: | | -(GetDeviceCaps(hdc, LOGPIXELSY) * 12 / 72) |
Is what's used.
And I tihnk not declaring g_hffont is a typo. Look under choosing fonts, he declares it there. _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu May 01, 2008 3:16 pm Post subject: |
|
|
Well. Well how do you know to divide by 72? _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu May 01, 2008 3:18 pm Post subject: |
|
|
I don't know, but that's what you always do.
GetDeviceCaps(hdc, LOGPIXELSY) gets you pixels/inch. a font hight of that*12/72 gives you 6 lines per inch. I'm guessing that 12 and 72 mean something, but all it's really doing is setting how big you want it, so you can set it to whatever you want. _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu May 01, 2008 4:16 pm Post subject: |
|
|
Well still the last question, why the -MultDiv() instead of just MultDiv()? _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu May 01, 2008 4:20 pm Post subject: |
|
|
It has to be negative...that's just how it is. I haven't messed around with fonts too much, so I couldn't tell you why they did it like that, but that's just what they did. _________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu May 01, 2008 4:33 pm Post subject: |
|
|
= - means | Code: | | lfHeight = (lfHeight - MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72)) |
Shorter i guess |
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu May 01, 2008 4:38 pm Post subject: |
|
|
I thought the - had to be in front? I saw some other code with "0-getdev...".
http://msdn.microsoft.com/en-us/library/ms534214(VS.85).aspx
| Quote: | > 0 The font mapper transforms this value into device units and matches it against the cell height of the available fonts.
0 The font mapper uses a default height value when it searches for a match.
< 0 The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts. |
Makes sense _________________
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|