Home > Archive > Visual Basic > May 2004 > SetWindowPos Problems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SetWindowPos Problems
|
|
| John Bennett 2004-05-27, 4:31 pm |
| I am using SetWindowPos to keep a password prompt form always on top while it is visible. The prompt is always visible but is not always the active window. What I want is that when this prompt form is visible all the keyboard input should go to that for
m's text boxes. But sometimes while my form is on top the title bar is grayed and a lower form from other applications received the keyboard input, Is there a way to remedy this?
| |
|
| Hi John!
From what i've understood you should not need the SetWindowsPos() function
at all. Just show your Form modally. It will prevent other windows in your
process from getting focus while the modally form is shown.
'***
Call Form1.Show(vbModal)
'***
--
Best Regards
Yanick Lefebvre
"John Bennett" <anonymous@discussions.microsoft.com> a écrit dans le message
de news:C82436F2-100F-4A30-9761-68406BA502AC@microsoft.com...
> I am using SetWindowPos to keep a password prompt form always on top while
it is visible. The prompt is always visible but is not always the active
window. What I want is that when this prompt form is visible all the
keyboard input should go to that form's text boxes. But sometimes while my
form is on top the title bar is grayed and a lower form from other
applications received the keyboard input, Is there a way to remedy this?
| |
| John Bennett 2004-05-27, 8:30 pm |
| The problem is not withing my application. It is other windows that are starting that were being brought to the foreground. The SetWindowPos has kept my form on top but sometimes it is not the current active window. So if the user is not looking and be
gin entering the password it is actually going to another window.
| |
| Bob O`Bob 2004-05-27, 10:30 pm |
| =?Utf-8?B?Sm9obiBCZW5uZXR0?= <anonymous@discussions.microsoft.com> wrote:
>
> The problem is not withing my application.
looks like it's about time
for another rousing chorus of
"that's what they all say!"
| |
| John Bennett 2004-05-27, 11:30 pm |
| I am always grateful for helpful suggestions so want to extend my thanks to Bob...
But let me correct my earlier statements.
It is not accurate to state that the problem is not within my application. Obviously I do not have something right.
But what is happening is that I Show my vbModal form and it is the only visible form that is part of my application. But keyboard input is going to other application forms. So the issue I am trying to resolve is how to direct keyboard input to my vbMo
dal form while it is visible.
| |
| Bob O`Bob 2004-05-28, 12:30 am |
| =?Utf-8?B?Sm9obiBCZW5uZXR0?= wrote:
>
> I am always grateful for helpful suggestions so want to extend my thanks to Bob...
>
> But let me correct my earlier statements.
>
> It is not accurate to state that the problem is not within my application. Obviously I do not have something right.
>
> But what is happening is that I Show my vbModal form and it is the only visible form that is part of my application. But keyboard input is going to other application forms. So the issue I am trying to resolve is how to direct keyboard input to my vb
Modal form while it is visible.
I believe the buzzwords you probably want to google for are "system modal" - something
that VB can not do natively, but you can establish with an API call or two.
I haven't done it myself in ages, but I have seen some demo code which claims that
this is the call you need:
Declare Function SetSysModalWindow Lib "User" (ByVal hWnd As Integer) As Integer
Note that you pass it the HWnd of the form, and I *think* it returns
the HWnd of whatever had been system modal before, i.e.- usually nothing.
Don't know if that's the right track, but it's more you can look at, anyway.
Bob
| |
| J French 2004-05-28, 2:30 am |
| On Thu, 27 May 2004 20:20:47 -0700, Bob O`Bob
<filterbob@yahoogroups.com> wrote:
>=?Utf-8?B?Sm9obiBCZW5uZXR0?= wrote:
bModal form while it is visible.[color=darkred]
>
>
>I believe the buzzwords you probably want to google for are "system modal" - something
>that VB can not do natively, but you can establish with an API call or two.
>
>I haven't done it myself in ages, but I have seen some demo code which claims that
>this is the call you need:
>
>Declare Function SetSysModalWindow Lib "User" (ByVal hWnd As Integer) As Integer
>
>Note that you pass it the HWnd of the form, and I *think* it returns
>the HWnd of whatever had been system modal before, i.e.- usually nothing.
>
>Don't know if that's the right track, but it's more you can look at, anyway.
From the Win32 Programmer's Reference Help File
<quote>
The SetSysModalWindow function is obsolete. This function is provided
only for compatibility with 16-bit versions of Windows. The new input
model does not allow for System Modal windows.
</quote>
This is due to Windows 'locking down' Apps controlling the screen
However, in the past few days there have been some interesting posts
describing how to fool Windows
- perhaps AttachThreadInput is the way to go
| |
| Zoury 2004-05-28, 11:30 am |
| here's something quite simple.. starts a new app with a form and a module in
it and try this code..
'***
' Form1
Option Explicit
Private Sub Form_Load()
Call SetModal(Me.hwnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnSetModal(Me.hwnd)
End Sub
'***
'***
' Module1
Option Explicit
Private Declare Function CallWindowProc _
Lib "user32" _
Alias "CallWindowProcA" _
( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long _
) As Long
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 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 Declare Function SetFocus _
Lib "user32" _
( _
ByVal hwnd As Long _
) As Long
Private Const WM_KILLFOCUS As Long = &H8
Private Const SWP_NOMOVE As Long = 2
Private Const SWP_NOSIZE As Long = 1
Private Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST As Long = -1
Private Const HWND_NOTOPMOST As Long = -2
Private Const GWL_WNDPROC As Long = -4
Private m_lOldProc As Long
Public Sub SetModal(ByRef hwnd As Long)
Debug.Print SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
m_lOldProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnSetModal(ByRef hwnd As Long)
Call SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
Call SetWindowLong(hwnd, GWL_WNDPROC, m_lOldProc)
End Sub
Public Function WindowProc _
( _
ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long _
) As Long
Select Case uMsg
Case WM_KILLFOCUS
Call SetFocus(hwnd)
End Select
WindowProc = CallWindowProc(m_lOldProc, hwnd, uMsg, wParam, lParam)
End Function
'***
if sets the form topmost and prevents it to loose the focus. The only
problem I could see if it's your app hangs while the form is shown.. you
might not be able to do much if it happens.... :O)
--
Best Regards
Yanick Lefebvre
| |
| John Bennett 2004-05-29, 9:30 am |
| Thanks, I will give this a try.
|
|
|
|
|