Please help me to configure object Button properties with MASM32

Started by elmo, October 19, 2010, 05:40:56 AM

Previous topic - Next topic

elmo

I have problems:
1.PROBLEM 1
I create button with X=20, Y=30, Width=100, Height=20 on hWin

   ;CREATE BUTTON
   invoke CreateWindowEx,
         0,ADDR BUTTONclass,
         ADDR BUTTON1caption,
         WS_CHILD or WS_VISIBLE,   
         20,30,100,20, hWin,1,
         400000h,NULL
   mov hButton1,eax

It 100% work perfectly.
But I want do this:
When I click that Button, I want to show X, Y, Width, Height, hButton1 of that Button in a MessageBox.
Could you help me to solve this problem? Thank you.






2.PROBLEM2
I can change the Caption' properties of that button with:
   invoke SetWindowText,hButton1,SADD("Button1")

In that code, I must write hButton1.

I try to get the value of hButton1 with:

invoke MessageBox, 0, str$(hButton1), str$("This is value of hButton1. Try to change properties of Button1 with this value."), 0

Example: it's value is 144750. I type this value on a TextBox. I get that value from the TextBox. Save it to IdValue. Then, I do the same thing when I change the Caption' properties of that Button with:

   Invoke GetWindowText,hEdit1,addr IdValue,30
   invoke SetWindowText, IdValue,SADD("Button2")

But. It can't change the caption of that button.
Could you help me to solve this problem? Thank you.








3.PROBLEM3
In Borland C++Builder6 or other languages,
if you want to create button: you just click it from the toolbox then click on the Form area.
And it's property (like caption, etc..) appear on the ObjectInspector (in BorlandC++Builder6).
We can change top, left' value of that button by click it and drag it to other position in the Form area.
I try the same thing with MASM32.
I create button with:

   ;CREATE BUTTON
   invoke CreateWindowEx,
         0,ADDR BUTTONclass,
         ADDR BUTTON1caption,
         WS_CHILD or WS_VISIBLE,   
         20,30,100,20, hWin,1,
         400000h,NULL
   mov hButton1,eax

Then I run it's exe file. I try to change top, left' value of that button by click it and drag it to other position in the Form area.
But I can't do this.
That's very hard to do this.
Could you help me to solve this problem? Thank you.

Fritz Gamaliel

Sorry for ask you a lot of questions.
be the king of accounting programmer world!

jj2007

invoke SetWindowText,hButton1,SADD("Button1")
...
invoke SetWindowText,idValue,SADD("Button2")

BogdanOntanu

Fritz,

We are not here to solve your problems (no matter how many they are) ...

We are here to teach you how to solve your problems yourself.

Apparently your "Problem.2" was solved nicely by jj2007.

Can you tell us what did you do in order to try and solve the "problem.1" and "problem.3" in your message?

Share your thoughts and research on those problems... how do you expect them to be "solved" conceptually speaking?

Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

jj2007

Quote from: BogdanOntanu on October 19, 2010, 07:50:42 AM
Apparently your "Problem.2" was solved nicely by jj2007.

Well, not really. I had read it superficially - the problem is here:
QuoteExample: it's value is 144750. I type this value on a TextBox. I get that value from the TextBox. Save it to IdValue.

Fritz, check in \masm32\help\masmlib.chm the atodw function. Besides, Bogdan is perfectly right: You will not learn programming with copy & paste and asking many questions. \masm32\help\* is full of interesting stuff, read it together with the Masm32 examples. Then, if you have a concrete problem with own code, come back here and ask.

If you want to get quickly a useful application, and if you are familiar with BASIC syntax, try MasmBasic: It's a library that allows to mix Masm32 with Basic. Not everybody's taste, of course, but it might help you to concentrate on real assembly problems. Note that push eax and pop eax are the only "real" assembly instructions in the example below, but really, you can mix MB freely with the Masm32 library...

Quoteinclude \masm32\MasmBasic\MasmBasic.inc
Init
   GetFiles *.asm   ; get all assembler sources in the current folder, put them in the Files$() array
   push eax      ; #files found
   Print Str$("%i files found:
\nNo.\tBytes\tName", [esp])   ; \n is newline, \t is tab
   pop eax
   For_ n=0 To Min(9, eax-1)   ; eax-1 is valid syntax, also ebx+9, eax-ebx, MyDword+eax etc; only first arg can be mem variable
      Print Str$("\n#%i\t", n+1)
      Print Str$(Lof(Files$(n))), Tb$, Files$(n)
   Next
   Inkey
CrLf$, "--- press any key ---"
Exit
end start

Your problem 2 would look as follows in MB:
Button1 proc ; this proc called when clicking upper button
SetWin$ hEdit=Str$("%i \nWow!", hButton1)
ret
Button1 endp

Button2 proc uses esi ebx ; this proc called when clicking lower button
Let esi=Win$(hEdit) ; get the current string in editbox
mov ebx, Val(esi) ; get the number
SetWin$ ebx=Mid$(esi, Instr_(esi, Cr$)+1) ; use it to set the text after CR aka chr$(13)
SetWin$ hEdit=LastError$() ; show success or failure in the editbox
ret
Button2 endp


Test its behaviour with the attached executable. I deliberately do not provide the full source.

elmo

Here is my code.
I create 1 Toolbar, 1 Button, 1 EditBox.
When I do right-click , it will show value of hButton1.
I type it on the EditBox. Then, I click Toolbar New. It will get the Text from EditBox and change the caption of that Button via SendMessage. But, It fail.
Could you help me to solve this problem?
Thank you


For Problem1, When I click that Button1 , it's fail to get it's X,Y,Width,Height
For Problem3, When I drag it to other position in Form area, it can't move.
I want it move and show it X,Y,Width,Height.
Could you help me to solve this problem?
Thank you



      .if uMsg == WM_CREATE
         ;CREATE THE TOOLBAR
         mov tbb.iBitmap,   0
         mov tbb.idCommand, 0
         mov tbb.fsState,   TBSTATE_ENABLED
         mov tbb.fsStyle,   TBSTYLE_SEP
         mov tbb.dwData,    0
         mov tbb.iString,   0

         invoke CreateToolbarEx,
                  hWin,
                  WS_CHILD or WS_CLIPSIBLINGS,
                  300,1,0,0,ADDR tbb,
                  1,16,16,0,0,sizeof TBBUTTON
         mov hToolBar4, eax
         invoke ShowWindow,hToolBar1,SW_SHOW



         ;SELECT TOOLBAR BITMAP FRM COMMCTRL DLL
         mov tba.hInst, HINST_COMMCTRL
         mov tba.nID, 2      ;btnsize 1=big 2=small
         invoke SendMessage,hToolBar1,TB_ADDBITMAP,1,ADDR tba


         ;ADD BUTTONS TO TOOLBAR
         ;TOOLBAR NEW
         mov tbb.iBitmap,   STD_NEW
         mov tbb.idCommand, 1001
         mov tbb.fsStyle,   TBSTYLE_BUTTON
         invoke SendMessage,hToolBar1,TB_ADDBUTTONS,1,ADDR







         ;CREATE BUTTON1
         invoke CreateWindowEx,
                  0,ADDR BUTTONclass,
                  ADDR BUTTON1caption,
                  WS_CHILD or WS_VISIBLE,   
                  20,30,100,20, hWin,1,
                  400000h,NULL
         mov hButton1,eax





         ;CREATE EDITOR
         mov eStyle, WS_VISIBLE or WS_CHILDWINDOW or WS_VSCROLL or WS_HSCROLL or ES_NOHIDESEL or ES_AUTOVSCROLL or ES_AUTOHSCROLL or ES_MULTILINE
         invoke CreateWindowEx,
                  WS_EX_CLIENTEDGE,ADDR EDITclass,
                  NULL,
                  eStyle,5,0,1000,700,hWin,555,400000h,NULL
         mov hEdit1, eax




         ret






      .elseif uMsg == WM_RBUTTONUP
         ;GET HANDLE VALUE OF hButton1
         ;invoke MessageBox, hWin, str$(hButton1), chr$("This is handle value of hButton1. Try to configure properties of Button1 with this value."), 0

         ret








      .elseif uMsg == WM_COMMAND
         ;TOOLBAR NEW
         .if wParam == 1001
               invoke GetWindowText,hEdit1,ADDR IdValue,30

               ;I WANT DO THIS BUT I CAN'T
               invoke SetWindowText,IdValue,SADD("Caption1")
               ;invoke SetWindowText,hButton1,SADD("Caption1")


         .endif
      .endif
            
be the king of accounting programmer world!

elmo


In my other program,
I create a toolbox by do right-click.
It only contain button.
If I click it, it will show button in a Form with ID=1
Then I click it again, it must the new button ID=2
I have create program below:
But new button with ID=2 is not detected.
Could you help me to solve this problem?
Thank you

Fritz Gamaliel

   .elseif uMsg2 == WM_RBUTTONUP
      add ID,1
      invoke CreateWindowEx,
               0,ADDR BUTTONclass,
               ADDR BUTTON1caption,
               WS_CHILD or WS_VISIBLE,
               x,y,width,height,hWin,ID,
               400000h,NULL


   .elseif uMsg2 == WM_COMMAND
         .if wParam2 == 1
            invoke MessageBox,hWin2,chr$("you click button1"),ADDR MSG_TITLECloseForm1,MB_YESNOCANCEL+MB_ICONQUESTION
            ret
         .endif

         .if wParam2 == 2
            invoke MessageBox,hWin2,chr$("you click button2"),ADDR MSG_TITLECloseForm1,MB_YESNOCANCEL+MB_ICONQUESTION
            ret
         .endif
be the king of accounting programmer world!

elmo

I do the same thing.
But now is for configure height,top,left,width properties of the object


Now, I know how to change width, height, top, left properties of the object:
Example: I want to change width, height, top, left properties of the Button, I only do this:
      invoke MoveWindow,hButton1,0,0,100,100,TRUE

But, when I change that value with variable DWORD type:
      invoke GetWindowText,hEdit1,ADDR STRTop,30
      invoke GetWindowText,hEdit2,ADDR STRLeft,30
      invoke GetWindowText,hEdit3,ADDR STRWidth,30
      invoke GetWindowText,hEdit4,ADDR STRHeight,30


      invoke lstrcpy,addr top,addr STRTop
      invoke lstrcpy,addr left,addr STRLeft
      invoke lstrcpy,addr width,addr STRWidth
      invoke lstrcpy,addr height,addr STRHeight

      invoke MoveWindow,hButton1,top,left,height,width,TRUE

It not work.
Could you help me to solve this problem?
Thank you.
be the king of accounting programmer world!

jj2007


elmo

be the king of accounting programmer world!

elmo

Hi jj2007,
Here I have try your suggestion:
Below is my code:

add ID,1
mov x,0
mov y,0
invoke atodw,addr ID

invoke CreateWindowEx,
0,ADDR BUTTONclass,
ADDR BUTTON1caption,
WS_CHILD or WS_VISIBLE,
x,y,75,25,hWin2,ID,
400000h,NULL

it still can not detect button with ID=2
it only can detect button with ID=1.
Could you help me to solve this problem?
Thank you
Fritz Gamaliel
be the king of accounting programmer world!

jj2007

Quote from: FritzCAT22 on October 21, 2010, 06:31:12 AM
Hi jj2007,
Here I have try your suggestion:
Below is my code:

add ID,1


That is not 'your code'. It's a tiny snippet that just shows that you have not read the documentation. Learn to zip your complete code, and to attach it to your posts.