|
turn your UA_Listbox struct into a class and add a constructor:
class UA_Listbox {
public:
INT iUserID;
WCHAR *szFirstName;
WCHAR *szLastName;
WCHAR *szAccountName;
UA_Listbox()
: iUserID(0)
, szFirstName(NULL)
, szLaszName(NULL)
, szAccountName(NULL)
{
}
} UA_LISTBOX;
If you mean, you want to initialize the items differently (so every item gets different values) then you won't be able to do it that way, you will need to have a pointer-array and add the items one-by-one, eg:
UA_Listbox **uaListBoxPtrArray;
...
uaListBoxPtrArray = new UA_ListBox*[dwCount];
for (DWORD i = 0; i < dwCount; i++)
{
uaListBoxPtrArray[i] = new UA_Listbox;
uaListBoxPtrArray[i]->iUserID = ...
}
You might try using std::vector too, like:
std::vector<UA_Listbox *> arListBox;
for (DWORD i = 0; i < dwCount; i++)
{
arListBox.push_back(new UA_Lostbox(...));
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Code-o-mat wrote: turn your UA_Listbox struct into a class and add a constructor:
So make the class first. I'am storing different values in it
01 Joe Smoe jSmoe
02 John Doe jdoe
Then make the constructor
Are vectors the preferred way of packaging data?
|
|
|
|
|
jkirkerx wrote: So make the class first. I'am storing different values in it
01 Joe Smoe jSmoe
02 John Doe jdoe
Then make the constructor
I'm not sure i understand what you mean. Basicaly, structs and classes are the same in C++ except that the default access type for a class is "private" while for a struct it's "public". It's just personal preference -i guess- that i only use struct when all it does is to group a few data members together, but if it has a constructor/destructor or other methods defined, i use class.
I don't think there's a "prefered" way of "packaging data" as you said, it all depends on your needs, your requirements, your habits... you might as well use a linked list, a bi-directional linked list, hell, you could use a tree or a hash table if that is what best suits you.
P.S. if you use a pointer array, don't forget to delete your items before deallocating the struct itself.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I wrote all the hard functions for my program first, like registry values, encrypting, creating a database, downloading programs, SQL ODBC Calls for Data.
Now I'm gluing it all together with the GUI interfaces, so because I came from VB Windows and the web world, I'm in new territory here as to best practices. I don't have any preferences yet, and I had no idea there was so many ways to do it.
Let me finish my Dialog Box first, so I can populate it and read the data entered, then I'll get back to the listbox and sql data packaging.
Thanks for the suggestions, I'm sure one of them will work out for me.
|
|
|
|
|
All right, good luck.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Did I get this right?
I'm missing something here, I get a single structure, and not an array structure. I just keep writing the data to the same single structure. I must be missing something in the class, but I'm not sure what. Or maybe I didn't initialize it right.
This is for populating the array
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS) {
UA_Listbox **uaPtr;
uaPtr = new UA_Listbox*[dwCount];
INT i = 0;
INT pzUserID;
WCHAR pzFirstName[cbFirstName];
WCHAR pzLastName[cbLastName];
WCHAR pzUserName[cbUserName];
while (SQLFetch(hstmt) == SQL_SUCCESS) {
SQLGetData(hstmt, 1, SQL_C_ULONG, &pzUserID, 0, NULL );
SQLGetData(hstmt, 2, SQL_C_WCHAR, &pzFirstName, cbFirstName, NULL );
SQLGetData(hstmt, 3, SQL_C_WCHAR, &pzLastName, cbLastName, NULL );
SQLGetData(hstmt, 4, SQL_C_WCHAR, &pzUserName, cbUserName, NULL );
uaPtr[i] = new UA_Listbox;
uaPtr[i]->iUserID = pzUserID;
uaPtr[i]->szFirstName = pzFirstName;
uaPtr[i]->szLastName = pzLastName;
uaPtr[i]->szAccountName = pzUserName;
++i;
}
This is the class
class UA_Listbox {
public:
INT iUserID;
WCHAR *szFirstName;
WCHAR *szLastName;
WCHAR *szAccountName;
UA_Listbox():
iUserID(0),
szFirstName(NULL),
szLastName(NULL),
szAccountName(NULL)
{
// Constructor
}
~UA_Listbox()
{
// Deconstructor
}
};
|
|
|
|
|
jkirkerx wrote: uaPtr[i]->szFirstName = pzFirstName;
uaPtr[i]->szLastName = pzLastName;
uaPtr[i]->szAccountName = pzUserName;
You store pointers to the same buffers N times.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Your database layer should be distinct from your display layer.
Your display layer uses the database layer. There is no display information/design in the database layer (noting of course that the application design of a simple app might seem to drive directly through the two layers.)
jkirkerx wrote: I thought it would be written like this ...
What exactly is the question?
You need a pointer. You need to new an array. Then you initialize each member in the array.
If you are asking how to access a member of the array then you do it as
uaList[0].iUserID
uaList[1].iUserID
etc.
(Presumably you are also providing code to clear up every single allocation.)
Also given that you are using C++ why are not just using a straight forward class with string members?
Formatting suggestions.
- Don't put underscores in the middle of names.
- Don't put underscores at the beginning of method names.
- If a method belongs to a class then don't prefix the class name to the method.
|
|
|
|
|
I probably should of just asked what the preferred method of packaging data is.
I'm still in c++ 100 here, I started in vb.
in vb, I would of just typed
Dim UserInfo(6, TheCount) As String
UserInfo = Users.Get_ListBoxInfo()
I'll try the post above and see how it works.
|
|
|
|
|
Minor suggestion
It is either struct - structure or an array of ... whatever.
Or an array of struct.
It appears that you are after single struct of strings.
Anyway, just a suggestion since you asked what is prefered.
And a really small suggestion - if the function finds a count of items, the return value should be the count and not just true / false. Unless of course you really do not need the count.
Vaclav
|
|
|
|
|
I thought I had to dimension the array first, guess that's not needed if I write better code.
Well here goes, finished my dialog form, so I'm back to the array now.
|
|
|
|
|
jkirkerx wrote: I thought I had to dimension the array first
You might want to experiment with some simpler arrays first. I would suggest an array of ints then an array of strings (the string class, not a char*).
Allocate the arrays, assign values to members of the array, then sequence through the array to verify, then deallocate the array.
After that your implementation is just a variation on the above (especially since string is a class so you will have already created an array of classes.)
|
|
|
|
|
That's a good idea. I will start with some small simple arrays first and get the hang of it in c++, then take it from there.
Thanks jschell
|
|
|
|
|
In MFC, UNIT how to convert an int,can you help me? Master
|
|
|
|
|
Just like that :
int i = 0;
UINT u = 9;
i = (int)u;
TRACE("%d\n",i);
or
int i = 0;
UINT u = 9;
u = (UINT)i;
TRACE("%d\n",u);
|
|
|
|
|
Assuming that you mean UINT rather than UNIT you just need to cast it thus:
UINT uIntValue = 100;
int intValue = uIntValue;
Be aware that any values greater than 2147483647 (0x7FFFFFFF) will be negative in the resulting integer.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thank you, I understand. But the source is so written.
for (UINT uiLineStyleCmd = ID_LINE_STYLE_1;
uiLineStyleCmd <= ID_LINE_STYLE_10;
uiLineStyleCmd++)
{
int iIndex = pMenuPopup->GetMenuBar ()->CommandToIndex (uiLineStyleCmd);
if (iIndex >= 0)
{
pMenuPopup->GetMenuBar ()->m_bDisableSideBarInXPMode = TRUE;
//----------------------------
// Obtain item text and style:
//----------------------------
CString strText = pMenuPopup->GetMenuBar ()->GetButtonText (iIndex);
UINT uiStyle = pMenuPopup->GetMenuBar ()->GetButtonStyle (iIndex);
//------------------
// Calc. line width:
//------------------
int nWidth = uiLineStyleCmd - ID_LINE_STYLE_1 + 1;
//-------------------
// Replace menu item:
//-------------------
pMenuPopup->GetMenuBar ()->ReplaceButton (uiLineStyleCmd,
CLineStyleMenuItem (nWidth,
uiLineStyleCmd,
strText,
uiStyle & TBBS_CHECKED));
}
|
|
|
|
|
Firstly, please use <pre> tags around your code and ensure that it is formatted properly. Secondly, what is your problem?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Please do not use direct eamil to update details of open issues.
You responded to my question:
Message from dlsyaim:
Source is defined so
#define ID_LINE_STYLE_1 32833
But UINT 0 - 4294967295
Source code is no problem
What exactly does this mean, and what is your problem?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
In MFC. I added BCGControlBar control, I do not know how to load line type, source of these. Our manager let me look at this change.
// Replace ID_VIEW_TOOLBARS menu item to the toolbars list:
//---------------------------------------------------------
if (pMenuPopup->GetMenuBar ()->CommandToIndex (ID_VIEW_TOOLBARS) >= 0)
{
if (CBCGPToolBar::IsCustomizeMode ())
{
//----------------------------------------------------
// Don't show toolbars list in the cuztomization mode!
//----------------------------------------------------
return FALSE;
}
pMenuPopup->RemoveAllItems ();
CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE);
}
//-------------------------------------------------------------------
// Replace all "line style" menu items by CLineStyleMenuItem objects:
//-------------------------------------------------------------------
for (UINT uiLineStyleCmd = ID_LINE_STYLE_1;
uiLineStyleCmd <= ID_LINE_STYLE_10;
uiLineStyleCmd++)
{
int iIndex = pMenuPopup->GetMenuBar ()->CommandToIndex (uiLineStyleCmd);
if (iIndex >= 0)
{
pMenuPopup->GetMenuBar ()->m_bDisableSideBarInXPMode = TRUE;
//----------------------------
// Obtain item text and style:
//----------------------------
CString strText = pMenuPopup->GetMenuBar ()->GetButtonText (iIndex);
UINT uiStyle = pMenuPopup->GetMenuBar ()->GetButtonStyle (iIndex);
//------------------
// Calc. line width:
//------------------
int nWidth = uiLineStyleCmd - ID_LINE_STYLE_1 + 1;
//-------------------
// Replace menu item:
//-------------------
pMenuPopup->GetMenuBar ()->ReplaceButton (uiLineStyleCmd,
CLineStyleMenuItem (nWidth,
uiLineStyleCmd,
strText,
uiStyle & TBBS_CHECKED));
}
}
|
|
|
|
|
Please edit this post and put <pre> tags around your code as I asked. Please also explain exactly what problem you are having.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
dlsyaim wrote: int nWidth = uiLineStyleCmd - ID_LINE_STYLE_1 + 1;
Is this the statement in question? If so, what is the compiler error or warning that you are receiving?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi. I have a SDI app, with CView based on CListView. In edit menu, I enable / disable some items dependes some conditions with :
ON_UPDATE_COMMAND_UI(ID_EDIT_REFRESH, OnUpdateEditRefresh)
the same edit menu I load in right-click :
void CMyView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
CMenu menu;
menu.LoadMenu(IDR_TERMTYPE2);
CMenu* pContextMenu = menu.GetSubMenu(1);
POINT point;
CPoint pt(pNMListView->ptAction);
point.x = pt.x;
point.y = pt.y;
::ClientToScreen(pNMHDR->hwndFrom,&point);
int nID = pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,point.x,point.y,this);
*pResult = 0;
}
but all items from edit menu are enable ... and I must enable/disable depndes by the same conditions like main edit menu ... my question is, how can enable/disable edit menu items in OnRclick handler but some how using ON_UPDATE_COMMAND_UI ?
|
|
|
|
|
See this[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I solve my problem ! Thank you very much !
|
|
|
|
|