|
Dear,
You need not take that much pain to accomplish this.
If all you need to inform is a count and some other simple parameters,
why dont you put them in the APP, and once you got the parameters from the dialog, AfxGetAPP(), update / set variables and then... your task is done...
regards,
haribabu
|
|
|
|
|
Hi, thank you very much. Do you mean the following?
(1)in APP.cpp
CDialog dialog
int t1 = dialog.parameter1
(2)in View.cpp
T1 = AfxgetApp()->t1
|
|
|
|
|
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?
|
|
|
|
|
No, the above code has nothing to do with C#, it is straight C++.
|
|
|
|
|
then I'm more newbie than I thought :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
|
|
|
|
|
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 (!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 (!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.
|
|
|
|
|
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?
|
|
|
|
|
If you want to set text for a control Textbox(editbox) or button you can use of SetWindowText();
|
|
|
|
|
Hi all,
I have created a dll file in VC++ 6 and use that dll file in VB.Net. But unfortunately, in VC++, I'm using some datatype that aren't supported in VB.Net. So i couldn't use that dll file.
Please show me what datatype i should use in VB.NET appropriate with following datatype in VC++ 6 :
BSTR -> what datatype in VB.NET i should use
LPCTSTR -> what datatype in VB.NET i should use
LPSTR -> what datatype in VB.NET i should use
unsigned int -> what datatype in VB.NET i should use
DWORD -> what datatype in VB.NET i should use
Please show me some guide. Any help will be welcome.
Best Regards
|
|
|
|
|
BSTR->string
LPCTSTR->const string
LPSTR -> string
unsigned int->UInt32
DWORD -> long
|
|
|
|
|
Hi
Cool guys of this messageboards suggested me to use RegNotifyChangeKeyValue() function in order to be informed/notified of registry modifications (what i'm looking at).
It works but it only notifies me that something changed but i can't find how to figure exactly WHAT changed ?
thanks
|
|
|
|
|
RegNotifyChangeKeyValue() will notify you of any changes that is made to the key that *you* pass the API as the first parameter, hKey .
Alexandre GRANVAUD wrote: It works but it only notifies me that something changed but i can't find how to figure exactly WHAT changed ?
Use RegQueryValueEx() to get the modified value of the registry key. You could compare it to the old value, and you'd know what's changed.
Shog on learning VB6: Ah, that would have been VB6. Kicked my ass anyway. So easy to learn, just like falling down a flight of stairs...
|
|
|
|
|
yes but i need to know which subkeys are created in a large tree
|
|
|
|
|
Hi all,
I have a little problem with printing. The case is that my program has multiple views and I need to print different things depending of the view that is active in this moment. I have derived a Dialog from CPrintDialog to allow some parameters selection and to print different outputs according to these parameters. I have successfully called the new DialogBox and set the parameters to choose the output. My problem is that, as I have overridden the CNewPrintDialog::OnOk () to modify the things I need, when I click OK in my dialog and send the work to print… I have an error because the DeviceContext for the printer is not correctly saved in pInfo->m_pPD->m_pd.m_hDC. My question is… where can I find the implementation (not the definition) of the CPrintDialog to see its CPrintDialog::OnOk and copy what I need in my Dialog???
Or… How should I make it to successfully send the datas to be printed? I have tried to print with what Chris Maunder’s says in one of his articles (Printing without the Document/View framework) but it doesn’t solves my problem because I do use the framework
Any help will be wellcome
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?
|
|
|
|
|
Nelek wrote: an error because the DeviceContext for the printer is not correctly saved in pInfo->m_pPD->m_pd.m_hDC
Can you show how do you set m_hDC and see Print Bitmaps without Doc/View Framework[^] is helpfuls?
|
|
|
|
|
Hi,
I have made:
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
CMyDoc* pDoc = GetDocument ();
ASSERT_VALID (pDoc);
delete pInfo->m_pPD ;
pInfo->m_pPD = new CDlgPrinting(FALSE, PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION, this) ;
pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
pInfo->m_pPD->m_pd.lpPrintTemplateName = MAKEINTRESOURCE(IDD_PRINT_PRDLG);
pInfo->m_pPD->m_pd.Flags |= PD_ENABLEPRINTTEMPLATE;
pInfo->m_pPD->m_pd.nMinPage = 1;
pInfo->SetMaxPage (CalculateNumberOfPages ());
int nAnswer = pInfo->m_pPD->DoModal ();
if (nAnswer == IDCANCEL)
return FALSE;
CDC dc;
dc.Attach (pInfo->m_pPD->GetPrinterDC ());
pInfo->m_pPD->m_pd.m_hDC = dc.GetSafeHdc ();
if (m_byPrintParam)
AfxMessageBox ("Parameters modified");
else
MessageBox (NULL, "Error by taking parameters", "Error", MB_OK);
dc.Detach ();
return TRUE;
}
But I get an Assertion and he brings me to code
ASSERT (pInfo->m_pPD->m_pd.m_hDC != NULL);
EDIT
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?
|
|
|
|
|
Did you check step by step whats return value of dc.Attach ?
|
|
|
|
|
Hi,
CDC dc;
dc.Attach (pInfo->m_pPD->GetPrinterDC ());
pInfo->m_pPD->m_pd.hDC = dc.GetSafeHdc ();
does nothing, the return is 0x000000. I think it is because I have overriden the CMyPrintDialog::OnOK () and then is not making the things it should. Because of that I asked at the beggining of the post, where can I find the implementation of the Windows-CPrintDialog?? I have searched in my VC++ folder but I have only found the definitions in one .h but there is no .cpp for it.
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?
|
|
|
|
|
If you like you can send your program for me,if I can find problem I send answer for you.
|
|
|
|