Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 23rd, 2005, 2:11 PM   #1
drumltd
Newbie
 
Join Date: Aug 2005
Posts: 19
Rep Power: 0 drumltd is on a distinguished road
Get Focus from a Console App?

Anybody know how I can get the focus from a console application?

I've tried geting the HWND and using SetFocus but that appears not to work.
drumltd is offline   Reply With Quote
Old Aug 23rd, 2005, 2:45 PM   #2
Scorpions4ever
Programmer
 
Join Date: Jun 2005
Posts: 86
Rep Power: 4 Scorpions4ever is on a distinguished road
You want the console window that your app is running under to get the focus? If so, here's what you do (the first 5 instructions are per a Microsoft KB article from a long time ago):

1. Use GetConsoleTitle() to get the current title of the Console Window
2. Use SetConsoleTitle() to set the title of the current window to something unique.
3. Sleep(50) milliseconds for the title to update
4. Use FindWindow() to get the Window handle by the new title name
5. Restore the original title with SetConsoleTitle().
6. Bring the console window to the foreground with SetForegroundWindow() and pass the window handle for the console window to it.
Scorpions4ever is offline   Reply With Quote
Old Aug 23rd, 2005, 2:55 PM   #3
drumltd
Newbie
 
Join Date: Aug 2005
Posts: 19
Rep Power: 0 drumltd is on a distinguished road
Thanks, I'd got all of that apart from I was using SetFocus instead of SetForeGroundWindow.

Quick Easy answer I like that thanks.
drumltd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC