News:

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

Finding the checked radio button in a dialog

Started by mkdutchman, January 16, 2008, 06:12:06 PM

Previous topic - Next topic

mkdutchman

Hi all,
Today I ran into another problem, I have a group of radio buttons in a dialog, and am trying to find out which button is checked. I did not find a call to do so, other than the IsDlgButtonChecked function. It must not be the right one, as it consistantly returns with a value of 0. What am I missing?



DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if uMsg == WM_INITDIALOG
      invoke SendMessage,hWin,WM_SETICON,1,FUNC(LoadIcon,NULL,IDI_APPLICATION)

    invoke OpenClipboard,NULL
    invoke GetClipboardData,CF_TEXT
    mov hClipboard,eax
    invoke GlobalLock,eax
    invoke SendDlgItemMessage,hWin,101,WM_SETTEXT,NULL,eax
    invoke GlobalUnlock,hClipboard
    invoke CloseClipboard

    invoke CheckRadioButton,hWin,106,109,106
    ; -------------------------------------
    ; return 1 to set focus to 1st control
    ; -------------------------------------
      mov eax, 1
      ret

    .elseif uMsg == WM_COMMAND
      .if wParam == 100
        invoke GetDlgItemText,hWin,101,addr Addrstring,500
        invoke GetDlgItemText,hWin,102,addr ref,10
        invoke GetDlgItemText,hWin,103,addr BoxCount,4

        invoke IsDlgButtonChecked,hWin,106
            cmp eax,NULL
            jz  next107
            mov eax,OFFSET PrMail
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0

next107:
        invoke IsDlgButtonChecked,hWin,107
            cmp eax,NULL
            jz  next108
            mov eax,OFFSET ParMail
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0

next108:
        invoke IsDlgButtonChecked,hWin,108
            cmp eax,NULL
            jz  next109
            mov eax,OFFSET n9to5
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0

next109:
            mov eax,OFFSET CustPickup
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0
       .endif

    .elseif uMsg == WM_CLOSE
      quit_dialog:
        invoke EndDialog,hWin,0
        invoke ExitProcess,NULL

    .endif

    ; -------------------------------
    ; return zero for default action
    ; -------------------------------
    xor eax, eax
    ret

DlgProc endp

george999

I tried this and is working:
invoke IsDlgButtonChecked,hWin,1002
        .if eax==TRUE
        invoke MessageBox,0,0,0,0
        ret
        .endif

MichaelW

mk,

I can't see anything in the code that you posted that would cause IsDlgButtonChecked to return zero for a checked BS_RADIOBUTTON or BS_AUTORADIOBUTTON button.
eschew obfuscation

Tedd

Just for sanity, check that you're actually using the correct dialog item IDs (and they match in the resource definition)..

Otherwise it's "post your code" time :bdg
No snowflake in an avalanche feels responsible.

mkdutchman

Alright, I finally found the bug. Seems the EndDialog API doesn't end the Dialog Procedure on the spot, rather it justs sets a flag and returns. I was thinking the Dialog Procedure terminates as soon as the EndDialog API is called................the error is quite obvious. Below is the debuuged code.
    .elseif uMsg == WM_COMMAND
      .if wParam == 100
        invoke GetDlgItemText,hWin,101,addr Addrstring,500
        invoke GetDlgItemText,hWin,102,addr ref,10
        invoke GetDlgItemText,hWin,103,addr BoxCount,4

        invoke IsDlgButtonChecked,hWin,106
            cmp eax,NULL
            jz  next107
            mov ecx,OFFSET PrMail
            jmp donechk
next107:
        invoke IsDlgButtonChecked,hWin,107
            cmp eax,NULL
            jz  next108
            mov ecx,OFFSET ParMail
            jmp donechk
next108:
        invoke IsDlgButtonChecked,hWin,108
            cmp eax,NULL
            jz  next109
            mov ecx,OFFSET n9to5
            jmp donechk
next109:
           mov ecx,OFFSET CustPickup
donechk:
        invoke EndDialog,hWin,ecx
       .endif


And here is the buggy part

    .elseif uMsg == WM_COMMAND
      .if wParam == 100
        invoke GetDlgItemText,hWin,101,addr Addrstring,500
        invoke GetDlgItemText,hWin,102,addr ref,10
        invoke GetDlgItemText,hWin,103,addr BoxCount,4

        invoke IsDlgButtonChecked,hWin,106
            cmp eax,NULL
            jz  next107
            mov eax,OFFSET PrMail
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0

next107:
        invoke IsDlgButtonChecked,hWin,107
            cmp eax,NULL
            jz  next108
            mov eax,OFFSET ParMail
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0

next108:
        invoke IsDlgButtonChecked,hWin,108
            cmp eax,NULL
            jz  next109
            mov eax,OFFSET n9to5
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0

next109:
            mov eax,OFFSET CustPickup
            mov ShMethodStrptr,eax
        invoke EndDialog,hWin,0
       .endif