# 这条语句是什么意思呢？解决思路

www.MyException.Cn  网友分享于：2013-01-22  浏览：9次

size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100)

------解决方案--------------------

MulDiv(a,b,c)
=a*b/c;

MulDiv

The MulDiv function multiplies two 32-bit values and then divides the 64-bit result by a third 32-bit value. The return value is rounded up or down to the nearest integer.

int MulDiv(
int nNumber,
int nNumerator,
int nDenominator
);

Parameters
nNumber
[in] Multiplicand.
nNumerator
[in] Multiplier.
nDenominator
[in] Number by which the result of the multiplication (nNumber * nNumerator) is to be divided.
Return Values
If the function succeeds, the return value is the result of the multiplication and division. If either an overflow occurred or nDenominator was 0, the return value is –1.

------解决方案--------------------
; int __stdcall MulDiv(int nNumber, int nNumerator, int nDenominator)
public MulDiv
MulDiv proc near

nNumber= dword ptr 4
nNumerator= dword ptr 8
nDenominator= dword ptr 0Ch

mov eax, [esp+nNumber]
or eax, eax
js short loc_7C8098A6
mov edx, [esp+nNumerator]
or edx, edx
js loc_7C80992C
mul edx
mov ecx, [esp+nDenominator]
or ecx, ecx
js loc_7C80996E
sar ecx, 1
add eax, ecx
adc edx, 0
cmp edx, [esp+nDenominator]
jnb short loc_7C8098A0
div [esp+nDenominator]
or eax, eax
js short loc_7C8098A0
retn 0Ch

loc_7C8098A0:
xor eax, eax
dec eax
retn 0Ch

loc_7C8098A6:
neg eax
mov edx, [esp+nNumerator]
or edx, edx
js short loc_7C8098D2
mul edx
mov ecx, [esp+nDenominator]
or ecx, ecx
js short loc_7C8098FC
sar ecx, 1
add eax, ecx
adc edx, 0
cmp edx, [esp+nDenominator]
jnb short loc_7C8098F6
div [esp+nDenominator]
neg eax
jg short loc_7C8098F6
retn 0Ch

loc_7C8098D2:
neg edx
mul edx
mov ecx, [esp+nDenominator]
or ecx, ecx
js short loc_7C809914
sar ecx, 1
add eax, ecx
adc edx, 0
cmp edx, [esp+nDenominator]
jnb short loc_7C8098F6
div [esp+nDenominator]
or eax, eax
js short loc_7C8098F6
retn 0Ch

loc_7C8098F6:
xor eax, eax
dec eax
retn 0Ch

loc_7C8098FC:
neg ecx
push ecx
sar ecx, 1
add eax, ecx
adc edx, 0
pop ecx
cmp edx, ecx
jnb short loc_7C8098F6
div ecx
or eax, eax
js short loc_7C8098F6
retn 0Ch

loc_7C809914:
neg ecx
push ecx
sar ecx, 1
add eax, ecx
adc edx, 0
pop ecx
cmp edx, ecx
jnb short loc_7C8098F6
div ecx
neg eax
jg short loc_7C8098F6
retn 0Ch

loc_7C80992C:
neg edx
mul edx
mov ecx, [esp+nDenominator]
or ecx, ecx
js short loc_7C809956
sar ecx, 1
add eax, ecx
adc edx, 0
cmp edx, [esp+nDenominator]
jnb short loc_7C809950
div [esp+nDenominator]
neg eax
jg short loc_7C809950
retn 0Ch

loc_7C809950:
xor eax, eax
dec eax
retn 0Ch

loc_7C809956:
neg ecx
push ecx
sar ecx, 1
add eax, ecx
adc edx, 0
pop ecx
cmp edx, ecx
jnb short loc_7C809950