明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 5714|回复: 30

[求助]如何在应用程序中得知用户按了OK按扭?

  [复制链接]
发表于 2005-4-22 17:04:00 | 显示全部楼层 |阅读模式
通过非模态对话框获得用户输入的数据赋值给变量,但是在XXXXCommand.cpp文件中想引用这些变量却出现“未声明变量”。后将变量声明为extern XXX,又出现link时“未解决的外部标识......"

这是为何?
另:如何在应用程序中得知用户按了OK按扭?

发表于 2005-4-22 17:54:00 | 显示全部楼层

回复

有程序吗?传上来吧
 楼主| 发表于 2005-4-22 19:30:00 | 显示全部楼层
//----------------------------------------------------------------------------- //这是一个图框生成程序 //-----------------------------------------------------------------------------
//----- DwgboxDlg.cpp : implementation file
#include "StdAfx.h"
#include "resource.h"
#include "DwgboxDlg.h" //-----------------------------------------------------------------------------
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif //-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC (DwgboxDlg, CAcUiDialog) BEGIN_MESSAGE_MAP(DwgboxDlg, CAcUiDialog)
//{{AFX_MSG_MAP(DwgboxDlg)
ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus) // Needed for modeless dialog.
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO10, OnRadio10)
ON_BN_CLICKED(IDC_RADIO11, OnRadio11)
ON_BN_CLICKED(IDC_RADIO12, OnRadio12)
ON_BN_CLICKED(IDC_RADIO13, OnRadio13)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
ON_BN_CLICKED(IDC_RADIO8, OnRadio8)
ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP() //-----------------------------------------------------------------------------
DwgboxDlg::DwgboxDlg (CWnd* pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/) : CAcUiDialog (DwgboxDlg::IDD, pParent, hInstance) {
//{{AFX_DATA_INIT(DwgboxDlg)
m_bEnableTKtb = TRUE;
m_bEnableTkhq = TRUE;
m_nTKsize = 1;
m_nTKHorVer = 0;
m_nTKratio = 1;
m_fTKwidth = 841;
m_fTKhight = 594;
m_fTKscale = 100;
//}}AFX_DATA_INIT
} void DwgboxDlg::DoDataExchange (CDataExchange *pDX) {
CAcUiDialog::DoDataExchange (pDX) ;
//{{AFX_DATA_MAP(DwgboxDlg)
DDX_Control(pDX, IDCANCEL, m_TKCancelMsg);
DDX_Check(pDX, IDC_CHECK1, m_bEnableTKtb);
DDX_Check(pDX, IDC_CHECK2, m_bEnableTkhq);
DDX_Radio(pDX, IDC_RADIO1, m_nTKsize);
DDX_Radio(pDX, IDC_RADIO6, m_nTKHorVer);
DDX_Radio(pDX, IDC_RADIO8, m_nTKratio);
DDX_Text(pDX, IDC_EDIT1, m_fTKwidth);
DDX_Text(pDX, IDC_EDIT2, m_fTKhight);
DDX_Text(pDX, IDC_EDIT3, m_fTKscale);
//}}AFX_DATA_MAP
} // Needed for modeless dialogs to keep focus.
// Return FALSE to not keep the focus, return TRUE to keep the focus
LONG DwgboxDlg::OnAcadKeepFocus(UINT, UINT)
{
return TRUE;
} //----------------------------------------------------------------------------- void DwgboxDlg::OnOK()
{
// TODO: Add extra validation here
CAcUiDialog::OnOK();
DestroyWindow();
tk();
} void DwgboxDlg::OnCancel()
{
// TODO: Add extra cleanup here

CAcUiDialog::OnCancel();
DestroyWindow();
} void DwgboxDlg::OnCheck1()
{
// TODO: Add your control notification handler code here
if(m_bEnableTKtb == TRUE)
{
m_bEnableTKtb = FALSE;
}
else
{
m_bEnableTKtb = TRUE;
}
} void DwgboxDlg::OnCheck2()
{
// TODO: Add your control notification handler code here
if(m_bEnableTkhq == TRUE)
{
m_bEnableTkhq = FALSE;
}
else
{
m_bEnableTkhq = TRUE;
}
} void DwgboxDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CAcUiDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here
BOOL UpdateData(BOOL bSaveAndValidate=TRUE);
} void DwgboxDlg::OnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CAcUiDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here
BOOL UpdateData(BOOL bSaveAndValidate=TRUE);
} void DwgboxDlg::OnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CAcUiDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here
BOOL UpdateData(BOOL bSaveAndValidate=TRUE);
} void DwgboxDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
m_nTKsize=0;
m_fTKwidth = 1189.0;
m_fTKhight = 841.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio10()
{
// TODO: Add your control notification handler code here
m_nTKratio=2;
m_fTKscale = 50.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio11()
{
// TODO: Add your control notification handler code here
m_nTKratio=3;
m_fTKscale = 20.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio12()
{
// TODO: Add your control notification handler code here
m_nTKratio=4;
m_fTKscale = 10.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio13()
{
// TODO: Add your control notification handler code here
m_nTKratio=5;
m_fTKscale = 1.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
m_nTKsize=1;
m_fTKwidth = 841.0;
m_fTKhight = 594.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
m_nTKsize=2;
m_fTKwidth = 594.0;
m_fTKhight = 420.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
m_nTKsize=3;
m_fTKwidth = 420.0;
m_fTKhight = 297.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio5()
{
// TODO: Add your control notification handler code here
m_nTKsize=4;
m_fTKwidth = 210.0;
m_fTKhight = 297.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio6()
{
// TODO: Add your control notification handler code here
m_nTKHorVer=0;
} void DwgboxDlg::OnRadio7()
{
// TODO: Add your control notification handler code here
m_nTKHorVer=1;
} void DwgboxDlg::OnRadio8()
{
// TODO: Add your control notification handler code here
m_nTKratio=0;
m_fTKscale = 200.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} void DwgboxDlg::OnRadio9()
{
// TODO: Add your control notification handler code here
m_nTKratio=1;
m_fTKscale = 100.0;
BOOL UpdateData(BOOL bSaveAndValidate=FALSE);
} //----------------------------------------------------------------------------- BOOL startDlg()
{
DwgboxDlg *gpDlg=NULL;
gpDlg = new DwgboxDlg(acedGetAcadFrame());
gpDlg->Create(IDD_DIALOG1);
gpDlg->ShowWindow(SW_SHOW);
gpDlg->CenterWindow();
return true;
}

//-----------------------------------------------------------------------------

/*BOOL endDlg()
{
DwgboxDlg *gpDlg=NULL;
if(!gpDlg)return TRUE;
BOOL b = gpDlg->DestroyWindow();
if(b)gpDlg = NULL;
return b;
}*/ void DwgboxDlg::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
delete this; //删除当前指针
CAcUiDialog::PostNcDestroy();
}
 楼主| 发表于 2005-4-22 19:33:00 | 显示全部楼层
//上个程序为DwgboxDlg.cpp //现为DwgboxDlg.h //------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if !defined(ARX__DWGBOXDLG_H__20050416_161606)
#define ARX__DWGBOXDLG_H__20050416_161606 //-----------------------------------------------------------------------------
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 //-----------------------------------------------------------------------------
class DwgboxDlg : public CAcUiDialog {
DECLARE_DYNAMIC (DwgboxDlg) public:
DwgboxDlg (CWnd* pParent =NULL, HINSTANCE hInstance =NULL) ; //{{AFX_DATA(DwgboxDlg)
enum { IDD = IDD_DIALOG1 };
CButton m_TKCancelMsg;
BOOL m_bEnableTKtb;
BOOL m_bEnableTkhq;
int m_nTKsize;
int m_nTKHorVer;
int m_nTKratio;
float m_fTKwidth;
float m_fTKhight;
float m_fTKscale;
//}}AFX_DATA //{{AFX_VIRTUAL(DwgboxDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void PostNcDestroy();
//}}AFX_VIRTUAL protected:
//{{AFX_MSG(DwgboxDlg)
afx_msg LONG OnAcadKeepFocus(UINT, UINT);
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnCheck1();
afx_msg void OnCheck2();
afx_msg void OnRadio1();
afx_msg void OnRadio10();
afx_msg void OnRadio11();
afx_msg void OnRadio12();
afx_msg void OnRadio13();
afx_msg void OnRadio2();
afx_msg void OnRadio3();
afx_msg void OnRadio4();
afx_msg void OnRadio5();
afx_msg void OnRadio6();
afx_msg void OnRadio7();
afx_msg void OnRadio8();
afx_msg void OnRadio9();
afx_msg void OnChangeEdit1();
afx_msg void OnChangeEdit2();
afx_msg void OnChangeEdit3();
//}}AFX_MSG DECLARE_MESSAGE_MAP()
} ; //{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif //----- !defined(ARX__DWGBOXDLG_H__20050416_161606)
 楼主| 发表于 2005-4-22 19:41:00 | 显示全部楼层
//此为DwgboxCommand.cpp //-------------------------------------------------------------- //
// ObjectARX defined commands, created by [2005-4-16], , #include "StdAfx.h"
#include "StdArx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "resource.h"
#include "DwgboxDlg.h"
//#include "DwgboxDlg.cpp"
#include "aced.h"
#include "acedads.h"
#include "acutads.h"
#include "rxdefs.h"
#include "adslib.h"
//-----------------------------------------------------------------------------
void pointset();
void drawbz (ads_point pt);
void lineset();
void drabox(ads_point p1,ads_point p2,ads_real wh); int anset=0,ansetxy=0,ansetw=0,anseth=0,bx=0,bax=0,bcx=0,box=0,accepted=0;
ads_real bbx,bbl,nx,ny;
ads_point basept={0,0,0},pp={0,0,0};
int change_var(char *varstr,int value,int *ocmd);
float m_fTKwidth,m_fTKhight,m_fTKscale; //-----------------------------------------------------------------------------
// This is command 'DWGBOX, by [2005-4-16], ,
void Dwgbox()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - Dwgbox() called.");
#endif // OARXWIZDEBUG // TODO: Implement the command //-----------------------------------------------------------------------------
BOOL startDlg();
startDlg();
}
//-----------------------------------------------------------------------------
void tk()
{ ads_point basept1,ppt;
int old1,old2,old3,valxy;
change_var("blipmode",0,&old1);
change_var("cmdecho",0,&old2);
change_var("osmode",0,&old3);

if(m_fTKwidth!=0.0 && m_fTKhight!=0.0 && m_fTKscale!=0.0 )//此处变量无法从DwgboxDlg.cpp中定义的对话框变量传递数据.
{
basept[0]=0.00;basept[1]=0.00;basept[2]=0.00;
if((valxy=acedGetPoint(NULL,"\n请拾取图框左下角点位置:",ppt))!=RTCAN)
{
basept1[0]=ppt[0];
basept1[1]=ppt[1];
basept1[2]=ppt[2];
if (valxy==RTNONE)
{
drawbz(basept);
}
else
{
basept[0]=basept1[0];
basept[1]=basept1[1];
basept[2]=basept1[2];
drawbz(basept);
}
}
else
{
nx=0;ny=0;bbx=0;anset=0;ansetxy=0;ansetw=0;anseth=0;bx=0;bax=0;bcx=0;box=0;
acutPrintf("\n用户中断!\n");
}
pointset();
}
else
{
if(accepted==0)//此处想获得用户如果按了"取消"按钮消息,未成功.
{
nx=0;ny=0;bbx=0;anset=0;ansetxy=0;ansetw=0;anseth=0;bx=0;bax=0;bcx=0;box=0;
acutPrintf("\n*Cancel*\n");
}
else
{
nx=0;ny=0;bbx=0;anset=0;ansetxy=0;ansetw=0;anseth=0;bx=0;bax=0;bcx=0;box=0;
acutPrintf("\n参数选择错误!\n");
}
}
if(m_fTKwidth!=0.0 && m_fTKhight!=0.0 && m_fTKscale!=0.0)
{
lineset();
}
}
void pointset()
{
if (m_fTKwidth!=0 && m_fTKhight!=0)
{
pp[0]=m_fTKwidth;
pp[1]=m_fTKhight;
}
if(m_fTKscale!=0)
{
bbl=m_fTKscale;
}
pp[0]=basept[0]+pp[0]*bbl;
pp[1]=basept[1]+pp[1]*bbl;
acedCommand(RTSTR,"limits",RTPOINT,basept,RTPOINT,pp,RTNONE);
acedCommand(RTSTR,"zoom",RTSTR,"a",RTNONE);
} int change_var(char *varstr,int value,int *ocmd)
{
struct resbuf *rb0;
int status; rb0=acutNewRb(RTSHORT);
status=acedGetVar(varstr,rb0);
if(status != RTNORM)
{
acdbFail("\nacedGetVar(varstr.. fail)");
return RTERROR;
}
*ocmd=rb0->resval.rint;
rb0->resval.rint=value;
rb0->rbnext=NULL;
status=acedSetVar(varstr,rb0); acutRelRb(rb0);
if(status != RTNORM)
{
acdbFail("\nacedSetVar(varstr.. fail)");
return RTERROR;
}
return RTNORM;
} void drawbz (ads_point pt)
{
struct resbuf *rb2;
ads_point pp1,pp2,pp3,pp4;
ads_real aa;
rb2=acutNewRb(RTREAL);
acedGetVar("VIEWSIZE",rb2);
aa=0.020000*rb2->resval.rreal;
rb2->rbnext=NULL;
acutRelRb(rb2);
pp1[0]=pt[0]+aa;pp1[1]=pt[1]+aa;
pp2[0]=pt[0]-aa;pp2[1]=pt[1]-aa;
pp3[0]=pt[0]+aa;pp3[1]=pt[1]+(-aa);
pp4[0]=pt[0]-aa;pp4[1]=pt[1]-(-aa);
acedGrDraw(pp1,pp2,-1,0);
acedGrDraw(pp3,pp4,-1,0);
}
void lineset()
{
ads_real w;
ads_point pt3={0,0,0},
pt4={0,0,0},
pt5={0,0,0},
pt6={0,0,0};
acedCommand(RTSTR,"layer",RTSTR,"m",RTSTR,"tk",RTSTR,"c",RTSTR,"cyan",RTSTR,"",RTSTR,"",RTNONE);
acedCommand(RTSTR,"linetype",RTSTR,"s",RTSTR,"bylayer",RTSTR,"",RTNONE);
acedCommand(RTSTR,"color",RTSTR,"bylayer",RTNONE); drabox(basept,pp,0.0);
pt3[0]=basept[0]+bbl*25;
if(box==1)
{
pt3[1]=basept[1]+bbl*10;
pt4[0]=pp[0]-bbl*10;
pt4[1]=pp[1]-bbl*10;
}
else
{
pt3[1]=basept[1]+bbl*5;
pt4[0]=pp[0]-bbl*5;
pt4[1]=pp[1]-bbl*5;
}
w=0.700000*bbl;

drabox(pt3,pt4,w);
pt5[0]=pt4[0];pt5[1]=pt3[1];
pt6[0]=pt3[0];pt6[1]=pt4[1];
if (box==1)
{
acedCommand(RTSTR,"insert",RTSTR,"tb",RTPOINT,pt5,RTREAL,bbl,RTREAL,bbl,RTREAL,0.0,RTNONE);
acedCommand(RTSTR,"insert",RTSTR,"hq",RTPOINT,pt6,RTREAL,bbl,RTREAL,bbl,RTREAL,0.0,RTNONE);
}
else
{
acedCommand(RTSTR,"insert",RTSTR,"tb1",RTPOINT,pt5,RTREAL,bbl,RTREAL,bbl,RTREAL,0.0,RTNONE);
}
acedCommand(RTSTR,"layer",RTSTR,"s",RTSTR,"0",RTSTR,"",RTNONE);
box=0;bx=0;bax=0;bcx=0;anset=0;ansetxy=0;ansetw=0;anseth=0;
} void drabox(ads_point p1,ads_point p2,ads_real wh)
{
ads_point p3,p4;
p3[0]=p2[0];p3[1]=p1[1];
p4[0]=p1[0];p4[1]=p2[1];
acedCommand(RTSTR,"pline",RTPOINT,p1,RTSTR,"w",RTREAL,wh,RTREAL,wh,RTPOINT,p3,RTPOINT,p2,RTPOINT,p4,RTSTR,"c",RTNONE);
}
发表于 2005-4-22 20:31:00 | 显示全部楼层
你把工程贴上来比这样要好,


压缩成rar文件
 楼主| 发表于 2005-4-23 01:39:00 | 显示全部楼层
rar 文件如何传?
发表于 2005-4-23 07:45:00 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2005-4-23 08:11:00 | 显示全部楼层
程序还未写完.请指教
 楼主| 发表于 2005-4-23 08:14:00 | 显示全部楼层
程序上传后我怎么看不见?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-21 03:18 , Processed in 0.168347 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表