Erro ao abrir Dialog GetOpenFileName

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
clodoaldomonteiro
Usuário Nível 4
Usuário Nível 4
Mensagens: 821
Registrado em: 30 Dez 2006 13:17
Localização: Teresina-PI
Contato:

Erro ao abrir Dialog GetOpenFileName

Mensagem por clodoaldomonteiro »

Olá,

Estou tentando usar o Dialog GetOpenFileName para abrir arquivos diversos, .Dat, ZIP e etc., porém quando o sistema chama a função: WVT__GETOPENFILENAME() o sistema simplesmente trava, não dá nem erro ou coisa assim, mostra aquela janela do Windows com duas opções: "Procurar solução" ou "Fechar Programa".

Estou usando o xHarbour 1.2.3 com BCC 7.3.

No arquivo .HBP, coloco a seguinte configuração:

Código: Selecionar todos

SCP21H.PRG
Funcoes_C.PRG
Funcoes_WVW.PRG
Funcoes_XLS.PRG
GetSysG.prg
LIBGASHB.PRG
NFWHPDF.PRG
SCP_Array.PRG
SCP_Menu.PRG
SCP_ATR1.PRG
SCP_ATR2.PRG
SCP_ATR3.PRG
SCP_ATR4.PRG
SCP_ATR5.PRG
SCP_ATR6.PRG
SCP_ATRI.PRG
SCP_ESTACAO.PRG
SCP_ESTRUTURA.PRG
SCP_FUNCOES.PRG
Scp_Funcoes2.PRG
SCP_PROC.PRG
SCP_OUTR.PRG
SCP_Comp.PRG
SCP_SOBR.PRG
Novidade.PRG
Erro.PRG
MNU.PRG

-gtwvt
-gtwvw
-lct
-lhbzip

-workdir=c:\temp\scp21H
-oc:\SimplesInfo\Scp21H\Scp21H
O .BAT de chamada é:

Código: Selecionar todos

@Echo Script Compilação xHarbour com HBMK2, Forum xHarbour Google

SET HB_INSTALL_PREFIX=C:\xBase\xHb123Bcc73
SET HB_COMPILER=bcc
SET HB_COMPILER_VER=0730
SET HBMK_OPTIONS=

SET INCLUDE=C:\xBase\BCC73\include\dinkumware;C:\xBase\BCC73\include\windows\crtl;C:\xBase\BCC73\include\windows\crtl\sys;C:\xBase\BCC73\include\windows\rtl;C:\xBase\BCC73\include\windows\sdk;C:\xBase\BCC73\include\windows\sdk\atl;C:\xBase\BCC73\include\windows\sdk\gl;C:\xBase\BCC73\include\windows\sdk\idl;C:\xBase\xHb123Bcc73\include
SET LIB=C:\xBase\BCC73\lib;C:\xBase\BCC73\lib\psdk;C:\xBase\xHb123Bcc73\lib
SET PATH=C:\xBase\xhb123Bcc73\bin;C:\xBase\BCC73\BIN

C:\xBase\xhb123Bcc73\bin\hbmk2 @scp21.hbp -comp=bcc -xhb 
O sistema é Console, com a Lib GTWVW.

Desde já agradeço a todos.
At. Clodoaldo Monteiro
Linguagens: Clipper / Harbour
Área de Atuação: Sistemas de gestão para Prefeituras Municipais
Fones: (86)3223-0653, 98859-0236
www.simplesinformatica.com.br
Avatar do usuário
clodoaldomonteiro
Usuário Nível 4
Usuário Nível 4
Mensagens: 821
Registrado em: 30 Dez 2006 13:17
Localização: Teresina-PI
Contato:

Erro ao abrir Dialog GetOpenFileName (Resposta)

Mensagem por clodoaldomonteiro »

Consegui resolver o problema do GetOpenFileName, colocando os fontes da What32.lib no sistema, sem fazer a Lib mesmo.

WinCdlg.PRG

Código: Selecionar todos

// WHAT32
// Common Dialog interface
#Define WT_DIALOG     0      // used internally (user custom dialog class - advanced option)
#Include "commdlg.ch"
#Include "winuser.ch"
/*
pragma(4)
#Include "ctruct.ch"
#Include "WinStruc.ch"
*/

// Under development !!!

*-----------------------------------------------------------------------------*

// FindText()
// don't forget to call RegisterWindowMessage(FINDMESSAGESTRING) before calling
// SYNTAX: FinText(<hWnd>,[<hInst>],<nFlags>,<cFindWhat>,[<bAction>]) -> hDlg
// isDialogMessage() will detect this dialog automatically, if called in auto mode

Function FindText( hWnd, hInst, nFlags, cFindWhat, bAction)

   LOCAL nIndex
   LOCAL n
   LOCAL aDialog := _Get_aDialog()
   LOCAL aWindow := _Get_aWindow()
   LOCAL hDlg

   // register the dialog

   If  ( nIndex := aScan( aDialog, { | x | x[ 1 ] == NIL } ) ) == 0
      aAdd( aDialog, { 0, bAction, 1 } )
      nIndex := Len( aDialog )
   Else
      aDialog[ nIndex ] := { 0, bAction, 1 }  // 0 means waiting...
   EndIf                                      // 1 means modal

   // we need to add it here too, to QUIT on the last window !!!
   // note type 0

   If ( n := aScan( aWindow, { | x | x[ 1 ] == NIL } ) ) == 0
      aAdd( aWindow, { 0, WT_DIALOG, { } } )
      n := Len( aWindow )
   Else
      aWindow[ n ] := { 0, WT_DIALOG, { } }  // window 0 means waiting ...
   EndIf

   // create the dialog
   hDlg := _FindText( hWnd, hInst, nFlags, cFindWhat) //, _GetDlgProc( ) )

   If hDlg == 0
      aDialog[ nIndex ] := { NIL , NIL, NIL }
      aWindow[ n ] := { NIL , NIL , { } }
      __KillWindow( )
   EndIf

   Return( hDlg )

   *-----------------------------------------------------------------------------*

   // FindText()
   // don't forget to call RegisterWindowMessage(FINDMESSAGESTRING) before calling
   // SYNTAX: ReplaceText(<hWnd>,[<hInst>],<nFlags>,<cFindWhat>,<cReplaceWith>,[<bAction>]) -> hDlg
   // isDialogMessage() will detect this dialog automatically, if called in auto mode

Function ReplaceText( hWnd, hInst, nFlags, cFindWhat, cReplaceWith, bAction)

   LOCAL n
   LOCAL nIndex
   LOCAL aDialog := _Get_aDialog()
   LOCAL aWindow := _Get_aWindow()
   LOCAL hDlg

   // register the dialog

   If  ( nIndex := aScan( aDialog, { | x | x[ 1 ] == NIL } ) ) == 0
      aAdd( aDialog, { 0, bAction, 1 } )
      nIndex := Len( aDialog )
   Else
      aDialog[ nIndex ] := { 0, bAction, 1 }  // 0 means waiting...
   EndIf                                      // 1 means modal

   // we need to add it here too, to QUIT on the last window !!!
   // note type 0

   If ( n := aScan( aWindow, { | x | x[ 1 ] == NIL } ) ) == 0
      aAdd( aWindow, { 0, WT_DIALOG, { } } )
      n := Len( aWindow )
   Else
      aWindow[ n ] := { 0, WT_DIALOG, { } }  // window 0 means waiting ...
   EndIf

   // create the dialog
   hDlg := _ReplaceText( hWnd, hInst, nFlags, cFindWhat,cReplaceWith ) //, _GetDlgProc( ) )

   // if failed to create
      If hDlg == 0
         aDialog[ nIndex ] := { NIL , NIL, NIL }
         aWindow[ n ] := { NIL , NIL , { } }
         __KillWindow( )
      EndIf

      Return( hDlg )


      *-----------------------------------------------------------------------------*

      /*

      GetOpenFileName( hWnd, @cPath, cTitle, aFilter, nFlags, cInitDir, cDefExt, nIndex)

      hWnd:     Handle to parent window
      cPath:    (optional) if OFN_ALLOWMULTISELECT the path is stored
      cTitle:   Window Title
      aFilter:  Array of Files Types i.e. { {'Data Bases','*.dbf'},{'Clipper','*.prg'} }
      nFlags:   OFN_* values default to OFN_EXPLORER
      cInitDir: Initial directory
      cDefExt:  Default Extension i.e. 'DBF'
      nIndex:   Index position of types

      Returns:  If OFN_ALLOWMULTISELECT
      Array of files selected
   else
      FileName.
   endif


   */

FUNCTION GetOpenFileName( hWnd, cPath, cTitle, aaFilters, nFlags, cIniDir, cDefExt, nIndex )

   LOCAL aFiles, cRet, cFile, x, aFilter, cFilter := "", cItem, nAt, cChar

   IF cPath == NIL
      cPath := ""
   ENDIF

   IF ValType( aaFilters ) == "A"
      FOR EACH aFilter IN aaFilters
         cFilter += aFilter[1] + Chr(0) + aFilter[2] + Chr(0)
      NEXT
   ENDIF

   IF AND(nFlags,OFN_ALLOWMULTISELECT ) > 0
      cFile := Space( 32000 )
   ELSE
      cFile := Padr( Trim( cPath ), 256, Chr(0) )
   ENDIF

   cRet := _GetOpenFileName( hWnd, @cFile, cTitle, cFilter, nFlags, cIniDir, cDefExt, @nIndex )

   IF AND( nFlags, OFN_ALLOWMULTISELECT ) > 0
      nAt := At( Chr(0) + Chr(0), cFile )

      cFile := Left( cFile, nAt )
      aFiles := {}

      IF nAt == 0 // no double chr(0) user must have pressed cancel
         RETURN( aFiles )
      ENDIF

      x := At( Chr(0), cFile ) // fist null
      cPath := Left( cFile, x )

      cFile := StrTran( cFile, cPath, "" )

      IF ! Empty(cFile) // user selected more than 1 file
         cItem := ""

         FOR EACH cChar IN cFile
            IF cChar == 0
               aAdd( aFiles, StrTran( cPath, Chr(0), "" ) + '\' + cItem )
               cItem := ""
               LOOP
            ENDIF

            cItem += cChar
         NEXT
      ELSE
         /*
         cFile:=cPath
         x:=RAT('\',cFile)
         cPath:=LEFT(cFile,x-1)
         */
         aFiles := { StrTran( cPath, CHR(0), "" ) } //STRTRAN(STRTRAN(cFile,cPath),'\')}
      ENDIF

      Return( aFiles )
   ELSE
      //cRet := Left( cRet, At( chr(0), cRet ) -1 )
   ENDIF

   RETURN cRet



   *-----------------------------------------------------------------------------*

   /*
   GetSaveFileName( hWnd, cFile, cTitle, aFilter, nFlags, cInitDir, cDefExt, nIndex)

   hWnd:     Handle to parent window
   cFile:    (optional) Default FileName
   cTitle:   Window Title
   aFilter:  Array of Files Types i.e. { {'Data Bases','*.dbf'},{'Clipper','*.prg'} }
   nFlags:   OFN_* values default to OFN_EXPLORER
   cInitDir: Initial directory
   cDefExt:  Default Extension i.e. 'DBF'
   nIndex:   Index position of types

   Returns:  FileName.
   */


FUNCTION GetSaveFileName(hWnd, cFile, cTitle, aFilter, nFlags, cIniDir, cDefExt, nIndex )
   local n,c:=''
   IF aFilter==nil
      aFilter:={}
   END
   FOR n:=1 TO LEN(aFilter)
      c+=aFilter[n][1]+chr(0)+aFilter[n][2]+chr(0)
   NEXT
   cFile:=_GetSaveFileName(hWnd, cFile, cTitle, c, nFlags, cIniDir, cDefExt, @nIndex )
   Return(cFile)


////////////////////////////////////////////////////////////////////////////////
//Outros funcoes
*-----------------------------------------------------------------------------*
// internal to access setting dialog procedures as codeblocks
// for external/common dialogs.

FUNCTION _Get_aDialog()

  RETURN(aDialog)

*-----------------------------------------------------------------------------*
// internal to access setting window procedures as codeblocks
// for external/common dialogs.

FUNCTION _Get_aWindow()

  RETURN(aWindow)

*-----------------------------------------------------------------------------*

   // must be called on WM_NCDESTROY, which is irreversable !
   // but only after processing our codeblock chain

Function __KillWindow( hWnd )

   Local n

   If hWnd <> NIL .AND. ( n := aScan( aWindow, { | x | hWnd == x[ 1 ] } ) ) > 0
      aWindow[ n ] := { NIL, NIL, { } }
   EndIf

   If aScan( aWindow, { | x | ! Empty( x[ 1 ] ) } ) == 0
      PostQuitMessage( 0 )
   EndIf

   Return( NIL )

_Wincldg.C

Código: Selecionar todos

// WHAT32

// Common dialogs





#define _WIN32_WINNT   0x0400

#include <windows.h>
#include <shlobj.h>
//#include <commdlg.h>

#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"

//extern __DlgProc ;

/*
(HWND) hdlg,      // handle to the dialog box window
                         (UINT) uiMsg      // message identifier
                         (WPARAM) wParam,  // message parameter
                         (LPARAM) lParam   // message parameter
                        );

*/
//----------------------------------------------------------------------------
// DWORD CommDlgExtendedError(VOID)

HB_FUNC( COMMDLGEXTENDEDERROR )
{
  hb_retnl( CommDlgExtendedError() ) ;
}

//---------------------------------------------------------------------

//Syntax: ChooseFont( cf:value) -> structure buffer, or NIL

HB_FUNC( CHOOSEFONT )
{
  CHOOSEFONT *cf =  (CHOOSEFONT * ) hb_param( 1, HB_IT_STRING )->item.asString.value;

  cf->lStructSize = sizeof(CHOOSEFONT);

  if (ChooseFont( cf ) )
      hb_retclen( (char *) cf, sizeof( CHOOSEFONT )) ;
}

//----------------------------------------------------------------------------

// to be called called via FindText (in WinCDlg.Prg)

HB_FUNC( _FINDTEXT )
{
   FINDREPLACE fr ;

   fr.lStructSize = sizeof( fr );

   fr.hwndOwner        = (HWND) hb_parnl( 1 ) ;
   fr.hInstance        = (HINSTANCE) hb_parnl( 2 ) ;
   fr.Flags            = (DWORD)  hb_parnl( 3 ) ;
   fr.lpstrFindWhat    = (LPTSTR) hb_parcx( 4 ) ;
   fr.lpstrReplaceWith = NULL ;
   fr.wFindWhatLen     = (WORD) hb_parclen(4) ;
   fr.wReplaceWithLen  = 0 ;
   fr.lCustData        = 0 ;
//   fr.lpfnHook         = ISNIL(5) ? NULL : __DlgProc ;
   fr.lpTemplateName   = NULL ;


   hb_retnl( (LONG) FindText( &fr ) ) ;
}

//----------------------------------------------------------------------------

// to be called called via FindText (in WinCDlg.Prg)

HB_FUNC( _REPLACETEXT )
{
   FINDREPLACE fr ;

   fr.lStructSize = sizeof( fr );

   fr.hwndOwner        = (HWND) hb_parnl( 1 ) ;
   fr.hInstance        = (HINSTANCE) hb_parnl( 2 ) ;
   fr.Flags            = (DWORD)  hb_parnl( 3 ) ;
   fr.lpstrFindWhat    = (LPTSTR) hb_parcx( 4 )  ;
   fr.lpstrReplaceWith = (LPTSTR) hb_parcx( 5 )  ;
   fr.wFindWhatLen     = (WORD) hb_parclen( 4 ) ;
   fr.wReplaceWithLen  = (WORD) hb_parclen( 5 ) ;
   fr.lCustData        = 0 ;
//   fr.lpfnHook         = ISNIL(5) ? NULL : __DlgProc ;
   fr.lpTemplateName   = NULL ;

   hb_retnl( (LONG) FindText( &fr ) ) ;
}


//----------------------------------------------------------------------------

HB_FUNC( PRINTDLG )
{

   PRINTDLG *pd  = ( PRINTDLG * ) hb_param( 1, HB_IT_STRING )->item.asString.value;

   pd->lStructSize = sizeof(PRINTDLG);

   if ( PrintDlg( pd ) )
   {
      hb_storclen( (char*) pd, sizeof(PRINTDLG), 1 );
      hb_retl(TRUE);
   }
   else
     hb_retl(FALSE);
}

//----------------------------------------------------------------------------

//NT

/*
HB_FUNC( PRINTDLGEX )
{

   PRINTDLGEX *pd  = ( PRINTDLGEX * ) hb_param( 1, HB_IT_STRING )->item.asString.value;

   pd->lStructSize = sizeof(PRINTDLGEX);

   if ( PrintDlgEx( pd ) )
   {
      hb_storclen( (char*) pd, sizeof(PRINTDLGEX), 1 );
      hb_retl(TRUE);
   }
   else
     hb_retl(FALSE);
}
*/

//----------------------------------------------------------------------------

HB_FUNC( PAGESETUPDLG )
{

   PAGESETUPDLG *psd = (PAGESETUPDLG * ) hb_param( 1, HB_IT_STRING )->item.asString.value;

   psd->lStructSize = sizeof(PAGESETUPDLG);

   if ( PageSetupDlg( psd ) )
   {
      hb_storclen( (char*) psd, sizeof(PAGESETUPDLG), 1 );
      hb_retl(TRUE);
   }
   else
     hb_retl(FALSE);

}


//----------------------------------------------------------------------------

// nColor := ChooseColor( [hParentWnd],[nInitColor],[aCustColors[16]],[nFlags])

HB_FUNC( CHOOSECOLOR )
{
   CHOOSECOLOR cc ;
   COLORREF crCustClr[16] ;
   int i ;

   for( i = 0 ; i <16 ; i++ )
     crCustClr[i] = (ISARRAY(3) ? hb_parnl(3,i+1) : RGB(0,0,0)) ;// GetSysColor(COLOR_BTNFACE)) ;

   cc.lStructSize    = sizeof( CHOOSECOLOR ) ;
   cc.hwndOwner      = ISNIL(1) ? GetActiveWindow():(HWND) hb_parnl(1) ;
   cc.rgbResult      = (COLORREF)ISNIL(2) ?  0 : hb_parnl(2) ;
   cc.lpCustColors   = crCustClr ;
   cc.Flags          = (WORD) (ISNIL(4) ? CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT : hb_parnl(4) ) ;
   if ( ChooseColorA( &cc ) )
      hb_retnl( cc.rgbResult );

}


//----------------------------------------------------------------------------

// to be called via GetOpenFileName in WinCDlg.Prg

HB_FUNC( _GETOPENFILENAME )
{
   OPENFILENAME ofn;
   char *szFileName =(char*) hb_xgrab( hb_parcsiz(2));

   strcpy( szFileName, hb_parcx( 2 ) );

   ZeroMemory( &ofn, sizeof(ofn) );
   ofn.hInstance       = GetModuleHandle(NULL)  ;
   ofn.lStructSize     = sizeof(ofn);
   ofn.hwndOwner       = (ISNIL  (1) ? GetActiveWindow() : (HWND) hb_parnl(1));
   ofn.lpstrTitle      = hb_parc (3);
   ofn.lpstrFilter     = hb_parc (4);
   ofn.Flags           = (ISNIL  (5) ? OFN_EXPLORER : hb_parnl(5) );
   ofn.lpstrInitialDir = hb_parc (6);
   ofn.lpstrDefExt     = hb_parc (7);
   ofn.nFilterIndex    = hb_parni(8);
   ofn.lpstrFile       = szFileName;
   ofn.nMaxFile        = hb_parcsiz(2);

   if( GetOpenFileName( &ofn ) )
   {
      hb_stornl( ofn.nFilterIndex, 8 );
      hb_storclen( szFileName, hb_parcsiz(2), 2 ) ;
      hb_xfree( szFileName );
      hb_retc( ( char * ) ofn.lpstrFile );
   }
   else
   {
      hb_retc( "" );
   }
}



//----------------------------------------------------------------------------

// to be called via GetSaveFileName in WinCDlg.Prg

HB_FUNC( _GETSAVEFILENAME )
{
    OPENFILENAME ofn;
    char szFileName[MAX_PATH+1] ;
    strcpy( szFileName, hb_parc (2) );
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.hInstance       = GetModuleHandle(NULL)  ;
    ofn.lStructSize     = sizeof(ofn);
    ofn.hwndOwner       = ISNIL   (1)  ? GetActiveWindow() : (HWND) hb_parnl(1);
    ofn.lpstrTitle      = hb_parc (3);
    ofn.lpstrFilter     = hb_parc (4);
    ofn.Flags           = (ISNIL  (5) ? OFN_FILEMUSTEXIST|OFN_EXPLORER : hb_parnl(4) );
    ofn.lpstrInitialDir = hb_parc (6);
    ofn.lpstrDefExt     = hb_parc (7);
    ofn.nFilterIndex    = hb_parni(8);
    ofn.lpstrFile       = szFileName;
    ofn.nMaxFile        = MAX_PATH;
    if(GetSaveFileName(&ofn))
     {
      hb_stornl(ofn.nFilterIndex , 8 );
      hb_retc( ofn.lpstrFile );
     }
    else
     {
      hb_retc( "" );
   }
}


//----------------------------------------------------------------------------

//SYNTAX: SHBrowseForFolder([<hWnd>],[<cTitle>],<nFlags>,[<nFolderType>])

HB_FUNC( SHBROWSEFORFOLDER )
{
   HWND hwnd = ISNIL   (1)  ? GetActiveWindow() : (HWND) hb_parnl(1);
   BROWSEINFO BrowseInfo;
   char *lpBuffer = (char*) hb_xgrab( MAX_PATH + 1 );
   LPITEMIDLIST pidlBrowse;

   SHGetSpecialFolderLocation(hwnd, ISNIL(4) ? CSIDL_DRIVES : hb_parni(4), &pidlBrowse) ;
   BrowseInfo.hwndOwner = hwnd;
   BrowseInfo.pidlRoot = pidlBrowse;
   BrowseInfo.pszDisplayName = lpBuffer;
   BrowseInfo.lpszTitle = ISNIL (2) ?  "Select a Folder" : hb_parcx(2);
   BrowseInfo.ulFlags = hb_parni(3);
   BrowseInfo.lpfn = NULL;
   BrowseInfo.lParam = 1;
   BrowseInfo.iImage = 0;
   pidlBrowse = SHBrowseForFolder(&BrowseInfo);

   if ( pidlBrowse )
   {
     SHGetPathFromIDList(pidlBrowse,lpBuffer);
     hb_retc( lpBuffer );
   }
   else
   {
     hb_retc( "" );
   }

   hb_xfree( lpBuffer);
}

////////////////////////////////////////////////////////////////////////////////
//Outras Funções
//-------------------------------------------------------------------//

HB_FUNC( AND )
{
  hb_retnl( hb_parnl(1) & hb_parnl(2) ) ;
}

//-----------------------------------------------------------------------------

HB_FUNC( POSTQUITMESSAGE )
{
  PostQuitMessage(hb_parni(1));
}

Fica pra registro.
T+
At. Clodoaldo Monteiro
Linguagens: Clipper / Harbour
Área de Atuação: Sistemas de gestão para Prefeituras Municipais
Fones: (86)3223-0653, 98859-0236
www.simplesinformatica.com.br
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Erro ao abrir Dialog GetOpenFileName

Mensagem por JoséQuintas »

Só um comentário sobre a formatação de cores do fonte, pelo fórum:
a formatação de cores está se perdendo nas aspas simples.
Começou na palavra don't, e a partir daí, parece que considerou string entre uma aspa simples e outra, mesmo em linhas diferentes.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder