News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

wsprintf [resolved]

Started by chemicalNova, May 05, 2005, 05:09:24 PM

Previous topic - Next topic

chemicalNova

Howdy all,

I know how sprintf() works in C++, but was wondering as to the syntax in MASM? I'm trying to set the title of my application, by combining the currently open filename, and the application title. I believe this is the standard? "Filename - Program name". The parameter I'm using is of a DWORD type, and I'm wondering if this will work with wsprintf? Actually, I'm kinda

Ta in advance, :8)

chem

Nilrem


    invoke wsprintf, addr Buffer, addr var1, addr var1
    invoke StdOut, addr Buffer

Hope this helps.

chemicalNova

Hey Nilrem,

It kinda does, but I kinda need a bit more. For example, a translation of this would be..

sprintf (buffer, "%d plus %d is %d", a, b, a+b);

?

I just need a comparison/conversion from C++ to get it..

Thanks in advance, :8)

chem

chemicalNova

Ok, I got that working, it assembles fine, but when I try and set the window title, it crashes (the program, not my PC).

szWinDocTitleBuff "%s - %s",0

...

invoke SetWinDocTitle,szFileName
invoke SetWindowText,hWin,szWinDocTitleBuff

...

SetWinDocTitle proc szFN:DWORD
;set the title of the editor, as "Filename - Cdelia Edit"
invoke wsprintf,szWinDocTitleBuff,szFN,szDisplayName
SetWinDocTitle endp

Does that look correct?

Ta in advance,

chem :8)

Nilrem

I think I understand your question, well what you would do is define a or b as %d.
Well...

--
int wsprintf(

    LPTSTR lpOut,   // pointer to buffer for output
    LPCTSTR lpFmt,    // pointer to format-control string
    ...   // optional arguments
   );
--

so you need a buffer
addr buffer
and a format-control string
so in .data
FormatString db "%d",0
String db "Hi",0

so...


invoke wsprintf, addr buffer, addr FormatString, addr SomeString
invoke StdOut, addr buffer


hmmm I think that is right, not really sure.

Nilrem

No idea for the second question sorry.

chemicalNova

It still crashes, but assembles without error. Is anyone able to shed some light on the wsprintf function, and how I can use it to change the text of my application, in this format: "Filename - Application Name"?

Sorry, it's just bugging me. I'll keep trying. If I can't get it soon, I'll just sleep on it :)

chem


SamiP

Hope this helps.


.486
.MODEL FLAT, STDCALL
option casemap:none

include d:\masm32\include\windows.inc
include d:\masm32\include\kernel32.inc
include d:\masm32\include\user32.inc
include d:\masm32\include\masm32.inc
includelib d:\masm32\lib\kernel32.lib
includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\masm32.lib


Main PROTO

.const

.data
FileName db "This is your filename", 0
AppName db "This is your Applications name", 0
FormatString db "%s - %s", 0
OutputBuffer db 1024 dup (0)

.data?

.code
Start:
invoke Main
invoke ExitProcess, eax

Main proc
invoke wsprintf, ADDR OutputBuffer, ADDR FormatString, ADDR FileName, ADDR AppName
invoke StdOut, ADDR OutputBuffer
xor eax, eax

Exitus:
ret
Main endp

end Start

chemicalNova

I got it working all :8)

Thanks for the help guys, those were both very helpful.

invoke wsprintf,ADDR szWinDocTitleBuff, ADDR szWinDocTitleFormat, ADDR szFileName, ADDR szDisplayName
;invoke StdOut,ADDR szWinDocTitleBuff
;xor eax,eax
invoke SetWindowText,hWin,ADDR szWinDocTitleBuff

Ta :8)

chem

pbrennick

chemicalNova,

I see you have solved your problem but I would do it slightly different.


invoke wsprintf,ADDR szWinDocTitleBuff, ADDR szWinDocTitleFormat, ADDR szFileName, ADDR szDisplayName
xor eax,eax
invoke SetWindowText,hWin,EAX   ; Sends a NULL so as to clear the caption first
invoke SetWindowText,hWin,ADDR szWinDocTitleBuff


Your method of building the filename buffer is simpler then the one I always use, though, I employ a subroutine to build the string without using wsprinf (never cared for it).  Also, my method will build it with the name of the editor followed by [UNTITLED] until a file is actually opened.  And it will append an asterisk if the file has been modified, think about that.

Paul