News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Win32 My First Window

Started by tda0626, April 24, 2024, 11:05:19 AM

Previous topic - Next topic

C3

Quote from: NoCforMe on May 05, 2024, 12:39:41 PM
Quote from: sinsi on May 05, 2024, 12:27:05 PM
Quote from: NoCforMe on May 05, 2024, 12:22:45 PMTested?
yep
Is .const a different initialized data area, separate from .data?
Pardon my ignorance; never heard of that nor used it.

Read only memory segment.

tda0626

Quote from: NoCforMe on May 05, 2024, 07:00:06 PMYay! It works.

OP: Use Timo's macro instead (below). Much simpler than sinsi's. Use str$("text") in your structure.

Quote from: TimoVJL on May 05, 2024, 06:48:37 PMstr$ MACRO any_text:VARARG
LOCAL txtname
.const
txtname db any_text,0
.data
EXITM <OFFSET txtname>
ENDM
Even I can understand what's going on there.



OK so like this?

str$ MACRO any_text:VARARG
LOCAL txtname
.const
txtname db any_text,0
.data
EXITM <OFFSET txtname>
ENDM

NUMLINES EQU  $sysmetricsSize / sizeof SYSMETRIC_ENTRY

SYSMETRIC_ENTRY STRUCT

            iIndex    DD ?
            szLabel   DD ?
            szDesc    DD ?
           
SYSMETRIC_ENTRY    ENDS





sysmetrics    LABEL SYSMETRIC_ENTRY

SYSMETRIC_ENTRY     <SM_CXSCREEN,    str$("SM_CXSCREEN"),    str$("Screen width in pixels")>
...

$sysmetricsSize    EQU $-sysmetrics

tda0626

Ok I got it to compile and link fine. The program pops up the window but it only prints the last  string entry and some other random garbage.

str$("Same color format flag")

Picture of window

Source code is attached with the inc file.

TimoVJL

I just tested sinsi's idea with .const (.rdata) with poasm.exe and after that with ml.exe and uasm32.exe
uasm.exe gives best error messages.
May the source be with you

jj2007

Quote from: tda0626 on May 06, 2024, 12:03:36 AMthe window but it only prints the last  string

    local    cxChar:DWORD
    local    cxCaps:DWORD
    ; local    cyChar:DWORD
    local    hdc:HDC
    local    i:DWORD
    local    ps:PAINTSTRUCT   
    local    tm:TEXTMETRIC
    local    buffer_size:DWORD
    local    index:DWORD
    local    x:DWORD
    local    y:DWORD
    .DATA?
    cyChar dd ?
      .CODE

Remember that local variables are not permanent.

tda0626

Wow JJ, moved most of the locals to .data? and now it shows  all the data.  :thumbsup: I was thinking it was going to be something complicated with my multiple TextOut sections but never that simple.

Minor issue, if the string has a dash, '-', it doesn't print it correctly.Do you think it might be simple as using a format specifier?

Sysmets1 Working Image


Tim

sudoku

#186
Testing sinsi's pair of macros. Yes you need both! And it werks.
Commenting out either of the pair yields errors.  Must be used together.
Simpler version than originally posted here. (It used a register and 'assume', but opted for the simpler form as shown here).
        include \masm32\include\masm32rt.inc
cstr MACRO lbl,string:VARARG
LOCAL s,x,z
    IFDEF __UNICODE__
        align 2
        IFNB <lbl>
            lbl LABEL WORD
        ENDIF
        FOR s,<string>
            IFIDN @SubStr(s,1,1),<">
                x SUBSTR <s>,2,(@SizeStr(s)-2)
                % FORC c,<x>
                     dw "&c"
                  ENDM
            ELSE
                dw s
            ENDIF
        ENDM
        dw 0
    ELSE
        IFNB <lbl>
            lbl LABEL BYTE
        ENDIF
        FOR s,<string>
            IFIDN @SubStr(s,1,1),<">
                x SUBSTR <s>,2,(@SizeStr(s)-2)
                % FORC c,<x>
                     db "&c"
                  ENDM
            ELSE
                db s
            ENDIF
        ENDM
        db 0
    ENDIF
ENDM

@cstr MACRO string:VARARG
LOCAL s,sss1
sss1 TEXTEQU @CurSeg
.const
cstr s,string
IFIDNI sss1,<_TEXT>
    .code
ELSEIFIDNI sss1,<_BSS>
    .data?
ELSEIFIDNI sss1,<_DATA>
    .data
ENDIF
    EXITM <offset s>
ENDM


RCT1 RECT <@cstr("hello world"), @cstr("masm32 rocks!"), 0, 0>

.code

start:

invoke MessageBox, 0, RCT1.left, RCT1.top, 0
invoke ExitProcess, 0

end start

Yes, I used a RECT structure for this example. We are not drawing with it, so why not. :biggrin:

:cool:

jj2007

Quote from: tda0626 on May 06, 2024, 12:51:16 AMWow JJ, moved most of the locals to .data? and now it shows  all the data.

Locals are fine if you use them inside the same message, i.e. the same handler. Their values are lost when you hit return, but inside the WndProc they are ok.

NoCforMe

Quote from: jj2007 on May 06, 2024, 01:52:56 AMLocals are fine if you use them inside the same message, i.e. the same handler. Their values are lost when you hit return, but inside the WndProc they are ok.
To be more precise: "their (local) values are lost when the routine they're in exits.". Also known as "going out of scope".

Easy to understand why this is: because local variables are allocated on the stack, every time you enter a routine you get whatever stack space happens to be available (meaning that ESP, the stack pointer, will be at some random, though DWORD-aligned, place). So whatever is on the stack when you enter the routine is what you get in any local variable, AKA "garbage". Could be the previous routine's return address, a pointer to something, a temp variable, anything.

Some high-level languages might clear locals to zero on entry to a routine, but one thing you can be sure of is that you can't rely on locals retaining their values from one entry into a routine to another. You might get lucky and find an existing value still there, but don't count on that!

Dunno what hitting return has to do with it. Ah, I get it; I thought you meant "hitting <Return>". You mean reaching the RET of the subroutine. Got it.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: jj2007 on May 06, 2024, 01:52:56 AMTheir values are lost when you hit return

Quote from: NoCforMe on May 06, 2024, 05:02:27 AMtheir (local) values are lost when the routine they're in exits

Apart from returning, are there other ways to exit a proc?

NoCforMe

Sure:
    XOR  ECX, ECX
    DIV  ECX
Assembly language programming should be fun. That's why I do it.

tda0626

Quote from: tda0626 on May 06, 2024, 12:51:16 AMMinor issue, if the string has a dash, '-', it doesn't print it correctly.Do you think it might be simple as using a format specifier?


Never mind, I figured it out. When I was coping from the book, the dash in the book is different than an ASCII dash. Replaced all those in my inc file and now it shows it fine.

 

NoCforMe

Quote from: tda0626 on May 06, 2024, 12:51:16 AMMinor issue, if the string has a dash, '-', it doesn't print it correctly.
The problem is your source (the file sysmets.inc): all the hyphen characters in that file aren't just regular ASCII hyphens, but some kind of Unicode character (maybe an em dash?) that doesn't render correctly. Just go through the file with a regular ASCII text editor and change them all to "normal" hyphens.

I see you answered your own question. Good going!

And congrats on getting this working.
Assembly language programming should be fun. That's why I do it.

sudoku

Congrats, tda0626  :thumbsup:

Hopefully Petzolds next project will be a little more straightforward.  :biggrin:
:cool:

tda0626

Quick question, how would you handle the C Break statement in assembler? Like a jmp to the DefWndProc function?

case WM_VSCROLL:
 switch (LOWORD (wParam))
 {
 case SB_LINEUP:
 iVscrollPos −= 1 ;
 break ;
 case SB_LINEDOWN:
 iVscrollPos += 1 ;
 break ;
 case SB_PAGEUP:
 iVscrollPos −= cyClient / cyChar ;
 break ;
 case SB_PAGEDOWN:
 iVscrollPos += cyClient / cyChar ;
 break ;
 case SB_THUMBPOSITION:
 iVscrollPos = HIWORD (wParam) ;
 break ;
 default :
 break ;
 }