[每日一码] 接受LISP参数,实现文本编辑框
// (C) Copyright 2002-2005 by Autodesk, Inc.//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. ** is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//-----------------------------------------------------------------------------
//----- TextBox.cpp : Implementation of TextBox
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "TextBox.h"
//-----------------------------------------------------------------------------
IMPLEMENT采用DYNAMIC (TextBox, CAcUiDialog)
BEGIN采用MESSAGE采用MAP(TextBox, CAcUiDialog)
ON采用MESSAGE(WM采用ACAD采用KEEPFOCUS, OnAcadKeepFocus)
END采用MESSAGE采用MAP()
//-----------------------------------------------------------------------------
TextBox::TextBox (CWnd *pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/)
: CAcUiDialog (TextBox::IDD, pParent, hInstance) , m采用editBoxString(采用T("")) , m采用labelString(采用T(""))
{
}
//-----------------------------------------------------------------------------
void TextBox::DoDataExchange (CDataExchange *pDX) {
CAcUiDialog::DoDataExchange (pDX) ;
DDX采用Text(pDX, IDC采用EDIT1, m采用editBoxString);
DDX采用Text(pDX, IDC采用LABEL, m采用labelString);
DDX采用Control(pDX, IDC采用EDIT1, m采用editControl);
}
//-----------------------------------------------------------------------------
//----- Needed for modeless dialogs to keep focus.
//----- Return FALSE to not keep the focus, return TRUE to keep the focus
LRESULT TextBox::OnAcadKeepFocus (WPARAM, LPARAM) {
return (TRUE) ;
}
//
BOOL TextBox::OnInitDialog()
{
CAcUiDialog::OnInitDialog();
//set the caption
SetWindowText(m采用caption);
//set focus to the editbox
m采用editControl.SetFocus();
return FALSE;
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//-----------------------------------------------------------------------------
#pragma region //DlgTextBox
//(crptextbox "Title" "Label" "Default Text")
int DlgTextBox(void)
{
LPCTSTR pszCaption;
LPCTSTR pszLabel;
LPCTSTR pszText;
//get args from lisp
struct resbuf *pArgs = acedGetArgs();
if (pArgs == NULL)
return acedRetNil();
//get caption string
if (pArgs->restype != RTSTR )
return acedRetNil();
pszCaption = pArgs->resval.rstring;
//get label string
if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR )
return acedRetNil();
pszLabel = pArgs->resval.rstring;
//get the defaul text
if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR)
pszText = 采用T("");
else
pszText = pArgs->resval.rstring;
///////Dialog Stuff
CAcExtensionModule objResOverride;
TextBox dlg(CWnd::FromHandle(adsw采用acadMainWnd()));
//
dlg.m采用caption = pszCaption;
dlg.m采用editBoxString = pszText;
dlg.m采用labelString = pszLabel;
int m采用dlgResult = dlg.DoModal();
if ( m采用dlgResult != IDOK )
return acedRetNil();
else
pszText = dlg.m采用editBoxString;
//
if ( 采用tcslen(pszText) == 0 )
return acedRetNil();
acedRetStr(pszText);
return (RSRSLT) ;
}
#pragma endregion
#pragma region //DlgIntBox
//(crpintbox "Title" "Label" 12)
int DlgIntBox(void)
{
LPCTSTR pszCaption;
LPCTSTR pszLabel;
LPCTSTR pszIntText;
ACHAR buf = {0};
int iInt;
//
struct resbuf *pArgs = acedGetArgs() ;
if (pArgs == NULL)
return acedRetNil();
//
if (pArgs->restype != RTSTR )
return acedRetNil();
else
pszCaption = pArgs->resval.rstring;
//
if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR )
return acedRetNil();
else
pszLabel = pArgs->resval.rstring;
//
if ((pArgs = pArgs->rbnext) != NULL )
{
if (pArgs->restype == RTSHORT)
pszIntText = 采用itot(pArgs->resval.rint , buf, 10);
else if (pArgs->restype == RTLONG)
pszIntText = 采用itot(pArgs->resval.rlong ,buf, 10);
else if (pArgs->restype == RTREAL)
pszIntText = 采用itot((int)pArgs->resval.rreal , buf, 10);
else
pszIntText = 采用T("");
}
else
{
pszIntText = 采用T("");
}
///////Dialog Stuff
CAcExtensionModule objResOverride;
//
TextBox dlg(CWnd::FromHandle(adsw采用acadMainWnd()));
//
dlg.m采用caption = pszCaption;
dlg.m采用labelString = pszLabel;
dlg.m采用editBoxString = pszIntText;
//
int m采用dlgResult = dlg.DoModal();
//
if ( m采用dlgResult != IDOK )
return acedRetNil();
else
pszIntText = dlg.m采用editBoxString;
if ( 采用tcslen(pszIntText) == 0 )
return acedRetNil();
//
iInt = 采用ttoi(pszIntText);
//
acedRetInt(iInt);
return (RSRSLT) ;
}
#pragma endregion
#pragma region //DlgRealBox
//(crprealbox "Title" "Label" 12.23)
int DlgRealBox(void)
{
LPCTSTR pszCaption;
LPCTSTR pszLabel;
LPCTSTR pszRealText;
ACHAR buf;
double dReal;
//
struct resbuf *pArgs = acedGetArgs() ;
if (pArgs == NULL)
return acedRetNil();
//
if (pArgs->restype != RTSTR )
return acedRetNil();
pszCaption =pArgs->resval.rstring;
//
if ((pArgs = pArgs->rbnext) == NULL || pArgs->restype != RTSTR )
return acedRetNil();
pszLabel = pArgs->resval.rstring;
//
if ((pArgs = pArgs->rbnext) != NULL)
{
if (pArgs->restype == RTREAL )
采用stprintf(buf , 采用T("%0.2f") , (double)pArgs->resval.rreal );
else if (pArgs->restype == RTLONG)
采用stprintf(buf, 采用T("%0.2f") ,(double)pArgs->resval.rlong );
else if (pArgs->restype == RTSHORT)
采用stprintf( buf , 采用T("%0.2f") ,(double)pArgs->resval.rint );
else
buf = '\0';
}
else
buf = '\0';
pszRealText = buf;
///////Dialog Stuff
CAcExtensionModule objResOverride;
//
TextBox dlg(CWnd::FromHandle(adsw采用acadMainWnd()));
//
dlg.m采用caption = pszCaption;
dlg.m采用labelString = pszLabel;
dlg.m采用editBoxString = pszRealText;
//
int m采用dlgResult = dlg.DoModal();
if ( m采用dlgResult != IDOK )
return acedRetNil();
else
pszRealText = dlg.m采用editBoxString;
//
if ( 采用tcslen(pszRealText) == 0 )
return acedRetNil();
//
dReal = 采用tstof(pszRealText);
//
acedRetReal(dReal);
return (RSRSLT) ;
}
#pragma endregion
页:
[1]