Click here to Skip to main content
15,909,091 members
Home / Discussions / Windows Forms
   

Windows Forms

 
QuestionIcons in Visual Basic 6.0 Pin
nhss16-Oct-07 20:10
nhss16-Oct-07 20:10 
AnswerRe: Icons in Visual Basic 6.0 Pin
Kristian Sixhøj16-Oct-07 21:05
Kristian Sixhøj16-Oct-07 21:05 
Questionword finder Pin
gilbert28216-Oct-07 5:53
gilbert28216-Oct-07 5:53 
AnswerRe: word finder Pin
Paul Conrad27-Oct-07 13:36
professionalPaul Conrad27-Oct-07 13:36 
Questionclick A button Upon giving its handle ? Pin
jadothebest15-Oct-07 9:58
jadothebest15-Oct-07 9:58 
AnswerRe: click A button Upon giving its handle ? Pin
TJoe15-Oct-07 10:32
TJoe15-Oct-07 10:32 
GeneralRe: click A button Upon giving its handle ? Pin
jadothebest15-Oct-07 11:58
jadothebest15-Oct-07 11:58 
QuestionAfter a keyboard hook, GetTopWindow returns the window for ctfmon.exe Pin
alex_bol15-Oct-07 8:35
alex_bol15-Oct-07 8:35 
I am working on an application that must respond to a combination of keys, no matter which application the user is currently using, and that must know what is the application where the user was. I am using for this a keyboard hook, like in the article http://www.codeproject.com/csharp/globalhook.asp

The problem is that after responding to the hook, the only way I can think of to find out which application the user was using is to call GetTopWindow() and then find out the process to which the window belongs. The code returns always "ctfmon.exe". I don't know if this happens because the hook is triggered by ctfmon; in this case, how can I find out which application the user was in?

Can anybody help me?

See the code below:

<br />
        [DllImport("user32.dll")]<br />
        static extern IntPtr GetTopWindow(IntPtr hWnd);<br />
        [DllImport("user32.dll", SetLastError = true)]<br />
        public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint lpdwProcessId);<br />
<br />
void FindWindow()<br />
{<br />
        string processName = "Unknown";<br />
<br />
        IntPtr pTopWindow = GetTopWindow(IntPtr.Zero);<br />
<br />
        uint processId;<br />
        if (GetWindowThreadProcessId(pTopWindow, out processId) != 0)<br />
        {<br />
            Process runningProc = Process.GetProcessById((int)processId);<br />
            processName = runningProc.ProcessName;<br />
        }<br />
<br />
        processNameLabel.Text = processName;<br />
}<br />


Thanks a lot,
Alex
AnswerRe: After a keyboard hook, GetTopWindow returns the window for ctfmon.exe Pin
Dave Kreskowiak15-Oct-07 10:05
mveDave Kreskowiak15-Oct-07 10:05 
QuestionHow can i intercept Escape button in dialog form? Pin
wolfgangpuelm15-Oct-07 3:10
professionalwolfgangpuelm15-Oct-07 3:10 
AnswerRe: How can i intercept Escape button in dialog form? Pin
Giorgi Dalakishvili15-Oct-07 3:42
mentorGiorgi Dalakishvili15-Oct-07 3:42 
GeneralRe: How can i intercept Escape button in dialog form? Pin
wolfgangpuelm15-Oct-07 4:12
professionalwolfgangpuelm15-Oct-07 4:12 
AnswerRe: How can i intercept Escape button in dialog form? Pin
Mike Dimmick15-Oct-07 4:14
Mike Dimmick15-Oct-07 4:14 
AnswerRe: How can i intercept Escape button in dialog form? Pin
wolfgangpuelm15-Oct-07 4:39
professionalwolfgangpuelm15-Oct-07 4:39 
Questioncreating new shell for windows Pin
sresth14-Oct-07 17:52
sresth14-Oct-07 17:52 
AnswerRe: creating new shell for windows Pin
Pete O'Hanlon15-Oct-07 1:13
mvePete O'Hanlon15-Oct-07 1:13 
AnswerRe: creating new shell for windows Pin
TyrionTheImp15-Oct-07 21:00
TyrionTheImp15-Oct-07 21:00 
QuestionHow to highlight an item in the ListBox control Pin
Mike Borozdin14-Oct-07 5:19
Mike Borozdin14-Oct-07 5:19 
AnswerRe: How to highlight an item in the ListBox control Pin
Mike Borozdin14-Oct-07 7:20
Mike Borozdin14-Oct-07 7:20 
QuestionHow to get HWND from System::Windows::Forms::Panel^ panel [modified] Pin
Newbie0014-Oct-07 0:05
Newbie0014-Oct-07 0:05 
QuestionText in label is mangled Pin
sudhirkamath9-Oct-07 9:40
sudhirkamath9-Oct-07 9:40 
AnswerRe: Text in label is mangled Pin
Paul Conrad27-Oct-07 13:37
professionalPaul Conrad27-Oct-07 13:37 
QuestionBackup Database Using Threads Pin
jikubhai9-Oct-07 4:25
jikubhai9-Oct-07 4:25 
AnswerRe: Backup Database Using Threads Pin
Koltz11-Oct-07 20:57
Koltz11-Oct-07 20:57 
QuestionLock Menus/Toolbars on Window Scroll Pin
Elizma9-Oct-07 0:57
Elizma9-Oct-07 0:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.