The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: hfheatherfox07 on May 06, 2011, 10:36:24 PM

Title: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 06, 2011, 10:36:24 PM
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...

Title: Re: Get PictureW and PictureH form DIALOG
Post by: qWord on May 06, 2011, 10:51:21 PM
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.
Title: Re: Get PictureW and PictureH form DIALOG
Post by: 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
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 06, 2011, 11:03:03 PM
 ....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)


(http://www.angryduck.com/pictures/2010_11/Coding_Drunk.jpg)


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"


Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 06, 2011, 11:04:37 PM
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
Title: Re: Get PictureW and PictureH form DIALOG
Post by: qWord on May 06, 2011, 11:10:56 PM
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
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 06, 2011, 11:14:18 PM
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
Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 06, 2011, 11:14:26 PM
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
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 06, 2011, 11:15:29 PM
 Thank you...I will give that a try...
Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 07, 2011, 12:01:06 AM
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
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 12:15:36 AM
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?



Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 07, 2011, 12:22:09 AM
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
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 12:28:05 AM
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

Title: Re: Get PictureW and PictureH form DIALOG
Post by: qWord on May 07, 2011, 12:31:07 AM
.IF [ptX] > PictureW || [ptY] > PictureH ; check the position->
mov ecx,PictureW
mov edx,PictureH
.if ptX > ecx || ptY > edx
...
Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 07, 2011, 12:36:40 AM
i see a possible problem coming up   :P

hopefully, ptX and ptY are client coordinates
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 12:39:43 AM
dunno what that means but all assembled OK... Program still crashed? :dazzled:
Title: Re: Get PictureW and PictureH form DIALOG
Post by: qWord on May 07, 2011, 12:40:22 AM
pls upload the source
Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 07, 2011, 12:41:48 AM
i was just looking at the working examples
Tom's FPU examples are nice - the other two eat up too much CPU time
although they could probably be fixed with a little effort
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 12:55:39 AM
Quote from: qWord on May 07, 2011, 12:40:22 AM
pls upload the source

LOL I have a lot of mistakes in it I have WM_CREATE and WM_INITDIALOG
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 12:58:37 AM
Quote from: dedndave on May 07, 2011, 12:41:48 AM
i was just looking at the working examples
Tom's FPU examples are nice - the other two eat up too much CPU time
although they could probably be fixed with a little effort

By the way I got those from here:

http://www.asmfr.com/codes/STARFIELD-3D-MASM_15236.aspx

I use Google translate so I don't mind the French

there are lots of MASM32 example there  :bg

Also you can set your e mail to get notification every time some one posted new source ...

you guys might benefit more than me from some of the sources there .... there are a little bit beyond my pay grade right now :)
Title: Re: Get PictureW and PictureH form DIALOG
Post by: qWord on May 07, 2011, 01:47:28 AM
hfheatherfox07,
stay away from copying code together - it wont work. There was a lot of mistakes!
Quoteinclude masm32rt.inc

WndProc PROTO :DWORD, :DWORD, :DWORD, :DWORD
   

IDD_DLG1    equ 101
TIMER1       equ 1
Stars       equ 200 ; number of stars

.DATA
szClassName    db "Win32asm_class",0
szDisplayName    db " FPU SAMPLE by TOM",0
   
noir dd ?
   
pt dd Stars dup (0,0,0) ;x,y,z+color
   
ptX dd 0
ptY dd 0
   
random dd 0
   
num256 REAL4 400.00 ; starting cluster size
   
.DATA?
hInstance       HINSTANCE ?
hmainDC       HDC ?
hmainbmp       HBITMAP ?
WindowRect       RECT      <?>
MyRect          RECT <?>
rClientWindow   RECT      <?>
hbmp         HANDLE      ?
chdc         HDC      ?

PictureW       dd ?
PictureH       dd ?
hDialog       HWND ?
.CODE
start:
   
   
mov hInstance,rv(GetModuleHandle,0)
INVOKE InitCommonControls   
INVOKE DialogBoxParam, hInstance, IDD_DLG1 , NULL, ADDR WndProc, 0
INVOKE ExitProcess, 0

WndProc PROC uses  ebx esi edi hWnd:HWND,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT
 
   .IF uMsg == WM_INITDIALOG
   
      INVOKE  GetClientRect,hWnd,ADDR rect
         m2m PictureW,rect.right
         m2m PictureH,rect.bottom

      mov noir,rv(CreateSolidBrush,noir)
      
      invoke SetTimer, hWnd, TIMER1, 10, NULL
      
      invoke GetDC, hWnd
      mov hdc, eax
      
      mov esi,PictureW
      mov edi,PictureH

      invoke CreateCompatibleDC, hdc
      mov hmainDC,eax
      
      invoke CreateCompatibleBitmap, hdc, esi, edi
      mov hmainbmp,eax

      invoke SelectObject, [hmainDC], eax
      
      invoke ReleaseDC,hWnd, hdc
   
      invoke GetTickCount
      mov random,eax
      
      xor esi,esi

      CREATE_STARS:
      
      push eax
      
      imul ax,cx
      movsx eax,ax
      mov edx,eax
      shr edx,8
      mov ah,dh
      add al,3
      mov dword ptr [pt+esi],eax
      
      pop eax
      xor eax,[$+esi]
      movsx eax,ax
      mov edx,eax
      shr edx,8
      mov ah,dh
      mov dword ptr [pt+esi+4], eax

      imul ax,cx
      xor ax,si
      mov random,eax
      
      
      mov ecx,eax
      mov ch,1
      and ecx,0fffh
      mov dword ptr [pt+esi+8], ecx
      
      add esi,12
      cmp esi,Stars*12
      jne CREATE_STARS
      mov eax,1
      ret
   .ELSEIF uMsg == WM_PAINT
         mov hdc,rv(BeginPaint,hWnd,ADDR ps)
         invoke GetClientRect,hWnd,ADDR rect
      invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hmainDC,0,0,SRCCOPY
      invoke EndPaint,hWnd,addr ps
      mov eax,1
      ret
   .ELSEIF uMsg == WM_KEYDOWN
      cmp wParam, VK_ESCAPE
      je destroy
      mov eax,1
      ret
   .ELSEIF uMsg == WM_TIMER
      xor esi,esi
      invoke GetClientRect,hWnd,ADDR rect
      invoke FillRect,hmainDC,ADDR rect,rv(GetStockObject,BLACK_BRUSH)
      .while esi < Stars*12
         call starfield
         invoke SetPixel, hmainDC, ptX, ptY, eax
         add esi,12 ; next stars
         .endw
      invoke InvalidateRect,hWnd,0,0
         mov eax,1
         ret
   .ELSEIF uMsg == WM_CLOSE
      destroy:
      invoke PostQuitMessage,NULL
      invoke DeleteDC, [hmainDC]
      invoke DeleteObject, [hmainbmp]
      invoke DeleteObject, noir
      invoke KillTimer, hWnd, TIMER1
      INVOKE EndDialog,hWnd, 0
   .ENDIF
   
   xor eax,eax
   ret
   
   
   starfield:
   
   finit
   
   dec dword ptr [pt+esi+8]
   
   fild word ptr [pt+esi+8] ;z
   fld num256
   
   fild dword ptr [pt+esi] ;x
   fmul st(0),st(1)
   fdiv st(0),st(2)
   fistp dword ptr [ptX]
  mov     eax,PictureW
      shr     eax,1
      add     ptX,eax ; center
   
   
   fild dword ptr [pt+esi+4] ;y
   fmul st(0),st(1)
   fdiv st(0),st(2)
   fistp dword ptr [ptY]
   mov     eax,PictureH
      shr     eax,1
      add     ptY,eax

   
   
   
   mov ecx,PictureW
   mov edx,PictureH
   .if ptX > ecx || ptY > edx
   call CHANGE_STARS
   .ENDIF
   
   
   xor eax,eax
   mov al,byte ptr [pt+esi+8+3] ; color
   mov ah,al
   shl eax,8
   mov al,ah
   
   
   .IF byte ptr [pt+esi+8+3] != 0FFh ; color white max
   inc byte ptr [pt+esi+8+3]
   .ENDIF
   
   
   retn
   
   
   CHANGE_STARS: ;change stars coord.
   
   mov eax, random
   
   push eax
   
   imul ax,cx
   movsx eax,ax
   mov edx,eax
   shr edx,8
   mov ah,dh
   add al,3
   mov dword ptr [pt+esi],eax
   
   pop eax
   xor eax,[$+esi]
   movsx eax,ax
   mov edx,eax
   shr edx,8
   mov ah,dh
   mov dword ptr [pt+esi+4], eax
   
   
   imul ax,cx
   xor ax,si
   mov random,eax
   
   
   mov ecx,eax
   mov ch,1
   and ecx,0fffh
   mov dword ptr [pt+esi+8], ecx ; éfface z et raz la couleur
   
   
   retn
   ;-------------------------------------------------------------------------
WndProc ENDP

END start
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 02:14:23 AM
Thanks qWord ... I am going to retry the other example so I can understand them ....

I think I lack the understanding in registries  ....

When you posted posted converting this:

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

Than knew to convert it to:

mov ecx,PictureW
mov edx,PictureH
.if ptX > ecx || ptY > edx
...


and when dedndave posted converting this :

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

to this:

      mov     eax,PictureW
        shr     eax,1
        add     ptX,eax


I realized that I am lacking some major registry knowledge... I only have one tutorial explaining that ....

are there any plain English tuts that explain what registers do? :(




Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 07, 2011, 02:53:44 AM
the first 6 chapters, plus chapter 15 will give you a good start

http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 03:18:18 AM
LOL I downloaded that whole book in pdf format .... long ago...
I read a bit of it and got so discouraged , it looks like it uses the old MASM before Hutch's  http://webster.cs.ucr.edu/AsmTools/MASM/

This is a very discouraging book  :(....maybe I will buy the paperback and it won't be so bad...

I was hoping to find more tutorials....
Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 07, 2011, 03:31:10 AM
the online version may be different
at any rate, it gives you the basics that you need

here is what i suggest...
read some of it - maybe a chapter - they are short
when you have problems, ask us - we can help make sense of it for you   :P

a number of beginners that post here have problems with data types, registers, memory, etc
they become discouraged and move on
it can't be too hard - i can do it   :lol
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 07, 2011, 03:48:38 AM
At the risk of sounding crazy.... for now I take apart any source that I can find and do example from that....

For example I find something that has in it a color link that opens emails.... What I will do is make a new exe that only has a link that opens emails ...that is all it does....

So far I made over 125 examples ..... of how to do different things using MASM....from transparent windows , animate window at start up...etc...
( I still have problems making a user defined button.... I just will put that one off for a while.... I can make the color of the button but not set the text or the frame????? )

I understand the principle of MASM ( The API calls that you need to invoke using .inc's and .lib's) and I know that Microsoft has pages upon pages of api functions ....

( I do use win32api.hlp alsmost every day) however the date is 2000 I can not find any newer once.....but even with the API fonctions they look like they are C+ Format and
not MASM ...also some of the stuff is not in there?


Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 07, 2011, 04:50:06 AM
that old win help file is nice to have
if you want to write programs that will work on windows 2000, for example   :U
unless i am doing something fancy, i try to make them work on win 98 and up - lol

following examples is a good idea
but, it will be more meaningful if you have a grasp on the basics

if you don't do anything else, have a look at Randy's chapter 6 - that will help a lot
and - don't try to read it like a book
instead, browse through it
if you find something that looks like fun, try it out in some code

assemble as a console app...
        INCLUDE \masm32\include\masm32rt.inc

        .CODE

_main   PROC

        mov     eax,12345678h
        push    eax
        print   uhex$(eax),32
        pop     eax
        bswap   eax
        print   uhex$(eax),13,10
        inkey
        exit

_main   ENDP

        END     _main
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 08, 2011, 01:42:10 AM
@ qWord I noticed that you replaced the contents of WM_TIMER with the contents of  WM_PAINT from the original example by Tom ....I was wondering the reason for this...


LOL I was at this all night last night , I had the widows open and suddenly I heard Birds Chirping I went to sleep at 6am....

I converted  the second example by Tom to work with a resource file ...how ever my stars came out RED, why???

I also tried to convert the original example of starfield ( which is the one I wanted LOL ) I got the stars on the screen but they freeze , the screen is in complete for some reason...
I assemble using RADASM (Love it) when the exe pops up on the screen , it takes a while for the stars to show , than it works in frames , any thought???


Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 08, 2011, 01:57:25 AM
Quote from: dedndave on May 07, 2011, 04:50:06 AM
that old win help file is nice to have
if you want to write programs that will work on windows 2000, for example   :U
unless i am doing something fancy, i try to make them work on win 98 and up - lol

following examples is a good idea
but, it will be more meaningful if you have a grasp on the basics

if you don't do anything else, have a look at Randy's chapter 6 - that will help a lot
and - don't try to read it like a book
instead, browse through it
if you find something that looks like fun, try it out in some code

assemble as a console app...
        INCLUDE \masm32\include\masm32rt.inc

        .CODE

_main   PROC

        mov     eax,12345678h
        push    eax
        print   uhex$(eax),32
        pop     eax
        bswap   eax
        print   uhex$(eax),13,10
        inkey
        exit

_main   ENDP

        END     _main


Thanks ...
By the way here is were you can download a bigger win32.hlp... a complete one.... my AV delete some files ..they could be a false positive

http://www.carabez.com/downloads/win32api_big.zip

From here:

http://www.carabez.com/downloads.html
Title: Re: Get PictureW and PictureH form DIALOG
Post by: dedndave on May 08, 2011, 03:00:57 AM
you might try this one
it may be the same thing   :P
http://www.masm32.com/board/index.php?topic=5433.msg130336#msg130336
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 08, 2011, 03:20:21 AM
LOL for a second I was excited I got some help with my attachments  :dazzled: 
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 08, 2011, 06:50:04 PM
Quote from: hfheatherfox07 on May 08, 2011, 01:42:10 AM
@ qWord I noticed that you replaced the contents of WM_TIMER with the contents of  WM_PAINT from the original example by Tom ....I was wondering the reason for this...


LOL I was at this all night last night , I had the widows open and suddenly I heard Birds Chirping I went to sleep at 6am....

I converted  the second example by Tom to work with a resource file ...how ever my stars came out RED, why???

I also tried to convert the original example of starfield ( which is the one I wanted LOL ) I got the stars on the screen but they freeze , the screen is in complete for some reason...
I assemble using RADASM (Love it) when the exe pops up on the screen , it takes a while for the stars to show , than it works in frames , any thought???





Any thing I try I still get RED stars??? :(
Title: Re: Get PictureW and PictureH form DIALOG
Post by: qWord on May 08, 2011, 07:00:37 PM
Quote from: hfheatherfox07 on May 08, 2011, 06:50:04 PM
Quote from: hfheatherfox07 on May 08, 2011, 01:42:10 AM
@ qWord I noticed that you replaced the contents of WM_TIMER with the contents of  WM_PAINT from the original example by Tom ....I was wondering the reason for this...
IMO the painting should appear while handling WM_TIMER - WM_PAINT should be used to copy an backbuffer to the screen when windows request it. However, this is my opinion - you can surely do the drawing stuff while processing WM_PAINT.

Quote from: hfheatherfox07 on May 08, 2011, 06:50:04 PM
Any thing I try I still get RED stars??? :(
Die you understand the code your are modifying? Also: did you know Iczelion's Tutorials?

qWord
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 08, 2011, 07:34:43 PM
Thank you for explaining that switch in between the two...

I do not recall which one of Iczelion's Tutorials actually deals with this ( I have them all)... but I hit a dead end...

and the original starfiled that I tried to convert has no WM_TIMER ....

Oh well back to the drawing board  ::)



Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 10, 2011, 02:49:07 AM
 :( Again....

This time I tried....

API:

SM_CXFULLSCREEN,
SM_CYFULLSCREEN,

Width and height of the client area for a full-screen window.
To get the coordinates of the portion of the screen not obscured by the tray,
call the SystemParametersInfo function with the SPI_GETWORKAREA value.


So I did:

.code

Start:

invoke GetSystemMetrics, SM_CXFULLSCREEN
mov Xfenetre, eax
shr eax, 1
mov Xfenetrediv2, eax
invoke GetSystemMetrics, SM_CYFULLSCREEN
mov Yfenetre, eax
shr eax, 1
mov Yfenetrediv2, eax   

I still get the same freezing results of the stars... at least I fixed the full screen problem an now the [ESC] works as well

I also had another go at the rotation one...  I think I isolated  the problem to the actual rotate 2D butt but what???

If anybody has some free time to look at this .... I would appropriate that... I hit a wall
Title: Re: Get PictureW and PictureH form DIALOG
Post by: hfheatherfox07 on May 10, 2011, 08:01:22 PM
Success  :bg

If anybody wants it.....