analise este codigo por mim

26/12/2005

0

procedure TForm1.Timer3Timer(Sender: TObject);
var
  Flags: dword; 
  X: dword; 
  S: string;
  NotifyIconData : TNotifyIconData;
begin
  X := 0; // este valor deve ser zero senão falha
  if InternetGetConnectedState(@Flags, X) then begin
    S := ´´;
    if (Flags and INTERNET_CONNECTION_MODEM) <> 0  then begin
      S := S + ´via modem ´;
    end;
    Timer1.Enabled := True;
  end
  else begin
    Timer1.Enabled := false;
  end;
   //icone
   Application.ShowMainForm := False;
   with NotifyIconData do begin
   if S <> ´´ then
     begin
       Shell_NotifyIcon(NIM_DELETE,@NotifyIconData); //Pare recirar o icone na bandeja
       cbSize := sizeof(TNotifyIconData);
       Wnd := Self.Handle;
       uId := 0;
       uCallBackMessage := WM_TRAYICON;
       uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
       application.Icon.LoadFromFile(´c:\Alerta\imagem\Sapo.ico´);
       hIcon := Application.Icon.handle;
       szTip := ´GerDow CTT conectado´;
   end
   else
    begin
      //precisa destruio icone e recriar
       Shell_NotifyIcon(NIM_DELETE,@NotifyIconData); //Pare recirar o icone na bandeja
      cbSize := sizeof(TNotifyIconData);
      Wnd := Self.Handle;
      uId := 0;
      uCallBackMessage := WM_TRAYICON;
      uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
      Application.Icon.LoadFromFile(´c:\Alerta\imagem\Sapo1.ico´);
      hIcon := Application.Icon.handle;
      szTip := ´GerDow CTT não conectado´;
   end;
   end;
     Shell_NotifyIcon(NIM_ADD,@NotifyIconData);

end;

Estou fazendo um gerenciador de Dowloand e esta tudo pronto, faço a verificação da conexão e se existe arquivo no servidor, agora preciso fazer uma forma de trocar o icone no tray dependendo se estive conectado ou não na net, fiz este codigo acima, mas fica piscando a barra porque tenho que deleter o icone e recria-lo novamnte, alguem podeira me dar uma dica de fazer isto sem ter que pisca a barra.
quero que fique como o AVG, mudar o icone dependendo do estado de conexão.
agradeço qualquer dica


Dpinho

Dpinho

Responder

Posts

05/01/2006

Dpinho

Alguem pode me ajudar a fazer esta troca, no codigo acima é para meu ftp


Responder

05/01/2006

Michael

Olá!

Li em outro tópico que vc é contra usar componentes de terceiros, correto?

Bom, existe um que resolveria seu problema. É o [b:bf5f4fef08]CoolTrayIcon[/b:bf5f4fef08], o controle mais avançado que eu já encontrei para Delphi para gerenciar ícones na área de notificações do Windows. Vc pode fazer muitas coisas, como animações (algumas pré-definidas), exibir balões indicativos, etc.

Ele é free e open source. Por vir com o código fonte, acho q vc não deve ter problemas em migrá-lo para versões diferentes do Delphi. Eu já o utilizei nas versões 7 e 2005.

Se mesmo assim vc ainda não quiser usá-lo, pelo menos baixe e estude seu código fonte. ;-)

[]´s


Responder

05/01/2006

Emerson Nascimento

faça assim:

procedure TForm1.Timer3Timer(Sender: TObject);
const
  aopcao: array[0..1,0..1] of string = ((´sapo´,´´),(´sapo1´,´não ´));
var
  Flags: dword;
  X: dword;
  S: string;
  NotifyIconData : TNotifyIconData;
  Dica: string;
begin
  Timer1.Enabled := False;

  if InternetGetConnectedState(@Flags, 0) then
  begin
    S := ´´;
    if (flags and INTERNET_CONNECTION_MODEM) =
        INTERNET_CONNECTION_MODEM then
      S := ´via modem ´
    else
    if (flags and INTERNET_CONNECTION_LAN) =
        INTERNET_CONNECTION_LAN then
      S := ´via rede ´
    else
    if (flags and INTERNET_CONNECTION_PROXY) =
        INTERNET_CONNECTION_PROXY then
      S := ´via proxy ´
    else
    if (flags and INTERNET_CONNECTION_MODEM_BUSY) =
        INTERNET_CONNECTION_MODEM_BUSY then
      S := ´modem ocupado ´;

    Timer1.Enabled := True;
  end
  else
    Timer1.Enabled := false;

  //icone
  Application.ShowMainForm := False;
  with NotifyIconData do
  begin
    if teste // S <> ´´
    then X := 0
    else X := 1;

    application.Icon.LoadFromFile(´c:\Alerta\imagem\´+aopcao[X,0]+´.ico´);
    application.mainform.update;

    dica := ´GerDow CTT ´+PChar(aopcao[X,1])+´conectado ´+S;
    StrPCopy(szTip,dica);
    hIcon := Application.Icon.handle;
    cbSize := sizeof(TNotifyIconData);
    Wnd := Self.Handle;
    uId := 0;
    uCallBackMessage := WM_TRAYICON;
    uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;

    Shell_NotifyIcon(NIM_MODIFY,@NotifyIconData);
  end;
end;


e, no OnCreate do form, coloque:
procedure TForm1.FormCreate(Sender: TObject);
var
  NotifyIconData : TNotifyIconData;
begin
  with NotifyIconData do
  begin
    szTip := ´GerDow CTT conectando... ´;
    hIcon := Application.Icon.handle;
    cbSize := sizeof(TNotifyIconData);
    Wnd := Self.Handle;
    uId := 0;
    uCallBackMessage := WM_TRAYICON;
    uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
    Shell_NotifyIcon(NIM_ADD,@NotifyIconData);
  end;
end;



Responder

05/01/2006

Emerson Nascimento

uma pequena correção...

[b:14ed8787e2]onde se lê[/b:14ed8787e2]
    if teste // S <> ´´
    then X := 0
    else X := 1;


[b:14ed8787e2][size=18:14ed8787e2]leia-se[/size:14ed8787e2][/b:14ed8787e2]
    if S <> ´´
    then X := 0
    else X := 1;



Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar