Clipper On Line • Ver Tópico - OpenDialog - Como abrir a janela do windows para selec...?
Mudar para estilo Clássico
Discussão sobre a biblioteca Fivewin - O Clipper para Windows.
Postar uma resposta

OpenDialog - Como abrir a janela do windows para selec...?

12 Ago 2015 10:55

Pessoal,como faço para abrir aquela janela do windows para selecionar um arquivo?
vou mandar um print para melhor entendimento
Anexos
abrirarq.jpg
Editado pela última vez por Toledo em 16 Ago 2015 19:01, num total de 1 vezes
Razão: O presente tópico foi movido da seção Harbour, uma vez que seu conteúdo não tem relação com os objetivos daquela seção, onde só podem constar dúvidas técnicas de programação diretamente relacionadas com o [x]Harbour.

OpenDialog - Como abrir a janela do windows para selec...?

12 Ago 2015 11:15

Código:
#include 'fivewin.ch'

#define OFN_PATHMUSTEXIST            0x00000800
#define OFN_NOCHANGEDIR              0x00000008
#define OFN_ALLOWMULTISELECT         0x00000200
#define OFN_EXPLORER                 0x00080000     // new look commdlg
#define OFN_LONGNAMES                0x00200000     // force long names for 3.x modules
#define OFN_ENABLESIZING             0x00800000
#define OFN_HIDEREADONLY             0x00000004     // Oculta a caixa de seleção Somente leitura.
#define OFN_NONETWORKBUTTON          0x20000        // Desabilita o botão [ REDE ] da Dlg

function aGetFiles( cMask, cTitle, nDefaultMask, cInitDir )

   local cSelect, nAt, aFiles := {}
   /*
   local nFlags   := nOr( OFN_PATHMUSTEXIST , OFN_NOCHANGEDIR , ;
                     OFN_ALLOWMULTISELECT , OFN_EXPLORER , ;
                     OFN_LONGNAMES, OFN_ALLOWMULTISELECT )
   */
   local nFlags   := nOr( OFN_PATHMUSTEXIST, OFN_NOCHANGEDIR, OFN_ALLOWMULTISELECT, ;
                          OFN_LONGNAMES, OFN_NONETWORKBUTTON )

   SKINBUTTONS()

   //cSelect  := cGetFile( cMask, cTitle, nDefaultMask, cInitDir, .f., .t., nFlags )
   cSelect := cGetFile( "Bitmap (*.bmp)| *.bmp|"+      ;
                        "DIB   (*.dib)| *.dib|" +      ;
                        "PCX   (*.pcx)| *.pcx|" +      ;
                        "JPEG  (*.jpg)| *.jpg|" +      ;
                        "GIF   (*.gif)| *.gif|" +      ;
                        "TARGA (*.tga)| *.tga|" +      ;
                        "RLE   (*.rle)| *.rle|" +      ;
                        "Todos os Arquivos (*.*)|*.*|" ;
                        ,"Selecione a Foto Desejada",1,,.F.,, nFlags )

   cSelect  := Left( cSelect, At( Chr( 0 ) + Chr( 0 ), cSelect ) - 1 )

   if ! Empty( cSelect )
      cSelect  := StrTran( cSelect, Chr( 0 ), "," )
      aFiles  := hb_aTokens( cSelect, "," )
      if Len( aFiles ) > 1
         for nAt := 2 TO Len( aFiles )
            aFiles[ nAt ] := aFiles[ 1 ] + "\" + aFiles[ nAt ]
         next nAt
         ADel( aFiles, 1 )
         ASize( aFiles, Len( aFiles ) - 1 )
      endif
   endif

return aFiles



OpenDialog - Como abrir a janela do windows para selec...?

12 Ago 2015 11:18

Inclua este código no seu aplicativo.

D:\TEMP_FIN = pasta inicial para procura, informe a que desejar, ou deixe em branco para iniciar a partir do da pasta raiz do so.

cFolder:=HBG_GETFOLDER(Nil,"Informe o destino (Pasta padrão: D:\TEMP_FIN)",Nil,Nil,"D:\TEMP_FIN")

Código:
#pragma BEGINDUMP

#define _WIN32_WINNT   0x0400
#include <windows.h>
#include "hbapi.h"
#include <commdlg.h>
#include <shlobj.h>
#include <commctrl.h>
#include "hbapi.h"

HB_FUNC ( HBG_PUTFILE )
{
    OPENFILENAME ofn;
    char buffer[512];

    int flags = OFN_FILEMUSTEXIST | OFN_EXPLORER ;

    if ( hb_parl(4) )
    {
        flags = flags | OFN_NOCHANGEDIR ;
    }

    strcpy( buffer, "" );

    memset( (void*) &ofn, 0, sizeof( OPENFILENAME ) );
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = GetActiveWindow() ;
    ofn.lpstrFilter = hb_parc(1) ;
    ofn.lpstrFile = buffer;
    ofn.nMaxFile = 512;
    ofn.lpstrInitialDir = hb_parc(3);
    ofn.nFilterIndex    = hb_parni(5);
    ofn.lpstrTitle = hb_parc(2) ;
    ofn.Flags = flags;

    if( GetSaveFileName( &ofn ) )
    {
        hb_stornl(ofn.nFilterIndex, 5 );
        hb_retc( ofn.lpstrFile );
    }
    else
    {
        hb_retc( "" );
    }
}

int CALLBACK BrowseCallbackProc( HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData )
{
   TCHAR szPath[ MAX_PATH ];

   switch( uMsg )
   {
      case BFFM_INITIALIZED:  if( lpData )
            SendMessage( hWnd, BFFM_SETSELECTION, TRUE, lpData );
         break;
      case BFFM_SELCHANGED:   SHGetPathFromIDList( ( LPITEMIDLIST ) lParam, szPath ); SendMessage( hWnd, BFFM_SETSTATUSTEXT, 0, ( LPARAM ) szPath );
   }

   return 0;
}

HB_FUNC( HBG_GETFOLDER )  // Syntax: C_BROWSEFORFOLDER([<hWnd>],[<cTitle>],[<nFlags>],[<nFolderType>],[<cInitPath>])
{
   HWND         hWnd = HB_ISNIL( 1 ) ? GetActiveWindow() : ( HWND ) hb_parnl( 1 );
   BROWSEINFO   BrowseInfo;
   char *       lpBuffer = ( char * ) hb_xgrab( MAX_PATH + 1 );
   LPITEMIDLIST pidlBrowse;

   SHGetSpecialFolderLocation( hWnd, HB_ISNIL( 4 ) ? CSIDL_DRIVES : hb_parni( 4 ), &pidlBrowse );

   BrowseInfo.hwndOwner      = hWnd;
   BrowseInfo.pidlRoot       = pidlBrowse;
   BrowseInfo.pszDisplayName = lpBuffer;
   BrowseInfo.lpszTitle      = HB_ISNIL( 2 ) ? "Select a Folder" : hb_parc( 2 );
   BrowseInfo.ulFlags        = HB_ISCHAR( 5 ) ? BIF_STATUSTEXT : hb_parni( 3 );
   BrowseInfo.lpfn   = HB_ISCHAR( 5 ) ? BrowseCallbackProc : NULL;
   BrowseInfo.lParam = HB_ISCHAR( 5 ) ? ( LPARAM ) ( char * ) hb_parc( 5 ) : 0;
   BrowseInfo.iImage = 0;

   pidlBrowse = SHBrowseForFolder( &BrowseInfo );

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

   hb_xfree( lpBuffer );
}

#pragma ENDDUMP

OpenDialog - Como abrir a janela do windows para selec...?

12 Ago 2015 15:31

asimoes escreveu:Inclua este código no seu aplicativo

A função do colega funcionou certinho com harbour 3.2. Asimões, sabe se o harbour 3.2 tem essa função nativamente?

Ate+

OpenDialog - Como abrir a janela do windows para selec...?

12 Ago 2015 18:35

Andril,

Essa função foi copiada da minigui.
O harbour não tem essa função no seu projeto.

OpenDialog - Como abrir a janela do windows para selec...?

12 Ago 2015 20:34

Seleção de arquivos:

* Seleção multipla
a := Getfile ( { {'All Files','*.*'} } , 'Open File(s)' , HB_DirBase() , .t. , .t. )
msginfo(VALTOPRG(a))

* Seleção simples

cFile:=Getfile ( , 'Open a File' , , , .t. )
msginfo(cFile)

Função GetFile
Código:
*-----------------------------------------------------------------------------*
FUNCTION GetFile( aFilter, title, cIniFolder, multiselect, lNoChangeCurDir, nFilterIndex )
*-----------------------------------------------------------------------------*
   LOCAL fileslist:={}
   LOCAL cFilter:=""
   LOCAL n, files

   hb_default( @multiselect, .F. )
   hb_default( @nFilterIndex, 1 )

   IF HB_ISARRAY( aFilter )
      AEval( aFilter, { | x | cFilter += x[1] + Chr( 0 ) + x[2] + Chr( 0 ) } )
      cFilter += Chr( 0 )
   ENDIF

   files := HBG_SelectFile( cFilter, title, cIniFolder, multiselect, lNoChangeCurDir, nFilterIndex )

   IF multiselect
      IF Len( files ) > 0
         IF ValType( files ) == "A"
            FOR n := 1 TO Len( files )
               IF At( "\\", files[n] ) > 0 .AND. Left( files[n], 2 ) != "\\"
                  files[n] := StrTran( files[n] , "\\", "\" )
               ENDIF
            NEXT
            fileslist := AClone( files )
         ELSE
            AAdd( fileslist, files )
         ENDIF
      ENDIF
   ELSE
      fileslist := files
   ENDIF

RETURN ( fileslist )


Código:
#pragma BEGINDUMP

#define _WIN32_WINNT   0x0400
#include <windows.h>
#include "hbapi.h"
#include <commdlg.h>
#include <shlobj.h>
#include <commctrl.h>
#include "hbapi.h"

#define HB_PARNL( n, x )      hb_parvnl( n, x )
#define HB_STORC( n, x, y )   hb_storvc( n, x, y )
#define HB_STORL( n, x, y )   hb_storvl( n, x, y )
#define HB_STORNI( n, x, y )  hb_storvni( n, x, y )
#define HB_STORNL( n, x, y )  hb_storvnl( n, x, y )

HB_FUNC ( HBG_PUTFILE )
{
    OPENFILENAME ofn;
    char buffer[512];

    int flags = OFN_FILEMUSTEXIST | OFN_EXPLORER ;

    if ( hb_parl(4) )
    {
        flags = flags | OFN_NOCHANGEDIR ;
    }

    strcpy( buffer, "" );

    memset( (void*) &ofn, 0, sizeof( OPENFILENAME ) );
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = GetActiveWindow() ;
    ofn.lpstrFilter = hb_parc(1) ;
    ofn.lpstrFile = buffer;
    ofn.nMaxFile = 512;
    ofn.lpstrInitialDir = hb_parc(3);
    ofn.nFilterIndex    = hb_parni(5);
    ofn.lpstrTitle = hb_parc(2) ;
    ofn.Flags = flags;

    if( GetSaveFileName( &ofn ) )
    {
        hb_stornl(ofn.nFilterIndex, 5 );
        hb_retc( ofn.lpstrFile );
    }
    else
    {
        hb_retc( "" );
    }
}

int CALLBACK BrowseCallbackProc( HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData )
{
   TCHAR szPath[ MAX_PATH ];

   switch( uMsg )
   {
      case BFFM_INITIALIZED:  if( lpData )
            SendMessage( hWnd, BFFM_SETSELECTION, TRUE, lpData );
            SetWindowText( hWnd , lpData );
            //SendMessage( hWnd, WM_SETTEXT, 0, "Teste" );
         break;
      case BFFM_SELCHANGED:   SHGetPathFromIDList( ( LPITEMIDLIST ) lParam, szPath ); SendMessage( hWnd, BFFM_SETSTATUSTEXT, 0, ( LPARAM ) szPath );
   }

   return 0;
}

HB_FUNC( HBG_GETFOLDER )  // Syntax: C_BROWSEFORFOLDER([<hWnd>],[<cTitle>],[<nFlags>],[<nFolderType>],[<cInitPath>])
{
   HWND         hWnd = HB_ISNIL( 1 ) ? GetActiveWindow() : ( HWND ) hb_parnl( 1 );
   BROWSEINFO   BrowseInfo;
   char *       lpBuffer = ( char * ) hb_xgrab( MAX_PATH + 1 );
   LPITEMIDLIST pidlBrowse;

   SHGetSpecialFolderLocation( hWnd, HB_ISNIL( 4 ) ? CSIDL_DRIVES : hb_parni( 4 ), &pidlBrowse );

   BrowseInfo.hwndOwner      = hWnd;
   BrowseInfo.pidlRoot       = pidlBrowse;
   BrowseInfo.pszDisplayName = lpBuffer;
   BrowseInfo.lpszTitle      = HB_ISNIL( 2 ) ? "Select a Folder" : hb_parc( 2 );
   BrowseInfo.ulFlags        = HB_ISCHAR( 5 ) ? BIF_STATUSTEXT : hb_parni( 3 );
   BrowseInfo.lpfn           = HB_ISCHAR( 5 ) ? BrowseCallbackProc : NULL;
   BrowseInfo.lParam         = HB_ISCHAR( 5 ) ? ( LPARAM ) ( char * ) hb_parc( 5 ) : 0;
   BrowseInfo.lParam         = hb_parc( 2 );
   BrowseInfo.iImage         = 0;
   
   pidlBrowse = SHBrowseForFolder( &BrowseInfo );

   SendMessage( hWnd, WM_SETTEXT, 0, "Teste" );
   
   if( pidlBrowse )
   {

      SHGetPathFromIDList( pidlBrowse, lpBuffer );
      SendMessage( hWnd, WM_SETTEXT, 0, "Teste" );
      //SetWindowText( hWnd , "" );
      //SetWindowText(GetDlgItem(hWnd, IDC_FILE), "Teste");
      hb_retc( lpBuffer );
   }
   else
      hb_retc( "" );

   hb_xfree( lpBuffer );
}

HB_FUNC( HBG_SELECTFILE )
{
   OPENFILENAME ofn;
   char         buffer[ 32768 ];
   char         cFullName[ 256 ][ 1024 ];
   char         cCurDir[ 512 ];
   char         cFileName[ 512 ];
   int          iFilterIndex = 1;       
   int          iPosition    = 0;
   int          iNumSelected = 0;
   int          n;

   DWORD flags = OFN_FILEMUSTEXIST;

   buffer[ 0 ] = 0;

   if( hb_parl( 4 ) )
      flags = flags | OFN_ALLOWMULTISELECT | OFN_EXPLORER;

   if( hb_parl( 5 ) )
      flags = flags | OFN_NOCHANGEDIR;

   if( hb_parni( 6 ) )
      iFilterIndex = hb_parni( 6 );

   memset( ( void * ) &ofn, 0, sizeof( OPENFILENAME ) );
   ofn.lStructSize     = sizeof( ofn );
   ofn.hwndOwner       = GetActiveWindow();
   ofn.lpstrFilter     = hb_parc( 1 );
   ofn.nFilterIndex    = ( DWORD ) iFilterIndex;
   ofn.lpstrFile       = buffer;
   ofn.nMaxFile        = sizeof( buffer );
   ofn.lpstrInitialDir = hb_parc( 3 );
   ofn.lpstrTitle      = hb_parc( 2 );
   ofn.nMaxFileTitle   = 512;
   ofn.Flags           = flags;

   if( GetOpenFileName( &ofn ) )
   {
      if( ofn.nFileExtension != 0 )
         hb_retc( ofn.lpstrFile );
      else
      {
         wsprintf( cCurDir, "%s", &buffer[ iPosition ] );
         iPosition = iPosition + strlen( cCurDir ) + 1;

         do
         {
            iNumSelected++;
            wsprintf( cFileName, "%s", &buffer[ iPosition ] );
            iPosition = iPosition + strlen( cFileName ) + 1;
            wsprintf( cFullName[ iNumSelected ], "%s\\%s", cCurDir, cFileName );
         }
         while( ( strlen( cFileName ) != 0 ) && ( iNumSelected <= 255 ) );

         if( iNumSelected > 1 )
         {
            hb_reta( iNumSelected - 1 );

            for( n = 1; n < iNumSelected; n++ )
               HB_STORC( cFullName[ n ], -1, n );
         }
         else
            hb_retc( &buffer[ 0 ] );
      }
   }
   else
      hb_retc( "" );
}

// JK JP

HB_FUNC( C_PUTFILE )
{
   OPENFILENAME ofn;
   char         buffer[ 512 ];
   char         cExt[ 4 ];
   int          iFilterIndex = 1;       
   DWORD        flags = OFN_FILEMUSTEXIST | OFN_EXPLORER;

   if( hb_parl( 4 ) )
      flags = flags | OFN_NOCHANGEDIR;

   if( strlen( hb_parc( 5 ) ) != 0 )
      strcpy( buffer, hb_parc( 5 ) );
   else
      strcpy( buffer, "" );
   strcpy( cExt, "" );

   if( hb_parni( 6 ) )
      iFilterIndex = hb_parni( 6 );

   memset( ( void * ) &ofn, 0, sizeof( OPENFILENAME ) );
   ofn.lStructSize     = sizeof( ofn );
   ofn.hwndOwner       = GetActiveWindow();
   ofn.lpstrFilter     = hb_parc( 1 );
   ofn.nFilterIndex    = ( DWORD ) iFilterIndex;
   ofn.lpstrFile       = buffer;
   ofn.nMaxFile        = 512;
   ofn.lpstrInitialDir = hb_parc( 3 );
   ofn.lpstrTitle      = hb_parc( 2 );
   ofn.Flags           = flags;
   ofn.lpstrDefExt     = cExt;

   if( GetSaveFileName( &ofn ) )
   {
      if( ofn.nFileExtension == 0 )
      {
         ofn.lpstrFile = strcat( ofn.lpstrFile, "." );
         ofn.lpstrFile = strcat( ofn.lpstrFile, ofn.lpstrDefExt );
      }
      if( HB_ISBYREF( 6 ) )
         hb_storni( ( int ) ofn.nFilterIndex, 6 );

      hb_retc( ofn.lpstrFile );
   }
   else
      hb_retc( "" );
}
#pragma ENDDUMP

OpenDialog - Como abrir a janela do windows para selec...?

13 Ago 2015 14:50

Obrigada a todos pela ajuda.
consegui fazer da forma que o Kapiaba mandou

OpenDialog - Como abrir a janela do windows para selec...?

13 Ago 2015 15:17

Parabéns!! Mas poste suas dúvidas na seção FiveWin, fica mais fácil para ajudá-la, senão dá a impressão que você está usando outra ferramenta que não seja FiveWin. Você usa FiveWin for xHarbour. Abs.

OpenDialog - Como abrir a janela do windows para selec...?

12 Jan 2017 19:29

Bom dia, pessoal.

Também desejo "ABRIR JANELA DO WINDOWS PARA SELECIONAR ARQUIVOS" em Xharbour e nesse tópico tem várias dicas, só que em HARBOUR

Alguém poderia me passar uma função que faça o mesmo em Xharbour ??

Grato

OpenDialog - Como abrir a janela do windows para selec...?

12 Jan 2017 20:25

Olhem com atenção todos os exemplos anteriores.

Agora vejam quando existe uma função "wrapper" padronizada.

Código:
      cFileExcel := win_GetOpenFileName(, "Arquivo a importar", "importa\", "XLS", "*.XLS", 1 )


É isso que chamo de padronizar.
Não apenas a questão do nome ou localização, mas usar diretamente no fonte Harbour.
Tudo seria melhor se fosse padronizado.

Só fazer igual no xHarbour, e usar nas LIBs.... Todo mundo ganharia com isso.

o resultado (não sei se o ícone igual aplicativo é normal)
selarquivo.png

OpenDialog - Como abrir a janela do windows para selec...?

12 Jan 2017 20:46

Quintas, eu sei que se trata de Fivewin, só quis aproveitar a temática e pedir o mesmo código para Xharbour,
como outros precisavam e pediram em harbour...

Eu testei todos os códigos antes de concluir q não funcionam pra Xharbour e inclusive testei esse que vc postou e
que também acusou erros na compilação em Xharbour 1.0.0

É q nenhuma dessas postagens anteriores apresenta a função
Código:
win_GetOpenFileName()

OpenDialog - Como abrir a janela do windows para selec...?

12 Jan 2017 21:48

Pensei que postaram rotinas pra xHarbour.

Então a falta de padronização está pior do que eu pensava.

A função que postei faz parte do HARBOUR.
Se as rotinas acima NÃO SÃO pra XHarbour, não sei pra que servem.

OpenDialog - Como abrir a janela do windows para selec...?

12 Jan 2017 22:11

Veja... fonte completo, com tudo:

Código:
PROCEDURE Main

   LOCAL cFileExcel

   cFileExcel := win_GetOpenFileName(, "Arquivo a importar", "importa\", "XLS", "*.XLS", 1 )

   ? cFileExcel

   RETURN


open1.png


open2.png


Por isso pensei que as rotinas fossem pra xHarbour.

Infelizmente não mexo com xHarbour e não posso ajudar.
Mas alguém deve saber.

OpenDialog - Como abrir a janela do windows para selec...?

12 Jan 2017 22:33

Infelizmente faltou mencionar:

A função do colega funcionou certinho com harbour 3.2. Asimões, sabe se o harbour 3.2 tem essa função nativamente?


Essa função foi copiada da minigui.
O harbour não tem essa função no seu projeto.


d:\>hbmk2 -find openfile
gtwvg.hbc (installed):
wvt_GetOpenFileName()
hbwin.hbc (installed):
win_GetOpenFileName()
xhb.hbc (installed):
NetOpenFiles()

OpenDialog - Como abrir a janela do windows para selec...?

11 Out 2023 16:42

Boa tarde Prezados ...

Estou utilizando o exemplo dos arquivos para selecionar arquivos .. ficou show !! compila e funciona perfeito, porém dá um solicitação de "WARNINGS" na ultima linha e não entendi porque .. alguem já passou por isso ??

é na ultima linha .. não tem nada aí !!

"W8080 PrtToPrt64 is declared but never used"

estou usando HARBOUR 3.2 + BCC582 + GTWVG

Abraço!
Anexos
BUSCA XML.jpg
FUNCIONA!!
warnings compiler.jpg
Postar uma resposta