Balloon Message

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Balloon Message

Post by edk »

Hello, I have a question to Grigory Filatov.
I wanted to use your code to display Balloon Message. I changed it by adding the ability to choose the type of messages: Info | Warning | Error | Custom.
It works correctly under Wndows 10, but on Windows XP crashes at:

Code: Select all

if (stricmp (TEXT (szType), "INFO") == 0 || stricmp (TEXT (szType), "I") == 0)

Code: Select all

Application Internal Error - demo.exe
Terminated at: 2017-02-13 10:19:12
Unrecoverable error 6005: Exception error:

    Exception Code:C0000005 ACCESS_VIOLATION
    Exception Address:77C383B7
    EAX:003F1E49  EBX:77C4F7A0  ECX:00000000  EDX:000001FC
    ESI:005E4081  EDI:00000000  EBP:0022F9F0
    CS:EIP:001B:77C383B7  SS:ESP:0023:0022F9E4
    DS:0023  ES:0023  FS:003B  GS:0000
    Flags:00010206
    Exception Parameters: 00000000 00000000
    CS:EIP: 8A 27 47 38 C4 74 F2 2C 41 3C 1A 1A C9 80 E1 20
    SS:ESP: 77C4F7A0 00000000 00000000 0022FA08 77C3627D 00000000 005E4080 0022FA24 0000001E 00000000 004016C1 00000000 005E4080 00000001 0048B8D4 00DB4BA8

    C stack:
    EIP:     EBP:       Frame: OldEBP, RetAddr, Params...
    77C383B7 0022F9F0   0022FA08 77C3627D 00000000 005E4080 0022FA24 0000001E


Modules:
00400000 0032F000 demo.exe
7C900000 000B1000 C:\WINDOWS\system32\ntdll.dll
7C800000 000FD000 C:\WINDOWS\system32\kernel32.dll
77DC0000 000AC000 C:\WINDOWS\system32\ADVAPI32.dll
77E70000 00092000 C:\WINDOWS\system32\RPCRT4.dll
77FE0000 00011000 C:\WINDOWS\system32\Secur32.dll
773C0000 00103000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\COMCTL32.DLL
77C00000 00058000 C:\WINDOWS\system32\msvcrt.dll
77F10000 00049000 C:\WINDOWS\system32\GDI32.dll
7E360000 00091000 C:\WINDOWS\system32\USER32.dll
77F60000 00076000 C:\WINDOWS\system32\SHLWAPI.dll
76380000 00049000 C:\WINDOWS\system32\COMDLG32.DLL
7C9C0000 0081E000 C:\WINDOWS\system32\SHELL32.dll
76350000 00005000 C:\WINDOWS\system32\MSIMG32.DLL
75B80000 00021000 C:\WINDOWS\system32\MSVFW32.DLL
76B20000 0002E000 C:\WINDOWS\system32\WINMM.dll
774D0000 0013D000 C:\WINDOWS\system32\ole32.dll
77110000 0008B000 C:\WINDOWS\system32\OLEAUT32.dll
72F90000 00026000 C:\WINDOWS\system32\WINSPOOL.DRV
5B1D0000 00038000 C:\WINDOWS\system32\uxtheme.dll

Called from SHOWNOTIFYINFO(0)
Called from MSGBALLOON(38) in demo.prg
Called from MAIN(6) in demo.prg
------------------------------------------------------------------------
I'm not an expert C and I don't know what's going on.

Edward.
Attachments
MsgBalloon.7z
(1.06 MiB) Downloaded 245 times
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Balloon Message

Post by gfilatov »

edk wrote: Mon Feb 13, 2017 9:51 am Hello, I have a question to Grigory Filatov.
I wanted to use your code to display Balloon Message. I changed it by adding the ability to choose the type of messages: Info | Warning | Error | Custom.
I'm not an expert C and I don't know what's going on.
Hello Edward,

Please try the following working sample from HMG EE distribution with supporting of a Notify Icon Infotip flags at 7-th parameter.

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-06 Roberto Lopez <harbourminigui@gmail.com>
 * http://harbourminigui.googlepages.com/
 *
 * Copyright 2007-2013 Grigory Filatov <gfilatov@inbox.ru>
*/

#include "minigui.ch"

#define PROGRAM "MsgBalloon Demo"
#define VERSION " version 1.1"
#define COPYRIGHT " Grigory Filatov, 2007-2013"

#define		IDI_MAIN	1001

*--------------------------------------------------------*
Procedure Main()
*--------------------------------------------------------*

	SET MULTIPLE OFF

	DEFINE WINDOW Form_1 			;
		AT 0,0 				;
		WIDTH 0 HEIGHT 0 		;
		TITLE PROGRAM 			;
		ICON IDI_MAIN			;
		MAIN NOSHOW 			;
		ON INIT Start()	  		;
		NOTIFYICON IDI_MAIN		;
		NOTIFYTOOLTIP PROGRAM

	END WINDOW

	ACTIVATE WINDOW Form_1

Return

*--------------------------------------------------------*
Static Procedure Start()
*--------------------------------------------------------*

	IF IsWinNT()

		MsgBalloon( "Initializing" )
		Inkey(3)

		MsgBalloon( "A long time operation..", "Processing", 2 )
		Inkey(3)

		MsgBalloon( "Quitting.." )
		Inkey(3)

		ActivateNotifyMenu()

	ELSE

		MsgStop( 'This Program Runs In Win2000/XP Only!', 'Stop' )
		Form_1.Release

	ENDIF

Return

// Notify Icon Infotip flags
#define NIIF_NONE       0x00000000
// icon flags are mutualy exclusive
// and take only the lowest 2 bits
#define NIIF_INFO       0x00000001
#define NIIF_WARNING    0x00000002
#define NIIF_ERROR      0x00000003
*--------------------------------------------------------*
Static Procedure MsgBalloon( cMessage, cTitle, nIconIndex )
*--------------------------------------------------------*
	Local i := GetFormIndex( "Form_1" )

	Default cMessage := "Prompt", cTitle := PROGRAM, nIconIndex := NIIF_INFO

	ShowNotifyInfo( _HMG_aFormhandles[i], .F. , NIL, NIL, NIL, NIL, 0 )

	ShowNotifyInfo( _HMG_aFormhandles[i], .T. , ;
		LoadTrayIcon( GetInstance(), _HMG_aFormNotifyIconName[i] ), ;
		_HMG_aFormNotifyIconToolTip[i], cMessage, cTitle, nIconIndex )

Return

*--------------------------------------------------------*
Static Procedure ActivateNotifyMenu()
*--------------------------------------------------------*
	Local i := GetFormIndex( "Form_1" )

	ShowNotifyInfo( _HMG_aFormhandles[i], .F. , NIL, NIL, NIL, NIL, 0 )

	ShowNotifyIcon( _HMG_aFormhandles[i], .T. , LoadTrayIcon( GetInstance(), ;
		_HMG_aFormNotifyIconName[i] ), _HMG_aFormNotifyIconToolTip[i] )

	DEFINE NOTIFY MENU OF Form_1
		ITEM 'A&bout...'	ACTION ShellAbout( "About " + PROGRAM + "#", ;
			PROGRAM + VERSION + CRLF + "Copyright " + Chr(169) + COPYRIGHT, ;
			LoadTrayIcon(GetInstance(), IDI_MAIN) )
		SEPARATOR	
		ITEM 'E&xit'		ACTION Form_1.Release
	END MENU

Return

/*
 * C-level
*/
#pragma BEGINDUMP

#define _WIN32_IE      0x0500
#define _WIN32_WINNT   0x0400

#include <windows.h>
#include "hbapi.h"

static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, LPSTR szInfo, LPSTR szInfoTitle, DWORD nIconIndex);

HB_FUNC ( SHOWNOTIFYINFO )
{
	ShowNotifyInfo( (HWND) hb_parnl(1), (BOOL) hb_parl(2), (HICON) hb_parnl(3), (LPSTR) hb_parc(4), 
			(LPSTR) hb_parc(5), (LPSTR) hb_parc(6), (DWORD) hb_parnl(7) );
}

static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, LPSTR szInfo, LPSTR szInfoTitle, DWORD nIconIndex)
{
	NOTIFYICONDATA nid;

	ZeroMemory( &nid, sizeof(nid) );

	nid.cbSize		= sizeof(NOTIFYICONDATA);
	nid.hIcon		= hIcon;
	nid.hWnd		= hWnd;
	nid.uID			= 0;
	nid.uFlags		= NIF_INFO | NIF_TIP | NIF_ICON;
	nid.dwInfoFlags		= nIconIndex;

	lstrcpy( nid.szTip, TEXT(szText) );
	lstrcpy( nid.szInfo, TEXT(szInfo) );
	lstrcpy( nid.szInfoTitle, TEXT(szInfoTitle) );

	if(bAdd)
		Shell_NotifyIcon( NIM_ADD, &nid );
	else
		Shell_NotifyIcon( NIM_DELETE, &nid );

	if(hIcon)
		DestroyIcon( hIcon );
}

#pragma ENDDUMP
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Balloon Message

Post by edk »

Thanks a lot Grigory.
I have another problem, with the "balloon icon's title"
Have you tried to use the icon in hBalloonIcon Identified as the notification balloon's title icon? Https://msdn.microsoft.com/en-us/librar ... s.85).aspx

If I define nid.hBalloonIcon = hIcon; and nid.dwInfoFlags = NIIF_USER; balloon message does not appear at all.

See: Default icon MsgBalloon and Custom icon MsgBalloon

Code: Select all

#include "hmg.ch"

Procedure Main
_HMG_DefaultIconName:='ZZZ_AAAWINDOW'

MsgBalloon( 'Info message', 'MsgBalloon')
msgbox("Info MsgBalloon")

MsgBalloon( 'Warning message', 'MsgBalloon', 'W')
msgbox("Warning MsgBalloon")

MsgBalloon( 'Error message', 'MsgBalloon', 'E')
msgbox("Error MsgBalloon")

MsgBalloon( 'Default icon', 'MsgBalloon', 'C')
msgbox("Default icon MsgBalloon")

MsgBalloon( 'Custom icon', 'MsgBalloon', 'C', '_DBGICON')
msgbox("Custom icon MsgBalloon")

MsgBalloon( 'Without icon', 'MsgBalloon', 'C', '')
msgbox("Without icon MsgBalloon")

RETURN
 
************************************************************************************
Procedure MsgBalloon( cMessage, cTitle , cTypeMsg, tipIcon, cTip)
************************************************************************
* This part of the code, was copied of TrayBalloon demo avaliable on HMG Extended
* This source was writen by Grigory Filatov
************************************************************************
	Local hWnd := GetActiveWindow(), nFlag
	Default tipIcon := _HMG_DefaultIconName, cTypeMsg :="INFO" 
	Default cMessage := "", cTitle := "", cTip:=""


/* win_ShellNotifyIcon() <nInfoFlags> values */
#define NIIF_NONE                      0x00000000
#define NIIF_INFO                      0x00000001
#define NIIF_WARNING                   0x00000002
#define NIIF_ERROR                     0x00000003
#define NIIF_USER                      0x00000004
	
	DO CASE
		CASE UPPER(cTypeMsg)=="INFO" .OR. UPPER(cTypeMsg)=="I"
			nFlag := NIIF_INFO
		CASE UPPER(cTypeMsg)=="WARNING" .OR. UPPER(cTypeMsg)=="W"
			nFlag := NIIF_WARNING
		CASE UPPER(cTypeMsg)=="ERROR" .OR. UPPER(cTypeMsg)=="E"
			nFlag := NIIF_ERROR
		CASE UPPER(cTypeMsg)=="USER" .OR. UPPER(cTypeMsg)=="U" .OR. UPPER(cTypeMsg)=="CUSTOM" .OR. UPPER(cTypeMsg)=="C"
			nFlag := NIIF_USER
		OTHER
			nFlag := NIIF_NONE
	ENDCASE
	
	ShowNotifyInfo( hWnd, .F. , NIL, NIL, NIL, NIL, 0)
	Millisec(100)
	ShowNotifyInfo( hWnd, .T. , LoadTrayIcon( GetInstance(), tipIcon ),;
				cTip, cMessage, cTitle, nFlag)
	
Return
*************************************************************************************
/*
 * C-level
*/
#pragma BEGINDUMP
#define NTDDI_VERSION NTDDI_VISTA

#define _WIN32_IE      0x0500
#define _WIN32_WINNT   0x0400

#define HB_OS_WIN_32_USED
#include <shlobj.h>

#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"

static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szTip, LPSTR szMessage, LPSTR szTitle, DWORD nFlag);


HB_FUNC ( SHOWNOTIFYINFO )
{
	ShowNotifyInfo( (HWND) hb_parnl(1), (BOOL) hb_parl(2), (HICON) hb_parnl(3), (LPSTR) hb_parc(4), 
			(LPSTR) hb_parc(5), (LPSTR) hb_parc(6), (DWORD) hb_parnl(7));
}

static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szTip, LPSTR szMessage, LPSTR szTitle, DWORD nFlag)
{
	NOTIFYICONDATA nid;
	
	ZeroMemory( &nid, sizeof(nid) );

	nid.cbSize	= sizeof(NOTIFYICONDATA);
	nid.hIcon		= hIcon;
	nid.hWnd		= hWnd;
	nid.uID		= 0;
	nid.uFlags	= NIF_INFO | NIF_TIP | NIF_ICON | NIF_STATE;
	nid.dwInfoFlags = nFlag;
	
	lstrcpy( nid.szTip, TEXT(szTip) );
	lstrcpy( nid.szInfo, TEXT(szMessage) );
	lstrcpy( nid.szInfoTitle, TEXT(szTitle) );
	
	nid.hBalloonIcon = hIcon;
	
	if(bAdd)
		Shell_NotifyIcon( NIM_ADD, &nid );
	else
		Shell_NotifyIcon( NIM_DELETE, &nid );

	if(hIcon)
		DestroyIcon( hIcon );
}

#pragma ENDDUMP
Regards, Edward
Post Reply