Page 1 of 2 12>
Topic Options
#186781 - 2008-04-07 09:41 PM MS commondialog object
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This is kinda tied to
OpenFile() - Brings up the open dialog and lets you select a file. By CJ
MSCommonDialog() - Common Dialog Box to select files. By Witto
Save() - Brings up the save file dialog and lets you save a file. By me


Maybe I don't get it but is it so that on every system you want to use the commondialog object in a script you will need to install some MS visual studio stuff for it to work properly? That sucks \:\(

Because of the fact that my Save UDF will fail on Vista (have no Vista so did not test but it is also mentioned on the posts above) and we use it in at least one crucial app I was looking for an alternative way compatible with XP and Vista to alter my UDF. After reading the stuff in the post above about the MS commondialog object I got kind of irritated about the way one could use that object from a script. You need a license for it. Afaik it is used in all kinds of MS apps without any problems but a small script requires a license? WTF

Am I just not getting it or is this a real issue? If not then can someone please explain it to me?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#186785 - 2008-04-07 11:33 PM Re: MS commondialog object [Re: Mart]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
I suspect that the version that most apps use is from an API that is not available to COM calls. The ones that are are probably just wrappers to the API anyway. I dropped file open dialog in vbscript into google and found references to UserAccounts.CommonDialog, SAFRCFileDlg.FileOpen and Shell.Application in the first 4 results.

Maybe someone should make a single UDF that tries all the possible objects in order of usefullness, transparently to the user..

cj

Top
#186790 - 2008-04-08 11:00 AM Re: MS commondialog object [Re: cj]
Arend_ Moderator Offline
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 ;\)
 Code:
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 Offline
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
 Code:
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 \:D

cj


Attachments
cjDialogs.zip (284 downloads)
Description: An ActiveX/COM dll to provide File Open and File Save dialogs



Top
#186805 - 2008-04-09 09:33 AM Re: MS commondialog object [Re: cj]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You bata's!
Now I'm confused
Thanks to Witto I got the hang of it a bit but you guys screwed it all up again. Have to site down and lockout the outside world some time soon to get this into my head.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#186823 - 2008-04-10 05:30 AM Re: MS commondialog object [Re: Mart]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
lol, I created that DLL with the idea that it'll work on XP, Vista and others because some of the aforementioned DLLs appear to be XP only or VB present only. If someone has a win9x box, I'd be interested to hear if my DLL works..

cj

Top
#186886 - 2008-04-13 11:58 PM Re: MS commondialog object [Re: cj]
cj Offline
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.

 Code:
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
#186887 - 2008-04-14 12:05 AM Re: MS commondialog object [Re: cj]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Who fixes UBB? The 'Attachements' on the bottom of my previous post is not disabling bolded text. Here's the problem, from the source of this page:

<br /><br />
<b>Attachments<b>
<br />

That should be </b>

cj

Top
#186991 - 2008-04-17 12:20 AM Re: MS commondialog object [Re: cj]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Added Font selection dialog.

 Code:
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 Offline
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
 Code:
$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
#187227 - 2008-04-23 07:35 PM Re: MS commondialog object [Re: cj]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Whow cj, you are really spoiling Mart.
Top
#187229 - 2008-04-23 08:47 PM Re: MS commondialog object [Re: Witto]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yeah. He posted his cjDialogs object on the 9th of April that happens to be my birthday. Nice present thanks.
Didn't have time to play with it yet due to some busy days and some downright f-ed up evil days at work. Tomorrow I'll be helping a friend with some stuff that needs to be done on here house so I'll try to do some coding with it on Friday or early next week. I’ll keep you guys posted.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187254 - 2008-04-24 02:26 AM Re: MS commondialog object [Re: Mart]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
heh, happy birthday then. I still have a few more dialogs to add to it, but it's getting there.

cj

Top
#187365 - 2008-04-27 11:34 PM Re: MS commondialog object [Re: cj]
cj Offline
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 \:D

 Code:
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
#187366 - 2008-04-28 10:17 AM Re: MS commondialog object [Re: cj]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
CJ,

Works great.
One question/comment.
When registering the dll with regsvr32 and the /s option all questions and stuff are suppressed but not your message "Thank you for using cjDialogs :)". When registering the dll silently you still have to click OK before the regsvr32 command is executed. Not that silent imho because user interaction is required.

Lets imagine that you are registering the dll with a startup script (using regsvr32 and the /s option) because regular users cannot register a dll. The message box will also be displayed. All script execution is halted until the user clicks OK (if he/she even sees the message during a startup script) or script execution continues and parts that rely on the dll will fail.

Is there any way to "fix" this?


Edited by Mart (2008-04-28 10:20 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187373 - 2008-04-28 11:29 PM Re: MS commondialog object [Re: Mart]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
hmmm, I thought I had it detecting /s and not displaying that message. I will remove the message, it was an experiment in hooking the registerDLL call.

cj

Top
#187374 - 2008-04-28 11:32 PM Re: MS commondialog object [Re: cj]
cj Offline
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
#187377 - 2008-04-29 09:30 AM Re: MS commondialog object [Re: cj]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Thanks
I'll play some more with it today.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187719 - 2008-05-18 02:44 PM Re: MS commondialog object [Re: Mart]
SharkD Offline
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 Offline
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 \:D

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
Page 1 of 2 12>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.251 seconds in which 0.202 seconds were spent on a total of 20 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org