//==============================================================================
// WARNING!! This file is overwritten by the Block UI Styler while generating
// the automation code. Any modifications to this file will be lost after
// generating the code again.
//
// Filename: D:\NXopen\BaiduSyncdisk\studio\jiamiceshi\ui\jiamiceshi.cpp
//
// This file was generated by the NX Block UI Styler
// Created by: MICH-ROG
// Version: NX 12
// Date: 08-19-2025 (Format: mm-dd-yyyy)
// Time: 14:36 (Format: hh-mm)
//
//==============================================================================
//==============================================================================
// Purpose: This TEMPLATE file contains C++ source to guide you in the
// construction of your Block application dialog. The generation of your
// dialog file (.dlx extension) is the first step towards dialog construction
// within NX. You must now create a NX Open application that
// utilizes this file (.dlx).
//
// The information in this file provides you with the following:
//
// 1. Help on how to load and display your Block UI Styler dialog in NX
// using APIs provided in NXOpen.BlockStyler namespace
// 2. The empty callback methods (stubs) associated with your dialog items
// have also been placed in this file. These empty methods have been
// created simply to start you along with your coding requirements.
// The method name, argument list and possible return values have already
// been provided for you.
//==============================================================================
//------------------------------------------------------------------------------
//These includes are needed for the following template code
//------------------------------------------------------------------------------
#include "jiamiceshi.hpp"
// 配置文件读取工具类
class ConfigReader {
public:
// 获取整数配置值
static int GetInt(const char* section, const char* key, int defaultValue) {
char configPath[MAX_PATH] = { 0 };
// 获取当前DLL路径
HMODULE hModule = GetModuleHandle(NULL);
if (hModule) {
GetModuleFileName(hModule, configPath, MAX_PATH);
}
// 替换文件名为config.ini
char* lastBackslash = strrchr(configPath, '\\');
if (lastBackslash) {
strcpy_s(lastBackslash + 1, MAX_PATH - (lastBackslash - configPath) - 1, "config.ini");
}
else {
strcat_s(configPath, MAX_PATH, "\\config.ini");
}
// 使用Windows API读取INI文件中的整数值
return GetPrivateProfileInt(section, key, defaultValue, configPath);
}
};
// 添加日期限制检查函数实现
bool jiamiceshi::CheckDateLimit() {
// 从配置文件读取日期,如果没有则使用默认值
const int limitYear = ConfigReader::GetInt("Expiry", "Year", 2025);
const int limitMonth = ConfigReader::GetInt("Expiry", "Month", 7);
const int limitDay = ConfigReader::GetInt("Expiry", "Day", 30);
// 获取当前系统时间
time_t now = time(0);
tm* ltm = localtime(&now);
int currentYear = 1900 + ltm->tm_year;
int currentMonth = ltm->tm_mon + 1;
int currentDay = ltm->tm_mday;
// 比较日期
if (currentYear > limitYear) {
return true;
}
else if (currentYear == limitYear) {
if (currentMonth > limitMonth) {
return true;
}
else if (currentMonth == limitMonth) {
if (currentDay > limitDay) {
return true;
}
}
}
return false;
} // 未过期,功能可用
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(jiamiceshi::theSession) = NULL;
UI *(jiamiceshi::theUI) = NULL;
//------------------------------------------------------------------------------
// Constructor for NX Styler class
//------------------------------------------------------------------------------
jiamiceshi::jiamiceshi()
{
try
{
// Initialize the NX Open C++ API environment
jiamiceshi::theSession = NXOpen::Session::GetSession();
jiamiceshi::theUI = UI::GetUI();
theDlxFileName = "jiamiceshi.dlx";
theDialog = jiamiceshi::theUI->CreateDialog(theDlxFileName);
// Registration of callback functions
theDialog->AddApplyHandler(make_callback(this, &jiamiceshi::apply_cb));
theDialog->AddOkHandler(make_callback(this, &jiamiceshi::ok_cb));
theDialog->AddUpdateHandler(make_callback(this, &jiamiceshi::update_cb));
theDialog->AddInitializeHandler(make_callback(this, &jiamiceshi::initialize_cb));
theDialog->AddDialogShownHandler(make_callback(this, &jiamiceshi::dialogShown_cb));
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
throw;
}
}
//------------------------------------------------------------------------------
// Destructor for NX Styler class
//------------------------------------------------------------------------------
jiamiceshi::~jiamiceshi()
{
if (theDialog != NULL)
{
delete theDialog;
theDialog = NULL;
}
}
//------------------------------- DIALOG LAUNCHING ---------------------------------
//
// Before invoking this application one needs to open any part/empty part in NX
// because of the behavior of the blocks.
//
// Make sure the dlx file is in one of the following locations:
// 1.) From where NX session is launched
// 2.) $UGII_USER_DIR/application
// 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
// recommended. This variable is set to a full directory path to a file
// containing a list of root directories for all custom applications.
// e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_BASE_DIR\ugii\menus\custom_dirs.dat
//
// You can create the dialog using one of the following way:
//
// 1. USER EXIT
//
// 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
// 2) Invoke the Shared Library through File->Execute->NX Open menu.
//
//------------------------------------------------------------------------------
extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
{
jiamiceshi *thejiamiceshi = NULL;
try
{
thejiamiceshi = new jiamiceshi();
// The following method shows the dialog immediately
thejiamiceshi->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
jiamiceshi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
if(thejiamiceshi != NULL)
{
delete thejiamiceshi;
thejiamiceshi = NULL;
}
}
//------------------------------------------------------------------------------
// This method specifies how a shared image is unloaded from memory
// within NX. This method gives you the capability to unload an
// internal NX Open application or user exit from NX. Specify any
// one of the three constants as a return value to determine the type
// of unload to perform:
//
//
// Immediately : unload the library as soon as the automation program has completed
// Explicitly : unload the library from the "Unload Shared Image" dialog
// AtTermination : unload the library when the NX session terminates
//
//
// NOTE: A program which associates NX Open applications with the menubar
// MUST NOT use this option since it will UNLOAD your NX Open application image
// from the menubar.
//------------------------------------------------------------------------------
extern "C" DllExport int ufusr_ask_unload()
{
//return (int)Session::LibraryUnloadOptionExplicitly;
return (int)Session::LibraryUnloadOptionImmediately;
//return (int)Session::LibraryUnloadOptionAtTermination;
}
//------------------------------------------------------------------------------
// Following method cleanup any housekeeping chores that may be needed.
// This method is automatically called by NX.
//------------------------------------------------------------------------------
extern "C" DllExport void ufusr_cleanup(void)
{
try
{
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
jiamiceshi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
int jiamiceshi::Show()
{
try
{
theDialog->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
jiamiceshi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//------------------------------------------------------------------------------
//---------------------Block UI Styler Callback Functions--------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Callback Name: initialize_cb
//------------------------------------------------------------------------------
void jiamiceshi::initialize_cb()
{
try
{
group0 = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group0"));
selection0 = dynamic_cast<NXOpen::BlockStyler::SelectObject*>(theDialog->TopBlock()->FindBlock("selection0"));
expression0 = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()->FindBlock("expression0"));
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
jiamiceshi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//------------------------------------------------------------------------------
//Callback Name: dialogShown_cb
//This callback is executed just before the dialog launch. Thus any value set
//here will take precedence and dialog will be launched showing that value.
//------------------------------------------------------------------------------
// 修改对话框显示回调函数
void jiamiceshi::dialogShown_cb()
{
try
{
// 在对话框显示时检查日期限制
if (CheckDateLimit()) {
// 显示过期消息
theUI->NXMessageBox()->Show("MICH-明:V:jianjian19951231", NXMessageBox::DialogTypeError,
"此功能已过期,无法使用!\n请联系开发者获取更新版本。");
// 禁用所有控件
group0->SetEnable(false); // 禁用组
selection0->SetEnable(false); // 禁用选择对象控件
expression0->SetEnable(false); // 禁用表达式控件
// 隐藏确定和应用按钮
PropertyList* okProps = GetBlockProperties("OK"); // 获取OK按钮属性
if (okProps) {
okProps->SetLogical("Show", false); // 隐藏确定按钮
}
PropertyList* applyProps = GetBlockProperties("Apply"); // 获取应用按钮属性
if (applyProps) {
applyProps->SetLogical("Show", false); // 隐藏应用按钮
}
}
}
catch (exception& ex)
{
// 异常处理
theUI->NXMessageBox()->Show("错误提示:", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//------------------------------------------------------------------------------
//Callback Name: apply_cb
//------------------------------------------------------------------------------
// 修改应用回调函数
int jiamiceshi::apply_cb()
{
int errorCode = 0;
try
{
// 检查日期限制
if (CheckDateLimit()) {
theUI->NXMessageBox()->Show("MICH-明:V:jianjian19951231", NXMessageBox::DialogTypeError,
"此功能已过期,无法执行操作!");
return 1; // 返回错误代码
}//结束日期检查
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
jiamiceshi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Callback Name: update_cb
//------------------------------------------------------------------------------
int jiamiceshi::update_cb(NXOpen::BlockStyler::UIBlock* block)
{
try
{
if(block == selection0)
{
//---------Enter your code here-----------
}
else if(block == expression0)
{
//---------Enter your code here-----------
}
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
jiamiceshi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//------------------------------------------------------------------------------
//Callback Name: ok_cb
//------------------------------------------------------------------------------
int jiamiceshi::ok_cb()
{
int errorCode = 0;
try
{
errorCode = apply_cb();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
jiamiceshi::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Function Name: GetBlockProperties
//Description: Returns the propertylist of the specified BlockID
//------------------------------------------------------------------------------
PropertyList* jiamiceshi::GetBlockProperties(const char *blockID)
{
return theDialog->GetBlockProperties(blockID);
}
报错:严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2039 "CreateDialogParamA": 不是 "NXOpen::UI" 的成员 jiamiceshi D:\NXopen\BaiduSyncdisk\studio\jiamiceshi\jiamiceshi.cpp 123
错误(活动) E0135 class "NXOpen::UI" 没有成员 "CreateDialogParamA" jiamiceshi D:\NXopen\BaiduSyncdisk\studio\jiamiceshi\jiamiceshi.cpp 120
错误 C2059 语法错误:“,” jiamiceshi D:\NXopen\BaiduSyncdisk\studio\jiamiceshi\jiamiceshi.cpp 123
最新发布