The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Magnum on November 13, 2010, 03:39:18 AM

Title: Works fine in most instances
Post by: Magnum on November 13, 2010, 03:39:18 AM
This works when posting to boards and in Word.

It doesn't when inserting into Notepad.
I am curious as to why.



;clip.asm Use to "pre-fill the clipboard for later use
;
    include \masm32\include\masm32rt.inc

    .data
   
  hglb dd 0
  str1 db "Have a great day,",13, "                          Andy",13,13,"http://intouch.org/magazine/daily-devotional",0

;http://www.happynews.com/

    .code

start:

    ;------------------------------
    ; Place str1 on the clipboard.
    ;------------------------------

    invoke OpenClipboard,NULL
    .IF (eax)
      invoke EmptyClipboard
      invoke GlobalAlloc,GMEM_MOVEABLE,SIZEOF str1
      .IF (eax)
        mov hglb, eax
        invoke GlobalLock,hglb
          ;---------------------
          ; Pointer now in eax.
          ;---------------------
        invoke MemCopy,ADDR str1,eax,SIZEOF str1
        invoke GlobalUnlock,hglb
        invoke SetClipboardData,CF_TEXT,hglb
          ;--------------------------------------------
          ; System now owns object identified by hglb.
          ;--------------------------------------------
        .IF (eax == 0)
          print "SetClipboardData failed",13,10
        .ENDIF
      .ELSE
        print "GlobalAlloc failed",13,10
      .ENDIF
      invoke CloseClipboard
    .ELSE
      print "OpenClipboard failed",13,10
    .ENDIF

    exit
end start

Title: Re: Works fine in most instances
Post by: sinsi on November 13, 2010, 03:49:36 AM
I assume that it is supposed to be 4 lines and notepad makes it one?

13,10 is usual for ascii text -
13 is carriage return (CR), puts the cursor at the start of the line (x=0,y=y)
10 is line feed (LF), puts the cursor one line down (x=x,y=y+1)
Title: Re: Works fine in most instances
Post by: dedndave on November 13, 2010, 03:54:03 AM
QuoteI assume that it is supposed to be 4 lines and notepad makes it one?

and you only see the text in the last line (plus remnants, perhaps), as the previous text is overwritten   :P
Title: Re: Works fine in most instances
Post by: sinsi on November 13, 2010, 04:06:43 AM
That is, of course, on a text screen. Notepad seems to ignore CR if there's no following LF so the message is concatenated.
Title: Re: Works fine in most instances
Post by: dedndave on November 13, 2010, 04:23:12 AM
ah yes - that's right
it will display the ole box char where the CR is   :P
Title: Re: Works fine in most instances
Post by: Magnum on November 13, 2010, 10:45:51 AM
Quote from: sinsi on November 13, 2010, 03:49:36 AM
I assume that it is supposed to be 4 lines and notepad makes it one?

13,10 is usual for ascii text -
13 is carriage return (CR), puts the cursor at the start of the line (x=0,y=y)
10 is line feed (LF), puts the cursor one line down (x=x,y=y+1)


Thanks, putting in the LF made it perfect.


str1 db 'Have a great day,',13,10, '                          Andy',13,10,13,10 ,\
  'http://intouch.org/magazine/daily-devotional',13,10,'http://www.happynews.com/'



Have a great day,
                          Andy

http://intouch.org/magazine/daily-devotional
http://www.happynews.com