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? | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2542/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-20-04 09:24 AM Link | Quote
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?
dan

Snap Dragon
Level: 43

Posts: 289/782
EXP: 534516
For next: 30530

Since: 03-15-04

Since last post: 20 hours
Last activity: 14 hours
Posted on 12-20-04 01:02 PM Link | Quote
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
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2543/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-20-04 08:00 PM Link | Quote
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.
sloat

Level: 16

Posts: 23/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 12-20-04 11:25 PM Link | Quote
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
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2557/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-21-04 01:31 AM Link | Quote
*sigh* Any other ideas? The best I managed to do with that was minimize it.
Gavin

Fuzzy
Rhinoceruses don't play games. They fucking charge your ass.
Level: 43

Posts: 357/799
EXP: 551711
For next: 13335

Since: 03-15-04
From: IL, USA

Since last post: 13 hours
Last activity: 13 hours
Posted on 12-21-04 05:26 AM Link | Quote
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
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2569/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-21-04 09:49 PM Link | Quote
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.
sloat

Level: 16

Posts: 24/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 12-21-04 11:57 PM Link | Quote
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
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2580/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-22-04 06:46 AM Link | Quote
It's always worked fine before. Plus,
Originally posted by HyperHacker
I've checked that the code does actually run
sloat

Level: 16

Posts: 25/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 12-22-04 09:03 AM Link | Quote
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.
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
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.008 seconds.