【NX二次开发】常用的标准对话框
1.uc1601 单按钮模态对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); uc1601("单选模态对话框!", 1); UF_terminate(); }
2.UF_UI_message_dialog 多按钮模态对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); int response = 0; char title_string[] = "王牌飞行员_里海"; char *sMessages = "多按钮模态对话框"; UF_UI_MESSAGE_DIALOG_TYPE dialog_type = UF_UI_MESSAGE_QUESTION;//对话框类型 UF_UI_MESSAGE_ERROR,UF_UI_MESSAGE_WARNING,UF_UI_MESSAGE_INFORMATION,UF_UI_MESSAGE_QUESTION UF_UI_message_buttons_s button; button.button1 = true;//是否显示 button.button2 = true; button.button3 = true; button.label1 = "是";//按钮名 button.label2 = "否"; button.label3 = "取消"; button.response1 = 1;//返回值 button.response2 = 2; button.response3 = 3; UF_UI_message_dialog(title_string, dialog_type, &sMessages, 1, 0, &button, &response); switch (response) { case 1: uc1601(button.label1, 1); break; case 2: uc1601(button.label2, 1); break; case 3: uc1601(button.label3, 1); break; default: uc1601("未知按钮", 1); break; } UF_terminate(); }
3.文件选择对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); //文件选择对话框 char sPromptStr[] = "部件选择对话框"; //快捷信息(在提示栏显示) char sTitleStr[] = "部件选择对话框"; //对话框标题(如图) char sFilterStr[] = ".prt"; //文件过滤器,即只处理某一种类型文件(如图) char sDefaultStr[] = "*.prt"; //默认文件名(如图) char sFilePath[256] = ""; //用户选择的文件全路径 int iRespones = 0; //函数返回值 UF_UI_create_filebox(sPromptStr, sTitleStr, sFilterStr, sDefaultStr, sFilePath, &iRespones); uc1601(sFilePath, 1); UF_terminate(); }
4.文件夹选择对话框
#include "Text.h" #include <Windows.h> #include <ShlObj.h> #include <tchar.h> //来自“王牌飞行员_里海”的测试源码(qq群753801561) void OnBnClickedButton1(); extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); OnBnClickedButton1(); UF_terminate(); } extern int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); } int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { switch (uMsg) { case BFFM_INITIALIZED: //选择目录对话框初始化时 选中指定目录 //BFFM_INITIALIZED表示浏览对话框已经初化结束,参数lParam为NULL //设置初始选项 ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); //关于BFFM_SETSELECTION消息的说明 //wParam :标记lParam参数包含一个ITEMIDLIST结构(PIDL)还是一个目录路径名 // 如果为TRUE,lParam内容为路径名;否则lParam包含一个路径PIDL。 //lParam :内容为浏览对话框所选的路径。如果wParam为TRUE,lParam内容为一个 // 以NULL结尾的字符串的指针,否则为PIDL break; default: break; } return 0; } void OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 BROWSEINFO bi; char Buffer[MAX_PATH]; LPWSTR aaa = CA2W(Buffer); //初始化入口参数bi开始 bi.hwndOwner = NULL; bi.pidlRoot = NULL;//初始化制定的root目录很不容易 bi.pszDisplayName = aaa;//此参数如为NULL则不能显示对话框 bi.lpszTitle = _T("选择目标文件路径"); bi.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE; //CString file_puch=_T("D:\\HYS_tool_code\\code\\tihuan_excel\\x64\\Release\\data"); CString file_puch = _T("D:\\");// bi.lParam = (long)(file_puch.GetBuffer(file_puch.GetLength()));//初始化路径,形如(_T("c:\\Symbian")); bi.lpfn = BrowseCallbackProc; //初始化入口参数bi结束 LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);//调用显示选择对话框 if (pIDList) { SHGetPathFromIDList(pIDList, aaa); //取得文件夹路径到Buffer里 file_puch = aaa;//将路径保存在一个CString对象里 /*你的代码 */ char chArray[500]; CString2Char(file_puch, chArray); //CString转char uc1601(chArray, 1); } // free memory used IMalloc * imalloc = 0; if (SUCCEEDED(SHGetMalloc(&imalloc))) { imalloc->Free(pIDList); imalloc->Release(); } }
5.单选菜单对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char sPrompStr[] = "单选菜单对话框";//显示在提示栏中的信息 int iDefault = 0;//0:确定灰显 1:确定激活 char asOptions[][38] = { "菜单选项1", "菜单选项2","菜单选项3"}; int iNumOfOptions = 3;//最多包含14个菜单选项 uc1603(sPrompStr, iDefault, asOptions, iNumOfOptions); UF_terminate(); }
6.多选菜单对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char sPrompStr[] = "多选菜单对话框";//显示在提示栏中的信息 int iDefault = 0;//0:确定灰显 1:确定激活 char asOptions[][38] = { "菜单选项1", "菜单选项2","菜单选项3" }; int iRe = 0; int iNumOfOptions = 3;//最多包含14个菜单选项 uc1605(sPrompStr, iDefault, asOptions, iNumOfOptions,&iRe); UF_terminate(); }
7.单对象选择对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) int selectface();//选面 extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); selectface(); UF_terminate(); } extern int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); } int init_proc_face(UF_UI_selection_p_t select, void* user_data)//选面 { int num_triples = 1; UF_UI_mask_t mask_triples[] = { UF_solid_type,0,20 }; if (UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples) == 0) { return (UF_UI_SEL_SUCCESS); } return (UF_UI_SEL_FAILURE); } int selectface()//选面 { tag_t tagSeleceFaceOcc = 0; int iReturn = 0; int iSelResp = 0; double pDblCursorPosTemp[3]; tag_t tagViewTemp; tag_t pTagObjs; iReturn = UF_UI_select_with_single_dialog("提示请选择面", "标题请选择面", UF_UI_SEL_SCOPE_NO_CHANGE, init_proc_face, NULL, &iSelResp, &pTagObjs, pDblCursorPosTemp, &tagViewTemp); if (!iReturn&&pTagObjs != NULL_TAG) { tagSeleceFaceOcc = pTagObjs; UF_DISP_set_highlight(pTagObjs, false); return 0; } else { return 1; } }
8.按类选择对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) int selectPartBody();//选择体; extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); selectPartBody(); UF_terminate(); } extern int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); } static int face_sel_cb(int num_sel, tag_p_t sel_objects, int num_deselected, tag_p_t deselected_objs, void *user_data, UF_UI_selection_p_t select) { int i = 0; tag_t tagObjTemp; UF_OBJ_translucency_t TRANSLUCENCY = NULL; for (i = 0; i < num_sel; i++) { if (UF_ASSEM_is_occurrence(sel_objects[i])) { tagObjTemp = UF_ASSEM_ask_prototype_of_occ(sel_objects[i]); } else { tagObjTemp = sel_objects[i]; } UF_UI_remove_from_sel_list(select, 1, &sel_objects[i], true); UF_OBJ_ask_translucency(tagObjTemp, &TRANSLUCENCY); if (TRANSLUCENCY != 0) { (UF_OBJ_set_translucency(tagObjTemp, 0)); (UF_OBJ_set_translucency(sel_objects[i], 0)); } else { (UF_OBJ_set_translucency(tagObjTemp, 50)); (UF_OBJ_set_translucency(sel_objects[i], 50)); } } return (UF_UI_CB_CONTINUE_DIALOG); } int init_proc_solid(UF_UI_selection_p_t select, void* user_data) { int iReturn = 0; const int num_triples = 1; UF_UI_mask_t mask_triples[num_triples]; mask_triples[0].object_type = UF_solid_type; //选择过滤 mask_triples[0].object_subtype = 0; mask_triples[0].solid_type = 0; iReturn = UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples); if (!iReturn) iReturn = (UF_UI_set_sel_procs(select, NULL, face_sel_cb, NULL)); if (iReturn == 0) { return (UF_UI_SEL_SUCCESS); } return (UF_UI_SEL_FAILURE); } int selectPartBody()//选择体 { int iReturn = 0; int iSelResp = 0; int iCountTemp = 0; double pDblCursorPosTemp[3]; tag_t *pTagObjs = NULL; //选择的对象 while (!iReturn) { iReturn = (UF_UI_select_with_class_dialog("提示选择体", "标题选择体", UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, init_proc_solid, NULL, &iSelResp, &iCountTemp, &pTagObjs)); if (iSelResp == UF_UI_CANCEL) return 1; } return iReturn; }
9.点构造器
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char sCA[] = "点构造器"; UF_UI_POINT_base_method_t base_method = UF_UI_POINT_INFERRED; tag_t tagPoint = NULL_TAG; double douBasePoint[] = {0.0, 0.0, 0.0}; int iRes; UF_UI_point_construct(sCA, &base_method, &tagPoint, douBasePoint, &iRes); UF_terminate(); }
10.拾取向量对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); double douVec[3], pnt[3]; int iMode = UF_UI_INFERRED; int iDispFlag = UF_UI_DISP_TEMP_VECTOR; int iRes = 0; UF_UI_specify_vector("选择一个矢量", &iMode, iDispFlag, douVec, pnt, &iRes); UF_terminate(); }
11.点收集器
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char cMessage[] = "点收集器"; bool boolCoincidentPoints = true; UF_UI_chained_points_p_t chainedPoints; int iCount; int iRes; UF_UI_select_point_collection(cMessage, boolCoincidentPoints, &chainedPoints, &iCount, &iRes); UF_terminate(); }
12.拾取屏幕位置
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char cMessage[] = "拾取屏幕位置"; double dOrigin[] = { 0.0, 0.0, 0.0 }; tag_t tagView; int iRes; UF_UI_specify_screen_position(cMessage, NULL, NULL, dOrigin, &tagView, &iRes); //dOrigin为选择的屏幕位置 UF_terminate(); }
13.特征选择对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char cMessage[] = "提示:特征选择对话框"; int iCount; tag_t* tagFeature; int iRes; UF_UI_select_feature(cMessage, NULL, &iCount, &tagFeature, &iRes); UF_terminate(); }
14.参数选择对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); UF_FEATURE_SIGN sign = UF_NULLSIGN; double douBlockOrig[3] = { 0.0, 0.0, 0.0 }; char* cBlockLengh[3] = { "6", "66", "666" }; tag_t tagBlockObj; char cMessage[] = "提示:参数选择对话框"; int iCount; tag_t* tagExp; int iRes; UF_MODL_create_block1(sign, douBlockOrig, cBlockLengh, &tagBlockObj); UF_UI_select_parameters(cMessage, tagBlockObj, &iCount, &tagExp, &iRes); UF_free(tagExp); UF_terminate(); }
15.拾取平面对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); double douOrientation[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; double douOrigin[3] = { 0, 0, 0 }; double douPts[6] = { 0, 0, 0, 0, 0, 0 }; int iMode = 1, display = 0, response; tag_t tagPlaneEid = NULL_TAG; UF_UI_specify_plane("指定平面", &iMode, display, &response, douOrientation, douOrigin, &tagPlaneEid); UF_terminate(); }
16.选择草图对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char cMessage[] = "提示:选择草图对话框"; tag_t tagSketch; int iRe; UF_UI_select_sketch(cMessage, NULL, &tagSketch, &iRe); UF_terminate(); }
17.拾取草图尺寸对话框
//来自“王牌飞行员_里海”的测试源码(qq群753801561) extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); char cMessage[] = "提示:拾取草图尺寸对话框"; tag_t tagSketch; int iCount; tag_t* tagExps = NULL; int iRes; UF_SKET_ask_active_sketch(&tagSketch); UF_UI_select_sketch_dimensions(cMessage, tagSketch, &iCount, &tagExps, &iRes); UF_free(tagExps); UF_terminate(); }