Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


WM_CONTEXTMENU problem

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Jul 05, 2008 12:01 pm    Post subject: WM_CONTEXTMENU problem Reply with quote

I'm trying to add a system system tray icon for my program but it won't show the menu. I'm not sure if I'm putting WM_CONTEXTMENU in the wrong place, but it could also be my menu. Here is my code for adding an icon and showing the menu and the message handler part.

Code:

void CreateIcon() {
   NOTIFYICONDATA nid;
   nid.cbSize = sizeof(NOTIFYICONDATA);
   nid.hWnd = hWnd;
   nid.uID = SYSTRAY;
   nid.uFlags = NIF_MESSAGE | NIF_ICON;
   nid.hIcon = LoadIcon(NULL, IDI_APPLICATION);
   nid.uCallbackMessage = SYSTRAYMSG;
   ShowWindow(hWnd, SW_HIDE);
   Shell_NotifyIcon(NIM_ADD, &nid);
}

void ShowMenu() {
   POINT point;
   GetCursorPos(&point);
   HMENU hMenu = CreatePopupMenu();
   AppendMenu(hMenu, MF_STRING, KILLPROCESS, "Kill Process");
   AppendMenu(hMenu, MF_SEPARATOR, 1, 0);
   AppendMenu(hMenu, MF_STRING, RESTORE, "Restore");
   AppendMenu(hMenu, MF_STRING, EXIT, "Exit");
   SetForegroundWindow(hWnd);
   TrackPopupMenu(hMenu, TPM_BOTTOMALIGN, point.x, point.y, 0, hWnd, NULL);
   DestroyMenu(hMenu);
}


Code:

case SYSTRAYMSG:
   switch(LOWORD(lParam)) {
      case WM_CONTEXTMENU:
         ShowMenu();
         break;
   }
break;

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sat Jul 05, 2008 12:35 pm    Post subject: Reply with quote

Try InsertMenu instead

http://www.stromcode.com/2008/03/02/win32-context-menus/

Also, shouldn't you put the code to load the menu in the WM_CREATE message?

_________________
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jul 05, 2008 12:41 pm    Post subject: Reply with quote

blankrider wrote:
Try InsertMenu instead

http://www.stromcode.com/2008/03/02/win32-context-menus/

Also, shouldn't you put the code to load the menu in the WM_CREATE message?


No the menu is created when the user right clicks the icon. And is filtered through the message defined in his NOTIFYICONDATA


Try filtering for WM_RBUTTONDOWN aswell?

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Jul 05, 2008 1:42 pm    Post subject: Reply with quote

Thanks it worked. But I modified my code a little so it would list out the processes. My problem is is that if I right click on my icon it doesn't do the bottom allign that it's supposed to, so it ends up like starting near the top, and you can't see anything. So I was wondering how can I make it not do that, but add a down arrow so you can scroll. Also, how can I make it so that the user can only check one process, and how do I get the process name that the user checked (for killing the process).

Code:

void ShowMenu() {
   POINT point;
   GetCursorPos(&point);
   HMENU hMenu = CreatePopupMenu();
   AppendMenu(hMenu, MF_STRING, KILLPROCESS, "Kill Process");
   AppendMenu(hMenu, MF_SEPARATOR, 1, 0);
   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
   PROCESSENTRY32 pe32;
   pe32.dwSize = sizeof(PROCESSENTRY32);
   int count = 1;
   Process32First(hSnapshot, &pe32);
   do {
      AppendMenu(hMenu, MF_STRING, count, pe32.szExeFile);
      count++;
   } while(Process32Next(hSnapshot, &pe32));
   AppendMenu(hMenu, MF_SEPARATOR, 1, 0);
   AppendMenu(hMenu, MF_STRING, RESTORE, "Restore");
   AppendMenu(hMenu, MF_STRING, EXIT, "Exit");
   SetForegroundWindow(hWnd);
   TrackPopupMenu(hMenu, TPM_BOTTOMALIGN, point.x, point.y, 0, hWnd, NULL);
   DestroyMenu(hMenu);
}

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jul 05, 2008 2:02 pm    Post subject: Reply with quote

Read Some stuff from here:

http://msdn.microsoft.com/en-us/library/ms674664.aspx

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites