************************************ * Changes default windows printer * * Traker International * * www.autotraker.com * * 07/16/2001 * ********************************************************************** * Changement de l'imprimante pas defaut de Windows * * source : http://dbase.autotraker.com/32bit/getPrint/index.html * * francisé M.Abraham * * modifications : * * imprimante par défaut affichée en rouge * * ajout d'un bouton Quitter avec icône * * fixation d'une largeur minimale de la fenêtre (SizeIt) * ********************************************************************** ** END HEADER -- do not remove this line // // Generated on 19/08/2009 // parameter bModal local f f = new GetPrintForm() if (bModal) f.mdi = false // ensure not MDI f.readModal() else f.open() endif class GetPrintForm of FORM with (this) onOpen = class::ONOPEN open = class::OPEN readModal = class::READMODAL height = 13.0 left = 19.4286 top = 7.3636 width = 66.0 text = "Choix de la nouvelle imprimante par défaut" autoCenter = true mdi = false icon = "" endwith this.LISTBOX1 = new LISTBOX(this) with (this.LISTBOX1) onLeftDblClick = {;form.PUSHBUTTON1_onClick()} height = 6.5 left = 1.0 top = 4.0 width = 64.0 id = 101 endwith this.PUSHBUTTON1 = new PUSHBUTTON(this) with (this.PUSHBUTTON1) onClick = class::PUSHBUTTON1_ONCLICK height = 1.0909 left = 26.86 top = 11.5455 width = 15.2857 text = "Sélectionne" speedTip = "Sélectionne cette imprimante" endwith this.DEFAULT = new TEXT(this) with (this.DEFAULT) height = 2.0909 left = 1.0 top = 0.8636 width = 64.0 colorNormal = "red/BtnFace" alignVertical = 1 // Middle fontBold = true text = "" endwith this.TEXT1 = new TEXT(this) with (this.TEXT1) height = 1.0 left = 1.0 top = 3.0 width = 64.0 border = true alignHorizontal = 1 // Center fontBold = true text = "Imprimantes installées" borderStyle = 2 // Lowered endwith this.TEXT2 = new TEXT(this) with (this.TEXT2) height = 1.0 left = 1.0 top = 0.0 width = 64.0 fontBold = true text = "Imprimante par défault activée :" endwith this.PUSHBUTTON2 = new PUSHBUTTON(this) with (this.PUSHBUTTON2) onClick = {;form.close()} height = 1.0909 left = 53.0 top = 11.5 width = 11.2857 text = "Quitter" upBitmap = "RESOURCE #1005" downBitmap = "RESOURCE #1006" focusBitmap = "RESOURCE #1005" endwith *************************************************************************** function Open *************************************************************************** this.Init() SUPER::OPEN() return *************************************************************************** function ReadModal *************************************************************************** this.Init() SUPER::READMODAL() return *************************************************************************** function Init *************************************************************************** // get the windows printers and put the info into arrays form.aPrinter = new array() form.aDriver = new array() form.aPorts = new array() aP = form.aPrinter aD = form.aDriver aR = form.aPorts cBuffer = GetSection("Win.ini","Devices") nLen = len(cBuffer) store 0 to nEntry, nLastNull, nNextNull, nStart, nChars do nLastNull = nNextNull nEntry++ nNextNull = at(chr(0), cBuffer, nEntry) nStart = nLastNull+1 nChars = nNextNull-nLastNull-1 cI = substr(cBuffer, nStart, nChars) aP.add(left(cI,at("=",cI)-1)) cV = right(cI,len(cI)-at("=",cI)) aD.add(left(cV,at(",",cV)-1)) aR.add(right(cV,len(cV)-at(",",cV))) until nNextNull >= nLen-1 // create an array to hold the printer decription form.aListArr = new array() for i = 1 to aP.size form.aListArr.add(FormatView(aP[i],aR[i])) next form.LISTBOX1.datasource = "array form.aListArr" // get the max width of the array for resizing for i = 1 to form.aListArr.Size form.MaxWidth = len(form.aListArr[i]) +15 // ajout MA next form.SizeIt() return *************************************************************************** function OnOpen *************************************************************************** // set the listbox selection to that of the default printer form.GetDefaultPrinter() for i = 1 to form.aListArr.Size if form.aListArr[i] = form.Default.text form.LISTBOX1.CurSel = i endif next *************************************************************************** function SizeIt *************************************************************************** // resize the components on the form oW = form.LISTBOX1 nX = form.MaxWidth - 4 // fixe une largeur minimale afin que le titre de la fenêtre s'affiche if nX < 55 nX = 55 endif oY = form.PUSHBUTTON1 oZ = form.PUSHBUTTON2 form.Default.width = nX oW.width = nX form.TEXT1.width = nX oW.height = form.aListArr.size * .80 form.width = nX + 2 oY.top = oW.height + oW.top + .5 oZ.top = oY.top oY.left = (form.width - (oY.width+ oZ.width))/2 oZ.left = form.width - (oZ.width + 1) form.height = oY.top + oY.height + .5 return *************************************************************************** function PUSHBUTTON1_onClick *************************************************************************** // set the default printer to the one selected nC = form.LISTBOX1.CurSel SetDefaultPrinter(form.aPrinter[nC]+","+form.aDriver[nC]+","+; form.aPorts[nC]) // confirm we changed printers form.GetDefaultPrinter() return *************************************************************************** Procedure GetDefaultPrinter *************************************************************************** // get the default printer cX = ReadIni("win.ini","windows","device") Form.Default.text = FormatView(left(cX,at(",",cX)-1),; substr(cX,rat(",",cX)+1,len(cX)-rat(",",cX))) return // endclass *************************************************************************** function FormatView(cP,cR) *************************************************************************** local all return cP + ' Imprimante - sur Port "' + cR + '"' *************************************************************************** function SetDefaultPrinter(cNewDefaultPrinter) *************************************************************************** #Define WM_WININICHANGE 26 #Define HWND_BROADCAST 65535 if type("SendMessage") # "FP" extern CLONG SendMessage(CHANDLE,CINT,CWORD,CLONG) ; USER32 from "SendMessageA" endif WriteIni("win.ini","Windows","device",cNewDefaultPrinter) // Flush cached WIN.INI - required for Win95/98/ME WriteIni("win.ini",NULL,NULL,NULL) // Let everyone know we changed WIN.INI SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, 0) return ************************************************************************** function GetSection(cIniFile,cSection) ************************************************************************** // returns section in a chr(0) delimited string if type("GetPrivateProfileSection") <> "FP" extern CLONG GetPrivateProfileSection(CSTRING,; CPTR,; CLONG,; CSTRING) ; kernel32 from "GetPrivateProfileSectionA" endif #define INI_SECTION_RETSIZE 32000 cBuffer = space(INI_SECTION_RETSIZE) nBytes = GetPrivateProfileSection(cSection,; cBuffer,; INI_SECTION_RETSIZE,; cIniFile ) cString = left(cBuffer,nBytes) oStr = new string() oStr.string = space(len(cString)*2) for n = 0 to len(cString) oStr.setByte(n*2, cString.getByte(n)) next n return trim(oStr.string) **** Function for Write ini files **************************************** function WriteIni (FileName, Section, Parameter, ProfileString) ************************************************************************** if type("WritePrivateProfileString") <> "FP" extern CLOGICAL WritePrivateProfileString( CSTRING,; CSTRING,; CSTRING,; CSTRING ) ; kernel32 from "WritePrivateProfileStringA" endif return WritePrivateProfileString(Section,Parameter,; ProfileString,FileName) ************************************************************************** function ReadIni (FileName, Section, Parameter) ************************************************************************** if type("GetPrivateProfileString") <> "FP" extern CLONG GetPrivateProfileString( CSTRING,; CSTRING,; CSTRING,; CSTRING,; CLONG,; CSTRING ) ; kernel32 from "GetPrivateProfileStringA" endif local code code = space(100) GetPrivateProfileString(Section, Parameter,; CHR(0), code, 100, FileName) return iif(code==CHR(0),"",code)