Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jan 26th, 2008, 2:35 PM   #1
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Exclamation A menu issue -

Sup guys,

A part of my menu is supposed to capture all open windows and list them, the problem is; since the number of windows could be random I have no way of knowing what's open so I need to know what the user clicked on, I prepared this piece of code to do that -

C++ Syntax (Toggle Plain Text)
  1. [WM_COMMAND]
  2. ...
  3. default :
  4. {
  5.  
  6. POINT CurMPos;
  7. int SelMI;
  8. char MenuString[255];
  9.  
  10. GetCursorPos(&CurMPos);
  11.  
  12. SelMI = MenuItemFromPoint(hWnd, WindowList, CurMPos);
  13.  
  14. GetMenuString(WindowList, SelMI, MenuString, 255, MF_BYPOSITION);
  15. MessageBox(NULL, MenuString, "Selected Window", MB_OK);
  16.  
  17. }
  18. ...

Sadly enough though my program does not retrieve the title... Do you guys know what went wrong or of any easier way?

Thanks.

Last edited by Ancient Dragon; Jan 26th, 2008 at 5:52 PM. Reason: corrected code tags -- do not put any spaces in them
pcbrainbuster is offline   Reply With Quote
Old Jan 26th, 2008, 5:57 PM   #2
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: A menu issue -

You need to check the return value of MenuItemFromPoint() to see if it is a valid position. It returns -1 on error. And is that code inside the menu event handler ?
Ancient Dragon is offline   Reply With Quote
Old Jan 26th, 2008, 8:25 PM   #3
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Exclamation Re: A menu issue -

Quote:
Originally Posted by Ancient Dragon View Post
You need to check the return value of MenuItemFromPoint() to see if it is a valid position. It returns -1 on error. And is that code inside the menu event handler ?
Well actually its like this -

C++ Syntax (Toggle Plain Text)
  1. case WM_COMMAND :
  2.  
  3. if(HIWORD(wParam) == BN_CLICKED)
  4. {
  5.  
  6. switch(LOWORD(wParam)
  7. {
  8.  
  9. // All my menu and button commands here
  10.  
  11. default :
  12.  
  13. //The code from above
  14.  
  15. }
  16.  
  17. }
  18.  
  19. break;

I have done it like this because if there is any menu item that has no identifier(in my code its only the list of windows) it would get passed to th default and I should be able to take things by doing that. When a user is to click on the unidentified menu item, I would retrieve the string from the clicked menu item then search for the window using FindWindow then do whatever I wish with the selected window. But at this point I can't figure out what went wrong Do you have any possible ideas/clues?

Thanks, a lot!

Last edited by Ancient Dragon; Jan 26th, 2008 at 9:44 PM. Reason: corrected code tags
pcbrainbuster is offline   Reply With Quote
Old Jan 26th, 2008, 9:50 PM   #4
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: A menu issue -

Thanks for attempting to use code tags, but next time don't put any spaces in them. You had the right characters, you just can't have any spaces between the brackets.

You probably should learn to use your compiler's debugger. I know Dev-C++ has one, but I don't know how to use it either. Search Dev-C++'s forums and you will probably find that information. Here is a good place to start.
Ancient Dragon is offline   Reply With Quote
Old Jan 26th, 2008, 10:18 PM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: A menu issue -

gdb is quite easy to use. All I know how to do is type "up" at the prompt but that is often enough to find the problem with my code. I code on Mac OS X, but I believe there is a Windows port available.
titaniumdecoy is offline   Reply With Quote
Old Jan 27th, 2008, 7:11 AM   #6
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: A menu issue -

Well, first of all I use Borland C++ Builder 6 secondly I don't know how to use a debugger And finally I am not sure it can help, because the code has runtime ISSUES and not problems(a debugger detects problems not issues(there is a slight difference)), by issues I am refering to the way something is coded...

Any ideas?

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 27th, 2008, 9:47 AM   #7
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: A menu issue -

>>secondly I don't know how to use a debugger
Learn. Its your program and your problem, now ours. If you are going to write programs them you must learn how to debug them.

debuggers will also help sort out issues as you like to call them.
Ancient Dragon is offline   Reply With Quote
Old Jan 27th, 2008, 1:33 PM   #8
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: A menu issue -

Well I guess I'll look for information in the time... Maybe its worth mensioning that the menu is not used using SetMenu() because my program is a tray icon and instead I use TrackMenuPopup()...

Any ideas?

Thanks.
pcbrainbuster 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Popup Menu titaniumdecoy Java 7 Mar 12th, 2006 11:17 AM
dropdown menu with persistence? kerriganm HTML / XHTML / CSS 11 Dec 17th, 2005 2:33 PM
Creating a menu within a loop? bivhitscar C 8 Nov 9th, 2005 6:35 AM
Need help with a realtime branching menu Zeteg JavaScript and Client-Side Browser Scripting 11 Aug 27th, 2005 11:36 AM
HELP!!! Perl script to display drop down menu on webpage domquem Perl 8 Jun 2nd, 2005 9:48 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:16 AM.

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