Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 threads:(

Thankyou again :)
Posted
Updated 21-Jul-12 14:14pm
v3
Comments
woutercx 21-Jul-12 20:12pm    
Which language are we talking about? C++? C#?
Allen Qake09 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 :) )
[no name] 21-Jul-12 20:15pm    
Implement your own WinProc procedure. Why on earth would you want to do this anyway?
Allen Qake09 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 22-Jul-12 8:45am    
Ah, now I see better what you're trying to accomplish. You didn't specify the language at first!

"How to get the handle of the window"

http://www.cplusplus.com/forum/beginner/3811/[^]
 
Share this answer
 
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:

C#
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:

C#
namespace KRBTabControl
{
    public partial class KRBTabControl : TabControl


which inherits from:

C#
namespace System.Windows.Forms
{
  public class TabControl : Control
 
Share this answer
 
v3
Comments
Allen Qake09 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 :)
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[^]
 
Share this answer
 
Comments
Allen Qake09 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 22-Jul-12 9:40am    
I c++ you can do almost everything.
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..
 
Share this answer
 
v2
Comments
Allen Qake09 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 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 22-Jul-12 9:14am    
Thanks now this is REALLY useful :)
woutercx 22-Jul-12 9:12am    
WndProc is used to recieve all messages/events directed at a window.
Allen Qake09 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 :)
Hmm seems like this could be a solution in autoit itself!

http://www.autoitscript.com/forum/topic/97867-keeping-my-gui-not-focused/[^]
 
Share this answer
 
Comments
Allen Qake09 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.
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 :-).
 
Share this answer
 
v2
Comments
Allen Qake09 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 29-Jul-12 7:46am    
Still working on the problem, I like simple challenges ;-)
woutercx 29-Jul-12 7:46am    
http://www.codinghorror.com/blog/images/coding-horror-official-logo-small.png
woutercx 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 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.....

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900