Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
What can I make to a window to NEVER receive any <b>WM_</b> message ? OR atleast to not process or apply them? Or to discard them from the Message Queue ?
 
<i>Can those functions be helpful ? :</i>
 
-GetMessage function ?
or
-DispatchMessage function ?
or
-PostQuitMessage function ?
or
-WaitMessage function ?
or
-PeekMessage()function ?
 
Thanks alot for any help!
 
EDIT: Im coming from another q/a site because no one wants to give any help there and keep closing my threadsFrown | :(
 
Thankyou again Smile | :)
Posted 21-Jul-12 13:06pm
Edited 21-Jul-12 14:14pm
Wes Aday84.2K
v3
Comments
woutercx at 21-Jul-12 20:12pm
   
Which language are we talking about? C++? C#?
Allen Qake09 at 22-Jul-12 8:29am
   
Right now I coded my program in the AutoIt scriptbased language, its still a powerful language, but I know C++ too( beginner-intermediate :) )
Wes Aday at 21-Jul-12 20:15pm
   
Implement your own WinProc procedure. Why on earth would you want to do this anyway?
Allen Qake09 at 22-Jul-12 8:32am
   
I want my browser window( Google Chrome ) to never loose the focus( I know I can activate it back immediately but its not fast enough ). So I need to stop receiving for example the WM_KILLFOCUS message .
woutercx at 22-Jul-12 8:45am
   
Ah, now I see better what you're trying to accomplish. You didn't specify the language at first!
Allen Qake09 at 22-Jul-12 8:51am
   
Yes :) MY fault , just like the SW_DISABLE attribute makes a window to not receive keyboard and mouse input, I need somehow to make a existent window to not response to any other messages or even better to only some messages. Can it be done somehow ? thanks alot :)
woutercx at 22-Jul-12 8:50am
   
I think what you're trying is, you're doing some kind of installation procedure where you want the browser to stay "on top" and "focused"?
Allen Qake09 at 22-Jul-12 8:52am
   
Its no problem if its topmost or not ,just the window to be always focused,yes.I studied and tried many things no work, and the really best way its by blocking the messages from that window.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

"How to get the handle of the window"
 
http://www.cplusplus.com/forum/beginner/3811/[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'll assume C#. What kind of messages do you not want to receive anymore? I assume keyboard messages?
 
Maybe I have an idea for you:
I used a certain control in my project:
KRBTabControl[^] that had an override:
 
  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == (Keys.Tab | Keys.Control)) || (keyData == (Keys.Tab | Keys.Shift | Keys.Control)))
            {
                if (!OnNavigateTabPage((keyData & Keys.Shift) != Keys.Shift ? this.SelectedIndex + 1 : this.SelectedIndex - 1, true))
                {
                    msg.Result = new IntPtr(1);
                    return true;
                }
            }
            else
            {
                switch (keyData)
                {
                    // Selects Last TabPage
                    case Keys.End:
                        if (!OnNavigateTabPage(this.TabCount - 1, false))
                        {
                            msg.Result = new IntPtr(1);
                            return true;
                        }
                        break;
                    // Selects First TabPage
                    case Keys.Home:
                        if (!OnNavigateTabPage(0, false))
                        {
                            msg.Result = new IntPtr(1);
                            return true;
                        }
                        break;
                    // Selects the tab on the left side of the currently selected TabPage
                    //case Keys.Left:
                    //    if (!OnNavigateTabPage(this.SelectedIndex - 1, false))
                    //    {
                    //        msg.Result = new IntPtr(1);
                    //        return true;
                    //    }
                    //    break;
                    //// Selects the tab on the right side of the currently selected TabPage
                    //case Keys.Right:
                    //    if (!OnNavigateTabPage(this.SelectedIndex + 1, false))
                    //    {
                    //        msg.Result = new IntPtr(1);
                    //        return true;
                    //    }
                    //    break;
                    case Keys.Insert:
                        if (conditionBooleanArray[3] && MessageBox.Show("Do you want to insert a new tab page here?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            TabPageEx tabPage = new TabPageEx();
                            this.Controls.Add(tabPage);
                        }
                        break;
                    case Keys.Delete:
                        if (conditionBooleanArray[3] && this.TabCount > 0)
                        {
                            if (MessageBox.Show("Do you want to remove the selected tab page?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                TabPageEx removingTabPage = this.SelectedTab as TabPageEx;
                                if (removingTabPage != null && removingTabPage.IsClosable && removingTabPage.Enabled)
                                {
                                    using (SelectedIndexChangingEventArgs e = new SelectedIndexChangingEventArgs(removingTabPage, this.SelectedIndex))
                                    {
                                        // Fire a Notification Event.
                                        OnTabPageClosing(e);
 
                                        if (!e.Cancel)
                                        {
                                            this.TabPages.Remove(removingTabPage);
                                            SelectNextAvailableTabPage();
                                        }
                                        else
                                            MessageBox.Show("The operation was canceled by the user.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("The selected tab page could not be deleted!!!, it may be due to the following reasons;\r\n\r\n1.Tab page might be null or disposed by the application.\r\n2.Tab page might not be closable.\r\n3.Tab page might be disable.",
                                        Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                        break;
                    case Keys.Escape:
                        break;
                    case Keys.F1:
                        break;
                    default:
                        return base.ProcessCmdKey(ref msg, keyData);
                }
            }
 
            return true;
        }
 
If I remove the two lines in this control:
 
default:
    return base.ProcessCmdKey(ref msg, keyData);
 
then the control doesn't take any input.
So maybe this will work in your project in the same way?
 
The method is part of this class:
 
namespace KRBTabControl
{
    public partial class KRBTabControl : TabControl
 
which inherits from:
 
namespace System.Windows.Forms
{
  public class TabControl : Control
  Permalink  
v3
Comments
Allen Qake09 at 22-Jul-12 8:39am
   
Hmm I see its useful the code, but can I block any message I want with it ? Also , Im not knowing c# so its pretty hard to understand any sourcecode,would be helpful just an explain on how to not receive the messages, in simple steps to apply it in other language too ;)
 
Thanks alot ,seems this site and the members are 10 times better here :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Or override WndProc in your form:
 
protected override void WndProc(ref Message m)
as they explain here:

http://msdn.microsoft.com/en-us/library/system.windows.forms.message.aspx[^]
  Permalink  
Comments
Allen Qake09 at 22-Jul-12 8:42am
   
I read about WndProc on other threads too about this idea too, do you think I can do it in c++ ? Also, can apply it for a pre-existent window ?
woutercx at 22-Jul-12 9:40am
   
I c++ you can do almost everything.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

What you want is a "system wide" filter on WM_ messages.
 
This is a Codeproject that provides something like that.
 
.NET system wide hotkey component[^]
 
Now the only thing you have to find out is to find the handle of the existing Chrome window.
 
Maybe this will be a good entrance.
 
http://www.pinvoke.net/default.aspx/user32/EnumWindows.html[^]
 
Anyway, you have to do some advanced Win32 Api stuff..
  Permalink  
v2
Comments
Allen Qake09 at 22-Jul-12 9:04am
   
I'm sorry, this is for a specific hotkeys registration so if you want CTRL + some other key to do something, you register the event,no ? It can be useful in blocking the messages for a specific window too??
 
Also with EnumWindows I only enumerate the windows, but how can I filter the messages and discard them for a specific window ?
woutercx at 22-Jul-12 9:11am
   
Yes, the override of WndProc is the filter to ALL WM_ messages I think. The only thing you have to do is get the proper handle to a Window. In C++ it is easy to do (if you've done it before).
Allen Qake09 at 22-Jul-12 9:14am
   
Thanks now this is REALLY useful :)
woutercx at 22-Jul-12 9:12am
   
WndProc is used to recieve all messages/events directed at a window.
Allen Qake09 at 22-Jul-12 12:53pm
   
Well, woutercx, I think I have a problem >.< The GetMessage() function used to get the window's received messages it doesn't work on windows that are not created by me. So its not working with Google Chrome.
 
Also, I dont understand the 'overwriting' part of the WndProc . What is WndProc( it is a func,or a message? ) or how it gets created and when, and what APIs or functions do I need to call to overwrite it ? I dont need any sourcecode just the basic instructions :)
 
EDIT: I think this will help many ppl too :)
woutercx at 22-Jul-12 17:35pm
   
Explained here:
http://www.hackcraft.net/cpp/windowsThunk/
woutercx at 23-Jul-12 0:51am
   
Still working on it, can't give up ;-)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hmm seems like this could be a solution in autoit itself!
 
http://www.autoitscript.com/forum/topic/97867-keeping-my-gui-not-focused/[^]
  Permalink  
Comments
Allen Qake09 at 22-Jul-12 9:11am
   
I saw this thread, its useful but only when you create your own GUI or window, and don't work on pre-existent windows like for a browser window.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

In C++
 
http://stackoverflow.com/questions/9164659/code-in-petzolds-programming-windows-making-window-error[^]
 
Closer to a solution, but still you'll have to know the proper handle of the Google Chrome window, and if you don't know what you're doing you can mess up your Window session pretty well Smile | :) .
  Permalink  
v2
Comments
Allen Qake09 at 22-Jul-12 9:18am
   
its damn easy to get the handle ,I can use the spy++ program ;) Thanks a ton for your help dude, you seem a nice member :)
woutercx at 29-Jul-12 7:46am
   
Still working on the problem, I like simple challenges ;-)
woutercx at 29-Jul-12 7:46am
   
http://www.codinghorror.com/blog/images/coding-horror-official-logo-small.png
woutercx at 29-Jul-12 7:51am
   
Setting a window as the active window, on top is a world of hurt..
You have SetWindowPos, SetForegroundWindow, ShowWindow. Everyone using his own version of a Win32 call.
I've tried all of those, none if seems to be able to bring a window to the foreground. Maybe it's because I have a 64 bits version of Windows (Windows 7 64 bits)..
woutercx at 29-Jul-12 7:53am
   
I did a test using calc.exe. I just found out from my Task Manager that calc.exe is a 64 bit process... Maybe that explains why it doesn't work.....
woutercx at 29-Jul-12 7:55am
   
For the API call it doesn't matter: http://stackoverflow.com/questions/1426286/does-p-invoke-on-64-bit-windows-require-different-signatures-than-on-32-bit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 534
1 Gihan Liyanage 298
2 ChintanShukla 295
3 RyanDev 250
4 Richard Deeming 250
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 22 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100