The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: mkdutchman on January 16, 2008, 06:12:06 PM

Title: Finding the checked radio button in a dialog
Post by: mkdutchman on January 16, 2008, 06:12:06 PM
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
Title: Re: Finding the checked radio button in a dialog
Post by: george999 on January 16, 2008, 07:01:29 PM
I tried this and is working:
invoke IsDlgButtonChecked,hWin,1002
        .if eax==TRUE
        invoke MessageBox,0,0,0,0
        ret
        .endif
Title: Re: Finding the checked radio button in a dialog
Post by: MichaelW on January 16, 2008, 10:11:15 PM
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.
Title: Re: Finding the checked radio button in a dialog
Post by: Tedd on January 17, 2008, 12:12:33 PM
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
Title: Re: Finding the checked radio button in a dialog
Post by: mkdutchman on January 17, 2008, 05:36:34 PM
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