Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jan 20th, 2008, 8:38 PM   #1
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Exclamation Menu updating -

Sup guys,

As some of you guys may know I recently had little trouble with EnumWindows, well that problem is gone now The new problem is that I have a menu that needs to be updated somehow. I'm just going to give you a task because it is easier this way(then to explain it). First create a dropdown menu called "Windows", now every seconds or two this menu should have a string that is updated with the total number of windows and that's it. I know this sounds possibly simple and/or stupid but its part of a bigger picture.

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 20th, 2008, 9:03 PM   #2
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 489
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Menu updating -

Search MSDN for GetMenu function. Now look on the left panel and you will see a list of menu functions that can manipulate the menu. Search those functions to see if you can find one that will solve your problem.

Near the bottom of the window you will also find some See Also links that give more information about menus
Ancient Dragon is offline   Reply With Quote
Old Jan 20th, 2008, 11:33 PM   #3
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Menu updating -

Well, Ancient Dragon, I've already tried that but I kept getting unexpected results which is why I asked for help here

Sorry for keep on asking you guys for so much help but could you please try and do the task listed above? As this will answer(most likely) my question.

Thank you .
pcbrainbuster is offline   Reply With Quote
Old Jan 20th, 2008, 11:43 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,791
Rep Power: 5 Sane will become famous soon enough
Re: Menu updating -

People aren't here to "do tasks for you". Post your code, and maybe someone can point out what you've done wrong. If you don't have any code to show for, then don't expect anyone to help someone who's shown no effort. If you expect that from us, then post this in the job offers where your "tasks" might be more welcome. The reason I say this, is because your request is not so simple. It takes time to do, and that's time you're most likely not going to get out of anyone here for free.
Sane is offline   Reply With Quote
Old Jan 21st, 2008, 12:35 AM   #5
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Menu updating -

That's alfirmative sarge!

c Syntax (Toggle Plain Text)
  1. #include <windows.h>
  2. #include <iostream.h>
  3.  
  4. const char *ClsName = "BasicApp";
  5. const char *WndName = "Test -";
  6.  
  7. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  8. BOOL CALLBACK EnumProc(HWND hWnd2, LPARAM lParam);
  9.  
  10. HINSTANCE hInstance;
  11. HWND hWnd;
  12. char String[3];
  13. int NumWnds;
  14.  
  15. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  16. LPSTR lpCmdLine, int nCmdShow)
  17. {
  18. MSG Msg;
  19. HWND hWnd;
  20. WNDCLASSEX WndClsEx;
  21.  
  22. // Create the application window
  23. WndClsEx.cbSize = sizeof(WNDCLASSEX);
  24. WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
  25. WndClsEx.lpfnWndProc = WndProc;
  26. WndClsEx.cbClsExtra = 0;
  27. WndClsEx.cbWndExtra = 0;
  28. WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  29. WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
  30. WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  31. WndClsEx.lpszMenuName = NULL;
  32. WndClsEx.lpszClassName = ClsName;
  33. WndClsEx.hInstance = hInstance;
  34. WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  35.  
  36. // Register the application
  37. RegisterClassEx(&WndClsEx);
  38.  
  39. // Create the window object
  40. hWnd = CreateWindow(ClsName,
  41. WndName,
  42. WS_OVERLAPPEDWINDOW,
  43. CW_USEDEFAULT,
  44. CW_USEDEFAULT,
  45. CW_USEDEFAULT,
  46. CW_USEDEFAULT,
  47. NULL,
  48. NULL,
  49. hInstance,
  50. NULL);
  51.  
  52. // Find out if the window was created
  53. if( !hWnd ) // If the window was not created,
  54. return 0; // stop the application
  55.  
  56. // Display the window to the user
  57. ShowWindow(hWnd, SW_SHOWNORMAL);
  58. UpdateWindow(hWnd);
  59.  
  60. // Decode and treat the messages
  61. // as long as the application is running
  62. while( GetMessage(&Msg, NULL, 0, 0) )
  63. {
  64. TranslateMessage(&Msg);
  65. DispatchMessage(&Msg);
  66. }
  67.  
  68. return Msg.wParam;
  69. }
  70.  
  71. LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  72. {
  73.  
  74. static HMENU MainMenu = CreateMenu(), TotalWnds = CreatePopupMenu();
  75.  
  76. switch(Msg)
  77. {
  78.  
  79. case WM_DESTROY :
  80.  
  81. KillTimer(hWnd, 201);
  82. PostQuitMessage(WM_QUIT);
  83.  
  84. break;
  85.  
  86. case WM_CLOSE :
  87.  
  88. DestroyWindow(hWnd);
  89.  
  90. break;
  91.  
  92. case WM_CREATE :
  93.  
  94. AppendMenu(MainMenu, MF_POPUP, (UINT)TotalWnds, "Total Windows");
  95. SetMenu(hWnd, MainMenu);
  96. SetTimer(hWnd, 201, 1000, NULL);
  97.  
  98. break;
  99.  
  100. case WM_TIMER :
  101.  
  102. switch(wParam)
  103. {
  104.  
  105. case 201 :
  106.  
  107. EnumWindows((WNDENUMPROC)&EnumProc, NULL);
  108. sprintf(String, "%d", NumWnds);
  109. AppendMenu(TotalWnds, MF_STRING, NULL, String);
  110.  
  111. NumWnds = 0;
  112.  
  113. break;
  114.  
  115. }
  116.  
  117. break;
  118.  
  119. }
  120.  
  121. return DefWindowProc(hWnd, Msg, wParam, lParam);
  122.  
  123. }
  124.  
  125. BOOL CALLBACK EnumProc(HWND hWnd2, LPARAM lParam)
  126. {
  127.  
  128. ++NumWnds;
  129.  
  130. return true;
  131.  
  132. }

Please help .

Thanks again!

Last edited by Ancient Dragon; Jan 21st, 2008 at 5:15 AM. Reason: add line numbers for easier referencing
pcbrainbuster is offline   Reply With Quote
Old Jan 21st, 2008, 5:38 AM   #6
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 489
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Menu updating -

I compiled and ran your program. Works (sortof) on my computer Every second or so it adds a new menu item with a number on it. Isn't that what you want ? If you want to just update an existing menu item instead of adding a new one (which makes more sense to me) than call SetMenuItemInfo() instead of AppendMenu() inside that timer event handler function.
Ancient Dragon is offline   Reply With Quote
Old Jan 21st, 2008, 7:18 AM   #7
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Menu updating -

Quote by Ancient Dragon: ""
Finally, a post with a smile(just kidding ) .

Well getting back to topic, the menu is updated every second which is great and all, but as you may have noticed the menu gows bigger and bigger which is not needed, so is there a way to get rid of the old value and get in the new one?

Thanks.
pcbrainbuster is offline   Reply With Quote
Old Jan 21st, 2008, 9:46 AM   #8
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 489
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Menu updating -

re-read my post because I already told you how to do it -- see the last sentence. I'll leave it up to you to figure out how to use that function.

"It works on my computer" got the smily because that is a famous comment by programmers whose program doesn't work when tested by someone else.
Ancient Dragon is offline   Reply With Quote
Old Jan 21st, 2008, 1:41 PM   #9
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Menu updating -

Oh sorry for that, my eye didn't seem to catch that Anyway, I don't really have experience with the function SetMenuItemInfo(...), actually I tried once and failed... Although I WILL try, could you(if you want), just edit the code above to show me how to do it?

Thank you.
pcbrainbuster is offline   Reply With Quote
Old Jan 21st, 2008, 3:32 PM   #10
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
Re: Menu updating -

RESOLVED - I found another method which works just fine.
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
Help with .css file and suckerfish menu csrocker101 HTML / XHTML / CSS 0 Aug 30th, 2007 5:59 PM
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
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 3:00 AM.

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