UG二次开发CreateDialog函数在UI.hxx文件和WinUser.h中的冲突

在UG二次开发中,若使用MFC库,一旦加上#include<Afx.h>头文件,下面这句话就报错

theDialog = GetPoints::theUI->CreateDialog(theDlxFileName);

解决CreateDialog函数在UI.hxx文件和WinUser.h中的冲突

在windows API中已经将CreateDialog定义为宏 CreateDialogW,如下图WinUser.h中

当编译到UI.hxx中时,CreateDialog函数背当作CreateDialogW函数,从而产生矛盾

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过继承JOptionPane类,重写createDialog()方法,在该方法添加自定义的小键盘组件,然后在调用JOptionPane.showInputDialog()时传入自定义的JOptionPane子类对象即可。 以下是一个简单的示例代码: ```java import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class CustomInputDialog extends JOptionPane { private JPanel keyboardPanel; private JTextField inputField; public CustomInputDialog(Component parentComponent, Object message, String title, int messageType) { super(message, messageType); this.inputField = new JTextField(); this.keyboardPanel = createKeyboardPanel(); setInputValue(inputField); setMessage(new Object[] {message, inputField}); JDialog dialog = createDialog(parentComponent, title); dialog.setContentPane(keyboardPanel); dialog.pack(); dialog.setVisible(true); } private JPanel createKeyboardPanel() { JPanel panel = new JPanel(new BorderLayout()); // 添加自定义的小键盘组件 KeyboardPanel keyboard = new KeyboardPanel(); keyboard.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { inputField.setText(inputField.getText() + e.getActionCommand()); } }); panel.add(keyboard, BorderLayout.CENTER); return panel; } public static String showCustomInputDialog(Component parentComponent, Object message, String title, int messageType) { CustomInputDialog pane = new CustomInputDialog(parentComponent, message, title, messageType); pane.setWantsInput(true); pane.selectInitialValue(); return (String) pane.getInputValue(); } public static void main(String[] args) { String input = showCustomInputDialog(null, "Please input something:", "Input", JOptionPane.PLAIN_MESSAGE); System.out.println("Input value: " + input); } } ``` 其,KeyboardPanel是一个自定义的小键盘面板,可以根据具体需求进行实现。在showCustomInputDialog()方法,创建自定义的CustomInputDialog对象,并将其作为参数传入到JOptionPane.showInputDialog()方法。最后,通过CustomInputDialog.getInputValue()方法获取用户输入的值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值