Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Bring Window To Top means bring the window to the top, right?
  
User name:
Password:
Reply:
 

UserPost
sloat
Posts: 25/85
Whoops...sorry. I can't read apparently.

Ok, there seems to be a quirk with BringWindowToTop. It doesn't seem to work if the calling window isn't active. The same with any of the other functions it seems. The only way I was sort of able to get it working was using SetWindowPos with HWND_TOPMOST. But then it would show up inactive. BringWindowToTop almost seems like a useless function, but I know you can use it to bring other windows to the top and to deactivate your window. It's probably a remnant from Windows 3.1, and back then it probably worked the way you want it to.

The alternative to SetWindowPos is to hide and show the window with either the form's methods, or the ShowWindow function. You will have to set your timer interval much higher though. 100ms worked fine for me, but I was using asm, so you might want to test for yourself.
HyperLamer
Posts: 2580/8210
It's always worked fine before. Plus,
Originally posted by HyperHacker
I've checked that the code does actually run
sloat
Posts: 24/85
The problem could be with GetAsyncKeyState.

From MSDN:

Windows NT/2000/XP: The return value is zero for the following cases:

The current desktop is not the active desktop.

The foreground thread belongs to another process and the desktop does not allow the hook or the journal record.


To test it, use a MessageBox just to see if the code is getting executed. The code should only work if the window already has the focus.

The only reliable ways to check for keystrokes cross-process are to either use a keyboard hook (you will need a third party control if you're using vb), or use direct input. i have no experience with direct input in vb, so i'm not sure if it's even feasible. either of those would be better than using a timer however.
HyperLamer
Posts: 2569/8210
I'll paste the relevant parts:


'In a Timer event, interval 5
If GetAsyncKeyState(vbKeyF12) Then 'Check for F12 key
'SetForegroundWindow Me.hwnd
'SetActiveWindow Me.hwnd
'SetFocusWindow Me.hwnd
BringWindowToTop Me.hwnd
'SetWindowPos Me.hwnd, HWND_TOP, 0, 0, 5, 5, SWP_NOSIZE Or SWP_NOMOVE 'Or SWP_SHOWWINDOW
End If

'-------------------------

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
HighlightedOption = (y - 60) \ 48
DrawMenu
End Sub

Private Sub Form_Paint()
DrawMenu
End Sub

Private Sub Form_Resize()
lblTitle.Width = Me.ScaleWidth
End Sub

Private Sub Form_Click()
If HighlightedOption < NumOptions And HighlightedOption >= 0 Then
CurrentOption = HighlightedOption
Form_KeyDown vbKeySpace, 0
End If
End Sub


I use GetAsyncKeyState() because it needs to catch keypresses when not in focus. The form starts maximized, with scale mode set to Pixel, ShowInTaskbar = True, BorderStyle = 2. I've checked that the code does actually run, and the form is enabled.
Gavin
Posts: 357/799
Originally posted by HyperHacker
SetForegroundWindow Me.hwnd
SetActiveWindow Me.hwnd
SetFocusWindow Me.hwnd
BringWindowToTop Me.hwnd

I've tried all of these functions (in fact, all of them at once), and while they flash the titlebar very nicely, they do not bring the window to the top! What's the big secret here?


you're doing something wrong then. BringWindowToTop works perfectly fine for me. What exactly does your code look like?
HyperLamer
Posts: 2557/8210
*sigh* Any other ideas? The best I managed to do with that was minimize it.
sloat
Posts: 23/85
SetWindowPos with HWND_TOPMOST for the 'hWndInsertAfter' parameter. Or if you don't want to keep it on top when the windows isn't active, try HWND_TOP.
HyperLamer
Posts: 2543/8210
I wouldn't normally do it, but in this case it's necessary. I'm making a simple file browser that can be used from far away, specially designed for movies (in essence, using the computer as a big VCR). Rather than require users to haul the keyboard around or build some kinda infrared/TV remote contraption, I figured I'd use the joystick as the controls. This means I need a way to bring the menu back up when a certain button is pressed.

As for that code, all it appears to do is maximize the window and use BringWindowToTop(), except that it's designed to search for windows. I'm doing it to my own window so I don't need to find it, and it's already maximized.
dan
Posts: 289/782
Doing that is evil. I personally hate applications that attempt to steal the focus, especially when I'm just in the middle of typing something.

Maybe, (and this is a long shot), but minimizing the application, then restoring it would bring it to the top. Maybe something like this?
HyperLamer
Posts: 2542/8210
SetForegroundWindow Me.hwnd
SetActiveWindow Me.hwnd
SetFocusWindow Me.hwnd
BringWindowToTop Me.hwnd

I've tried all of these functions (in fact, all of them at once), and while they flash the titlebar very nicely, they do not bring the window to the top! What's the big secret here?
Acmlm's Board - I2 Archive - Programming - Bring Window To Top means bring the window to the top, right?


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.012 seconds.