- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not sure if this is the right forum for this, but i'll give it a shot. I have a dialog box that pops up and displays a question to the user and there is a little edit control, and I want the user to be able to input a value. The value has certain irrelevant restrictions (numeric, scale from 1 to 6 or 1 to 9 depending on the question). Now my problem is this. I am going for user friendliness. I want a cursor ( the blinking vertical line kind) to be placed inside the edit control by default. The goal is for the user to simply hit the number key corresponding to their answer, then press enter and onto the next question. How do I get the edit control to have a blinking text cursor in it? I was thinking maybe having fortan hitting the tab key x times to get to the edit control or set focus to the edit control somehow. Anyone have any ideas of implementation?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All of that is indeed necessary for a general case of calling a windows API (namely, SetFocus or any other window-related Win32 function does not work until the dialog is "alive", and that is only during DlgModal).
However, Windows is supposed to give initial focus to the dialog control which is the first in the tab order. So, in the dialog editor, go to Layout/Tab order (Ctrl+D last time I checked) and click on the edit box first. No SetFocus necessary.
(My memory might fail me on this, though...)
However, Windows is supposed to give initial focus to the dialog control which is the first in the tab order. So, in the dialog editor, go to Layout/Tab order (Ctrl+D last time I checked) and click on the edit box first. No SetFocus necessary.
(My memory might fail me on this, though...)
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
try giving the edit control focus by using the DLGF_FOCUS flag.
Regards,
David
Regards,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use
iret=SetFocus(GetDlgItem(dlg%hWnd,ID_EDIT1) )
to set focus to the edit box with id ID_EDIT1.
To select all the characters in the edit box use
iresult = DLGSENDCTRLMESSAGE (dlg, controlid, msg, wparam, lparam)
with
controlid=ID_EDIT1
msg=EM_SETSEL
wparam=0
lparam=-1
DLG is the value returned by DLGINIT(id, DLG) when you initialise the dialog
and is of type Dialog which is defined in module IFLOGM if you are using
IVF (DFLOGM if you are using CVF).
iret=SetFocus(GetDlgItem(dlg%hWnd,ID_EDIT1) )
to set focus to the edit box with id ID_EDIT1.
To select all the characters in the edit box use
iresult = DLGSENDCTRLMESSAGE (dlg, controlid, msg, wparam, lparam)
with
controlid=ID_EDIT1
msg=EM_SETSEL
wparam=0
lparam=-1
DLG is the value returned by DLGINIT(id, DLG) when you initialise the dialog
and is of type Dialog which is defined in module IFLOGM if you are using
IVF (DFLOGM if you are using CVF).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've been using intel's visual fortran, but have been using dflogm and everything has been seeming to work fine. I am also using a quickwin approach, so I have a feeling that the code won't work? are the quickwin type(Dialog) and regular win32 type(Dialog) the same structure? Here's another edit control that I need to get a cursor into to give you an idea of what i'm talking about. Am I doing everything horrifically wrong?
subroutine getSubjectInfo(dlg,subjectID,session,bret,iret)
use dflib
use dfwin
use dflogm
!dummy arguments
type(dialog) dlg
integer(4) iret,session
logical(4) bret
character(7) subjectID
!local vars
logical(4) session1,session2
!need to include this, this is the file that knows how the dialog box looks
include 'resource.fd'
! create the dialog
bret = DlgInit(IDD_DIALOG1,dlg)
!I am still unsure whether I need to set focus before or after I set the dialog to modal, so i did both
iret=SetFocus(GetDlgItem(dlg%hWnd,IDC_EDIT1))
!set to modal
iret = dlgmodal(dlg)
iret=SetFocus(GetDlgItem(dlg%hWnd,IDC_EDIT1))
!get data from dialog
bret = dlgget(dlg,IDC_EDIT1,subjectID)
bret = dlgget(dlg,IDC_RADIO1,session1)
bret = dlgget(dlg,IDC_RADIO2,session2)
!close dialog
call DlgUnInit(dlg)
!session1 and session2 are boolean values corresponding to the two radio button,
!this translates the booleans into an integer
if(session1)session=1
if(session2)session=2
end subroutine getSubjectInfo
subroutine getSubjectInfo(dlg,subjectID,session,bret,iret)
use dflib
use dfwin
use dflogm
!dummy arguments
type(dialog) dlg
integer(4) iret,session
logical(4) bret
character(7) subjectID
!local vars
logical(4) session1,session2
!need to include this, this is the file that knows how the dialog box looks
include 'resource.fd'
! create the dialog
bret = DlgInit(IDD_DIALOG1,dlg)
!I am still unsure whether I need to set focus before or after I set the dialog to modal, so i did both
iret=SetFocus(GetDlgItem(dlg%hWnd,IDC_EDIT1))
!set to modal
iret = dlgmodal(dlg)
iret=SetFocus(GetDlgItem(dlg%hWnd,IDC_EDIT1))
!get data from dialog
bret = dlgget(dlg,IDC_EDIT1,subjectID)
bret = dlgget(dlg,IDC_RADIO1,session1)
bret = dlgget(dlg,IDC_RADIO2,session2)
!close dialog
call DlgUnInit(dlg)
!session1 and session2 are boolean values corresponding to the two radio button,
!this translates the booleans into an integer
if(session1)session=1
if(session2)session=2
end subroutine getSubjectInfo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are permitted to mix QuickWin and windows API functions.
After trying it myself, I have found that apparently Setfocus does not work. I have found that sending the Windows message WM_NEXTDLGCTL to the dialog box works.
You must send the message after the dialog has been created but before it is displayed. This is done by assigning a callback routine for the dialog IDD_DIALOG1 itself.
Add the following:
! This goes in the specification section before executable code
External editdialog1Sub
...
...
...
! create the dialog
bret = DlgInit(IDD_DIALOG1,dlg)
! You should do something if the dialog cannot be initialised...
if (bret == .FALSE.) Return
! define a call back subroutine to be executed after the dialog is created but before it is displayed...
lret = DlgSetSub(dlg, IDD_DIALOG1, editdialog1Sub)
...
!set to modal. After you do this, the dialog call-back is called and then the dialog is displayed
iret = dlgmodal(dlg)
....
...
!****************************************************************************
! SUBROUTINE: editdialog1Sub ( dlg, id, callbacktype )
! PURPOSE: Dialog box callback for initialization and destroy
! COMMENTS: Put your commands to control edit box focus in here
!****************************************************************************
SUBROUTINE editdialog1Sub( dlg, id, callbacktype )
!DEC$ ATTRIBUTES DEFAULT :: editdialog1Sub
use user32
use dflogm
! Include the resource.fd file as this is necessary
! to make the dialog box controls' IDs available to this subroutine
include 'resource.fd'
implicit none
type (dialog) dlg
integer id, callbacktype, iret
if (callbacktype == dlg_init) then
! uncomment the following to get diagnostic message confirming execution of this code
! lret=MessageBox(dlg%hwnd,'Dialog initialised'c,'Dialog Box message'c,MB_OK)
!This should ensure that the edit box has focus when the dialog is displayed
iret=PostMessage(dlg%hWnd, WM_NEXTDLGCTL,GetDlgItem(dlg%hWnd,IDC_EDIT1),1)
endif
if (callbacktype == dlg_destroy) then
call PostQuitMessage(0)
endif
END SUBROUTINE editdialog1Sub
After trying it myself, I have found that apparently Setfocus does not work. I have found that sending the Windows message WM_NEXTDLGCTL to the dialog box works.
You must send the message after the dialog has been created but before it is displayed. This is done by assigning a callback routine for the dialog IDD_DIALOG1 itself.
Add the following:
! This goes in the specification section before executable code
External editdialog1Sub
...
...
...
! create the dialog
bret = DlgInit(IDD_DIALOG1,dlg)
! You should do something if the dialog cannot be initialised...
if (bret == .FALSE.) Return
! define a call back subroutine to be executed after the dialog is created but before it is displayed...
lret = DlgSetSub(dlg, IDD_DIALOG1, editdialog1Sub)
...
!set to modal. After you do this, the dialog call-back is called and then the dialog is displayed
iret = dlgmodal(dlg)
....
...
!****************************************************************************
! SUBROUTINE: editdialog1Sub ( dlg, id, callbacktype )
! PURPOSE: Dialog box callback for initialization and destroy
! COMMENTS: Put your commands to control edit box focus in here
!****************************************************************************
SUBROUTINE editdialog1Sub( dlg, id, callbacktype )
!DEC$ ATTRIBUTES DEFAULT :: editdialog1Sub
use user32
use dflogm
! Include the resource.fd file as this is necessary
! to make the dialog box controls' IDs available to this subroutine
include 'resource.fd'
implicit none
type (dialog) dlg
integer id, callbacktype, iret
if (callbacktype == dlg_init) then
! uncomment the following to get diagnostic message confirming execution of this code
! lret=MessageBox(dlg%hwnd,'Dialog initialised'c,'Dialog Box message'c,MB_OK)
!This should ensure that the edit box has focus when the dialog is displayed
iret=PostMessage(dlg%hWnd, WM_NEXTDLGCTL,GetDlgItem(dlg%hWnd,IDC_EDIT1),1)
endif
if (callbacktype == dlg_destroy) then
call PostQuitMessage(0)
endif
END SUBROUTINE editdialog1Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All of that is indeed necessary for a general case of calling a windows API (namely, SetFocus or any other window-related Win32 function does not work until the dialog is "alive", and that is only during DlgModal).
However, Windows is supposed to give initial focus to the dialog control which is the first in the tab order. So, in the dialog editor, go to Layout/Tab order (Ctrl+D last time I checked) and click on the edit box first. No SetFocus necessary.
(My memory might fail me on this, though...)
However, Windows is supposed to give initial focus to the dialog control which is the first in the tab order. So, in the dialog editor, go to Layout/Tab order (Ctrl+D last time I checked) and click on the edit box first. No SetFocus necessary.
(My memory might fail me on this, though...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, you are right, that works and is much simpler as it requires no code. It just occurred to me too. Make the EDIT control the first in tab order using Layout in the resource editor.
Though I find that my suggested code works when the EDIT control is not number 1 in tab order.
Though I find that my suggested code works when the EDIT control is not number 1 in tab order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much guys. Both the tab order and the code works, but as the previous poster said, the tab layout answer requires no extra code, so I think that's the one i'll be going with. Thanks so much all!!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page