|
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 !
|
|
|
|
|
Congrats and yourwelcome.
> 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.<
|
|
|
|
|
It's always a pleasure to be on this forum ! Happy new year !
|
|
|
|
|
Thanks, a happy new year to you too!
> 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.<
|
|
|
|