(关乎饭碗100分)java中的窗体能不能一开起之后让其他任何程序的窗体都失去焦点,只等关闭此窗体后其他的窗体才能得到焦点

jsp_servlet_javabean 2004-09-03 11:53:28
如题
是不是一定要调用windows dll 才能实现
如是,如何实现
救命大虾?!
...全文
359 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
registered 2004-09-05
  • 打赏
  • 举报
回复
我上面的回复连接里面有 Always On Top 的解决方法
http://forum.java.sun.com/thread.jsp?forum=57&thread=121761&message=319301
其他情况就得另待高人了...
  • 打赏
  • 举报
回复
各位兄弟们,千万别让我的帖子沉下去,谢谢了
xyjack 2004-09-05
  • 打赏
  • 举报
回复
能不能在主程序中设置一BOOLEAN变量,控制焦点FOCUS的转移……
  • 打赏
  • 举报
回复
可能我的意思有点没表达正确
是这样的
主程序是vb写的,它呼叫一个java的frame
然后就是需要java的frame总是在顶层

c函数我已经找到了,它是接收一个窗口句柄CWnd ,它能将窗口置顶,就是不知道怎么用
是否要将java的frame对象传入c函数,但是java的frame对象怎么样转化成c函数需要的CWnd 类型
或者是根本不用转化

函数是我到vc那去问来的:

如何使窗口始终在最前方?
两种途径.
BringWindowToTop(Handle);
SetWindowPos函数,指定窗口的 最顶风格,用WS_EX_TOPMOST扩展窗口的 风格
Example:
void ToggleTopMost( CWnd *pWnd)
{
ASSERT_VALID(pWnd);
pWnd ->SetWindowPos(pWnd-> GetStyle( ) &WS_EX_TOPMOST)?
&wndNoTopMOST: &wndTopMost,0,0,0,0,SSP_NOSIZE|WSP_NOMOVE);
}



靠各位了
pigrain 2004-09-04
  • 打赏
  • 举报
回复
这么霸道在windows界面下的确没有见过
delphi2java 2004-09-04
  • 打赏
  • 举报
回复
没试过..
registered 2004-09-04
  • 打赏
  • 举报
回复
这里有一个权宜之计

final JFrame frame = new JFrame("Frame");
frame.addWindowListener(new WindowAdapter(){
public void windowDeactivated(WindowEvent e) {
frame.setState(JFrame.ICONIFIED);
frame.toFront();
frame.setState(JFrame.NORMAL);
}
}

引自:
http://forum.java.sun.com/thread.jsp?forum=57&thread=121761&message=319301
registered 2004-09-04
  • 打赏
  • 举报
回复
大兄弟, 我用了这么长时间电脑还没见过这样的程序...
Always On Top 也只是显示在最前方
全屏模式也能用 Alt + Esc 切换出来
从来没见过有程序能霸占着整个操作系统不让往别的程序切换的例子
也许是我孤陋寡闻, 个人感觉没法实现

不过你可以用GUI全屏模式试试看, 但是这样只能达到部分效果
tangbow 2004-09-03
  • 打赏
  • 举报
回复
up
射天狼 2004-09-03
  • 打赏
  • 举报
回复
你说的这是进程之间同步执行的问题,代码如下:(VB)

Option Explicit

Const INFINITE As Long = -1&
Const STATUS_WAIT_0 As Long = &H0
Const WAIT_OBJECT_0 As Long = STATUS_WAIT_0
Const NORMAL_PRIORITY_CLASS As Long = &H20&

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function InputIdle Lib "user32" Alias "WaitForInputIdle" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "Kernel32" (ByVal hObject As Long) As Long
Private Declare Function CreateProcessA Lib "Kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

Private Sub Command1_Click()
SyncShell "D:\ProgramsExample\DelphiExample\stk\Stk.exe"
End Sub

Public Function StartProcess(CommandLine As String, Optional Hide As Boolean = False) As Long
Const STARTF_USESHOWWINDOW As Long = &H1
Const SW_HIDE As Long = 0

Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO

'Initialize the STARTUPINFO structure:
Start.cb = Len(Start)
If Hide Then
Start.dwFlags = STARTF_USESHOWWINDOW
Start.wShowWindow = SW_HIDE
End If
'Start the shelled application:
CreateProcessA 0&, CommandLine, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc

StartProcess = proc.hProcess
End Function

Public Function SyncShell(CommandLine As String, Optional Timeout As Long, _
Optional WaitForInputIdle As Boolean, Optional Hide As Boolean = False) As Boolean

Dim hProcess As Long

Const STARTF_USESHOWWINDOW As Long = &H1
Const SW_HIDE As Long = 0

Dim ret As Long
Dim nMilliseconds As Long

If Timeout > 0 Then
nMilliseconds = Timeout
Else
nMilliseconds = INFINITE
End If

hProcess = StartProcess(CommandLine, Hide)

If WaitForInputIdle Then
'Wait for the shelled application to finish setting up its UI:
ret = InputIdle(hProcess, nMilliseconds)
Else
'Wait for the shelled application to terminate:
ret = WaitForSingleObject(hProcess, nMilliseconds)
End If

CloseHandle hProcess

'Return True if the application finished. Otherwise it timed out or erred.
SyncShell = (ret = WAIT_OBJECT_0)
End Function
  • 打赏
  • 举报
回复
兄弟
我的问题是主程序是vb做的,它bat文件叫起一个java做的frame,现在需要让vb的窗体失去焦点
也就是其他任何应用都得不到焦点,应该肯定要调用windows dll
怎么解决
救命啊
flyxxxxx 2004-09-03
  • 打赏
  • 举报
回复
JFrame parent;//这是主窗口
JDialog dialog=new JDialog(parent,true);这样就可以满足你的要求.
mq612 2004-09-03
  • 打赏
  • 举报
回复
用纯Java不能实现,Java的模态窗体只能对自己本身的母窗体有效,如果运行了很多别的程序,Java自己是没有办法总是排在最前列。
fmzbj 2004-09-03
  • 打赏
  • 举报
回复
可以的,我以前还做过,记不太清了,你查查Swing方面的API,好像很简单!
hpy121 2004-09-03
  • 打赏
  • 举报
回复
把你要打开的窗口设为模态就可以!
(JFrame) abc.setModal(true);
jerrysoft 2004-09-03
  • 打赏
  • 举报
回复
兄弟也是苦命人,哥们虽然帮不上忙,还能顶一把:)
  • 打赏
  • 举报
回复
feng8208(人是铁饭是钢)
兄弟:
你要快啊
下个星期一之前,我们的项目要结了,不然我挂了。
我的email:haitangli@hotmail.com
在此先行谢过!
feng8208 2004-09-03
  • 打赏
  • 举报
回复
不就是窗体置前吗 我那有代码 哪天代过来
  • 打赏
  • 举报
回复
不行
我的要求其实就可以像QQ开启时输入密码的窗体一样
尽管其他窗口可以打开,但QQ窗体总是在最前面

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧