Help with textbox control
-
Ok, I'm new to doing this in C++, although I have done it in C#. As this code has to work inside another larger C++ project I have (game program) I can't just do it in C#. In my click handler for a button I want to put text into a textbox control on my form. Unfortunately, the "text" is in a c-string (ie null terminated string), and so I'm not sure how to get it to work: System::Void btnGen_Click(System::Object^ sender, System::EventArgs^ e) { BYTE bMacaddress[MAC_DIM]; CSoftwareKey::RetrieveMACAddress(bMacaddress); char* pMacString = NULL; CSoftwareKey::Buffer2HexString( bMacaddress, MAC_DIM, &pMacString ); tbMacAddress->Text = *pMacString; // <---- Problem line } I tried first making a string: string strMacAddr(pMacString); and then: tbMacAddress->Text = pMacString; but this doesn't work either (and I'm sure you are laughing now) =) Anyway, how can I do this? Basically, pMacString points to something like this: "000C41805D2D\0" ( if I am making sense ) and so that's what I want in the text box. Thanks Patrick
Mmmm, are you asking to port from c# to c++? or c++ to c#? Because... there are elements in your code that are unknown for me :S
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Mmmm, are you asking to port from c# to c++? or c++ to c#? Because... there are elements in your code that are unknown for me :S
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Ok, I'm new to doing this in C++, although I have done it in C#. As this code has to work inside another larger C++ project I have (game program) I can't just do it in C#. In my click handler for a button I want to put text into a textbox control on my form. Unfortunately, the "text" is in a c-string (ie null terminated string), and so I'm not sure how to get it to work: System::Void btnGen_Click(System::Object^ sender, System::EventArgs^ e) { BYTE bMacaddress[MAC_DIM]; CSoftwareKey::RetrieveMACAddress(bMacaddress); char* pMacString = NULL; CSoftwareKey::Buffer2HexString( bMacaddress, MAC_DIM, &pMacString ); tbMacAddress->Text = *pMacString; // <---- Problem line } I tried first making a string: string strMacAddr(pMacString); and then: tbMacAddress->Text = pMacString; but this doesn't work either (and I'm sure you are laughing now) =) Anyway, how can I do this? Basically, pMacString points to something like this: "000C41805D2D\0" ( if I am making sense ) and so that's what I want in the text box. Thanks Patrick
-
:omg: then I'm more newbie than I thought :doh: :P hehehehe I've never seen "^" used as "System::Object^ sender" Nevermind, your tbMacAddress->Text is a string or a char[x]? I had some problems with CString and char* in VC++ because of the "\0" at the end of the CStrings. I solved it considering the CString as a vector and taking every letter in a loop and putting it in the place of the char[20] that was needed. Afterwards I passed the &char[0] where the LPCSTR was asked for and it worked. Finally I found another way to do it and changed it but... sometimes silly things give the way to the correct answer.
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
My question has nothing to do with managed code. Basically, forget the code which is confusing you, and just think of this as the question: If you have a c-string (ie a null terminated string) and you want to set the Text in a textbox to that value, how do you do it? For example, when a button on the form is pushed, set the textbox to the c-string's value. Patrick
-
My question has nothing to do with managed code. Basically, forget the code which is confusing you, and just think of this as the question: If you have a c-string (ie a null terminated string) and you want to set the Text in a textbox to that value, how do you do it? For example, when a button on the form is pushed, set the textbox to the c-string's value. Patrick
Hi, to do that I associate a member variable (CString) to the CEditBox and when I push a button or happens whatever it shall happen, call UpdateData (FALSE); On the other hand, as the CEdit is derived from CWnd. It should be possible to modify its text with SetWindowText( LPCTSTR lpszString ); but I'm not sure because I have never tried it, I do it as above (VC++ 6)
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
My question has nothing to do with managed code. Basically, forget the code which is confusing you, and just think of this as the question: If you have a c-string (ie a null terminated string) and you want to set the Text in a textbox to that value, how do you do it? For example, when a button on the form is pushed, set the textbox to the c-string's value. Patrick
If you want to set text for a control Textbox(editbox) or button you can use of
SetWindowText();
WhiteSky
-
Hi, to do that I associate a member variable (CString) to the CEditBox and when I push a button or happens whatever it shall happen, call UpdateData (FALSE); On the other hand, as the CEdit is derived from CWnd. It should be possible to modify its text with SetWindowText( LPCTSTR lpszString ); but I'm not sure because I have never tried it, I do it as above (VC++ 6)
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Code? So if I tell you that you are given a variable: myString[] = "0C34AZ"; // which is null terminated what would be working code to put it in a textbox?
Hi another time, ok, I have the DoDataExchange in my Form, and a member variable associated to my CEdit. DDX_Text(pDX, IDC_MYEDIT, m_szMemberString); I initialize it to “” (empty) in the constructor. And then, in some events/messages I put the name of another element I saved in the Document, in the example a click in a ListCtrl (report mode) where my elements are listed
void CMyFormView::OnClickCtrlList(NMHDR* pNMHDR, LRESULT* pResult)
{ POSITION pos = m_clcMyList.GetFirstSelectedItemPosition();//If the click was outside the range
if (!pos)
{ m_nRowNum = -1;
m_cbButton1.EnableWindow (FALSE);
m_ szMemberString = “”;
UpdateData (FALSE);
}while (pos) { m\_nRowNum = m\_clcRuleList.GetNextSelectedItem(pos); M\_szMemberString = pDoc->GetElementNameOfColumn (m\_nRowNum); m\_cbButton1.EnableWindow (TRUE); UpdateData (FALSE); } Invalidate (); UpdateWindow (); \*pResult = 0; return;
}
Another way (without member variables and the DoDataExchange) can be:
void CMyFormView::OnClickCtrlList(NMHDR* pNMHDR, LRESULT* pResult)
{ POSITION pos = m_clcMyList.GetFirstSelectedItemPosition();
CEdit* pEdit = (CEdit*)GetDlgItem (IDC_MYEDIT);//If the click was outside the range if (!pos) { m\_nRowNum = -1; m\_cbButton1.EnableWindow (FALSE); pEdit->SetWindowText (""); } while (pos) { m\_nRowNum = m\_clcRuleList.GetNextSelectedItem(pos); pEdit->SetWindowText (pDoc->GetElementNameOfColumn (m\_nRowNum)); m\_cbButton1.EnableWindow (TRUE); } Invalidate (); UpdateWindow (); \*pResult = 0; return;
}
The function I’m using is: CString CMyDoc::GetElementNameOfColumn (int nRow);
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Hi another time, ok, I have the DoDataExchange in my Form, and a member variable associated to my CEdit. DDX_Text(pDX, IDC_MYEDIT, m_szMemberString); I initialize it to “” (empty) in the constructor. And then, in some events/messages I put the name of another element I saved in the Document, in the example a click in a ListCtrl (report mode) where my elements are listed
void CMyFormView::OnClickCtrlList(NMHDR* pNMHDR, LRESULT* pResult)
{ POSITION pos = m_clcMyList.GetFirstSelectedItemPosition();//If the click was outside the range
if (!pos)
{ m_nRowNum = -1;
m_cbButton1.EnableWindow (FALSE);
m_ szMemberString = “”;
UpdateData (FALSE);
}while (pos) { m\_nRowNum = m\_clcRuleList.GetNextSelectedItem(pos); M\_szMemberString = pDoc->GetElementNameOfColumn (m\_nRowNum); m\_cbButton1.EnableWindow (TRUE); UpdateData (FALSE); } Invalidate (); UpdateWindow (); \*pResult = 0; return;
}
Another way (without member variables and the DoDataExchange) can be:
void CMyFormView::OnClickCtrlList(NMHDR* pNMHDR, LRESULT* pResult)
{ POSITION pos = m_clcMyList.GetFirstSelectedItemPosition();
CEdit* pEdit = (CEdit*)GetDlgItem (IDC_MYEDIT);//If the click was outside the range if (!pos) { m\_nRowNum = -1; m\_cbButton1.EnableWindow (FALSE); pEdit->SetWindowText (""); } while (pos) { m\_nRowNum = m\_clcRuleList.GetNextSelectedItem(pos); pEdit->SetWindowText (pDoc->GetElementNameOfColumn (m\_nRowNum)); m\_cbButton1.EnableWindow (TRUE); } Invalidate (); UpdateWindow (); \*pResult = 0; return;
}
The function I’m using is: CString CMyDoc::GetElementNameOfColumn (int nRow);
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
I just realised why I'm having the problem I'm having. I started a straight C++ project, and added a CLR form! I really didn't want a managed form, as I want to stick with unmanaged C++. duh So, basically, either I do this in C# ( or managed C++ ) or I have to learn how to do windows forms :( I think I'll stick to a console app to do this simple job and avoid the whole dang problem. Windows programming is just to much of a pain to learn.
-
I just realised why I'm having the problem I'm having. I started a straight C++ project, and added a CLR form! I really didn't want a managed form, as I want to stick with unmanaged C++. duh So, basically, either I do this in C# ( or managed C++ ) or I have to learn how to do windows forms :( I think I'll stick to a console app to do this simple job and avoid the whole dang problem. Windows programming is just to much of a pain to learn.
Hehehehe, This is the same my partner said. He try to piss me off with "look, in VB I can print with just 2 lines", because I'm having problems to personalize a PrintDialog, margins, Bitmaps... Windows programming is not easy at all. But it is not imposible, just a question of time and being persistent.
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?