Página 2 de 2

Mensagem BALÃO

Enviado: 26 Ago 2024 22:01
por rochinha
Não entendi.
Qual a diferença?
Aqui continua funcionando, na época era harbour 3.4 agora é harbour 3.2.
Meu Harbour não tem esta win_ShellNotifyIcon()
Harbour Compiler Alpha build 45.0 (Flex)
Copyright 1999-2005, http://www.harbour-project.org/

Mensagem BALÃO

Enviado: 16 Out 2024 13:45
por Fernando queiroz
alguém conseguiu fazer funcionar no windows 11????

Mensagem BALÃO

Enviado: 16 Out 2024 14:03
por rochinha
Amiguinhos,

Este sample me funciona no Windows 10

Código: Selecionar todos

********************************************************************************
*
* https://pctoledo.org/forum/viewtopic.php?f=43&t=26111
*
********************************************************************************
#include "fivewin.ch"
#include "struct.ch"

#define NIM_ADD                       0 // 0x00000000
#define NIM_DELETE                    2 // 0x00000002
#define NIM_MODIFY                    1 // 0x00000001
#define NIF_ICON                      2 // 0x00000002
#define NIF_MESSAGE                   1 // 0x00000001
#define NIF_TIP                       4 // 0x00000004

#define WIN_IMAGE_ICON                1 // 0x00000001
#define WIN_LR_LOADFROMFILE          16 // 0x00000010
#define WIN_NIIF_NONE                 0 // 0x00000000
#define WIN_NIIF_INFO                 1 // 0x00000001
#define WIN_NIIF_WARNING              2 // 0x00000002
#define WIN_NIIF_ERROR                3 // 0x00000003
#define WIN_NIIF_USER                 4 // 0x00000004
#define WIN_NIIF_NOSOUND             16 // 0x00000010
#define WIN_NIIF_LARGE_ICON          32 // 0x00000020
#define WIN_NIIF_RESPECT_QUIET_TIME 128 // 0x00000080
#define WIN_NIIF_ICON_MASK           15 // 0x0000000F

FUNCTION Main()

   MsgBalloon( "Minha mensagem teste", "Titulo" )

   RETURN Nil

Function MsgBalloon( cMessage, cTitle ) 
   ShowNotifyInfo( 0, .F. , NIL, NIL, NIL, NIL ) 
   ShowNotifyInfo( 0, .T. , Nil, Nil, cMessage, cTitle ) 
   Return Nil 

#pragma BEGINDUMP 
	#define _WIN32_IE      0x0500 
	#define HB_OS_WIN_32_USED 
	#define _WIN32_WINNT 0x0400 
	#define HB_OS_WIN_32_USED 
	#define _WIN32_WINNT 0x0400 
	#include <windows.h> 
	#include <commctrl.h> 
	#include <shlobj.h> 
	#include "hbapi.h" 
	#include "hbvm.h" 
	#include "hbstack.h" 
	#include "hbapiitm.h" 
	#define HDIB HANDLE 
	#include "hbapiitm.h" 
	
	extern HANDLE  hb_hInstance;
	static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, LPSTR szInfo, LPSTR szInfoTitle); 
	HB_FUNC ( SHOWNOTIFYINFO ) 
	{ 
		HICON hIcon;
		if ( ISNUM( 3 ) )
		{
			hIcon = LoadIcon( ( HINSTANCE ) hb_hInstance, MAKEINTRESOURCE( hb_parni( 3 ) ) );
		}
		else
		{
			hIcon = ( HICON ) LoadImage( ( HINSTANCE ) NULL, hb_parc( 3 ), IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
		}
	   ShowNotifyInfo( (HWND) hb_parnl(1), (BOOL) hb_parl(2), hIcon , (LPSTR) hb_parc(4), (LPSTR) hb_parc(5), (LPSTR) hb_parc(6) ); 
	} 
	
	static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, 
	LPSTR szInfo, LPSTR szInfoTitle) 
	{ 
	    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        = NIIF_INFO; 
	    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

Mensagem BALÃO

Enviado: 19 Out 2024 08:58
por Fernando queiroz
rochinha escreveu:Amiguinhos,

Este sample me funciona no Windows 10

Código: Selecionar todos

********************************************************************************
*
* https://pctoledo.org/forum/viewtopic.php?f=43&t=26111
*
********************************************************************************
#include "fivewin.ch"
#include "struct.ch"

#define NIM_ADD                       0 // 0x00000000
#define NIM_DELETE                    2 // 0x00000002
#define NIM_MODIFY                    1 // 0x00000001
#define NIF_ICON                      2 // 0x00000002
#define NIF_MESSAGE                   1 // 0x00000001
#define NIF_TIP                       4 // 0x00000004

#define WIN_IMAGE_ICON                1 // 0x00000001
#define WIN_LR_LOADFROMFILE          16 // 0x00000010
#define WIN_NIIF_NONE                 0 // 0x00000000
#define WIN_NIIF_INFO                 1 // 0x00000001
#define WIN_NIIF_WARNING              2 // 0x00000002
#define WIN_NIIF_ERROR                3 // 0x00000003
#define WIN_NIIF_USER                 4 // 0x00000004
#define WIN_NIIF_NOSOUND             16 // 0x00000010
#define WIN_NIIF_LARGE_ICON          32 // 0x00000020
#define WIN_NIIF_RESPECT_QUIET_TIME 128 // 0x00000080
#define WIN_NIIF_ICON_MASK           15 // 0x0000000F

FUNCTION Main()

   MsgBalloon( "Minha mensagem teste", "Titulo" )

   RETURN Nil

Function MsgBalloon( cMessage, cTitle ) 
   ShowNotifyInfo( 0, .F. , NIL, NIL, NIL, NIL ) 
   ShowNotifyInfo( 0, .T. , Nil, Nil, cMessage, cTitle ) 
   Return Nil 

#pragma BEGINDUMP 
	#define _WIN32_IE      0x0500 
	#define HB_OS_WIN_32_USED 
	#define _WIN32_WINNT 0x0400 
	#define HB_OS_WIN_32_USED 
	#define _WIN32_WINNT 0x0400 
	#include <windows.h> 
	#include <commctrl.h> 
	#include <shlobj.h> 
	#include "hbapi.h" 
	#include "hbvm.h" 
	#include "hbstack.h" 
	#include "hbapiitm.h" 
	#define HDIB HANDLE 
	#include "hbapiitm.h" 
	
	extern HANDLE  hb_hInstance;
	static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, LPSTR szInfo, LPSTR szInfoTitle); 
	HB_FUNC ( SHOWNOTIFYINFO ) 
	{ 
		HICON hIcon;
		if ( ISNUM( 3 ) )
		{
			hIcon = LoadIcon( ( HINSTANCE ) hb_hInstance, MAKEINTRESOURCE( hb_parni( 3 ) ) );
		}
		else
		{
			hIcon = ( HICON ) LoadImage( ( HINSTANCE ) NULL, hb_parc( 3 ), IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
		}
	   ShowNotifyInfo( (HWND) hb_parnl(1), (BOOL) hb_parl(2), hIcon , (LPSTR) hb_parc(4), (LPSTR) hb_parc(5), (LPSTR) hb_parc(6) ); 
	} 
	
	static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, 
	LPSTR szInfo, LPSTR szInfoTitle) 
	{ 
	    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        = NIIF_INFO; 
	    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
Rochinha o problema esta no W11 no 8,10 funciona normalmente, no W11 ouve uma mudança e não consigo fazer funcionar pois tem de criar uma tela e não entendi como a coisa funciona

Mensagem BALÃO

Enviado: 20 Out 2024 16:07
por rochinha
Amiguinhos,

Fernando queiroz se possivel reproduza o erro em imagem ou texto e cole para podermos verificar o que é possível fazer para resolver.

Como não tenho o W11 instalado não posso reproduzir.

Mensagem BALÃO

Enviado: 21 Out 2024 10:48
por Fernando queiroz
rochinha escreveu:Amiguinhos,

Fernando queiroz se possivel reproduza o erro em imagem ou texto e cole para podermos verificar o que é possível fazer para resolver.

Como não tenho o W11 instalado não posso reproduzir.
Rochinha não acontece erro , somente nao funciona, o mesmo programa em uma maquina W8, W10 funciona normalmente

Código: Selecionar todos

import os
import sys
import time
import win32api
import win32con
import win32gui_struct
import win32gui

class WindowsBalloonTip:
    def __init__(self, title, msg):
        message_map = {
            win32con.WM_DESTROY: self.on_destroy,
        }
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "PythonBalloonTip"
        wc.lpfnWndProc = message_map
        class_atom = win32gui.RegisterClass(wc)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(
            class_atom,
            "Taskbar",
            style,
            0,
            0,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            0,
            0,
            hinst,
            None,
        )
        hicon_path = os.path.abspath("SGC.ico")
        if not os.path.isfile(hicon_path):
            hicon_path = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
        else:
            hicon_path = win32gui.LoadImage(
                None,
                hicon_path,
                win32con.IMAGE_ICON,
                0,
                0,
                win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE,
            )

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (
            self.hwnd,
            0,
            flags,
            win32con.WM_USER + 20,
            hicon_path,
            "PIX Notification",
        )
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
        win32gui.Shell_NotifyIcon(
            win32gui.NIM_MODIFY,
            (
                self.hwnd,
                0,
                win32gui.NIF_INFO,
                win32con.WM_USER + 20,
                hicon_path,
                "PIX Notification",
                msg,
                200,
                title,
            ),
        )
        time.sleep(10)
        win32gui.DestroyWindow(self.hwnd)
        win32gui.UnregisterClass(class_atom, hinst)

    def on_destroy(self, hwnd, msg, wparam, lparam):
        nid = (self.hwnd, 0)
        win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)

def main():
    aResult = True  # Simulando que há resultado

    if aResult:
        WindowsBalloonTip("Verifique PIX", "PIX aguardando...")

if __name__ == "__main__":
    main()
criei essa rotina em python via chatgpt para o win 11 e vi que ele cria a tal janela, e funciona normalmente, isso foi implementado no win11

Mensagem BALÃO

Enviado: 25 Out 2024 13:26
por SOSSOFT
Muito tempo atrás tentei usar um pedacinho da HMG para fazer isso, funcionou bem, mas não lembro o que eu fiz e não tenho mais cópia.
Usava no modo console.

Mensagem BALÃO

Enviado: 25 Out 2024 23:32
por rochinha
Amiguinhos,

FernandoQueiroz
Fiz uma alteração no código Python para aceitar a passagem de parâmetros interativos, desingessando o código criado para permitir mensagens variadas:

Código: Selecionar todos

def main( titulo, mensagem ):
    aResult = True  # Simulando que há resultado

    if aResult:
        WindowsBalloonTip( titulo, mensagem )

if __name__ == "__main__":
    # main()
    if len(sys.argv) > 1 :
       if len(sys.argv[1]) <= 0:
            print(f"Faltou o titulo do balao.")
       if len(sys.argv[2]) <= 1:
            print(f"Faltou a mensagem do balao.")
       try:
           ballon_title   = sys.argv[1]  # Titulo do balao
           ballon_message = sys.argv[2]  # Mensagem do balao
           main( ballon_title, ballon_message )
       except Exception as e:
           print(f"Erro ocorrido: {str(e)}")
    else:
       print(f"Uso: ballon <titulo do balao> <mensagem do balao>")
       time.sleep(5)
Uso:
python ballon.py "Titulo da notificação" "Mensagem da notificação ao usuário"

Lógico que existe a necessidade de configurar o Windows para que apresente as notificações.

Passos:
Abra Configurações
Clique Sistemas
Clique Notificações e Ações(No menu à esquerda)
Em Obter notificações de aplicativos e outros remetentes - deixe ativado
Mais abaixo
Marque Mostrar notificações na tela de bloqueio
Clique em Configurações de Assistente de foco(No menu à esquerda), abra-o
Marque Desativado(Quando ativado ele esconde as notificações na widget lateral)
Nesta mesma tela em Regras automáticas desmarque todas opções indesejadas.
Complementando deixo um script .PS1 criado via lote de comandos em .BAT que recebe parâmetros e executa o PowerShell instalado na maquina para produzir a notificação.

Notifying.bat

Código: Selecionar todos

:notification
::Syntax is call :notification [Title] [Body] [Icon]
echo notification: %1 %2 %3

echo [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > notfy.ps1
echo $objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon  >> notfy.ps1
echo $objNotifyIcon.Icon = "%3" >> notfy.ps1
echo $objNotifyIcon.BalloonTipIcon = "None"  >> notfy.ps1
echo $objNotifyIcon.BalloonTipText = %2  >> notfy.ps1
echo $objNotifyIcon.BalloonTipTitle = %1 >> notfy.ps1
echo $objNotifyIcon.Visible = $True  >> notfy.ps1
echo $objNotifyIcon.ShowBalloonTip(10000) >> notfy.ps1

Powershell "& ""%cd%\notfy.ps1"""
del /f /q "notfy.ps1"
exit /b
Certifique-se de ter um arquivo .ICO a ser passado como parametro.

Uso:
notifying "Titulo da Notificacao" "Mensagem da notificacao" icon.ico

Mensagem BALÃO

Enviado: 26 Out 2024 22:38
por SOSSOFT
Retificando, usava um misto de console com HMG (onde a parte gráfica por assim dizer era somente na barra de acesso rápido com menu integrado e o balão do Windows).