在Java中修改运行时的内联常量(Modifying an inlined constant at runtime in Java)
我试图让SWT的DirectoryDialog打开,而不在Windows上显示“Make new folder”按钮。 Windows的API支持这一点,但不幸的是SWT没有。
你可以在这里看到SWT的Windows实现: http : //kickjava.com/src/org/eclipse/swt/widgets/DirectoryDialog.java.htm
第193行是神奇发生的地方。
lpbi.ulFlags = OS.BIF_NEWDIALOGSTYLE | OS.BIF_RETURNONLYFSDIRS | OS.BIF_EDITBOX | OS.BIF_VALIDATE;
我想将BIF_NONEWFOLDERBUTTON添加到标志中(请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/bb773205(v=vs.85).aspx )。
我试过通过一个丑陋的反射黑客实现这一点,我通过对静态字段执行按位OR将BIF_NONEWFOLDERBUTTON添加到OS.BIF_NEWDIALOGSTYLE。
不幸的是没有效果。 我假设它是因为Java内联它(因为它是编译时间常量)。
因此我的问题是:如何在运行时修改第193行以使其包含此常量?
I'm trying to get SWT's DirectoryDialog to open without the "Make new folder" button showing on Windows. Windows' API supports this but unfortunately SWT doesn't.
You can see SWT's Windows implementation here: http://kickjava.com/src/org/eclipse/swt/widgets/DirectoryDialog.java.htm
Line 193 is where the magic happens.
lpbi.ulFlags = OS.BIF_NEWDIALOGSTYLE | OS.BIF_RETURNONLYFSDIRS | OS.BIF_EDITBOX | OS.BIF_VALIDATE;
I would like to add BIF_NONEWFOLDERBUTTON to the flags (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb773205(v=vs.85).aspx).
I've tried achieving this through an ugly reflection hack where I added BIF_NONEWFOLDERBUTTON to OS.BIF_NEWDIALOGSTYLE by doing a bitwise OR to the static field.
Unfortunately that had no effect. I'm assuming it's because Java inlines it (since it's compile time constant).
My question is therefore: how do I modify line 193 at runtime so that it includes this constant?
原文:https://stackoverflow.com/questions/23239521