15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Scrolling Lists of Edit controls

Ross Cutler -- rgc@cs.umd.edu
Monday, August 19, 1996

Environment: Windows NT 4.0, Visual C++ 4.2

I need to create a control that looks like a scrollable list of CEdit 
controls (along with labels) in a dialog box.  The number of edit controls 
and the label contents need to be programable.  The number of rows will
be almost always be small (< 8).

Does anyone have a suggestion of a way to do this?  Thanks.  Ross.



Kostya Sebov -- sebov@is.kiev.ua
Friday, August 23, 1996

[Mini-digest: 8 responses]

>   Environment: Windows NT 4.0, Visual C++ 4.2
>
>   I need to create a control that looks like a scrollable list of CEdit
>   controls (along with labels) in a dialog box.  The number of edit controls
>   and the label contents need to be programable.  The number of rows will
>   be almost always be small (< 8).
>
>   Does anyone have a suggestion of a way to do this?  Thanks.  Ross.
>
If the view class is Ok then you may create CFormView-derived class based on
dialog template consisting of max number of rows (8?). Then in OnInitialUpdate
or OnUpdate (whatever is more appropriate) show/hide extra labels/edits and
SetScrollSizes to adjust the scrolling range.

If you really need control you can use CListCtrl whith in-place label editing
enabled if you can survive with edit fields FOLLOWED by the labels. Or implement
two-columned listbox (using LVS_USETABSTOPS style or something alike) and
roll your own in-place editing (there must be an article on the MSDN devoted to
such in-place editing -- didn't check, just heard).

--- 
Kostya Sebov. 
----------------------------------------------------------------------------
Tel: (38 044) 266-6387 | Fax: (38 044) 266-6195 | E-mail: sebov@is.kiev.ua
-----From: John Simmons 

How about building a dialog template that has (for the sake of example) 5
static text controls in a column, 5 edit controls in a colum , and then a
scrollbar. Next, build a linked list of structs that hold descriptions and
edit field contents, and use the scrollbar to update the fields in the dialog.

2nd Idea - put a listbox on the dialog with an edit control beside it.  Fill
the list box with the descriptions and update the edit control based on
which description is selected.
 

/=========================================================\
| John Simmons (Redneck Techno-Biker)                     |
|    jms@connectnet.com                                   |
| Home Page                                               |
|    www2.connectnet.com/users/jms/                       |
|---------------------------------------------------------|
| ViewPlan, Inc. home page (my employer)                  |
|    www.viewplan.com/index.html                          |
|---------------------------------------------------------|
| IGN #12 American Eagle Motorsports Zerex Ford	          |
|    Teammates - Steve Stevens (#13 Hooters Ford and      |
|                               1995 IGN Points Champ)    |
|                Pat Campbell (#14 Dr. Pepper Ford)       |
| American Eagle Motorsports Team Page                    | 
|    www2.connectnet.com/users/jms/ignteam                |
| Hawaii Multi-Player Nickname:  AEMwest                  |
|---------------------------------------------------------|
| Competitor - Longest Signature File On The Net          |
\=========================================================/

-----From: Paul Roub 

I'm doing something similar -- one scrollable pane in a splitter window,
which holds different controls at different times, depending on tree 
selections in another window.  Again, the number and types vary 
dynamically with the data.

Anyway, I just derived from CScrollView and set about creating and 
destroying the controls on the heap as needed.  It's working very well
for me.  

-paul

-- 
//	Paul Roub, Galacticomm Technical Operations
//	proub@gcomm.com
//	(954)583-5990
-----From: Brian_Dormer@ftdetrck-ccmail.army.mil

     There was an article a few months ago in Microsoft Systems Journal 
     that did exactly this.
     
     Their web site is at : http://www.mfi.com


        You can download the source to their class there.  You might also be
        able to order a back-issue if you want the explaination - but once you
        have the source, you should be all set.

        bd

-----From: Steve Mark 

FWIW I did this but not using a control.  I dynamically create edit controls
and put them on a CFormView-derived class.  Each control has the same ID
(e.g. ID_EDIT_BOX) and I keep an array matching CWnd*'s to identifying
information about each control.  When the user does something with a control
I do a table lookup into the array and then I know which control the user is
accessing.  In fact, it is database-table-based and can handle several
different kind of controls, allowing for runtime and modular changes of the
screen layout.


---------------------------------------------------------------------
| Steven Mark         | On-The-Mark Systems       | Custom Software |
| Tel: 510.648.9514   | 3494 Camino Tassajara Rd. |    Analysis     |
| Fax: 510.648.9507   | Suite 239                 |     Design      |
| http://www.otms.com | Danville, CA 94506        | Implementation  |
---------------------------------------------------------------------

-----From: "Greg Tighe" 

If you have a limit on the number of edit controls you will need you 
can:

1)  Use the ResourceView to create a dialog with the maximum number 
of edit controls with labels (be sure to give the static text 
controls unique ID if you want to programmatically set the label 
text.)  Set this dialog's style to 'Child' and enable the vertical 
and/or scrollbar options.

2)  You can vary the number of edit controls in use by showing the 
ones you want and hiding the ones you don't

3)  You will need to handle WM_VSCROLL/WM_HSCROLL messages to scroll 
the controls in your dialog.  ScrollWindow() works well for this.


To use this dialog as a control in another dialog:

1)  Add a member variable of type CMyScrollingEditControlDlgControl 
to your dialog.

2)  In the parent dialog's OnInitDialog() method you will need to 
call CMyScrollingEditControlDlgControl::Create().

3)  Move/size the control to the desired location within the parent 
dialog.

4)  You may need to reflect some WM_COMMAND messages from the control 
back to the parent dialog (especially IDOK and IDCANCEL messages.)


If you allow a totally arbitrary number of edit controls within the 
scrolling dialog control then you will need to dynamically Create() 
CStatic and CEdit controls within your scrolling dialog.

Hope this helps some.

	-Greg Tighe
	Applied Intelligent Systems, Inc.
	Ann Arbor, MI
	gdt@aisinc.com
-----From: ppbillc@srv2.sj.ablecom.net

 If you make the listbox the parent of the CEdit's during the Create 
phase. Then add a numer of strings to the listbox corresponding
to each line of  the text in the edit you create. The edits will 
'magically' appear in the listbox.

Bill




-----From: "Ramos-Bonilla, Ibsen" 

Hi Ross, 

If I what you're asking is what I did just a couple of months ago, then
you're in luck, if not sorry.
What I did is the following:

STEP #1:  Create your dialog box (CMyDialog) and add a picture box where
you want your scrollable list to appear and give it and ID (ID_MY_PIC).
Here is my header file:

class CMyDialog : public CDialog
{
// Construction
public:
	CMyDialog(CWnd* pParent = NULL);   // standard constructor
	CRect m_rectFrame, m_rectView;  // (m_rectFrame = picture box,
m_rectView = CFormView);

..............
};

Here is my implementation file:

#include "stdafx.h"
#include "MyApp.h"
#include "MyDialog.h"
#include "MyScrollList.h"

BOOL CMyDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// get a pointer to a new frame and view for the scrollable list
	CFrameWnd* pScrollListFrame = new CFrameWnd;
	CMyScrollList* pScrollListView = new CMyScrollList;

	// set the frame coordinates
	CWnd* pScrollListWnd = GetDlgItem(IDC_MY_PIC);
	pScrollListWnd->GetWindowRect(&m_rectFrame);
	ScreenToClient(&m_rectFrame);

	// create the scroll list frame
	pScrollListFrame->Create(NULL, NULL, WS_CHILD | WS_VISIBLE,
m_rectFrame, 
		this, NULL, 0, NULL);

	// set the view coordinates
	m_rectView.SetRect(0, 0, m_rectFrame.right - 24, m_rectFrame.bottom -
108);  // (set these coordinates depending on the size of your scroll
list form).
	
	// create the scroll list view
	pCriteriaView->Create(NULL, NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 
		m_rectView, pScrollListFrame, IDD_SCROLL_LIST, NULL);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


STEP #2: Create a CFormView (IDD_SCROLL_LIST) that contains all of your
CEdit controls and labels.  Make it's Style = Child, no title. 
Here is my header file:

class CMyScrollList : public CFormView
{
friend class CMyDialog; //<-very important !!!!!
protected:
	CMyScrollList();           // protected constructor used by dynamic
creation
	DECLARE_DYNCREATE(CMyScrollList)

// Form Data
public:
	//{{AFX_DATA(CMyScrollList)
	enum { IDD = IDD_SCROLL_LIST};
		// NOTE: the ClassWizard will add data members here
	//}}AFX_DATA

................
};


With this setup, you can continuously, keep on adding new controls to
the CFormView, without having to change your Dialog box.  Well, let me
know if that helped in any way..................!!!!!!   Have fun.....





| Вернуться в корень Архива |