Поднять приложеление над другими

Программирование на Visual Basic, главный форум. Обсуждение тем программирования на VB 1—6.
Даже если вы плохо разбираетесь в VB и программировании вообще — тут вам помогут. В разумных пределах, конечно.
Правила форума
Темы, в которых будет сначала написано «что нужно сделать», а затем просьба «помогите», будут закрыты.
Читайте требования к создаваемым темам.
Cellard
Новичок
Новичок
 
Сообщения: 49
Зарегистрирован: 15.10.2002 (Вт) 22:10
Откуда: Russia

Поднять приложеление над другими

Сообщение Cellard » 30.01.2004 (Пт) 20:03

Собственно сабж. Как сделать приложение поверх других.
Cellard

hCORe
VB - Экстремал
VB - Экстремал
Аватара пользователя
 
Сообщения: 2332
Зарегистрирован: 22.02.2003 (Сб) 15:21
Откуда: parent directory

Topmost

Сообщение hCORe » 30.01.2004 (Пт) 21:58

В смысле приоритет процесса или положение окна :?: :?: :?:

Если окно, то:

Код: Выделить всё
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
Const conHwndTopmost = -1
Const conHwndNoTopmost = -2
Const conSwpNoActivate = &H10
Const conSwpShowWindow = &H40

Private Sub SetTopMost(frm as Form)
On Error Resume Next
    Call SetWindowPos(frm.hWnd, _
    conHwndTopmost, _
    frm.Left / Screen.TwipsPerPixelX, _
    frm.Top / Screen.TwipsPerPixelY, _
    frm.Width / Screen.TwipsPerPixelX, _
    frm.Height / Screen.TwipsPerPixelY, _
    conSwpNoActivate Or conSwpShowWindow) ' всегда наверху!
End Sub

Private Sub SetNormal(frm as Form)
On Error Resume Next
    Call SetWindowPos(frm.hWnd, _
    conHwndNoTopmost, _
    frm.Left / Screen.TwipsPerPixelX, _
    frm.Top / Screen.TwipsPerPixelY, _
    frm.Width / Screen.TwipsPerPixelX, _
    frm.Height / Screen.TwipsPerPixelY, _
    conSwpNoActivate Or conSwpShowWindow) ' обычное состояние!
End Sub


SetTopMost (имя формы) делает ее поверх всех, SetNormal (имя формы) - восстанавливает нормальное состояние

а про процессы - не помню :cry:
Моду создают модоки, а распространяют модозвоны.

Amed
Алфизик
Алфизик
 
Сообщения: 5346
Зарегистрирован: 09.03.2003 (Вс) 9:26

Сообщение Amed » 31.01.2004 (Сб) 9:33

Код: Выделить всё
Declare Function SetPriorityClass Lib "kernel32" Alias "SetPriorityClass" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long


· hProcess
Identifies the process.
Windows NT: The handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Objects.

· dwPriorityClass
Specifies the priority class for the process. Specify one of the following values:
HIGH_PRIORITY_CLASS
Specify this class for a process that performs time-critical tasks that must be executed immediately. The threads of the process preempt the threads of normal or idle priority class processes. An example is Windows Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class application can use nearly all available CPU time.
IDLE_PRIORITY_CLASS
Specify this class for a process whose threads run only when the system is idle. The threads of the process are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle-priority class is inherited by child processes.
NORMAL_PRIORITY_CLASS
Specify this class for a process with no special scheduling needs.
REALTIME_PRIORITY_CLASS
Specify this class for a process that has the highest possible priority. The threads of the process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.

Код: Выделить всё
Const THREAD_BASE_PRIORITY_IDLE = -15
Const THREAD_BASE_PRIORITY_LOWRT = 15
Const THREAD_BASE_PRIORITY_MIN = -2
Const THREAD_BASE_PRIORITY_MAX = 2
Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)
Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)
Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
Const THREAD_PRIORITY_NORMAL = 0
Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT
Const HIGH_PRIORITY_CLASS = &H80
Const IDLE_PRIORITY_CLASS = &H40
Const NORMAL_PRIORITY_CLASS = &H20
Const REALTIME_PRIORITY_CLASS = &H100
Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long
Private Declare Function GetCurrentThread Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim hThread As Long, hProcess As Long
    'retrieve the current thread and process
    hThread = GetCurrentThread
    hProcess = GetCurrentProcess
    'set the new thread priority to "lowest"
    SetThreadPriority hThread, THREAD_PRIORITY_LOWEST
    'set the new priority class to "idle"
    SetPriorityClass hProcess, IDLE_PRIORITY_CLASS
    'print some results
    Me.AutoRedraw = True
    Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread))
    Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess))
End Sub

Cellard
Новичок
Новичок
 
Сообщения: 49
Зарегистрирован: 15.10.2002 (Вт) 22:10
Откуда: Russia

Сообщение Cellard » 31.01.2004 (Сб) 13:11

В смысле, сделать окно приложения поверх всех...

Спасибо за код.
Cellard

X-BOND
Реалист
Реалист
 
Сообщения: 944
Зарегистрирован: 19.08.2002 (Пн) 11:44
Откуда: Ukraine

Re: Topmost

Сообщение X-BOND » 02.02.2004 (Пн) 15:00

hCORe писал(а):В смысле приоритет процесса или положение окна :?: :?: :?:

Если окно, то:

Код: Выделить всё
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
Const conHwndTopmost = -1
Const conHwndNoTopmost = -2
Const conSwpNoActivate = &H10
Const conSwpShowWindow = &H40

Private Sub SetTopMost(frm as Form)
On Error Resume Next
    Call SetWindowPos(frm.hWnd, _
    conHwndTopmost, _
    frm.Left / Screen.TwipsPerPixelX, _
    frm.Top / Screen.TwipsPerPixelY, _
    frm.Width / Screen.TwipsPerPixelX, _
    frm.Height / Screen.TwipsPerPixelY, _
    conSwpNoActivate Or conSwpShowWindow) ' всегда наверху!
End Sub

Private Sub SetNormal(frm as Form)
On Error Resume Next
    Call SetWindowPos(frm.hWnd, _
    conHwndNoTopmost, _
    frm.Left / Screen.TwipsPerPixelX, _
    frm.Top / Screen.TwipsPerPixelY, _
    frm.Width / Screen.TwipsPerPixelX, _
    frm.Height / Screen.TwipsPerPixelY, _
    conSwpNoActivate Or conSwpShowWindow) ' обычное состояние!
End Sub


SetTopMost (имя формы) делает ее поверх всех, SetNormal (имя формы) - восстанавливает нормальное состояние

а про процессы - не помню :cry:

Ну зачем так сложно
SetWindowPos hwnd, -1, 0, 0, 0, 0, 3
Это вроде тоже нормально работает.

Kostyan
Постоялец
Постоялец
 
Сообщения: 439
Зарегистрирован: 20.09.2002 (Пт) 4:14
Откуда: Россия, Уссурийск

Сообщение Kostyan » 02.02.2004 (Пн) 16:29

Единственная проблема в том, что если объявляется другое приложение, считающее что именно его окно должно быть сверху, то винда делает верхним то, что было запущено позже. Так что SetWindowPos hwnd, -1, 0, 0, 0, 0, 3 нужно поставить в таймере, например раз в секунду.
Нет ничего невозможного для человека с интеллектом.

Cellard
Новичок
Новичок
 
Сообщения: 49
Зарегистрирован: 15.10.2002 (Вт) 22:10
Откуда: Russia

Сообщение Cellard » 03.02.2004 (Вт) 16:10

А мне и не требуется поставить окно ВСЕГДА наверх. Мне надо именно однократно. Так что - спасибо, то что надо.
Cellard


Вернуться в Visual Basic 1–6

Кто сейчас на конференции

Сейчас этот форум просматривают: AhrefsBot и гости: 20

    TopList