News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

EC 2. Little question.

Started by AssemblyChallenge, October 27, 2015, 07:15:17 AM

Previous topic - Next topic

AssemblyChallenge

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:


.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:


.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:


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

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

Ok, but seems like I'm not following the new rules  :lol:

As the procedure says:


.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:


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

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...
    .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...
    .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
    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

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

Thank you! Now it works :greenclp:

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

rsala

EC coder