Author Topic: In the gui path...  (Read 1915 times)

jj2007

  • Member
  • *****
  • Posts: 8243
  • Assembler is fun ;-)
    • MasmBasic
Re: In the gui path...
« Reply #15 on: November 05, 2017, 08:42:57 PM »
my programs will become obsolete in a year and I will not write any more as I would write a year ago. And there will be commands that will no longer support new processors that were two or five years ago

Carissimo Mikl,

A quick file search for the *.asc ending finds over 5,000 files in my \Masm32 folder, the oldest being about 10 years old. If one of them doesn't build by hitting F6, alarm bells ring in my head, and I start investigating what may have changed. Same for GfaBasic files with the *.gfw extension, they build fine even if they date back 40 years.

You may call that paranoid, but it distinguishes a serious coder from a trial-and-error script kiddie. You are not in the latter category, you have proven that you can produce great stuff here, especially with the Iczelion tutorials that you ported to 64-bit land. Google mikl Iczelion to see what I mean. People value your work.

The ability to build code that is more than a year old is also something that distinguishes the Masm32 SDK from "professional" packages like Visual Studio. The main reason why I don't take Micros**t seriously is indeed that everytime I find a little hello world proggie on the web that is older than, say: 2 years, and I try to load it into Visual Crap, the M$ flagship complains whiningly that it is unable to open such old stuff. Or it simply hangs. That is truely "professional", but guess what, we can do better, and we are proud of that :icon_mrgreen:

In short: Read carefully what Hutch writes above. He is 100% right ;-)

P.S.: "there will be commands that will no longer support new processors" - very unlikely. M$ is scared of breaking legacy code, and Intel/AMD sell CPUs for the M$ world. Even dinosaurs like lodsb and jecxz work just fine in 64-bit code (but aaa aad aam don't, see x64 Instructions). Of course, one has to draw a line somewhere - nobody here wants to support Windows 95. My rule with MasmBasic is to use SSE2 and below in library routines, which means it is fast enough and will run on 99.x% of all machines. Similar for API calls: XP must support it; if a user decides that a Vista API call is needed, so be it - he is free to do that in "pure" assembly, but a library should give a high weight to compatibility (one reason btw why Linux never got a foot in the door).

felipe

  • Member
  • ****
  • Posts: 608
  • Asssssssembly language...said the snake.
Re: In the gui path...
« Reply #16 on: November 06, 2017, 01:28:15 PM »
nobody here wants to support Windows 95.

 :lol:

=======================================================================
I'm agreed with all of you, basically because you all know the difference between building windows's "standard applications" and something particular. The later can be of different kinds. Of course the later type also should be based in reasonable knowledge and experience. By just trying things and see what happen later it will be probably a loose of time (at least for someone). But i do support to professionals (and with that i just mean someone who understand what he/she is doing) with some special works. They may not run in more than a few machines, but that's precisely one of the main advantages of assembly programming: the specific thing. Of course most will say is a disadvantage.
You all also know how OS specific it is, so yeah if someone want's to try more special things and is an assembly programmer  :P, if he/she knows what he/she is doing, so ok. If you don't know, don't loose your time in that way. First learn how things really work, then explore but based in what you already know of course.
Well at least that's how i work...

 :icon14: :icon14:
Felipe.

felipe

  • Member
  • ****
  • Posts: 608
  • Asssssssembly language...said the snake.
Re: In the gui path...
« Reply #17 on: December 13, 2017, 02:19:34 PM »
I had been very bussy, but now i have more time to work on my codings. Here it is a premature version of what should be a more complete version of the next example program just based in the book. Remember, just based, is not a copy, it's just a guide.
The .exe is attached.

Code: [Select]
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; This program was started by Felipe at 2017-12-12.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

.386
.model      flat,stdcall
option      casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\gdi32.inc
includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\gdi32.lib



.data
align 1
claname     byte        "TEXT CLASS",0
wndname     byte        "A WEIRD TEXT-GRAPHIC (WHAT?) PROGRAM JUST FOR ALL OF YOU!",0
textmsg     byte        "Hello friends, this is a very simple program. You can see it, hate it or laught of it."
            byte        "It's your choice...                                                                   "
            byte        "I'm working with that old (may i say old?) book from Petzold, but i had to write this "
            byte        "before  i finish the example that i'm studying.                                       "
            byte        "In my opinion, or IMHO, GDI looks pretty cool stuff.                                  "
            byte        "I hope you can visualize this text closely to normal, since i'm not trying to adjust  "
            byte        "in the program nothing related to your system metrics. Sorry for that, you know i'm a "
            byte        "beginner.                                                                             "
            byte        "Hey, i had an idea!: From now on all my post and replies will be in a window program  "
            byte        "like this one, with my opinions hardcoded in a text like this...                      "
            byte        "You will have to download them and ...HAHAHAHA!!! You will hate me more, right?       "                                       
            byte        "Ok, no more jokes.                                                                    "


.data?
align 4
hmodule     dword       ?
wndclaex    dword       12 dup(?)                                                       ; The WNDCLASSEX structure.
hwnd        dword       ?
msgstru     dword       7 dup(?)                                                        ; The MSG structure.
hdc         dword       ?
paintstru   dword       12 dup(?)                                                       ; The PAINTSTRUCT structure. 


.code
align 4
start:
            push        NULL
            call        GetModuleHandle
            mov         hmodule,eax

            mov         dword ptr wndclaex[0],sizeof wndclaex
            mov         dword ptr wndclaex[4],CS_HREDRAW or CS_VREDRAW
            mov         dword ptr wndclaex[8],wndproc
            mov         dword ptr wndclaex[12],0
            mov         dword ptr wndclaex[16],0
            mov         wndclaex[20],eax
            push        500
            push        eax
            call        LoadIcon
            mov         wndclaex[24],eax
            push        IDC_ARROW
            push        NULL
            call        LoadCursor
            mov         wndclaex[28],eax
            push        WHITE_BRUSH
            call        GetStockObject
            mov         wndclaex[32],eax
            mov         dword ptr wndclaex[36],NULL
            mov         dword ptr wndclaex[40],offset claname   
            mov         dword ptr wndclaex[44],NULL

            push        offset wndclaex
            call        RegisterClassEx

            push        NULL
            push        hmodule
            push        NULL
            push        NULL
            push        CW_USEDEFAULT
            push        CW_USEDEFAULT
            push        CW_USEDEFAULT
            push        CW_USEDEFAULT
            push        WS_OVERLAPPEDWINDOW
            push        offset wndname       
            push        offset claname
            push        WS_EX_OVERLAPPEDWINDOW
            call        CreateWindowEx
            mov         hwnd,eax

            mov         esi,eax

            push        SW_SHOWNORMAL
            push        esi
            call        ShowWindow

            push        esi
            call        UpdateWindow

            mov         esi,offset msgstru


align 4
msgloop:

            push        0
            push        0
            push        NULL
            push        esi
            call        GetMessage
            cmp         eax,0
            jz          endmsglop

            push        esi
            call        TranslateMessage

            push        esi
            call        DispatchMessage

            jmp         msgloop


align 4
endmsglop:
           
            push        dword ptr[esi+8]
            call        ExitProcess


align 4
wndproc:

            push        ebp
            mov         ebp,esp
         
            cmp         dword ptr[ebp+12],WM_PAINT
            jne         destroy

            push        offset paintstru
            push        hwnd
            call        BeginPaint
            mov         hdc,eax

            push        00e00000h                                                           ; Blue color for the text.
            push        eax
            call        SetTextColor

            mov         esi,offset textmsg
            xor         edi,edi                                                             ; The y coordinate.
            mov         ebx,12                                                              ; Number of lines.
           
         


align 4
allstri:
            push        86                                                                  ; Number of characters per line.
            push        esi                                                                 ; Line addresses.   
            push        edi                                                                 ; Y coordinate.   
            push        0                                                                   ; X coordinate.
            push        hdc
            call        TextOut
           
            add         edi,25                                                              ; Increase y coordinate.       
            add         esi,86                                                              ; Get the address of the next line of text.
            dec         ebx                                                                 ; Decrease the total of lines to print (draw).
            jnz         allstri                                                             ; Repeat until all the string are drawed.   
                               
            push        offset paintstru
            push        hwnd
            call        EndPaint

            xor         eax,eax

            mov         esp,ebp
            pop         ebp

            ret         16


align 4
destroy:

            cmp         dword ptr[ebp+12],WM_DESTROY
            jne         wnddefau
           
            push        0
            call        PostQuitMessage

            xor         eax,eax

            mov         esp,ebp
            pop         ebp

            ret         16


align 4
wnddefau:

            push        dword ptr[ebp+20]
            push        dword ptr[ebp+16]
            push        dword ptr[ebp+12]
            push        dword ptr[ebp+8]
            call        DefWindowProc

            mov         esp,ebp
            pop         ebp

            ret         16

            end         start

Felipe.

jj2007

  • Member
  • *****
  • Posts: 8243
  • Assembler is fun ;-)
    • MasmBasic
Re: In the gui path...
« Reply #18 on: December 13, 2017, 07:22:47 PM »
You could refine it and make it more efficient if you create the WNDCLASSEX structure directly on the stack:
Code: [Select]
  push NULL ; last arg of CreateWindowEx
  push NULL
  call GetModuleHandle
  push eax ; 2nd last arg of CreateWindowEx
  push 32512
  push eax
  xchg eax, ebx
  call LoadIcon
  push NULL ; wndclaex[44]
  push offset claname
  push NULL ; wndclaex[36]
  push WHITE_BRUSH
  call GetStockObject
  push eax ; wndclaex[32]
  push IDC_ARROW
  push NULL
  call LoadCursor
  push eax ; wndclaex[28]
  push 32512
  push ebx
  call LoadIcon
  push eax ; wndclaex[24]
  push ebx ; wndclaex[20]
  push 0 ; wndclaex[16]
  push 0 ; wndclaex[12]
  push wndproc
  push CS_HREDRAW or CS_VREDRAW
  push WNDCLASSEX
  push esp
  call RegisterClassEx
  push NULL
  push NULL
  push CW_USEDEFAULT
  push CW_USEDEFAULT
  push CW_USEDEFAULT
  push CW_USEDEFAULT
  push WS_OVERLAPPEDWINDOW
  push offset wndname
  push offset claname
  push WS_EX_OVERLAPPEDWINDOW
  call CreateWindowEx
  add esp, WNDCLASSEX

felipe

  • Member
  • ****
  • Posts: 608
  • Asssssssembly language...said the snake.
Re: In the gui path...
« Reply #19 on: December 14, 2017, 04:02:25 AM »
Man, i like it and i understood the sequence, but i'm a little confused with this:  :redface:

  push WNDCLASSEX           ; How this could give us
  push esp                          ;    the size of the structure?
 
And this:

add esp, WNDCLASSEX        ; Wow is possible to do this! (I already have assemble the code without errors).

I will check the code in a moment with a debugger to understand this three statments (instructions) later. I guess you were assuming a local wndclassex, but it make no sense for me by now, because looks like you don't use that local space. I mean you are using part of it but not all of it (maybe all the program is local?).
I will try it with a debugger in a moment. Thanks btw, i think it's a great job!  :icon14:
(But i need to know it for sure)  :biggrin:
Felipe.

felipe

  • Member
  • ****
  • Posts: 608
  • Asssssssembly language...said the snake.
Re: In the gui path...
« Reply #20 on: December 14, 2017, 05:16:40 AM »
Ok jj i solved the puzzle:  :biggrin:

push WNDCLASSEX           ; The size of the structure (in bytes).
push esp                          ; The starting address of the structure (wich is in the stack).

then:

add esp, WNDCLASSEX     ; Discarding the structure from the stack.

But this later statement most be located inmediately  after registering the class and before continuing pushing the remainders parameters for the CreateWindowsEx function.

You are a hard teacher... :redface:

 :P

Btw, one more thing: I'm still confused how WNDCLASSEX can be interpreted as a number of bytes. This only happen when we push the structure in the stack?, Why use sizeof if not? You have to admit that this is weird and if not, please explain me that.  :greensml:

Thanks.
 :icon14:
Felipe.

jj2007

  • Member
  • *****
  • Posts: 8243
  • Assembler is fun ;-)
    • MasmBasic
Re: In the gui path...
« Reply #21 on: December 14, 2017, 06:46:47 AM »
I'm still confused how WNDCLASSEX can be interpreted as a number of bytes.

WNDCLASSEX, RECT, DWORD etc are structures or types, but they are also just immediate numbers. Test it:
Code: [Select]
include \masm32\include\masm32rt.inc
.code
sometest proc
  ret
sometest endp
start:
  print str$(BYTE), 9, "a byte", 13, 10
  print str$(REAL8), 9, "a Real8", 13, 10
  print hex$(sometest)," a proc", 13, 10
  print hex$(WNDCLASSEX), " a struct", 13, 10
  print str$(sometest), 9, "a proc", 13, 10
  inkey str$(WNDCLASSEX), 9, "a struct", 13, 10
  exit
end start

Code: [Select]
1       a byte
8       a Real8
00401000 a proc
00000030 a struct
4198400 a proc
48      a struct

felipe

  • Member
  • ****
  • Posts: 608
  • Asssssssembly language...said the snake.
Re: In the gui path...
« Reply #22 on: December 14, 2017, 07:30:20 AM »
Cool stuff! Immediate numbers indicating the size in bytes of each one. So they should be just labels for the assembler for indicating to it how many bytes to store, reserve, etc. Nice to know this.


You are a hard teacher... :redface:

 :P


As a matter of fact you are a very good one.  ;) Thanks.
 :t
Felipe.