Author Topic: Arx SetWindowTextW Help  (Read 4399 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Arx SetWindowTextW Help
« on: March 27, 2007, 02:35:46 PM »
Someone want to help a total noob? I am trying to write my own version of DosLib’s DOS_GetString, I can’t for the life of me figure how to use SetWindowTextW() to set the dialog caption, or how to make a text lable. I would really appreciate any help I can get.

Thanks
Dan

I have attached the project and here is the lame function


Code: [Select]
static int ads_crptextbox(void)
    {
     
        wchar_t sCaption[256];
        wchar_t sLabel[256];
        wchar_t sText[1024] ;

        //
        struct resbuf *pArgs = acedGetArgs() ;

        if (pArgs == NULL || pArgs->restype != RTSTR )
        {
            acedRetNil();
            return (RSRSLT);
        }
        else
        {
            wcscpy_s(sCaption, 256 , pArgs->resval.rstring);
        }

        //
        if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR )
        {
            acedRetNil();
            return (RSRSLT);
        }
        else
        {
            wcscpy_s(sLabel, 256 , pArgs->resval.rstring);
        }

        //
        if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR  )
        {
            wcscpy_s(sText, 1024 , L"");
        }
        else
        {
            wcscpy_s(sText, 1024 , pArgs->resval.rstring);
        }

        ///////Dialog Stuff
        CString cText = sText;
        CString cCaption = sCaption;
        CString cLabel = sLabel;

        CAcExtensionModule objResOverride;
        TextBox * dlg = new TextBox(CWnd::FromHandle(adsw_acadMainWnd()));

        //-==-==-==-==-==--==

        //dlg->SetWindowTextW(cCaption); //This Crashes
        dlg->m_editBoxString = cText;
        //How do I make a label????

        //-==-==-==-==-==--==

        int m_dlgResult = dlg->DoModal();

        if ( m_dlgResult != IDOK )
        {
            cText = L"CANCEL";
        }
        else
        {
            cText = dlg->m_editBoxString;
        }

        acedRetStr(cText) ;

        return (RSRSLT) ;
        delete dlg;
    }

edit: removed the solution
« Last Edit: March 28, 2007, 12:17:14 AM by Danielm103 »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: Arx SetWindowTextW Help
« Reply #1 on: March 27, 2007, 02:41:58 PM »
Oh and here is the command and the current results

(crptextbox “Title” “Label” “Default Text”)


mjguzik

  • Newt
  • Posts: 30
Re: Arx SetWindowTextW Help
« Reply #2 on: March 27, 2007, 05:04:54 PM »
I not sure this is exact, but try looking at setting a public variable in the dialog class definition and setting the passed Dialog Title in the initialization function of the class.

SetWindowText(mTitle);

To convert a static you need to change the property from IDC_STATIC to IDC_LABEL.  Then attach a variable to it in the Dialog class.  Again in the initialization function pass your prompt to the class variable

mprompt.SetWindowTextW(strPrompt);

where mpropmt is the variable associated with the redefined static label. 

Fernando had an example on his web site in Example 3 I seem to recall.

Best regards,

MJG

MickD

  • Gator
  • Posts: 3420
  • (x-in)->[process]->(y-out)
Re: Arx SetWindowTextW Help
« Reply #3 on: March 27, 2007, 05:32:15 PM »
I think you may need the handle to the window you wish to change the text of, a window being any 'control' or visible object.
IOW, if you need to set the text of the label it would be something like ->

SetWidowTextW(hLabel, "Some Text");

this way it know which window to set the actual text to,
hth,
Mick.

Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Chuck Gabriel

  • Guest
Re: Arx SetWindowTextW Help
« Reply #4 on: March 27, 2007, 08:54:05 PM »
Mick,
He is using a member-function version of SetWindowText, so he doesn't need the window handle.  I can't see what he is doing wrong.

Daniel,
You shouldn't ever have to explicitly choose between SetWindowTextA and SetWindowTextW.  There are macros in the headers that should automagically select the correct version for you if you call SetWindowText.

Have you tried setting a breakpoint at the function call and double checking the value of cCaption?

MickD

  • Gator
  • Posts: 3420
  • (x-in)->[process]->(y-out)
Re: Arx SetWindowTextW Help
« Reply #5 on: March 27, 2007, 09:01:48 PM »
Mick,
He is using a member-function version of SetWindowText, so he doesn't need the window handle.  I can't see what he is doing wrong.

....


Ahh!, MFC eh?! < ..quickly runs for the hills :D >
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: Arx SetWindowTextW Help
« Reply #6 on: March 27, 2007, 10:32:36 PM »
...change the property from IDC_STATIC to IDC_LABEL...

MJG Thanks, This got the lable to work  :-)

Thanks Everyone! I will keep hacking at this
I tried
Code: [Select]
SetWindowText(dlg->GetSafeHwnd(), cCaption);which does nothing (better than crashing  :-D)




It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: Arx SetWindowTextW Help
« Reply #7 on: March 27, 2007, 11:58:17 PM »
I not sure this is exact, but try looking at setting a public variable in the dialog class definition and setting the passed Dialog Title in the initialization function of the class.

SetWindowText(mTitle);

This worked, Your Awesome  8-)

Thanks  :lol:

edit: attached the solution and .arx for those who want to play
« Last Edit: March 28, 2007, 12:20:36 AM by Danielm103 »

LE

  • Guest
Re: Arx SetWindowTextW Help
« Reply #8 on: April 04, 2007, 10:15:20 PM »
Code: [Select]
wcscpy_s(

Daniel;

I you plan to write code for different AutoCAD platforms and being able to use the same code for example in the VS2005 and VS2002, I will recommend to start using the Generic Routine Mappings, see the attached image (you get that after selecting the function name and pressing F1:


In your case, would be the _tcscpy_s()


HTH
« Last Edit: April 04, 2007, 10:17:54 PM by LE »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7032
  • AKA Daniel
Re: Arx SetWindowTextW Help
« Reply #9 on: April 05, 2007, 08:22:31 AM »
Thanks  Luis

I will have a look at that.