#186790 - 2008-04-08 11:00 AM
Re: MS commondialog object
[Re: cj]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Just to complicate things a little more here's another approach to save files 
Dim $objDialog
$objDialog = CreateObject("UserAccounts.CommonDialog")
$objDialog.Filter = "KiX Scripts (*.kix)|*.kix|"
$objDialog.FilterIndex = 1
$objDialog.InitialDir = "C:\"
$intResult = $objDialog.ShowOpen
? $objDialog.FileName
Edit: Sorry Cj, didn't see you mention this COM object already
Edited by apronk (2008-04-08 11:01 AM)
|
Top
|
|
|
|
#186803 - 2008-04-09 03:08 AM
Re: MS commondialog object
[Re: Arend_]
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
hehe, lemme have a hack at making it easier then. Find attached cjDialogs.dll. It's a normal COM dll so use regsvr32 to register it. Exposed interfaces at this time are OpenFile and SaveFile, I'll add Picture, Font, Colour and Printer dialogs later (I do have real work I am supposed to be doing right now )
Properties of both interfaces: Filename - the filename of the file being selected Filter - filters in the usual pipe separated format FilterIndex - the filters are a one indexed array, this is the default InitialDir - the folder the dialog starts in Title - the caption of the dialog form
OpenFile has an additional property MustExist - boolean, when true you have to select a file that already exists
SaveFile has an additional property OverwritePrompt - boolean, when true will prompt 'are you sure' when selecting an existing filename
Both interfaces have this method: Execute - boolean, if true then Filename will be set
examples of use
break on
dim $oDialog
$oDialog = CreateObject('cjDialogs.SaveFile')
$oDialog.Filter='Text Files|*.txt|All Files|*.*'
$oDialog.FilterIndex=2
$oDialog.InitialDir='c:\'
$oDialog.Title='Save my text file'
;$oDialog.MustExist=false
$oDialog.OverwritePrompt=true
if $oDialog.Execute
"filename: " $oDialog.Filename
else
"pressed cancel"
endif
?
You can change the SaveFile to OpenFile and move the ; to the next line down and it's the File Open dialog example.
This was written in Delphi 5 in about an hour, half of which was me learning how to create an ActiveX dll from scratch 
cj
Attachments
cjDialogs.zip (284 downloads) Description: An ActiveX/COM dll to provide File Open and File Save dialogs
|
Top
|
|
|
|
#186886 - 2008-04-13 11:58 PM
Re: MS commondialog object
[Re: cj]
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
Here's an update to cjDialogs to include OpenPicture dialog. Works the same as OpenFile.
break on
dim $oDialog
$oDialog = CreateObject('cjDialogs.OpenPicture')
$oDialog.Filter='Bitmaps|*.bmp|All Files|*.*'
$oDialog.FilterIndex=1
$oDialog.InitialDir='c:\'
$oDialog.Title='test'
$oDialog.MustExist=true
if $oDialog.Execute
"file: " $oDialog.Filename
else
"cancel"
endif
?
cj
Attachments
cjDialogs.zip (242 downloads) Description: cjDialogs v1.1
Supports OpenFile, SaveFile and OpenPicture
|
Top
|
|
|
|
#186991 - 2008-04-17 12:20 AM
Re: MS commondialog object
[Re: cj]
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
Added Font selection dialog.
break on
dim $oDialog
$oDialog = CreateObject('cjDialogs.SelectFont')
if $oDialog.Execute
"Name: " $oDialog.FontName ?
"Size: " $oDialog.Size ?
"Colour: " $oDialog.Color ?
"Bold: " if $oDialog.Bold "true" else "false" endif ?
"Italics: " if $oDialog.Italic "true" else "false" endif ?
"StrikeOut: " if $oDialog.Strikeout "true" else "false" endif ?
"Underline: " if $oDialog.Underline "true" else "false" endif ?
else
"cancel"
endif
?
cj
Attachments
cjDialogs.zip (218 downloads) Description: v1.2 added SelectFont interface
|
Top
|
|
|
|
#187151 - 2008-04-22 04:43 AM
Re: MS commondialog object
[Re: cj]
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
Added support for selecting a printer and it's options. This opens the printer dialog and lets you select a printer, number of copies, collation, page ranges etc etc.
Interface: PrintOptions
Simple Read/Write Properties Collate boolean - collate copies Copies integer - number of copies, default 1 FromPage integer - print from this page on, default 1 ToPage integer - stop printing on this page MinPage integer - set a minimum page number, default 1 MaxPage integer - set a maximum page number. User input is validated against MinPage and MaxPage PrintToFile boolean - the Print To File checkbox
Complex Read/Write Properties Options integer - A flags system which is the sum of the following four numbers: 1 - Show Print To File checkbox 2 - Allow page number inputs (must have MinPage and MaxPage set) 4 - Enables the 'Selection' option. This is to print the selected text on the calling program, prob not overly useful in a scripting context. 8 - Generates a warning message if the user tries to send a job to an uninstalled printer So setting Options to 5 is option 1 and option 4. Use 15 to enable all, default is 0 (all options disabled)
Read Only Properties PrintRange integer - Specifies the selected print range. Choice of: 0 for All Pages (default) 1 for Pages from FromPage to ToPage 2 for the 'Selection' option PrinterName string - returns the name of the selected printer PrinterIndex integer - returns the position in the list of printers of the selected printer where -1 means no printer selected and 0 is the top printer in the list.
To use in KiX code, it's the same as the other dialogs (scroll up) with the object call changed to $oDialog = CreateObject('cjDialogs.PrintOptions') and the property calls changed as required.
enjoy,
cj
Attachments
cjDialogs.zip (236 downloads) Description: v1.03 - added PrintOptions interface
|
Top
|
|
|
|
#187365 - 2008-04-27 11:34 PM
Re: MS commondialog object
[Re: cj]
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
Added Colour dialog, but I spelled it wrong for all you non-Aussies 
break on
dim $oDialog
$oDialog = CreateObject('cjDialogs.SelectColor')
$oDialog.UseNames=true
if $oDialog.Execute
"Executed " $oDialog.HTMLColor
else
"cancel"
endif
?
Opens the Colour selector dialog and lets you choose a colour. This is the same selector that MSPaint uses. You can expand it with the 'Custom' button and create any shade.
Properties: Color integer - this is the colour. 0 is black, 255 is red. The color is an integer that represents the red, green and blue components in the order blue, green and red. so 0 blue, 0 green and FF red is 0000ff or 255.
HTMLColor string - this is the same colour, but in HTML format #rrggbb. so red would be #FF0000. Confused yet? If there is enough call for it, I can convert the bbggrr output from .Color into rrggbb.
UseNames boolean - when set to true (default is false) it will try to find a name for the colour you have selected. eg red would be RED and #7FFFD4 would be AQUAMARINE. This list of names came from MSDN Colour names.
cj
Attachments
cjDialogs.zip (240 downloads) Description: v1.4 added Color (ahem coloUr) selector
|
Top
|
|
|
|
#187374 - 2008-04-28 11:32 PM
Re: MS commondialog object
[Re: cj]
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
ahh, it only checks for /s as the first param. as in regsrv32 /s cjdialogs.dll, not regsvr32 cjdialogs.dll /s. It's gone now anyway.
cj
Attachments
cjDialogs.zip (257 downloads) Description: v1.5 no nag message :)
|
Top
|
|
|
|
#187719 - 2008-05-18 02:44 PM
Re: MS commondialog object
[Re: Mart]
|
SharkD
Just in Town
Registered: 2008-05-18
Posts: 3
|
Hi! I found this thread after searching for a solution to the problems outlined in the first post. I have a couple of questions.
May I use this dll in my own application? What is the license for the dll? Are there any other dependencies for using the dll, such as the .NET framework, or some version of VB (I know the dll is written using Delphi...)?
I notice the dialog uses the old Win9x-style appearance. Is there any way you could update this to the modern buttons (or have it vary depending on version of Windows) and show the My Documents, My Computer, etc., buttons on the left?
The dialogs show up in the taskbar when activated. Is there any way to disable this?
Thanks you!
Edited by SharkD (2008-05-18 02:51 PM)
|
Top
|
|
|
|
#187721 - 2008-05-19 05:39 AM
Re: MS commondialog object
[Re: SharkD]
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
heya,
The licence is "You are welcome to do what you like with it, I don't guarantee that it'll do anything more than take up some disk space" I can give you the source code if you want. It's using the dialogs that come with Delphi 5, so it's prob not as nice as later, more theme aware versions. I threw it together mainly to teach myself how to make a COM dll in delphi.
No dependancies that I am aware of, it should be completely standalone; well as stand alone as it can be considering it uses kernel32.dll, user32.dll, advapi32.dll, oleaut32.dll, gdi32.dll, ole32.dll, comctl32.dll, winspool.drv and comdlg32.dll, but who doesn't these days 
When I finally upgrade to a newer version of Delphi (been trying to convince the boss to agree to that for 3 years now) I will re-build this and it should look a bit nicer.
Dunno about the taskbar thing, I might be able to stop that, but not sure how. I will endeavour to figure that out when I can next look at this. Work has been busy of late so I haven't played with this much.
cj
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|