Usuário com melhor resposta
Trabalhando file dialog com SAP

Pergunta
-
Boa noite
Tenho procurado na internet e não encontrado nenhuma solução para meu problema.
Eu tenho um sistema que o objetivo dele é anexar arquivos na aplicação. Eu já consegui fazer ele abrir o file dialog, mas na hora de escolher o arquivo eu não consigo trabalhar com a informação, porque a integração do sistema é em vb.net com o sistema SAP. Gostaria de saber se tem alguma forma de digitar o caminho em uma variável e passar para essa caixa de dialog. Eu recebi uma orientação de criar uma dll para capturar a caixa de dialog, mas não sei como fazer isso.
- Editado Shiirohige quinta-feira, 4 de agosto de 2016 01:47
Respostas
-
Eu trabalho com SAP scripting e consegui resolver essa questão..
Só que não tenho mais o código =/
O que tenho atualmente apenas dá um clique de OK em uma mensagem, mas creio que é uma questão de adaptação
Option Compare Database Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare PtrSafe Function FindWindowEx Lib "User32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Declare PtrSafe Function SendMessage Lib "User32" Alias "SendMessageA" _ (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare PtrSafe Function GetWindow Lib "User32" _ (ByVal hWnd As Long, ByVal wCmd As Long) As Long Public Declare PtrSafe Function GetWindowPlacement Lib "User32" _ (ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long Public Declare PtrSafe Function SetWindowPlacement Lib "User32" _ (ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long Public Declare PtrSafe Function SetForegroundWindow Lib "User32" _ (ByVal hWnd As Long) As Long Public Declare PtrSafe Function BringWindowToTop Lib "User32" _ (ByVal hWnd As Long) As Long Public Declare PtrSafe Function GetForegroundWindow Lib "User32" () As Long Declare PtrSafe Function MakePath Lib "imagehlp.dll" Alias "MakeSureDirectoryPathExists" _ (ByVal lpPath As String) As Long Const WM_SETTEXT As Long = &HC Const BM_CLICK = &HF5 Const GW_CHILD = 5 Const GW_HWNDNEXT = 2 Const SW_SHOWNORMAL = 1 Const SW_SHOWMINIMIZED = 2 Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Dim hWnd As Long Dim Childhwnd As Long Dim pos As RECT Public FileSaveAsPath Public Type POINTAPI X As Long Y As Long End Type Public Type WINDOWPLACEMENT Length As Long flags As Long showCmd As Long ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECT End Type Private Function ActivateWindow(xhWnd As String) As Boolean Dim Result&, WndPlcmt As WINDOWPLACEMENT With WndPlcmt .Length = Len(WndPlcmt) Result = GetWindowPlacement(xhWnd, WndPlcmt) If Result Then If .showCmd = SW_SHOWMINIMIZED Then .flags = 0 .showCmd = SW_SHOWNORMAL Result = SetWindowPlacement(xhWnd, WndPlcmt) Else Call SetForegroundWindow(xhWnd) Result = BringWindowToTop(xhWnd) End If If Result Then ActivateWindow = True End If End With End Function Private Function DeActivateWindow(xhWnd As String) As Boolean Dim Result&, WndPlcmt As WINDOWPLACEMENT With WndPlcmt .Length = Len(WndPlcmt) Result = GetWindowPlacement(xhWnd, WndPlcmt) If Result Then .flags = 0 .showCmd = SW_SHOWMINIMIZED Result = SetWindowPlacement(xhWnd, WndPlcmt) If Result Then DeActivateWindow = True End If End With End Function Sub SendMess_SaveFileNamePath(Message As String, hWnd As Long) Call SendMessage(hWnd, WM_SETTEXT, False, ByVal Message) End Sub Public Function trataTimeout() On Error GoTo err_handler Dim FileOpenPath Dim strFilename As String hWnd = FindWindow("#32770", "SAP GUI for Windows 730") If hWnd = 0 Then Exit Function End If ActivateWindow (hWnd) DoEvents SendMess_SaveFileNamePath strFilename, Childhwnd Childhwnd = FindWindowEx(hWnd, ByVal 0&, ByVal "Button", vbNullString) Childhwnd = GetWindow(Childhwnd, GW_HWNDNEXT) If Childhwnd = 0 Then MsgBox "Save Button in 'Save As'-dialog not found" Exit Function End If SendMessage Childhwnd, BM_CLICK, 0, ByVal 0& Exit Function err_handler: MsgBox Err.Description End Function
André Santo | basevba.wordpress.com
- Marcado como Resposta Robson William SilvaModerator quinta-feira, 11 de agosto de 2016 12:36
Todas as Respostas
-
Ola
Poderia descrever melhor seu cenario, pelo que entendi você tem um sistema SAP que gera o arquivo e sua aplicação ira abrir um diretorio especifico e você tera que selecionar o(s) arquivo(s) ?E seu filedialog não esta exibindo os arquivos ?
Se for isso tenta usar o openfolder para abrir o diretorio e veja a extensão dos arquivos contidos no diretórioJunior
-
Boa noite,
Não, eu tenho um código em vb.net que ao rodar ele me abre uma tela de file dialog no SAP. O código simplesmente vai em botão no sap e clica na opção para abrir a caixa, mas quando o dialog é aberto eu não sei como passar a informação do caminho que quero ir para o dialog, porque ele não foi criado pela minha aplicação.
Existe alguma maneira de eu conseguir passar a informação de um caminho para a caixa de dialog aberta?
- Editado Shiirohige quinta-feira, 4 de agosto de 2016 21:38
-
Boa tarde Shiirohige,
É possível que o que você precisa é a Classe FolderBrowserDialog e não a OpenFileDialog.
Atenciosamente,
Robson William Silva
Esse conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita
MSDN Community Support
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.
-
Boa tarde,
grato pela resposta... Realizei uma pesquisa sobre a classe, mas não sei se isso vai me ajudar. Como eu vou conseguir digitar o caminho do arquivo em uma janela que foi aberta direto pelo sistema? Esse dialog que mostrei na imagem não foi aberto por nenhum componente da minha aplicação.
-
Eu trabalho com SAP scripting e consegui resolver essa questão..
Só que não tenho mais o código =/
O que tenho atualmente apenas dá um clique de OK em uma mensagem, mas creio que é uma questão de adaptação
Option Compare Database Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare PtrSafe Function FindWindowEx Lib "User32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Declare PtrSafe Function SendMessage Lib "User32" Alias "SendMessageA" _ (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare PtrSafe Function GetWindow Lib "User32" _ (ByVal hWnd As Long, ByVal wCmd As Long) As Long Public Declare PtrSafe Function GetWindowPlacement Lib "User32" _ (ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long Public Declare PtrSafe Function SetWindowPlacement Lib "User32" _ (ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long Public Declare PtrSafe Function SetForegroundWindow Lib "User32" _ (ByVal hWnd As Long) As Long Public Declare PtrSafe Function BringWindowToTop Lib "User32" _ (ByVal hWnd As Long) As Long Public Declare PtrSafe Function GetForegroundWindow Lib "User32" () As Long Declare PtrSafe Function MakePath Lib "imagehlp.dll" Alias "MakeSureDirectoryPathExists" _ (ByVal lpPath As String) As Long Const WM_SETTEXT As Long = &HC Const BM_CLICK = &HF5 Const GW_CHILD = 5 Const GW_HWNDNEXT = 2 Const SW_SHOWNORMAL = 1 Const SW_SHOWMINIMIZED = 2 Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Dim hWnd As Long Dim Childhwnd As Long Dim pos As RECT Public FileSaveAsPath Public Type POINTAPI X As Long Y As Long End Type Public Type WINDOWPLACEMENT Length As Long flags As Long showCmd As Long ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECT End Type Private Function ActivateWindow(xhWnd As String) As Boolean Dim Result&, WndPlcmt As WINDOWPLACEMENT With WndPlcmt .Length = Len(WndPlcmt) Result = GetWindowPlacement(xhWnd, WndPlcmt) If Result Then If .showCmd = SW_SHOWMINIMIZED Then .flags = 0 .showCmd = SW_SHOWNORMAL Result = SetWindowPlacement(xhWnd, WndPlcmt) Else Call SetForegroundWindow(xhWnd) Result = BringWindowToTop(xhWnd) End If If Result Then ActivateWindow = True End If End With End Function Private Function DeActivateWindow(xhWnd As String) As Boolean Dim Result&, WndPlcmt As WINDOWPLACEMENT With WndPlcmt .Length = Len(WndPlcmt) Result = GetWindowPlacement(xhWnd, WndPlcmt) If Result Then .flags = 0 .showCmd = SW_SHOWMINIMIZED Result = SetWindowPlacement(xhWnd, WndPlcmt) If Result Then DeActivateWindow = True End If End With End Function Sub SendMess_SaveFileNamePath(Message As String, hWnd As Long) Call SendMessage(hWnd, WM_SETTEXT, False, ByVal Message) End Sub Public Function trataTimeout() On Error GoTo err_handler Dim FileOpenPath Dim strFilename As String hWnd = FindWindow("#32770", "SAP GUI for Windows 730") If hWnd = 0 Then Exit Function End If ActivateWindow (hWnd) DoEvents SendMess_SaveFileNamePath strFilename, Childhwnd Childhwnd = FindWindowEx(hWnd, ByVal 0&, ByVal "Button", vbNullString) Childhwnd = GetWindow(Childhwnd, GW_HWNDNEXT) If Childhwnd = 0 Then MsgBox "Save Button in 'Save As'-dialog not found" Exit Function End If SendMessage Childhwnd, BM_CLICK, 0, ByVal 0& Exit Function err_handler: MsgBox Err.Description End Function
André Santo | basevba.wordpress.com
- Marcado como Resposta Robson William SilvaModerator quinta-feira, 11 de agosto de 2016 12:36
-