Newbie here ... I would like to display an incrementing counter within a Window

Started by ograbme, December 13, 2007, 04:40:50 PM

Previous topic - Next topic

ograbme

Hello All,

The following is code I have cobbled together to "try" to display an incrementing counter within a Window.   It works per se, but has a flaw  :bg .   It requires me to click on the OK button within the window in order for the counter to increment and be displayed.  I would like to simply display a counter while it is incrementing until the decrementing loop has completed and the processing is essentially completed.

Can you point me in the direction to find another API or whatever method to accomplish this?  Obviously the MessageBox API apparently is not the way to go!  :dazzled:

Thanks in advance for any suggestions.

.386
.model flat, stdcall
option casemap :none

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


.data
  szCaption      db 'Message',0
  total          dd 0
  szFormat       db 'Total: %4d',0
  szBuffer       db 64 dup(0)

.code
start:

  mov edx,1000

label1:


  invoke wsprintf,offset szBuffer,offset szFormat,total
  invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK

  inc total
  dec edx
  jnz label1
 
  invoke ExitProcess,0
end start

donkey

A message box is not the way to go with this type of an application, it suspends execution of the thread that calls it until the user dismisses it (by pressing OK or cancel etc...), this is system-modal behaviour and cannot be changed. You should be using a dialog box, dialog boxes have a callback function that you can use to increment the counter.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ograbme

Thanks donkey,

I'll take a look at the dialog box API.  I'm not very familiar with the various API, but then again I'm not very familiar with MASM either!  But it's fun ... it keeps a 72 year out of trouble ... or should that read "in trouble"?   :bg

I'll not you know how I fair ... good or bad.  Appreciate the input.

donkey

Hi,

You should be looking at DialogBoxParam, you will be required to make an RC file and define the dialog, RadAsm can do this for you in it's visual dialog editor if you like however for a simple dialog the rc file would look like this...

#define IDD_DLG1 1000
#define IDC_STC1 1001
IDD_DLG1 DIALOGEX 6,6,194,106
CAPTION "Simple Counter"
FONT 8,"MS Sans Serif",0,0
STYLE 0x10CF0000
EXSTYLE 0x00000000
BEGIN
  CONTROL "",IDC_STC1,"Static",0x50000201,14,25,166,11,0x00000000
END


The actual code is fairly simple, the callback should look something like this, I have used a timer to increment the counter. Note that I program using GoAsm so there will be slight changes to make to translate this to MASM syntax, mainly the branches.

IDD_DLG1 equ 1000

DATA SECTION
hInstance DD ?
szText DB 256 DUP (?)
count DD 0

CODE SECTION

Start:
invoke GetModuleHandle, 0
mov [hInstance],eax
invoke DialogBoxParam,[hInstance],IDD_DLG1,0,ADDR DlgProc,0
invoke ExitProcess,0

DlgProc FRAME hwnd,uMsg,wParam,lParam

mov eax,[uMsg]
cmp eax,WM_INITDIALOG
jne >.WM_TIMER
invoke SetTimer, [hwnd], 99, 1000, NULL
jmp >.EXIT

.WM_TIMER
cmp eax,WM_TIMER
jne >.WM_COMMAND
inc D[count]
invoke wsprintf,offset szText,"Current count : %u", [count]
add esp,12
invoke SendDlgItemMessage,[hwnd], 1001, WM_SETTEXT,0, offset szText
jmp >.EXIT

.WM_COMMAND
cmp eax,WM_COMMAND
jne >.WM_CLOSE

jmp >.EXIT

.WM_CLOSE
cmp eax,WM_CLOSE
jne >.DEFPROC
invoke KillTimer, [hwnd], 99
invoke EndDialog,[hwnd],0

.DEFPROC
mov eax,FALSE
ret

.EXIT

mov eax, TRUE
ret
ENDF
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ograbme

Thanks donkey,

I think I may be in "deep bandini" at the moment.  LOL!  But I'll get there yet ... perhaps I should first take your code here and assemble it using ?RadASM? (I'm not familiar with this, but assume it is probably an IDE of sorts that supports GoASM.  I'll do the necessary search to find it via google as I know I have read something about it.  Then perhaps I will be better suited to make the necessary MASM changes.  I'm certainly have a lot to learn in all areas: e.g., MASM, WinAPI, et al.

I'm on an older system meaning ... Win98 SE so hopefully that won't be a big hinderance.

I'm off to see what I can find in order to assemble your above code and observe how it all plays together.  Thanks again.

donkey

Hi,

RadASM is the ide I use. You will certainly want to take a look at Iczelion's tutorials, they are available at the forum website.

Donkey

Here's the project zipped up for RadASM...

[attachment deleted by admin]
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ChrisLeslie

QuoteI think I may be in "deep bandini" at the moment.  LOL!  But I'll get there yet ...
ograbme, 72 year olds are not supposed to use "LOL"!! :8) :dance:
Chris  :U

ograbme

@Chris,

Ooops, I've been caught!  You've seen that commercial where one skis Mt. Bandini, right?  I do it everyday ... great exercise, but futile at times ...  :U  Aaah, each day brings new challenges whether you're young or old!

@donkey,

Got RasASM and the programming package (only the assembly package though) installed.  After some fiddling on my part got it squared away.  Pretty neat, but I haven't really done much with it as yet except ... to run your counter code.  Yup, that's what I was trying to do and yours was purring mightily pretty!  Thanks again so much.  I have to figure out the "translation" to MASM code so I'll be back (I'm sure) with some more questions.  I'm trying to pick up as much API knowledge as I can to do simple stuff.  I've read many so-called examples on the web, but they really don't go into the detail I need.  There must be some sort of rhyme and reason behind all the naming conventions.  I mean ... I've figured out from reading and observation ... MB_* denotes either Message Box or Message Button, WM_* means (probably Windows Manage(r/ment), etc.  Haven't figured out what WS_* or IDD_* might stand for, but I'm sure there is some sort of logical connotation with them.  I look at the Microsoft API dpcumentation and for whatever reason it looks like Greek to me!   :green

I'll take a look at Iczelion's tutorials ... thanks for pointing me to them.

donkey

Hi,

For messages the naming convention for some are as follows

WM_ Window message
LB_ Listbox message
TTM_ Tool tip message
LVM_ List view message
TVM_ Treeview message
TB_ Toolbar message
NM_ Notification message
HDM_ Header message
TCM_ Tab control message
CB_ Combo box message
PBM_ Progress bar message
STM_ Static control message
EM_ Edit control message
BM_ Button message
HKM_ Hot key message


There are more but that's about all I remember off the top of my head, for constants there are alot of them, 20 or 30 thousand IIRC and way too many prefixes to list here. Generally you don't have to remember them anyway, the PSDK will normally list all of the messages and constants you need, just press SYNC and press the Contents tab.

For WS_ it usually denotes a Window Style constant, IDD_ is not a defined Windows prefix, I use it (as does RadASM by default) to specify the ID of a Dialog, similarly it uses IDC_ to specify the ID of a Control.

Donkey
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ograbme

Hey Donkey,

Outstanding!  Those naming conventions you listed help me immensely to get a better grasp on things.  I'll try to learn how they relate to each of the many API's that exist.

I've been reading Iczelion's Tutorials that you pointed me to.  I like them in that .chm format ... easier for me to read.  I think I read where you had converted them to the .chm format somewhere; so if that is true, darn good job (and if anyone else contributed to that effort ... darn good job!).  This forum has a lot of good people on it willing to share their experiences and knowledge ... impressive IMHO.  Â