Using the enter key in dialog box

Using the enter key in dialog box

I've build a dialog box in a Fortran Windows Application without using any Win32 API functions. My goal is to have the enter key used at edit boxes the same behaviour as the tab key. Is this possible with the standard Fortran code?
Another question I have is how to get the cursor into a certain edit box without using any keys and without Win32 API functions.
I would be very pleased if someone could help me.

Bruce Curry

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The answer is no, you can't do it without using Win32 API.
For the first part, you even have to subclass edit boxes in
order to obtain this behaviour. This is not very complicated...
or it is, depending on how familiar with Win32 you are :-).
I can send you some samples (jdujic@uns.ns.ac.yu) if you
wish.

Regarding the putting caret in the edit boxes from the
code, you again have to use Win32. You can "link" DFLOGM
and Win32 using Dlg%hWnd member of Dialog structure
(be careful that it is valid _only_ after call to DlgModal, i.e.
in callback functions for controls and dialog itself). Focus
is set (i.e. caret placed into the edit box) using:

iSt = SetFocus(GetDlgItem(Dlg%hWnd,IDC_EDITBOX))

if you want to get the text selected also, call:

iSt = SendMessage(GetDlgItem(Dlg%hWnd,IDC_EDITBOX), EM_SETSEL, 0, -1)

(Tip: You can define a callback function for the dialog itself;
this function is called immediately on call to DlgModal, i.e. before
the dialog is displayed. Just call DlgSetSub(Dlg,IDD_DIALOG1,OnDlgInit) and make the standard callback with prototype OnDlgInit(Dlg,ID,iEvent).
You can place Win32 initialization in that subroutine, e.g. edit controls
subclassing, changing dialog title, repositioning the dialog etc.).

HTH

Jugoslav

Your two lines, Jugoslav, worked great for me in a Quickwin project. Another undocumented case of Win API working with Quickwin....but I noticed the two lines did not work at the beginning or middle of my callbacks - they had to be the last things called in the callback.

What I did is make one callback for the two edit boxes and one check box I wanted the enter key to move the cursor between, and I used a integer in commons called lastfocus to store a number for the last edit box called.

Then I created a button on the dialog, made it the default button (thus triggered by the enter key), and made it invisible. I also had a visible button (button1) which they could click if they were complete with the entry of that record (I let them by-pass the enter cycle by clicking the SAVE THIS RECORD button1 with the mouse).

In the callback for the invisible button, I checked which dialog was last in focus, and gave focus to the next dialog box using your two lines of code.

I've included some code below.

Thank you,

Keith Richardson

   
A. IN SUBROUTINE LAUNCHING DIALOG:  
!callbacks  
!1) for 2 edit boxes and check box  
retlog=DlgSetSub(dlg,IDC_EDIT3,FINDLAST,DLG_GAINFOCUS)  
retlog=DlgSetSub(dlg,IDC_EDIT4,FINDLAST,DLG_GAINFOCUS)  
retlog=DlgSetSub(dlg,IDC_CHECK1,FINDLAST,DLG_GAINFOCUS)  
  
!4) for pressing "SAVE RECORD" button  
retlog=dlgsetsub(dlg,idc_button1,COMPLETE)  
  
!5) for hitting enter button (calls invisible button2)  
retlog=dlgsetsub(dlg,idc_button2,COMPLETE)  
  
!launch dialog box  
retint=DlgModal(dlg)  
  
B. IN FINDLAST CALLBACK ROUTINE:  
if (id==idc_edit3) then  
        lastfocus=1     
elseif(id==idc_edit4) then  
         lastfocus=2  
elseif(id==idc_check1) then  
          lastfocus=3  
else  
          lastfocus=4   !i.e. button1 was pressed last  
endif  
  
C. COMPLETE CALLBACK ROUTINE:  
SUBROUTINE COMPLETE (DLG, ID, CALLBACKTYPE)  
!callback for when USER PRESSES "SAVE RECORD" (IDC_BUTTON1) AND also  
! when user hits enter key (calling default IDC_button2)  
USE DFLIB  
use dfwin      !<---I used this without the only statement and it worked - may need  
USE DFLOGM        !the only statement if you call library routines with conflicting  
IMPLICIT NONE    !definitions in dfwin and dflib/dflogm  
INCLUDE 'RESOURCE.FD'  
include 'tarcom.for'  
TYPE(DIALOG)DLG  
LOGICAL(KIND=4)RETLOG, fnddata, comp, nopos  
INTEGER(KIND=4)ID, CALLBACKTYPE, nchosen, iv, pos, lastpos, iv2  
INTEGER r, ivmrkrcnt, shift, z, y, hwnd, ist  
character str300*300, cv6*6,cv5*5, cv8*8  
real rv, rv1, rv2, rv3  
  
CALL UNUSEDQQ(ID, CALLBACKTYPE)  
  
!if they clicked on button1, skip the normal enter button cycle  
if (id==idc_button1) lastfocus=4  
  
!see if they hit enter to complete entry or to move to next item  
if (lastfocus==1) then      
     !last worked in mrkr len, so move to eff  
     hwnd=setfocus(getdlgitem(dlg%hwnd,idc_edit4))  
     iSt=SendMessage(GetDlgItem(Dlg%hwnd,idc_edit4),EM_SETSEL,0,-1)   
    lastfocus=2  
   return  
elseif (lastfocus==2) then     
    !last worked in mrkr eff, so move to check  
    hwnd=setfocus(getdlgitem(dlg%hwnd,idc_check1))  
   lastfocus=3  
   return  
else  !either it was check box or something else  
   lastfocus=1     
    ....here I have the code to store the data they entered and move  
    on to next record.....then at end just before return:  
     !put focus on first edit box in the se
ries  
     hwnd=setfocus(getdlgitem(dlg%hwnd,idc_edit3))  
     !select all text there  
    iSt=SendMessage(GetDlgItem(Dlg%hwnd,idc_edit3),EM_SETSEL,0,-1)   
     return  
endif  

Leave a Comment

Please sign in to add a comment. Not a member? Join today