Author Topic: EC 2. Little question.  (Read 2197 times)

AssemblyChallenge

  • Member
  • **
  • Posts: 110
EC 2. Little question.
« on: October 27, 2015, 07:15:17 AM »
Good friend Ramon:

I'm studing some examples here and just noticed a little change in the starting code from EC2. Before, you got something like:

Code: [Select]
.If uMsg == WM_CREATE

.ElseIf uMsg == WM_COMMAND ; you pressed some button
LoWord wParam

.If Ax == IDC_WINDOW1_THEBUTTONPRESSED
HiWord wParam
.If Ax == BN_CLICKED
                            ; do some stuff with button, etc


And now we got:

Code: [Select]
.If uMsg == WM_CREATE
;====================
; Initialization code
;====================
.ElseIf uMsg == WM_COMMAND
Mov Edx, wParam
Shr Edx, 16
Mov Eax, wParam
And Eax, 0000FFFFH
Invoke OnWindowCommand, hWnd, Eax, Edx, lParam
@@: Ret

My guess is that you can keep the queue cleaner by moving all the messages stuff into the (ie.) "OnWindowCommand" procedure and also unify the x86-x64 code. That's fine, now my question:

Can I just code as usual inside that procedure?. Example:

Code: [Select]
OnWindowCommand Proc Private hWndParent:HWND, uCtlID:ULONG, uCode:ULONG, hWndChild:HWND
;============================================================
; Code for WM_COMMAND messages (child controls notifications)
;============================================================
   
        LoWord wParam

.If Ax == IDC_WINDOW1_THEBUTTONPRESSED
HiWord wParam
.If Ax == BN_CLICKED
                            ; do some stuff with button, etc

Xor Eax, Eax ;Return FALSE
Ret
OnWindowCommand EndP

Because there are less examples now and none include this scenary, they just go as usual and don't use this new funcionality.

Regards.

rsala

  • Moderator
  • Member
  • *****
  • Posts: 274
    • Easy Code
Re: EC 2. Little question.
« Reply #1 on: October 27, 2015, 09:41:35 AM »
Dear AssemblyChallenge,

The answer to your question is YES, you can code as usual inside the "OnWindowCommand" procedure. The idea was to unify all WM_COMMAND messages in that procedure. The examples still are in the "old format" because they were converted from EC 1.

Regards.
EC coder

AssemblyChallenge

  • Member
  • **
  • Posts: 110
Re: EC 2. Little question.
« Reply #2 on: October 28, 2015, 05:26:55 AM »
Ok, but seems like I'm not following the new rules  :lol:

As the procedure says:

Code: [Select]
.ElseIf uMsg == WM_COMMAND
Mov Edx, wParam
Shr Edx, 16
Mov Eax, wParam
And Eax, 0000FFFFH
Invoke OnGroupTestCommand, hWnd, Eax, Edx, lParam

Then the right parameter would be Edx (meaning uCode) but it doesn't works if I do:

Code: [Select]
OnGroupTestCommand Proc Private hWndParent:HWND, uCtlID:ULONG, uCode:ULONG, hWndChild:HWND
;============================================================
; Code for WM_COMMAND messages (child controls notifications)
;============================================================

    LoWord uCode

.If Ax == IDC_GROUPTEST_BUTTON1
HiWord uCode
.If Ax == BN_CLICKED

Invoke MessageBox, NULL, Addr MsgBoxText, Addr MsgBoxCaption, MB_OK

Return TRUE
.EndIf
.EndIf

Xor Eax, Eax ;Return FALSE
Ret
OnGroupTestCommand EndP

Also tried the others who doesn't works or produce weird result. Could you please point my mistake?

Thank you.

dedndave

  • Member
  • *****
  • Posts: 8808
  • Still using Abacus 2.0
    • DednDave
Re: EC 2. Little question.
« Reply #3 on: October 28, 2015, 08:09:34 AM »
as it happens, BN_CLICKED is 0, and is in the high word of wParam
the low word is the control identifier (0 to 65535)

so, if you say...
Code: [Select]
    .if (word ptr wParam+2)==BN_CLICKED
        .if word ptr wParam)==MY_CONTROLID

you have verified that the high word is 0, and the low word is MY_CONTROLID

you can just as easily say...
Code: [Select]
    .if wParam==MY_CONTROLID
it saves you a step   :P

but - if you need to get both hi and low words....
we had a discussion about this - nidud had the best code

http://masm32.com/board/index.php?topic=3764.msg39845#msg39845

it went something like this
Code: [Select]
    mov     edx,wParam
    movzx   eax,dx        ;EAX = low word (unsigned)
    shr     edx,16        ;EDX = high word (unsigned)

;OR

    mov     edx,wParam
    movsx   eax,dx        ;EAX = low word (signed)
    sar     edx,16        ;EDX = high word (signed)

rsala

  • Moderator
  • Member
  • *****
  • Posts: 274
    • Easy Code
Re: EC 2. Little question.
« Reply #4 on: October 28, 2015, 10:38:24 AM »
AssemblyChallenge,

In the OnGroupTestCommand 'uCtlID' already is the loword of 'wParam' and 'uCode' already is the hiword of 'wParam', so you sholud not do this:

    LoWord uCode
    .If Ax == IDC_GROUPTEST_BUTTON1

Instead you should do:

    .If uCtlID == IDC_GROUPTEST_BUTTON1
        .If uCode == BN_CLICKED
            ;Button1 has been pushed
        .EndIf
    .EndIf


The idea of this new procedure was to simplify the WM_COMMAND messages. Extracting the CtrlID and the CtrlCode from 'wParam' is done in the WM_COMMAND message of the main procedure (.ElseIf uMsg == WM_COMMAND).

EC coder

AssemblyChallenge

  • Member
  • **
  • Posts: 110
Re: EC 2. Little question.
« Reply #5 on: October 29, 2015, 01:01:14 AM »
Thank you! Now it works :greenclp:

I overlooked the parameter stuff on OnGroupTestCommand. Time for more coffee.  :icon_redface:

rsala

  • Moderator
  • Member
  • *****
  • Posts: 274
    • Easy Code
Re: EC 2. Little question.
« Reply #6 on: October 29, 2015, 07:38:15 AM »
 :t
EC coder