Software Archive
Read-only legacy content
17061 Discussions

Stupid newbie question - writing from one edit box to another

Scott_W_1
Beginner
1,100 Views

I've been trying for HOURS to get text from my edit box (win32 app) and insert the text into the data that's been writing into a different editbox.

I keep getting errors on converting data types.

something like: 

//This code works

    std::ostringstream s;
    //s << "Frame: " << frameNumber << "\r\n";
    s << "Gesture Data: " << "\r\n";
    std::string sAlerts(s.str());
    bool fingerEnabled = false;
    sAlerts += sHdr;//sHdr defined and set earlier

//Here's where I fall apart:

gestName = GetDlgItem(hwndDlg, IDC_GESTURENAME);

sAlerts += gestName;

How can I get the text from the IDC_GESTURENAME editbox correctly formatted?

I've searched all over. Going home cranky today. Praying for grace so I treat my family right.

0 Kudos
1 Solution
Jack_K_1
New Contributor II
1,100 Views

Scott,

Windows uses Unicode, a 16-bit format for storing characters.  In Visual Studio you will see the phrase "Use Unicode Character Set" for the General>Character Set setting in the property page for the project; this results in defines UNICODE and _UNICODE being set.

If UNICODE is defined, GetDlgItemText becomes GetDlgItemTextW and Unicode characters are returned.  If UNICODE is not defined, GetDlgItemTexT becomes GetDlgItemTextA and ASCII characters are returned. 

Since Windows uses Unicode, not doing so means the API is constantly translating between Unicode and ASCII.

pxcCHAR is a wchar_t by the way.  The following pseudo code should work:

   const int maxlength = 256;

   wchar_t gestName[maxlength];

   GetDlgItemText(hwndDlg, IDC_GESTURENAME, gestName, maxlength);

   std::wstring alerts(gestName);

  loop over joint data

     alerts += sJoint;  // where sJoint is a std::wstring

  end loop

 

View solution in original post

0 Kudos
6 Replies
Jack_K_1
New Contributor II
1,100 Views

Scott,

I think you want to use GetDlgItemText to retrieve the text - see http://msdn.microsoft.com/en-us/library/windows/desktop/ms645489(v=vs.85).aspx

Regards,

Jack

0 Kudos
Scott_W_1
Beginner
1,100 Views

I tried GetDlgItemText too. The closest I could get is that the code would sometimes put my editBox text into the data followed by several characters. I'm going to try again, and get the exact code along with a sample of the output.

0 Kudos
Jack_K_1
New Contributor II
1,100 Views

Scott,

If you are using UNICODE, you need to use std::wstring instead of std::string.

Regards,

Jack

0 Kudos
Scott_W_1
Beginner
1,100 Views

I'll try that. How can I tell if the editBox uses Unicode? I'm starting to realize that I've lead a very sheltered programming life. I have never had to deal with encoding before.

I got SOME progress, but it's not pretty. I kind of cheated, iterating through the array of characters and extracting each character one by one. It does get the text from the dialog box, then moves it to the editbox that displays the data, but then it stops. The joint parameter data no longer goes in. 

Here's the code for reading the gesture name input box:

//first the data output array is initialized

static pxcCHAR arr[50000]; //will convert this to sizeof()
    std::ostringstream s;
    s << "";
    std::string sAlerts(s.str());

//next the gesture name input from the edit box is retrieved

pxcCHAR gestName[256];
    GetDlgItemText(hwndDlg,IDC_GESTURENAME,gestName,sizeof(gestName));
    std::ostringstream gs;
    gs << "Gesture: ";
    std::string gstNm(gs.str());
    for (int k = 0; k < sizeof(gestName); k++)
    {
        gstNm += gestName;
    }

//Then to add it to the data (as it loops through the joints)

sAlerts += gstNm; // if i remove this line, all the joint data displays beautifully, just without the gesture name.

// loop continues, adding the joint parameter data

0 Kudos
Jack_K_1
New Contributor II
1,101 Views

Scott,

Windows uses Unicode, a 16-bit format for storing characters.  In Visual Studio you will see the phrase "Use Unicode Character Set" for the General>Character Set setting in the property page for the project; this results in defines UNICODE and _UNICODE being set.

If UNICODE is defined, GetDlgItemText becomes GetDlgItemTextW and Unicode characters are returned.  If UNICODE is not defined, GetDlgItemTexT becomes GetDlgItemTextA and ASCII characters are returned. 

Since Windows uses Unicode, not doing so means the API is constantly translating between Unicode and ASCII.

pxcCHAR is a wchar_t by the way.  The following pseudo code should work:

   const int maxlength = 256;

   wchar_t gestName[maxlength];

   GetDlgItemText(hwndDlg, IDC_GESTURENAME, gestName, maxlength);

   std::wstring alerts(gestName);

  loop over joint data

     alerts += sJoint;  // where sJoint is a std::wstring

  end loop

 

0 Kudos
Scott_W_1
Beginner
1,100 Views

Wonderful! That did it. I had existing code which was using std::string to get the joint data into the box, but once I understood your explanation, I was able to bridge from the std::wstring to the std::string.

It works beautifully now. Now I can focus on the actual recognition algorithms. Thanks for your patience with me.

0 Kudos
Reply