Click here to Skip to main content
15,929,346 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Some MFC Process Checking ??? Pin
1-Mar-01 0:47
suss1-Mar-01 0:47 
AnswerRe: Some MFC Process Checking ??? Pin
markkuk28-Feb-01 21:48
markkuk28-Feb-01 21:48 
GeneralPropertySheet in CFrameWnd do not look like a Dlg Pin
HL123428-Feb-01 6:48
professionalHL123428-Feb-01 6:48 
GeneralProblems with hooking events!! HELP !! Pin
TomK27-Feb-01 21:51
TomK27-Feb-01 21:51 
GeneralRe: Problems with hooking events!! HELP !! Pin
28-Feb-01 0:21
suss28-Feb-01 0:21 
GeneralRe: Problems with hooking events!! HELP !! Pin
TomK28-Feb-01 2:21
TomK28-Feb-01 2:21 
GeneralRe: Problems with hooking events!! HELP !! Pin
28-Feb-01 4:32
suss28-Feb-01 4:32 
GeneralTray icon and a popup menu bug Pin
27-Feb-01 21:21
suss27-Feb-01 21:21 
Hi!

Anyone want to help me out? Smile | :)
I implemented a tray icon in my program and everything is working great in the way I want it to be. However, there's a slight problem. The popup menu doesn't disappear right away if I click outside the popup menu. But it will disappear if I move the cursor back to the popup menu. Frown | :(
Any idea what is wrong with my code?

#define WM_NOTIFYICON WM_USER + 50

HWND g_hWnd;
HINSTANCE g_hInst;
HICON g_hIcon;

BOOL TrayMessage(HWND hWnd, DWORD dwMsg, UINT uId)
{
NOTIFYICONDATA nd;

nd.cbSize = sizeof(NOTIFYICONDATA);
nd.hWnd = hWnd;
nd.uID = uId;
nd.uFlags = NIF_MESSAGE | NIF_ICON;
nd.uCallbackMessage = WM_NOTIFYICON;
nd.hIcon = g_hIcon;

return Shell_NotifyIcon(dwMsg, &nd);
}

void NotifyAdd()
{
TrayMessage(g_hWnd, NIM_ADD, 777);
}

void NotifyDelete()
{
TrayMessage(g_hWnd, NIM_DELETE, 777);
}

void OnContextMenu()
{
HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU1));
HMENU hPopup = GetSubMenu(hMenu, 0);
POINT pt;

GetCursorPos(&pt);
TrackPopupMenu(hPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, g_hWnd, NULL);
}

LRESULT OnNotifyIcon(LPARAM lParam)
{
switch (lParam)
{
case WM_RBUTTONUP:
OnContextMenu();
break;
}
return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_CLOSE:
NotifyDelete();
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CONTEXTMENU:
OnContextMenu();
break;
case WM_NOTIFYICON:
return OnNotifyIcon(lParam);
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int n)
{
MSG msg;
WNDCLASS wc;

memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_DBLCLKS;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = "popupwindowClass";

RegisterClass(&wc);

g_hInst = hInstance;
g_hWnd = CreateWindowEx(WS_EX_APPWINDOW, "popupwindowClass",
"popupmenu test", WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
0, 0, 320, 240, NULL, NULL, hInstance, NULL);

if (g_hWnd)
{
g_hIcon = LoadIcon(NULL, IDI_APPLICATION);
ShowWindow(g_hWnd, n);
UpdateWindow(g_hWnd);
NotifyAdd();
}

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

GeneralRe: Tray icon and a popup menu bug Pin
Daniel Ferguson28-Feb-01 3:37
Daniel Ferguson28-Feb-01 3:37 
GeneralRe: Tray icon and a popup menu bug Pin
3-Mar-01 9:23
suss3-Mar-01 9:23 
GeneralFile Handling Pin
27-Feb-01 19:53
suss27-Feb-01 19:53 
GeneralRe: File Handling Pin
l a u r e n27-Feb-01 19:58
l a u r e n27-Feb-01 19:58 
GeneralPrinter Context Menu Pin
27-Feb-01 19:22
suss27-Feb-01 19:22 
GeneralRe: Printer Context Menu Pin
Jason De Arte28-Feb-01 7:14
Jason De Arte28-Feb-01 7:14 
GeneralRe: Printer Context Menu Pin
12-Mar-01 12:05
suss12-Mar-01 12:05 
GeneralUnable to log on to Oracle?!!! Pin
27-Feb-01 16:14
suss27-Feb-01 16:14 
GeneralRe: Unable to log on to Oracle?!!! Pin
l a u r e n27-Feb-01 20:12
l a u r e n27-Feb-01 20:12 
QuestionFindinf my CFrameWnd ? Pin
Ariel27-Feb-01 15:23
Ariel27-Feb-01 15:23 
AnswerRe: Findinf my CFrameWnd ? Pin
Christian Graus27-Feb-01 16:31
protectorChristian Graus27-Feb-01 16:31 
GeneralRe: Findinf my CFrameWnd ? Pin
Ariel27-Feb-01 17:51
Ariel27-Feb-01 17:51 
GeneralCScrollView Pin
27-Feb-01 14:15
suss27-Feb-01 14:15 
GeneralRe: CScrollView Pin
l a u r e n27-Feb-01 20:03
l a u r e n27-Feb-01 20:03 
QuestionCan CListCtrl select all the row (not only the iSubItem=0 part)? Pin
Ariel27-Feb-01 14:09
Ariel27-Feb-01 14:09 
AnswerRe: Can CListCtrl select all the row (not only the iSubItem=0 part)? Pin
Daniel Ferguson28-Feb-01 3:49
Daniel Ferguson28-Feb-01 3:49 
GeneralRe: Can CListCtrl select all the row (not only the iSubItem=0 part)? Pin
Ariel28-Feb-01 19:52
Ariel28-Feb-01 19:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.