java最小化,在Java编程中,肿么将程序最小化到托盘中

在模块中写上

------------------------------

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

'---------- dwMessage可以是以下NIM_ADD、NIM_DELETE、NIM_MODIFY 标识符之一----------

Private Const NIM_ADD = &H0 '在任务栏中增加一个图标

Private Const NIM_DELETE = &H2 '删除任务栏中的一个图标

Private Const NIM_MODIFY = &H1 '修改任务栏中个图标信息

Private Const NIF_MESSAGE = &H1 'NOTIFYICONDATA结构中uFlags的控制信息

Private Const NIF_ICON = &H2

Private Const NIF_TIP = &H4

Private Const WM_MOUSEMOVE = &H200 '当鼠标指针移至图标上

Private Const WM_LBUTTONUP = &H202

Private Const WM_RBUTTONUP = &H205

Private Type NOTIFYICONDATA

cbSize As Long '该数据结构的大小

hwnd As Long '处理任务栏中图标的窗口句柄

uID As Long '定义的任务栏中图标的标识

uFlags As Long '任务栏图标功能控制,可以是以下值的组合(一般全包括)

'NIF_MESSAGE 表示发送控制消息;

'NIF_ICON表示显示控制栏中的图标;

'NIF_TIP表示任务栏中的图标有动态提示。

uCallbackMessage As Long '任务栏图标通过它与用户程序交换消息,处理该消息的窗口由hWnd决定

hIcon As Long '任务栏中的图标的控制句柄

szTip As String * 64 '图标的提示信息

End Type

Dim t As NOTIFYICONDATA '---------以上是在系统托盘显示图标的代码

Dim sHour, sMinute '自动关机的时间小时和分钟

'---------以下是不显示标题栏等的代码

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _

(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _

(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Const GWL_STYLE = (-16)

Private Const WS_CAPTION = &HC00000 ' WS_BORDER 或 WS_DLGFRAME

Private Const WS_MAXIMIZEBOX = &H10000

Private Const WS_MINIMIZEBOX = &H20000

Private Const WS_SYSMENU = &H80000

Private Declare Function SetWindowPos Lib "user32" _

(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _

ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Enum ESetWindowPosStyles

SWP_SHOWWINDOW = &H40

SWP_HIDEWINDOW = &H80

SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE

SWP_NOACTIVATE = &H10

SWP_NOCOPYBITS = &H100

SWP_NOMOVE = &H2

SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering

SWP_NOREDRAW = &H8

SWP_NOREPOSITION = SWP_NOOWNERZORDER

SWP_NOSIZE = &H1

SWP_NOZORDER = &H4

SWP_DRAWFRAME = SWP_FRAMECHANGED

HWND_NOTOPMOST = -2

End Enum

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Private Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Private Function ShowTitleBar(ByVal bState As Boolean)

Dim lStyle As Long

Dim tR As RECT

' 获取窗口的位置:

GetWindowRect Me.hwnd, tR

' 调整标题栏是否可见:

lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)

If (bState) Then

Me.Caption = Me.Tag

If Me.ControlBox Then

lStyle = lStyle Or WS_SYSMENU

End If

If Me.MaxButton Then

lStyle = lStyle Or WS_MAXIMIZEBOX

End If

If Me.MinButton Then

lStyle = lStyle Or WS_MINIMIZEBOX

End If

If Me.Caption <> "" Then

lStyle = lStyle Or WS_CAPTION

End If

Else

Me.Tag = Me.Caption

Me.Caption = ""

lStyle = lStyle And Not WS_SYSMENU

lStyle = lStyle And Not WS_MAXIMIZEBOX

lStyle = lStyle And Not WS_MINIMIZEBOX

lStyle = lStyle And Not WS_CAPTION

End If

SetWindowLong Me.hwnd, GWL_STYLE, lStyle

' 重新设定窗口:

SetWindowPos Me.hwnd, 0, tR.Left, tR.Top, tR.Right - tR.Left, tR.Bottom - tR.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED

Me.Refresh

' 你可能需要在Form_Resize中加一点代码,因为客户区的大小已经改变:

'Form_Resize

End Function '----------------以上是不显示标题栏工具栏等代码

Sub TaskSet(s As Integer)

Dim sTmp

t.cbSize = Len(t)

t.hwnd = Me.hwnd

t.uID = 0

t.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP

t.uCallbackMessage = WM_MOUSEMOVE

t.hIcon = Me.Icon.Handle

sTmp = "标 题"

t.szTip = sTmp

Select Case s

Case 1

Shell_NotifyIcon NIM_ADD, t

Case 2

Shell_NotifyIcon NIM_DELETE, t

End Select

End Sub

-------------------------------------------------------

在load中写上

ShowTitleBar False '让窗口标题消失

TaskSet 1 '不显示界面,在系统托盘显示

App.TaskVisible = False

me.icon是右下角图标

取消

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值