User defined default dialog button

User defined default dialog button

I have a dialog with three buttons -
Overwrite, Append & Cancel
Normally Overwrite is the default and is checked as being the default button.
For some applications I want the Append button to be the default.

I added iret=SetFocus(GetDlgItem(hWnd,IDC_APPEND))
Now the Overwrite button has a thicked border, the Append button has a dashed line around it but when I press Return Overwrite is activated.

I then tried adding a invisible default button IDC_RETURN but this does not help.

How can I change the default button?

Thanks,
David

	integer*4 function OverwriteProc(hwnd, message, wParam, lParam) 
	!**********************************************************
	!MS$ATTRIBUTES STDCALL, ALIAS : '_OverwriteProc@16' :: OverwriteProc
	! for Overwrite Dialog
	use dfwin

	include 'resource.fd'

	integer*4	hwnd, message, wParam, lParam
	integer*4	iret,iCtrl,imess,idControl
	logical*4	lret

	! Unreferenced variables
    lparam = lparam

    select case (message)
    case (WM_INITDIALOG)
		OverwriteProc = 1
		return

    case (WM_SHOWWINDOW)
		if (wParam) then
			iret=SetFocus(GetDlgItem(hWnd,IDC_APPEND))
			iret=ShowCursor(.TRUE.)
		endif
        OverwriteProc = 1
        return

    case (WM_COMMAND)                       ! message: received a command
		iCtrl=LOWORD(wParam)
		iMess=HIWORD(wParam)
		OverwriteProc = 1
		if (imess==EN_SETFOCUS) then
			IDControl=iCtrl					! for Return
		elseif (imess==EN_CHANGE) then
			OverwriteProc = 0
			IDControl=iCtrl					! for Return
			return
		end if
		
		select case (iCtrl)
					
		case (IDC_OVERWRITE)
			lret=EndDialog(hWnd,2)
                        OverwriteProc = 1
				
		case (IDC_APPEND)
			lret=EndDialog(hWnd,1)
                        OverwriteProc = 1

		case (IDCANCEL)		
                        lret = EndDialog(hWnd, 0)
                        OverwriteProc = 1

		case (IDC_RETURN)	! pressed Return 
			select case (IDControl)
			case (IDC_OVERWRITE)
				lret=SendMessage(hwnd,WM_NEXTDLGCTL,GetDlgItem(hWnd,IDC_OVERWRITE),.true.)
			case (IDC_APPEND)
				lret=SendMessage(hwnd,WM_NEXTDLGCTL,GetDlgItem(hWnd,IDC_APPEND),.true.)
			case (IDCANCEL)
				lret=SendMessage(hwnd,WM_NEXTDLGCTL,GetDlgItem(hWnd,IDCANCEL),.true.)
			end select
		end select

	case default
		OverwriteProc=0
	end select

	return

	end function OverwriteProc

4 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Add/remove BS_DEFPUSHBUTTON style using SetWindowLong(GWL_STYLE)?

Jugoslav
www.xeffort.com

...the reason I put the question mark at the end of my last post was because I knew that SetWindowLong(GWL_STYLE) does not always work. See here for a possible workaround.

Jugoslav
www.xeffort.com

Thanks for the suggestions.
BS_DEFPUSHBUTTON looked as if it might be what I wanted, but the documentation was in C and I wasn't sure where to make the call.
I ended up just replacing the SetFocus call in WM_SHOWWINDOW with a WM_NEXTDLGCTL call.
That mow seems to work.
Thanks,
David

	integer*4 function OverwriteProc(hwnd, message, wParam, lParam) 
	!**********************************************************
	!MS$ATTRIBUTES STDCALL, ALIAS : '_OverwriteProc@16' :: OverwriteProc
	! for Overwrite Dialog
	use dfwin

	include 'resource.fd'

	integer*4	hwnd, message, wParam, lParam
	integer*4	iret,iCtrl
	logical*4	lret

	! Unreferenced variables
    lparam = lparam

    select case (message)

    case (WM_INITDIALOG)
		OverwriteProc = 1
		return

	case (WM_SHOWWINDOW)
		if (wParam) then
			lret=SendMessage(hwnd,WM_NEXTDLGCTL,GetDlgItem(hWnd,IDC_APPEND),.true.)	
			iret=ShowCursor(.TRUE.)
		endif
        OverwriteProc = 1
        return

    case (WM_COMMAND)                       ! message: received a command
		iCtrl=LOWORD(wParam)
		
		select case (iCtrl)
					
		case (IDC_OVERWRITE)
			lret=EndDialog(hWnd,2)
            OverwriteProc = 1
				
		case (IDC_APPEND)
			lret=EndDialog(hWnd,1)
            OverwriteProc = 1

		case (IDCANCEL)
            lret = EndDialog(hWnd, 0)
            OverwriteProc = 1

		end select

	case default
		OverwriteProc=0
	end select

	return

	end function OverwriteProc

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi