NX二次开发 内部UI调用(调用没有类名的内部UI)

建议结合作者第一篇博客观看,本片博客是对于第一篇博客第三种方法的补充。

以加工模块创建刀具窗口为例,打开uifw侦察,发现并没有类名

直接上代码:

在你需要调用UG对话框的地方加入以下代码,参数ugButtonName参考第一篇博客方法一,

bool callUGButton(string ugButtonName)
{
    int button_id = 0;
    HWND ugWndH = NULL;
    ugWndH = (HWND)UF_UI_get_default_parent();
    UF_CALL(UF_MB_ask_button_id(ugButtonName.data(), &button_id));

    if (button_id)
    {
        //BOOL result = SendMessage(ugWndH, WM_COMMAND, button_id, 0);
        BOOL result = PostMessage(ugWndH, WM_COMMAND, button_id, 0);

        return result;
    }
    else 
    {
        return false;
    }
}

注意使用PostMessage发送消息;

这时运行程序,会弹出对话框,但是程序无法识别对话框什么时候弹出,什么时候关闭;再添加代码:

添加定时器:

HWND ugWndH = NULL;
ugWndH = (HWND)UF_UI_get_default_parent();
SetTimer(ugWndH, 1, 200, TimerProc);

定时器回调函数:

HWND g_hCreateTool = NULL;
HWND g_hMillCutParam = NULL;
int g_nLastMillCount = 0;
int g_nIsSearchCreateTool = 0;
int g_nSearchCount = 0;
VOID CALLBACK TimerProc(HWND hWnd, UINT msg, UINT_PTR id, DWORD time)
{
    if (g_hCreateTool == NULL)
    {
        g_hCreateTool = FindWindowW(NULL, L"创建刀具");
        if (g_hCreateTool && g_nIsSearchCreateTool == 0)
            g_nIsSearchCreateTool = 1;
    }

    if (g_hCreateTool == NULL || g_nIsSearchCreateTool == 0)
        return;

    if (IsWindowVisible(g_hCreateTool))
        return;

    if (g_hMillCutParam == NULL)
    {
        g_nSearchCount++;
        g_hMillCutParam = SearchWindow("NX_SURFACE_WND_DIALOG", "铣刀-5 参数");
        //g_hMillCutParam = FindWindowW(L"NX_SURFACE_WND_DIALOG", L"铣刀-5 参数");

        if (g_hMillCutParam == NULL)
            return;

        if (!IsWindowVisible(g_hMillCutParam))
        {
            //对话框关闭,执行你想要的动作;
        }

        if (g_nSearchCount >= 5 && g_hMillCutParam == NULL)
            KillTimer(hWnd, 1);
    }
}

注:发现问题或者有其他方案,欢迎评论指正

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值