15-08-20, 09:11 PM
معليش اخوي عبد العزيز انا نسخت الكود من موقع codeproject وعلى طول حطيته في ردي
لكن الان عدلت الكود وياليت تحذف الكود السابق اللي اعطيتك اياه وتستخدم التالي
مع ملاحظة استيراد فضاء الاسماء
لكن الان عدلت الكود وياليت تحذف الكود السابق اللي اعطيتك اياه وتستخدم التالي
مع ملاحظة استيراد فضاء الاسماء
كود :
Imports System.Runtime.InteropServicesكود :
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As SetWindowPosFlags) As Boolean
End Function
Private ReadOnly HWND_BOTTOM As New IntPtr(1)
Private ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
Private ReadOnly HWND_TOP As New IntPtr(0)
Private ReadOnly HWND_TOPMOST As New IntPtr(-1)
<Flags()> _
Private Enum SetWindowPosFlags As UInteger
SynchronousWindowPosition = &H4000
DeferErase = &H2000
DrawFrame = &H20
FrameChanged = &H20
HideWindow = &H80
DoNotActivate = &H10
DoNotCopyBits = &H100
IgnoreMove = &H2
DoNotChangeOwnerZOrder = &H200
DoNotRedraw = &H8
DoNotReposition = &H200
DoNotSendChangingEvent = &H400
IgnoreResize = &H1
IgnoreZOrder = &H4
ShowWindow = &H40
End Enum
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
setWindowOnTop(True)
End Sub
Private process As Process
Sub setWindowOnTop(Optional bool As Boolean = True)
process = process.GetProcessesByName("calc").FirstOrDefault()
If process Is Nothing Then Return
Dim hwnd As IntPtr = process.MainWindowHandle
Dim theFlags As String = SetWindowPosFlags.IgnoreMove Or SetWindowPosFlags.IgnoreResize Or SetWindowPosFlags.ShowWindow
If Not hwnd = IntPtr.Zero Then
If bool Then
'وضع الحاسبة في اعلى الشاشة
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, theFlags)
Else
'اعادة الحاسبة الى الوضع العادي
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, theFlags)
End If
End If
End Sub


