Previous part we stop at regestring WNDCLASSEX struct Lets look next code:

        mov Wwd, 500
        mov Wht, 350

        invoke GetSystemMetrics,SM_CXSCREEN
        invoke TopXY,Wwd,eax
        mov Wtx, eax

        invoke GetSystemMetrics,SM_CYSCREEN
        invoke TopXY,Wht,eax
        mov Wty, eax
It refers to TopXY proc so let's have a look at it:

TopXY proc wDim:DWORD, sDim:DWORD

    shr sDim, 1      ; divide screen dimension by 2
    shr wDim, 1      ; divide window dimension by 2
    mov eax, wDim    ; copy window dimension into eax
    sub sDim, eax    ; sub half win dimension from half screen dimension

    return sDim

TopXY endp
Before we can realize how big and long it is let's have a look for real mnemocode: 1st part ------------

.00401120: C745B0F4010000               mov       d,[-0050],0000001F4
.00401127: C745AC5E010000               mov       d,[-0054],00000015E
.0040112E: 6A00                                    push      000
.00401130: E8FB040000                       call     .000401630   -------- (1)
.00401135: 50                                        push      eax
.00401136: FF75B0                               push      d,[-0050]
.00401139: E843020000                       call     .000401381   -------- (2)
.0040113E: 8945A8                               mov       [-0058],eax
.00401141: 6A01                                   push      001
.00401143: E8E8040000                      call     .000401630   -------- (3)
.00401148: 50                                       push      eax
.00401149: FF75AC                              push      d,[-0054]
.0040114C: E830020000                      call     .000401381   -------- (4)
.00401151: 8945A4                               mov       [-005C],eax
it's to culculate size 154 - 120 = 34h = 52 bytes
.00401154: EB0F                         jmps     .000401165   -------- (5)
Now TopXY proc
.00401381: 55                           push      ebp
.00401382: 8BEC                         mov       ebp,esp
.00401384: D16D0C                       shr       d,[0000C],1
.00401387: D16D08                       shr       d,[00008],1
.0040138A: 8B4508                       mov       eax,[00008]
.0040138D: 29450C                       sub       [0000C],eax
.00401390: 8B450C                       mov       eax,[0000C]
.00401393: C9                           leave
.00401394: C20800                       retn      00008 ;" ?"

22 bytes
Altogether 73 bytes of code to culculate corection for centring window and put it to local variables
to use in CreateWindowEx for positioning the window.
Do you want to know how many clocks it takes?
Just ask :)
Or better count for yourself, it must become your everyday custom if you want be a creater and
have control.

I can just offer mutch shorter and faster way to do the same:

        invoke GetSystemMetrics,SM_CXSCREEN
        mov esi,eax ;esi == screen X
        invoke GetSystemMetrics,SM_CYSCREEN
        mov ecx,eax
        shr esi,1
        shr ecx,1
        sub esi,500/2
        sub ecx,350/2
Then in CreateWindowEx you use ecx,esi,500,350 instead of four local variables which will give you additional bonus to already decreased speed: push 2 registers 2 clocks 2 bytes vs 4 clocks 6 bytes and usage of imm will score you 1 clock for each + give possibilities for paring. As you can see we get less size, more speed and less typing wich make easier to follow code. be continued The Svin.
Posted on 2001-03-30 13:52:00 by The Svin