ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help with respect to CDialog-based display of dialog in Excelthrough xll (https://www.excelbanter.com/excel-programming/418437-need-help-respect-cdialog-based-display-dialog-excelthrough-xll.html)

ThirstyForKnowledge

Need help with respect to CDialog-based display of dialog in Excelthrough xll
 
Can anyone out there tell me how to display a CDialog-based dialog
control from within XLL. I have managed to cratee an MFC extension
XLL (i.e., originally dll but tweaked to become xll). I have
different NON-VISUAL functions and commands that can be used from
within excel spreadsheet and excel menus, but I cannoy manage to
create a command that will display an MFC CDialog -based dialog
control.

I would really appreciate if there are any experts who could give me
direction what do i need to do.

Thank you in advance

joel

Need help with respect to CDialog-based display of dialog in Excel
 
Why did you change DLL to XLL? You should be calling a DLL even if you are
calling it within the XLL.

Below is some code that may help. You need to declare the functions before
you use them as shown below.


Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function

Sub Folder()
Dim c As Range, rng As Range
Set rng = Range("H1:H10")
For Each c In rng
c.Value = GetFolder
Next c
End Sub


ThirstyForKnowledge

Need help with respect to CDialog-based display of dialog inExcel
 
On Oct 13, 1:55*pm, Joel wrote:
Why did you change DLL to XLL? You should be calling a DLL even if you are
calling it within the XLL.

Below is some code that may help. *You need to declare the functions before
you use them as shown below.

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
* * Alias "SHGetPathFromIDListA" _
* *(ByVal pidl As Long, _
* * ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
* * Alias "SHBrowseForFolderA" _
* *(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
* hOwner As Long
* pidlRoot As Long
* pszDisplayName As String
* lpszTitle As String
* ulFlags As Long
* lpfn As Long
* lParam As Long
* iImage As Long
End Type

* * '-------------------------------------------------------------
* * Function GetFolder(Optional ByVal Name As String = _
* * * * * * * * "Select a folder.") As String
* * '-------------------------------------------------------------
* * Dim bInfo As BROWSEINFO
* * Dim path As String
* * Dim oDialog As Long

* * * * bInfo.pidlRoot = 0& * * * * * * * * 'Root folder = Desktop

* * * * bInfo.lpszTitle = Name

* * * * bInfo.ulFlags = &H1 * * * * * * * * 'Type of directory to Return
* * * * oDialog = SHBrowseForFolder(bInfo) *'display the dialog

* * * * 'Parse the result
* * * * path = Space$(512)

* * * * GetFolder = ""
* * * * If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
* * * * * * GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
* * * * End If

* * End Function

Sub Folder()
Dim c As Range, rng As Range
Set rng = Range("H1:H10")
For Each c In rng
c.Value = GetFolder
Next c
End Sub


Hi Joel,

I'm sorry for not having been clear as to what I really need to find
out. I really need to solve that problem above with C++, not
VBA ...but thanks for your drive to help others and thanks for taking
the time to reply.

joel

Need help with respect to CDialog-based display of dialog in E
 
The solution for C++ is very similar to Visual Basic. You find plenty of
info on the web and at microsoft.com in you look a CDIALOG Win32 C++.

"ThirstyForKnowledge" wrote:

On Oct 13, 1:55 pm, Joel wrote:
Why did you change DLL to XLL? You should be calling a DLL even if you are
calling it within the XLL.

Below is some code that may help. You need to declare the functions before
you use them as shown below.

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function

Sub Folder()
Dim c As Range, rng As Range
Set rng = Range("H1:H10")
For Each c In rng
c.Value = GetFolder
Next c
End Sub


Hi Joel,

I'm sorry for not having been clear as to what I really need to find
out. I really need to solve that problem above with C++, not
VBA ...but thanks for your drive to help others and thanks for taking
the time to reply.



All times are GMT +1. The time now is 12:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com