//==============================================================================
// 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"
// 在jiamiceshi类实现中添加(jiamiceshi.cpp)
// 宽字符转窄字符
std::string jiamiceshi::WideToNarrow(const wchar_t* wideStr) {
if (!wideStr) return "";
int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, nullptr, 0, nullptr, nullptr);
if (bufferSize == 0) return "";
std::string narrowStr(bufferSize, 0);
WideCharToMultiByte(CP_UTF8, 0, wideStr, -1, &narrowStr[0], bufferSize, nullptr, nullptr);
return narrowStr;
}
// 显示宽字符消息
void jiamiceshi::ShowMessage(const wchar_t* message) {
if (theUI) {
std::string narrowMsg = WideToNarrow(message);
theUI->NXMessageBox()->Show("调试信息",
NXOpen::NXMessageBox::DialogTypeInformation,
narrowMsg.c_str());
}
}
// 显示窄字符消息
void jiamiceshi::ShowMessage(const char* message) {
if (theUI) {
theUI->NXMessageBox()->Show("调试信息",
NXOpen::NXMessageBox::DialogTypeInformation,
message);
}
}
// 修改后的CheckDateLimit函数
bool jiamiceshi::CheckDateLimit() {
try {
// 从配置文件读取日期
const int limitYear = ConfigReader::GetInt(L"Expiry", L"Year", 2025);
const int limitMonth = ConfigReader::GetInt(L"Expiry", L"Month", 9);
const int limitDay = ConfigReader::GetInt(L"Expiry", L"Day", 30);
// 获取当前系统时间
time_t now = time(0);
tm ltm;
if (localtime_s(<m, &now) != 0) {
ShowMessage("获取本地时间失败");
return false;
}
int currentYear = 1900 + ltm.tm_year;
int currentMonth = ltm.tm_mon + 1;
int currentDay = ltm.tm_mday;
// 显示当前日期和限制日期
wchar_t dateMsg[256];
swprintf_s(dateMsg, L"当前日期: %d-%d-%d\n限制日期: %d-%d-%d",
currentYear, currentMonth, currentDay,
limitYear, limitMonth, limitDay);
ShowMessage(dateMsg);
// 比较日期
if (currentYear > limitYear) {
ShowMessage(L"功能已过期:当前年份超过限制年份");
return true;
}
else if (currentYear == limitYear) {
if (currentMonth > limitMonth) {
ShowMessage(L"功能已过期:当前月份超过限制月份");
return true;
}
else if (currentMonth == limitMonth) {
if (currentDay > limitDay) {
ShowMessage(L"功能已过期:当前日期超过限制日期");
return true;
}
else if (currentDay == limitDay) {
ShowMessage(L"当前日期等于限制日期,功能仍可用");
return false;
}
}
}
ShowMessage(L"功能未过期");
return false;
}
catch (...) {
ShowMessage("检查日期限制时发生异常");
return false;
}
}
// 修改后的ConfigReader类
class ConfigReader {
public:
// 获取整数配置值(宽字符版本)
static int GetInt(const wchar_t* section, const wchar_t* key, int defaultValue) {
wchar_t configPath[MAX_PATH] = { 0 };
// 获取当前DLL路径
HMODULE hModule = GetModuleHandle(NULL);
if (hModule) {
// 使用宽字符版本API
DWORD pathLen = GetModuleFileNameW(hModule, configPath, MAX_PATH);
if (pathLen == 0 || pathLen >= MAX_PATH) {
// 路径获取失败,使用当前目录
GetCurrentDirectoryW(MAX_PATH, configPath);
PathAppendW(configPath, L"config.ini");
}
else {
// 替换文件名为config.ini
wchar_t* lastBackslash = wcsrchr(configPath, L'\\');
if (lastBackslash) {
wcscpy_s(lastBackslash + 1, MAX_PATH - (lastBackslash - configPath) - 1, L"config.ini");
}
else {
wcscat_s(configPath, MAX_PATH, L"\\config.ini");
}
}
}
else {
// 模块句柄获取失败
GetCurrentDirectoryW(MAX_PATH, configPath);
PathAppendW(configPath, L"config.ini");
}
// 显示配置文件路径
jiamiceshi::ShowMessage(L"配置文件路径: ");
jiamiceshi::ShowMessage(configPath);
// 检查配置文件是否存在
if (!PathFileExistsW(configPath)) {
jiamiceshi::ShowMessage(L"配置文件不存在,使用默认值");
return defaultValue;
}
// 使用宽字符版本API读取INI文件
return GetPrivateProfileIntW(section, key, defaultValue, configPath);
}
};
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);
}
:报错严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E0265 函数 "jiamiceshi::ShowMessage(const wchar_t *message)" (已声明 所在行数:52) 不可访问 jiamiceshi D:\NXopen\BaiduSyncdisk\studio\jiamiceshi\jiamiceshi.cpp 166
错误(活动) E0265 函数 "jiamiceshi::ShowMessage(const wchar_t *message)" (已声明 所在行数:52) 不可访问 jiamiceshi D:\NXopen\BaiduSyncdisk\studio\jiamiceshi\jiamiceshi.cpp 165
错误(活动) E0265 函数 "jiamiceshi::ShowMessage(const wchar_t *message)" (已声明 所在行数:52) 不可访问 jiamiceshi D:\NXopen\BaiduSyncdisk\studio\jiamiceshi\jiamiceshi.cpp 170
最新发布