News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Get PictureW and PictureH form DIALOG

Started by hfheatherfox07, May 06, 2011, 10:36:24 PM

Previous topic - Next topic

hfheatherfox07

Hi I am trying to change :

PictureW equ 300
PictureH equ 200

So I can get them from the dimension of a dialog, any thought on how to do that?

Later on they get used through out like so foe example:

mov esi,PictureW
mov edi,PictureH

and:

   
    .IF [ptX] > PictureW || [ptY] > PictureH ; check the position

I know of a few ways to get window rect from dialog but I get error messages form the above snippets that they require a value???

Thanks...


qWord

simple declare PictureW/H as an variable and then load them using GetWindow/ClientRect!?
However, the comparison in the .if-statement is done using CMP. Thus you cant use two memory operators - at least one must be placed in an register.
FPU in a trice: SmplMath
It's that simple!

dedndave

qWord is right  :P
also - the system requires EBX, EBP, ESI and EDI to be preserved inside callback functions, like WinProc

anyways, you can do something like this
DefPictureW EQU 300 ;default width
DefPictureH EQU 200 ;default height
;
;
        .DATA

PictureW dd DefPictureW
PictureH dd DefPictureH

hfheatherfox07

 ....I tried that and it did not work?

I was afraid of posting what I was working on ( you might see disorganized coding, and think I am completely nuts)





here is my work:

I am trying to make the examples form "working example folder" to work with a dialog in a rsrc.rc

you will see the format that I want to use in a folder called "starfieldblank"

All my failed attempts are in a folder called attempts -WARNING SOME YOU MAY HAVE TO LOSE FROM THE TRAYBAR OR USE "ALT+F4"



hfheatherfox07

Quote from: dedndave on May 06, 2011, 11:00:03 PM
qWord is right  :P
also - the system requires EBX, EBP, ESI and EDI to be preserved inside callback functions, like WinProc

anyways, you can do something like this
DefPictureW EQU 300 ;default width
DefPictureH EQU 200 ;default height
;
;
        .DATA

PictureW dd DefPictureW
PictureH dd DefPictureH


I am trying to eliminate the 200, and 300 dimensions and use the rsrc.rc dialog for dimension

qWord

The dimension definition in your resource file are independent from your program (at assembly time). As long as having the dialogs resource ID, you can obtain the dimensions by GetWindowRect (or GetClientRect) - more dynamically you wont get it
FPU in a trice: SmplMath
It's that simple!

hfheatherfox07

I have other example that I tried an fail with "GetWindowRect (or GetClientRect)"

how can I do that and connect them to :


.data
PictureW dd ?
PictureH  dd ?

so PictureW  and PictureH are the dimensions of the rsrc.rc

dedndave

ok
       .DATA?

PictureW dd ?
PictureH dd ?

dRect RECT <>
; left   dd ?
; top    dd ?
; right  dd ?
; bottom dd ?

       .CODE

       INVOKE  GetWindowRect,hDialog,offset dRect
       mov     eax,dRect.right
       sub     eax,dRect.left
       mov     PictureW,eax
       mov     eax,dRect.bottom
       sub     eax,dRect.top
       mov     PictureH,eax


notice that the left and top coordinates are inclusive and the right and bottom coordinates are exclusive
that way, you do not have to adjust the dimension values by 1

oops fixed a couple typos > dRect.top those are periods   :P

hfheatherfox07

 Thank you...I will give that a try...

dedndave

this is a bit smaller - same thing, though
we make room on the stack for the RECT structure, then POP it off
       .DATA?

PictureW dd ?
PictureH dd ?

       .CODE

        sub     esp,sizeof RECT
        INVOKE  GetWindowRect,hDialog,esp
        pop     ecx           ;RECT.left
        pop     edx           ;RECT.top
        pop     eax           ;RECT.right
        sub     eax,ecx
        mov     PictureW,eax
        pop     eax           ;RECT.bottom
        sub     eax,edx
        mov     PictureH,eax

hfheatherfox07

I am still getting an error @ lines:

add dword ptr [ptX],PictureW/2 ; center


add dword ptr [ptY],PictureH/2

and:

.IF [ptX] > PictureW || [ptY] > PictureH ; check the position

maybe I am not defining " hDialog" right?

also why are :

dRect RECT <>
; left   dd ?
; top    dd ?
; right  dd ?
; bottom dd ?

marked as comments?




dedndave

yes - marked as comments so you know what the member names are

add dword ptr [ptX],PictureW/2 ; center
PictureW/2 is legal for EQUates - not for variables
also, you are attempting to add one memory operand to another
get PictureW in a register
shr reg,1 to divide by 2
then add that register to ptX
        mov     eax,PictureW
        shr     eax,1
        add     ptX,eax


.IF [ptX] > PictureW || [ptY] > PictureH ; check the position
here, you are attempting to compare one memory operand against another, twice   :P
you can compare register to memory or memory to immediate (constant)
of course, you can compare register to register or register to immediate, but that doesn't help you

hfheatherfox07

It looks like I have a lot to learn... :(

I will try  :(

no idea how to resolve :

.IF [ptX] > PictureW || [ptY] > PictureH ; check the position


qWord

.IF [ptX] > PictureW || [ptY] > PictureH ; check the position->
mov ecx,PictureW
mov edx,PictureH
.if ptX > ecx || ptY > edx
...
FPU in a trice: SmplMath
It's that simple!

dedndave

i see a possible problem coming up   :P

hopefully, ptX and ptY are client coordinates