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

dunno what that means but all assembled OK... Program still crashed? :dazzled:

qWord

FPU in a trice: SmplMath
It's that simple!

dedndave

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

hfheatherfox07

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

hfheatherfox07

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 :)

qWord

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
FPU in a trice: SmplMath
It's that simple!

hfheatherfox07

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? :(





dedndave


hfheatherfox07

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....

dedndave

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

hfheatherfox07

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?



dedndave

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

hfheatherfox07

@ 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???



hfheatherfox07

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