- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can't seem to find in the documentation how to populate a combo/list box at run time. Can anyone help me out?
Thanks/
Thanks/
Link Copied
11 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
DlgSet(Dlg, IDC_LIST1, 5, DLG_NUMITEMS)
DlgSet(Dlg, IDC_LIST1, "Alpha", 1)
DlgSet(Dlg, IDC_LIST1, "Beta", 2)
DlgSet(Dlg, IDC_LIST1, "Gamma", 3)
...
DlgSet(Dlg, IDC_LIST1, "Alpha", 1)
DlgSet(Dlg, IDC_LIST1, "Beta", 2)
DlgSet(Dlg, IDC_LIST1, "Gamma", 3)
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I get this error trying to use that subroutine ...
guidts.obj : error LNK2001: unresolved external symbol _DLGSET@12
guidts.obj : error LNK2001: unresolved external symbol _DLGSET@12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, forgot the use statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do the following command and get no error, but nothing appears in the dropdown box; any ideas?
dummyint = SetDlgItemText(hDlg, IDC_THETA, "123"C)
dummyint = SetDlgItemText(hDlg, IDC_THETA, "123"C)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If your dialog is created using DFLOGM (DlgInit/DlgModal), you can not -- at least not always -- call Windows APIs, like SetDlgItem* to manage the dialog controls. DFLOGM is a wrapper, and does not cover all the stuff from Win32 APIs.
To set the text in edit portion of the combo box (I mean real combo, with Edit portion), use DlgSet(Dlg, IDC_THETA, "123", DLG_STATE) (speaking from memory -- check "Available indexes for dialog controls" help page).
However, you can use APIs to extend DFLOGM functionality -- but APIs which take a HWND as the first parameter will work only when called from dialog's callback routines. Handle of the dialog is Dlg%hWnd member, but it is a valid window handle only during DlgModal -- before or after the dialog doesn't exist.
Jugoslav
To set the text in edit portion of the combo box (I mean real combo, with Edit portion), use DlgSet(Dlg, IDC_THETA, "123", DLG_STATE) (speaking from memory -- check "Available indexes for dialog controls" help page).
However, you can use APIs to extend DFLOGM functionality -- but APIs which take a HWND as the first parameter will work only when called from dialog's callback routines. Handle of the dialog is Dlg%hWnd member, but it is a valid window handle only during DlgModal -- before or after the dialog doesn't exist.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using this statement to create the dialog box:
DialogBoxParam(ghInstance,LOC(lpszName),hWnd,&LOC(SelectFreqDlgProc), 0)
And then during the WM_INITDIALOG message to SelectFreqDlgProc I am trying to set the combo box text.
I'm not aware of how else I could set the text in the boxes.
DialogBoxParam(ghInstance,LOC(lpszName),hWnd,&LOC(SelectFreqDlgProc), 0)
And then during the WM_INITDIALOG message to SelectFreqDlgProc I am trying to set the combo box text.
I'm not aware of how else I could set the text in the boxes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using this statement to create the dialog box:
DialogBoxParam(...
Ah, sorry -- however, existence of DFLOGM along with native Win32 Dialog API brings in confusion -- people should say which one they use. I assumed DFLOGM in absence of evidence.
In that case, the code looks OK -- what's the return value from SetDlgItemText?
For filling in the contents of list&combo boxes, use CB_ADDSTRING/LB_ADDSTRING messages.
Jugoslav
DialogBoxParam(...
Ah, sorry -- however, existence of DFLOGM along with native Win32 Dialog API brings in confusion -- people should say which one they use. I assumed DFLOGM in absence of evidence.
In that case, the code looks OK -- what's the return value from SetDlgItemText?
For filling in the contents of list&combo boxes, use CB_ADDSTRING/LB_ADDSTRING messages.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The return from SetDlgItemText is zero but I don't know why it is failing.
What am I supposed to do with those messages you mentioned? Should they be in my Processing function? And if so what should I do when those messages get sent to it?
What am I supposed to do with those messages you mentioned? Should they be in my Processing function? And if so what should I do when those messages get sent to it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If this is a control without editable text (list box or drop-down combo box), I guess that you can't use SetDlgItemText.
There are (at least) two kinds of messages; I'll informally call them "informative" and "commanding". With the former, you are being told that something happened -- you do something with it or ignore it. With the latter, you send the message to the window in order to make it do something. Compare e.g. WM_SIZE and WM_SETTEXT -- the first one is "informative", i.e. you are told that the window is resized, but it does nothing by itself. (It's a common mistake by newbies -- "hey, I sent a WM_SIZE to my window but nothing happens" -- that's because WM_SIZE does nothing, it just informs the window, if it's interesting). WM_SETTEXT is "commanding", and you can use it instead of SetWindowText -- it actually does set the window caption.
All Windows controls have interface in form of "commanding" messages -- you do not normally handle these messages, but use Send(DlgItem)Message to the control in order to make it do something. Additionally, they send some "informative" or "notification" messages to their parent when user does something -- WM_COMMAND and WM_NOTIFY carry packed information about the event and control state. The usual naming convention is that the former have aaM_xxx or just aa_xxx, where aa is abbreviation of control type, while the latter have aaN_xxx -- compare e.g. LB_ADDSTRING and LBN_DBLCLK.
Thus, you should just SendDlgItemMessage(...(C)LB_ADDSTRING...) in your WM_INITDIALOG block in order to fill in the contents of the list/combo box.
Jugoslav
There are (at least) two kinds of messages; I'll informally call them "informative" and "commanding". With the former, you are being told that something happened -- you do something with it or ignore it. With the latter, you send the message to the window in order to make it do something. Compare e.g. WM_SIZE and WM_SETTEXT -- the first one is "informative", i.e. you are told that the window is resized, but it does nothing by itself. (It's a common mistake by newbies -- "hey, I sent a WM_SIZE to my window but nothing happens" -- that's because WM_SIZE does nothing, it just informs the window, if it's interesting). WM_SETTEXT is "commanding", and you can use it instead of SetWindowText -- it actually does set the window caption.
All Windows controls have interface in form of "commanding" messages -- you do not normally handle these messages, but use Send(DlgItem)Message to the control in order to make it do something. Additionally, they send some "informative" or "notification" messages to their parent when user does something -- WM_COMMAND and WM_NOTIFY carry packed information about the event and control state. The usual naming convention is that the former have aaM_xxx or just aa_xxx, where aa is abbreviation of control type, while the latter have aaN_xxx -- compare e.g. LB_ADDSTRING and LBN_DBLCLK.
Thus, you should just SendDlgItemMessage(...(C)LB_ADDSTRING...) in your WM_INITDIALOG block in order to fill in the contents of the list/combo box.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your introduction on messages was very enlightening -- thanks. I guess this leaves me one last problem, how do I convert a string pointer to the lParam type?
lParam = (LPARAM) (LPCTSTR) lpsz;
is listed in the help file where lpsz is the string I want added to the combo box.
lParam = (LPARAM) (LPCTSTR) lpsz;
is listed in the help file where lpsz is the string I want added to the combo box.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the LOC() function to get the address of the string (as you probably know, it has to be CHAR(0)-terminated).
Take a look at "Win32 Simple Data Types" page for the list of meanings of typedefs used in the API. Actually, most of them map to Fortran (32-bit) INTEGER. [First, Fortran doesn't have unsigned types. Second, LPxxx (except LPARAM) and Pxxx usually mean "address" or "reference", which is 32-bit integer on Win32 (but will be 64-bit integer on Win64). LPCTSTR, LPTSTR, and LPSTR usually map to CHARACTER(*) etc.]
It's usually a good idea to do a "Find in Files" in C:...Visual StudioDF98Include*.f90 for API you want to use and take a look at INTERFACE block. With some experience, you'll see the regularities in CVF translations from C-style APIs to Fortran.
Jugoslav
Take a look at "Win32 Simple Data Types" page for the list of meanings of typedefs used in the API. Actually, most of them map to Fortran (32-bit) INTEGER. [First, Fortran doesn't have unsigned types. Second, LPxxx (except LPARAM) and Pxxx usually mean "address" or "reference", which is 32-bit integer on Win32 (but will be 64-bit integer on Win64). LPCTSTR, LPTSTR, and LPSTR usually map to CHARACTER(*) etc.]
It's usually a good idea to do a "Find in Files" in C:...Visual StudioDF98Include*.f90 for API you want to use and take a look at INTERFACE block. With some experience, you'll see the regularities in CVF translations from C-style APIs to Fortran.
Jugoslav

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