简体   繁体   English

从命令行参数制作窗口

[英]Making a window from a command line argument

I've been making a screensaver in Java, and am now working on command line argument support. 我一直在用Java制作屏幕保护程序,现在正在研究命令行参数支持。 To that end, one of the potential arguments listed here is for putting the screensaver as a child of the specified window. 为此, 此处列出的潜在参数之一是将屏幕保护程序作为指定窗口的子级。 How can I take that argument and get the necessary window to put the screensaver into? 如何接受该参数并获取必要的窗口以将屏幕保护程序放入其中?

Also, what does it mean by 'modal to a window'? 另外,“模态窗口”是什么意思?

In Windows you set the screen saver from somewhere in the control panels . 在Windows中,您可以从控制面板中的某个位置设置屏幕保护程序。 In order for the control panel to interface with third-party screen savers, it is designed to run them with particular command line arguments. 为了使控制面板与第三方屏幕保护程序交互,它设计为使用特定的命令行参数运行它们。

So, when you select a screen saver from the list and hit the "Preview" button, the control panel executes this command: 因此,当您从列表中选择一个屏幕保护程序并单击“预览”按钮时,控制面板将执行以下命令:

ScreenSaver /p 1234

Here "ScreenSaver" woudl eb the path to your program, and 1234 would be an pointer value giving the HWND reference for the control panel window. 在这里,“ ScreenSaver”将为您的程序提供路径,而1234将是一个指针值,为控制面板窗口提供HWND参考。 The screen saver needs to then add itself as a child of that window to give a preview. 然后,屏幕保护程序需要将自身添加为该窗口的子级以进行预览。

Likewise, when you hit the "Settings" button, the control panel executes this command: 同样,当您单击“设置”按钮时,控制面板将执行以下命令:

ScreenSaver /c

The screen saver program needs to know that when it gets that command line argument, it should query the system for which window is in the foreground, and pop up a dialog in that window ("modal" means that it blocks access to that window until the dialog is closed). 屏幕保护程序需要知道,当它获取该命令行参数时,应查询系统哪个窗口位于前台,并在该窗口中弹出一个对话框(“模式”表示它将阻止对该窗口的访问,直到对话框关闭)。

Finally, when the control panel determines that it is actually time to run the screen saver, it executes this command: 最后,当控制面板确定是实际运行屏幕保护程序的时候,它将执行以下命令:

ScreenSaver /s

This is when your program should go fullscreen. 这是您的程序应全屏显示的时间。

Now, what does this mean to you as a Java developer? 现在,这对您作为Java开发人员意味着什么?

First of all, inserting a Java component into a system window would involve some complicated JNI work. 首先,将Java组件插入系统窗口将涉及一些复杂的JNI工作。 For the preview, the best you could do is the have your Java code render to an image that then gets drawn into an ordinary Windows component through JNI. 对于预览,最好的办法是将Java代码渲染为图像,然后通过JNI将其绘制到普通Windows组件中。 Launching a Java dialog within a system window is probably flat-out impossible. 在系统窗口中启动Java对话框可能完全不可能。

However, if you don't mind slight inconsistencies between your screensaver and native ones, you can probably get away without doing that. 但是,如果您不介意屏幕保护程序和本机屏幕保护程序之间存在细微的不一致,则可以不这样做而逃脱。 You could just have the Preview mode pop up a new window with the preview, and have the Settings mode likewise pop up its dialog in a new window. 您可以使“预览”模式与预览一起弹出一个新窗口,并让“设置”模式同样在新窗口中弹出其对话框。 And the fullscreen mode should work just fine without adjustment. 全屏模式无需调整即可正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM