Force showing system tray notification balloons - c++

My application (C++ WinAPI) creates an icon in the system tray. I have set a tooltip text for this icon, so that when a user places a mouse cursor over the icon, this text shows.
But I want to programmatically show different balloon notications when certan events occur and at the same time keep that behavior of showing the constant notification message when a user places a mouse over the icon.
How to achieve this in C++ WinAPI?
Thanks
Alexander Smirnov

You can add the balloon using the .szInfo (message) and .szInfoTitle (title) members of the NOTIFYICONDATA structure that you send to Shell_NotifyIcon(). The mouse-over tooltip text is set in .szTip so this is independent of the balloon - as long as you keep .szTip to the tooltip you want you can do as much NIM_MODIFY calls to change the balloon while not changing anything to the tooltip.

See http://www.stromcode.com/2008/03/02/cwin32-the-system-tray-and-balloon-tips/

Related

How to keep the focus on the top window of 1st screen after clicking 2nd screen

we have one desktop(1st screen) to display the image and another touchscreen(2nd screen) for the control, we wrote a virtual keyboard(html&javascript) on touchscreen, ideally when we touch the keys on the touchscreen, we could input text in editbox(in an input dialog window) in the 1st desktop. Now the problem is the mouse is lost(originally it is in a input dialog in 1st desktop) when we touch the touchscreen, so we have to create a global window in C++ program, and manually copy each possible input dialog window to this global window when it is in use, also we need to set focus for each possible editbox in this input dialog window. please see this:
for each possible input dialog, we add
extern HWND activeInputWindow;
activeInputWindow=m_Edit_Name.m_hWnd;
also for each possible input box in this window we have to add
activeInputWindow=GetDlgItem(IDC_EDIT_TEST)->m_hWnd;
then the program always do this to get back the original window after clicking the touchscreen(2nd window)
extern HWND activeInputWindow;
if(IsWindow(activeInputWindow))
::SetFocus(activeInputWindow);
suppose we have 10 input window and 10 input boxes in each window,then I need to code 100 places! There must have some simple ways, windows osk.exe (virtual keyboard) have no problem for this but we have to use our own virtual keyboard.... I tried GetTopWindow() and GetForegroundWindow() but not working.. Many thanks for the help
This is trying to solve the problem using the wrong tools. What you really want is a window that receives input, but rejects activation. To achieve this, handle the WM_MOUSEACTIVATE message by returning MA_NOACTIVATE. This also works for touch input.
See How can I have a window that rejects activation but still receives pointer input? for all the ins and outs.
The problem is that your virtual keyboard is stealing the focus of the edit control. You'll need to prevent this.
Try to set the flag WS_EX_NOACTIVATE for a window's style or other approaches from this or this answers.

Win32 popup menu width [duplicate]

I'm creating a custom control in wxWidgets that displays a menu as part of it, and currently working on the Windows side of things. wxWidgets doesn't have a way of setting the width of a menu. It just makes the window as wide as the longest string plus a few pixels on either side.
In the API, there is a way to get the actual Windows API menu handle. Does the Windows API have a method of setting the width of a menu other than just calculating it on its own based on the width of the string?
With the handle of the menu, you can cycle through the menu items and call SetMenuItemInfo, indicating that you want to owner-draw the menu items. When you do this, the window that the menu is attached to will receive the WM_MEASUREITEM message, which you would then respond to by setting the dimensions required for the menu. It is here you can set your width.
Of course, this means you have to subclass the windows message handler for the window that contains the menu.
First of all, try to obtain the HWND to the menu:
(1) WM_DRAWITEM (2)get the HDC (3)WindowFromDC(),
then you can arbitrarily adjust aspects of the menu.
NOTE: don't send WM_QUIT WM_CLOSE to the menu, or you'll effectively shut down your computer with no clue.

Reliably identifying any window's client area

I am working on a program that will replicate, and then extend the functionality of Aero Snap.
Aero Snap restores a maximized window, if the user "grabs" it's title bar, and I am having difficulties identifying this action.
Given a cursor position in screen coordinates, how would I check if the position is within the window's title bar? I am not really at home in the Win32 API, and could not find a way that works reliably for complicated scenarios such as:
Note that tabs that chrome inserts into the title bar. Office does something similar with the quick launch menu.
title bar hits are via the message "non client" messages - ie the area of a window that is not the client (or inner) window.
WM_NCLBUTTONDOWN is probably the message you want to trap.
You also probably want to set a window hook to hook mouse messages, if its the NC message you want, you handle it your way, if not - pass it on to the message chain.
Edit: if Chrome is using the DwmExtendFrameIntoClientArea calls to draw the tabs, then you will need to use WM_NCHITTEST.

Simulating right click on system tray icon and clicking on context menu in C++

I am a Python developer with a little knowledge of C++.
With that said, I would like to understand how I can right click on a system tray icon, and click on one of the options on the context menu.
I have looked around the internet and was unable to find something that can get me the location of the system tray icons relative to the 'Notification Area'. Also, I can get the Button text of the tray icon.
I get the handle of ToolbarWindow32 using FindWindowEx.
I have tried to send WM_RBUTTONDOWN and WM_RBUTTONUP to the handle of ToolbarWindow32 with the X and Y coordinates, using SendMessage and nothing happens.
I am completely oblivious as to how I can right click the icon, and get the context menu information, and using that, click on one of the options.
After my research there's no way to send a click message to a system tray icon, at least not through any API that I tried. The best way to do it and this is the way I'm following is the following:
You Send the message TB_GETBUTTON to the toolbar.
This will retrieve you an "idCommand" for the button you retrieve so you can use a loop to get all the "idCommand", which is found in the TBBUTTON structure.
With the idComman you can send a message to the toolbar button with the toolbar handle to get the dimensions of the icon with the TB_RECT message.
Once you know the dimensions of the button you just need to get the dimensions of the toolbar which is simple because it's just a window you make a cal to GetWindowRect
Last step is now you want to send the click you make a call to win32api.mouse_event with x being: the left bound of the toolbar + half the width of the icon and y being: the top bound of the toolbar + half the height of the icon. (so you're sending the click to the center).
That's it hope it helps!
I've asked a similar question and answered it here.

How can we capture a mouse event when it's already out of the client area?

I have an application that has a list of buttons and has customized tooltips. Whenever the mouse hovers through the buttons, the tooltips come out and is working fine. However, I want to hide the tooltips when the mouse cursor is outside the client area. How can I tell my application that the mouse is already out of the client area, when the mouse events I have are limited to the client area alone?
Thanks...
You use TrackMouseEvent, this will send you a WM_MOUSELEAVE message when the mouse leaves your window.
Or use GetCapture(), that's what I always do.