Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jan 25th, 2008, 8:24 PM   #1
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Exclamation Timers and hooks -

Sup guys,

Why is it that timers remove your hooks(in my case a mouse hook(WH_MOUSE_LL))?

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 26th, 2008, 8:12 AM   #2
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 93
Rep Power: 1 null_ptr0 is on a distinguished road
Re: Timers and hooks -

They do?
I thought you'd just have to call UnhookWindowsHook(Ex).
Oh, and thats a low level mouse hook, not just a mouse hook.
null_ptr0 is offline   Reply With Quote
Old Jan 26th, 2008, 9:01 AM   #3
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 544
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Timers and hooks -

Quote:
Originally Posted by pcbrainbuster View Post
Why is it that timers remove your hooksThanks.
Most likely because you wrote some crappy code that is destroy memory somewhere.
Ancient Dragon is offline   Reply With Quote
Old Jan 26th, 2008, 12:09 PM   #4
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Timers and hooks -

Quote: Crappy
:suprised: Harsh...

Hmm, according to the replies I think that timers don't remove hooks. Well I guess I'll revise my code and see what went wrong... It may be crappy code...

Thanks for now.
pcbrainbuster is offline   Reply With Quote
Old Jan 26th, 2008, 1:15 PM   #5
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Timers and hooks -

It took me some time but here is the offending code(the following code is what is causing problems) -

c++ Syntax (Toggle Plain Text)
  1. case 202 :
  2.  
  3. if(CurWndNo != 0)
  4. {
  5.  
  6. for(CurWndNo = WndList.size(); CurWndNo > 0; CurWndNo--)
  7. {
  8.  
  9. DeleteMenu(WindowList, 0, MF_BYPOSITION);
  10.  
  11. }
  12.  
  13. }
  14.  
  15. WndList.clear();
  16.  
  17. strcpy(WindowChoice, "Wnd List");
  18. EnumWindows((WNDENUMPROC)&EnumProc, NULL);
  19.  
  20. for(CurWndNo = 0; CurWndNo < WndList.size(); CurWndNo++)
  21. {
  22.  
  23. GetWindowText(WndList[CurWndNo], WndTitle, GetWindowTextLength(WndList[CurWndNo]) + 1);
  24. AppendMenu(WindowList, MF_STRING, NULL, WndTitle);
  25.  
  26. }
  27.  
  28. break;

Do you see any problems?

Thanks.

Last edited by Ancient Dragon; Jan 26th, 2008 at 5:38 PM. Reason: add line numbers for easier referencing
pcbrainbuster is offline   Reply With Quote
Old Jan 26th, 2008, 5:45 PM   #6
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 544
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Timers and hooks -

Quote:
:suprised: Harsh...
Oh so you don't think so ??? But don't feel too bad, I've written some crappy code too

line 2: why are you using numbers like that in the switch statement instead of the pre-defined macros from windows.h? It might work for now, but there is no guarentee those values won't change in the future.

line 9: why are you deleting the same menu multiple times? The first parameter is supposed to be HWND, don't know what WindowList is, but its value never changes inside that loop. Its possible that is whats producing the problem -

line 19: remove the & from in front of WinProc. Functions are always passed by reference so the & symbol is not needed.

line 20: what is the value of WndList.size() at that point? Answer: 0 because it was emptied on line 15. Consequently lines 23 and 24 will never get executed.
Ancient Dragon is offline   Reply With Quote
Old Jan 26th, 2008, 8:50 PM   #7
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Timers and hooks -

Well actually this is how I get all the open windows into a menu...

Quote: remove the & from in front of WinProc. Functions are always passed by reference so the & symbol is not needed.
R. I didn't know that, thanks!

Quote: line 20: what is the value of WndList.size() at that point? Answer: 0 because it was emptied on line 15. Consequently lines 23 and 24 will never get executed.
Maybe things will clear up if you have a look at this -

c++ Syntax (Toggle Plain Text)
  1. WndList.push_back(hWnd2);

That's basically what is happening in EnumWindows(...). Every three seconds(202, this is in WM_TIMER - which is why I am using a number) a menu called WindowList lists all the windows in the taskbar. You should now be able to see why I use WndList.clear() to clear all the windows in the array; to get a fresh list of new ones.

Quote: line 9: why are you deleting the same menu multiple times? The first parameter is supposed to be HWND, don't know what WindowList is, but its value never changes inside that loop. Its possible that is whats producing the problem -
R. Soory, the first parameter is HMENU

Any ideas?

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 26th, 2008, 9:43 PM   #8
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 544
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Timers and hooks -

Ok I understandand now about that WinList problem.

>>R. Soory, the first parameter is HMENU
Right, but the problem still exists. The value of that variable still doesn't change between loop iterations. My suggestion is to remove the loop around that line so that it gets executed only once. Sending an invalid HMENU to that function might produce undesireable and unpredictable results.
Ancient Dragon is offline   Reply With Quote
Old Jan 27th, 2008, 7:02 AM   #9
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Timers and hooks -

But WndList is being changed in EnumWindows(), I think I should mension that WndList is a vector<HWND> and in EnumWindows() I am appending handles to windows...

Any ideas?

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 27th, 2008, 9:51 AM   #10
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 544
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Timers and hooks -

are you deaf or something? you still don't get it? We are not talking about WinList but WindowList
      for(CurWndNo = WndList.size(); CurWndNo > 0; CurWndNo--)
      {

       DeleteMenu(WindowList, 0, MF_BYPOSITION);

      }
That loop passes the same argument to DeleteMenu() on every iteration. WindowList never changes.
Ancient Dragon 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 5:18 AM.

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