Página 1 de 1

HWG_MessageBoxTimeOut

Enviado: 07 Out 2013 10:27
por asimoes
HWG_MessageBoxTimeOut (Caixa de Mensagem com TimeOut)

Aproveitando a contribuição do Dr. Claudio Soto para a MiniGui, fiz a adaptação para HWGui.

Código: Selecionar todos

Exemplo de uso:

   nTypeButton:=MB_YESNO + MB_SYSTEMMODAL + MB_DEFBUTTON2
   
   nRet:=HWG_MessageBoxTimeout("Iniciar o processo ? ", "Atenção!", nTypeButton, 30000) // Aguarda 30 segundos.

   IF nRet # 6 // Resultado diferente de Sim ou o que vier do timeout.
      QUIT
   ENDIF

Código: Selecionar todos

#pragma BEGINDUMP

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


int WINAPI MessageBoxTimeout(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds) 
{
   typedef BOOL (WINAPI *PMessageBoxTimeout)(HWND,LPCTSTR,LPCTSTR,UINT,WORD,DWORD);
   static PMessageBoxTimeout pMessageBoxTimeout = NULL;
   if (pMessageBoxTimeout == NULL) 
   {
      HMODULE hLib = LoadLibrary ("User32.dll");
      #ifdef UNICODE
         pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(hLib, "MessageBoxTimeoutW");
      #else
         pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(hLib, "MessageBoxTimeoutA");
      #endif
   }
   if(pMessageBoxTimeout == NULL)
      return FALSE;
   return pMessageBoxTimeout(hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds);
}


//       HMG_MessageBoxTimeout (Text, Caption, nTypeButton, nMilliseconds) ---> Return iRetButton
HB_FUNC (HWG_MESSAGEBOXTIMEOUT)
{
   HWND  hWnd           = GetActiveWindow();
   TCHAR *lpText        = hb_parc (1);
   TCHAR *lpCaption     = hb_parc (2);
   UINT  uType          = HB_ISNIL(3) ? MB_OK : (UINT) hb_parnl (3);
   WORD  wLanguageId    = MAKELANGID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
   DWORD dwMilliseconds = HB_ISNIL(4) ? (DWORD)0xFFFFFFFF  : (DWORD) hb_parnl (4);
   int iRet = MessageBoxTimeout (hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds);
   hb_retni ((int) iRet);
}

#pragma ENDDUMP

HWG_MessageBoxTimeOut

Enviado: 11 Out 2013 06:59
por asimoes
Não funciona no WINDOWS XP (desabilitar os botões minimizar e maximizar)

No Windows 7 funcionou.

MSDN:

http://social.msdn.microsoft.com/Forums ... =vbgeneral

In addition, please read the article PRB: Cannot Remove Minimize or Maximize Button from Caption Bar

HWG_MessageBoxTimeOut

Enviado: 11 Out 2013 09:28
por asimoes
Não desiti, o comando para desabilitar os botões inclusive o X da janela:
DisableSysMenu(oMainWindow:handle,SC_CLOSE) // DESABILITOU O X DA JANELA
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_MAXIMIZEBOX,.T.) //DESABILITOU O MAXIMIZAR
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_MINIMIZEBOX,.T.) //DESABILITOU O MAXIMIZAR E MINIMIZAR
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_SIZEBOX,.T.) //DESABILITOU O SIZEBOX
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_SYSMENU,.T.) //DESABILITA TODO CONTROLE DA JANELA

Código: Selecionar todos

HB_FUNC ( _CONTROLPOS_C_SETSTYLE_ )
{
  LONG Style = GetWindowLong( (HWND) hb_parnl(1), GWL_STYLE );
  int menuItemCount;
   if (hb_parl(3))
   {
    SetWindowLong( (HWND) hb_parnl(1), GWL_STYLE, Style & (~hb_parni(2)) );
    hb_retni( 2 );
   }
}

HWG_MessageBoxTimeOut

Enviado: 11 Out 2013 10:06
por asimoes
Habilitar e desabilitar o controle:

_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_MAXIMIZEBOX,.F.) //Desabilitar o maximizar da janela
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_MAXIMIZEBOX,.T.) //Habilitar o maximizar da janela

Código: Selecionar todos

HB_FUNC ( _CONTROLPOS_C_SETSTYLE_ )
{
  LONG Style = GetWindowLong( (HWND) hb_parnl(1), GWL_STYLE );
  int menuItemCount;
   if (hb_parl(3))
   {
    SetWindowLong( (HWND) hb_parnl(1), GWL_STYLE, Style & (~hb_parni(2)) );
    hb_retni( 1 );
   }
   else
   {
    SetWindowLong( (HWND) hb_parnl(1), GWL_STYLE, Style | (hb_parni(2)) );
    hb_retni( 2 );   
   }
}

HWG_MessageBoxTimeOut

Enviado: 11 Out 2013 10:18
por Toledo
Alexandre, fantásticas estas funções... obrigado por compartilhar!

Abraços,

HWG_MessageBoxTimeOut

Enviado: 11 Out 2013 10:20
por asimoes
Acho que agora ficou completo:

DesabilitarX(oMainWindow:handle,.T.) //DESABILITOU O X DA JANELA
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_MAXIMIZEBOX,.T.) //DESABILITOU O MAXIMIZAR
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_SIZEBOX,.T.) //DESABILITOU O SIZEBOX

DesabilitarX(oMainWindow:handle,.F.) //HABILITOU O X DA JANELA
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_MAXIMIZEBOX,.F.) //HABILITOU O MAXIMIZAR
_CONTROLPOS_C_SETSTYLE_(oMainWindow:handle,WS_SIZEBOX,.F.) //HABILITOU O SIZEBOX

Código: Selecionar todos

HB_FUNC( DESABILITARX )
{
   if (hb_parl(2))
   {
    SetClassLong(( HWND ) hb_parnl( 1 ), GCL_STYLE,
                 GetClassLong(( HWND ) hb_parnl( 1 ), GCL_STYLE) | CS_NOCLOSE);
   }
   else
   {
    SetClassLong(( HWND ) hb_parnl( 1 ), GCL_STYLE,
              GetClassLong(( HWND ) hb_parnl( 1 ), GCL_STYLE) & ~ CS_NOCLOSE);
   }
}

HWG_MessageBoxTimeOut

Enviado: 11 Out 2013 11:53
por asimoes
A outra função DESABILITARX , embora desabilite o X da janela , mas não inibi o Alt-F4, a função abaixo desabilita ambos.

DesabilitarX2(oMainWindow:handle,.T.) //Desabilita
DesabilitarX2(oMainWindow:handle,.F.) //Habilita

Código: Selecionar todos

HB_FUNC( DESABILITARX2 )
{
   if (hb_parl(2))
   {
    EnableMenuItem(GetSystemMenu(( HWND ) hb_parnl( 1 ), FALSE), SC_CLOSE,
                   MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
   }
   else
   {
    EnableMenuItem(GetSystemMenu(( HWND ) hb_parnl( 1 ), TRUE), SC_CLOSE,
                   MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);   
   }
}