#1
|
||||
|
||||
[HELP] Dynamic ComboBox Add Items
I use a function "EnumDisplaySettings" which lists the resolutions supported by the display, this function is capable of the resolutions listed in a combo box with the style "csDropDown" I want fix the ComboBox style on "csOwnerDrawVariable", the challenge is to create an index for the value that will be read in an xml file, we do not just display text with the style "csOwnerDrawVariable" we are obliged to him indicated the corresponding ItemIndex, I can not find solution to this issue.
Sorry for my bad english, i use a translator... CheckResDynamic: Code:
#DEFINE NAME="CheckResDynamic" [Setup] AppName={#NAME} AppVersion=1.0 CreateAppDir=false OutputDir=. OutputBaseFilename={#NAME} [#Code] #ifdef UNICODE #define AW "W" #else #define AW "A" #endif const CCHFORMNAME = 32; CCHDEVICENAME = 32; SM_CXSCREEN = 0; SM_CYSCREEN = 1; type TDeviceMode = record dmDeviceName: array[0..CCHDEVICENAME - 1] of Char; dmSpecVersion: Word; dmDriverVersion: Word; dmSize: Word; dmDriverExtra: Word; dmFields: DWORD; dmOrientation: Smallint; dmPaperSize: Smallint; dmPaperLength: Smallint; dmPaperWidth: Smallint; dmScale: Smallint; dmCopies: Smallint; dmDefaultSource: Smallint; dmPrintQuality: Smallint; dmColor: Smallint; dmDuplex: Smallint; dmYResolution: Smallint; dmTTOption: Smallint; dmCollate: Smallint; dmFormName: array[0..CCHFORMNAME - 1] of Char; dmLogPixels: Word; dmBitsPerPel: DWORD; dmPelsWidth: DWORD; dmPelsHeight: DWORD; dmDisplayFlags: DWORD; dmDisplayFrequency: DWORD; dmICMMethod: DWORD; dmICMIntent: DWORD; dmMediaType: DWORD; dmDitherType: DWORD; dmICCManufacturer: DWORD; dmICCModel: DWORD; dmPanningWidth: DWORD; dmPanningHeight: DWORD; end; TDeviceFilter = record Width: DWORD; Height: DWORD; end; var ModeIndex: DWORD; ModeExists: Boolean; FilterIndex: Integer; DisplayPage: TWizardPage; DisplayCombo: TNewComboBox; DisplayModes: array of TDeviceFilter; DisplaySettings: TDeviceMode; function EnumDisplaySettings(lpszDeviceName: string; iModeNum: DWORD; var lpDevMode: TDeviceMode): BOOL; external 'EnumDisplaySettings{#AW}@user32.dll stdcall'; function GetSystemMetrics (nIndex: Integer): Integer; external '[email protected] stdcall setuponly'; function _MessageBoxW_(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer; external '[email protected] stdcall'; function SysMsgBox(const Caption, Message: String; const Flags: Integer): Integer; begin Result := _MessageBoxW_(StrToInt(ExpandConstant('{wizardhwnd}')), Message, Caption, Flags); end; procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean); begin Confirm:=False; Cancel:=True; end; function LoadValueFromXML(const AFileName, APath: string): string; var XMLNode: Variant; XMLDoc: Variant; begin Log('Get Xml text node: ' + AFileName); Result := ''; XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); Result := XMLNode.text; end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; function GetAttrValueFromXML(const AFileName, APath: string): string; var XMLNode: Variant; XMLDoc: Variant; begin Result := ''; XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); Result := XMLNode.NodeValue; end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure SaveValueToXML(const AFileName, APath, AValue: string); var XMLNode: Variant; XMLDoc: Variant; begin Log('Save Xml text node: ' + AFileName); XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); XMLNode.text := AValue; XMLDoc.save(AFileName); end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure SaveAttributeValueToXML(const AFileName, APath, AAttribute, AValue: string); var XMLNode: Variant; XMLDoc: Variant; begin Log('Save Xml attr: ' + AFileName); XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); XMLNode.setAttribute(AAttribute, AValue); XMLDoc.save(AFileName); end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure DisplayComboOnChange(Sender: TObject); var ModeIndex: DWORD; ModeExists: Boolean; FilterIndex,ProgressBarPos,ProgressBarMax: Integer; DisplayModes: array of TDeviceFilter; DisplaySettings: TDeviceMode; XMLFile: string; begin XMLFile := ExpandConstant('{src}\settings.xml'); ModeIndex := 0; while EnumDisplaySettings('', ModeIndex, DisplaySettings) do begin with DisplaySettings do begin Inc(ModeIndex); ModeExists := False; for FilterIndex := 0 to GetArrayLength(DisplayModes) - 1 do begin if (DisplayModes[FilterIndex].Width = dmPelsWidth) and (DisplayModes[FilterIndex].Height = dmPelsHeight) then begin ModeExists := True; Break; end; end; if not ModeExists then begin SetArrayLength(DisplayModes, GetArrayLength(DisplayModes) + 1); with DisplayModes[GetArrayLength(DisplayModes) - 1] do begin Width := dmPelsWidth; Height := dmPelsHeight; if DisplayCombo.Text = Format('%dx%d', [Width,Height]) then begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value',IntToStr(Width)); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value',IntToStr(Height)); end; end; end; end; end; end; procedure InitializeWizard; var xres,yres: integer; XMLFile,ResW,ResH: string; XMLDoc,NewNode,XMLNode,RootNode: Variant; AutoRunFormNotebook: TNewNotebook; AutoRunForm: TNewNotebookPage; begin xres := GetSystemMetrics(SM_CXSCREEN); yres := GetSystemMetrics(SM_CYSCREEN); XMLFile := ExpandConstant('{src}\settings.xml'); XMLDoc := CreateOleObject('MSXML2.DOMDocument'); XMLDoc.async := False; XMLDoc.resolveExternals := False; XMLDoc.load(XMLFile); XMLNode := XMLDoc.selectSingleNode('//Settings/FirstLaunch'); if ((XMLNode as IDispatch) = nil) then begin NewNode := XMLDoc.createElement('FirstLaunch'); RootNode := XMLDoc.documentElement; RootNode.appendChild(NewNode); RootNode.lastChild.text := '0'; XMLDoc.Save(XMLFile); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value',IntToStr(xres)); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value',IntToStr(yres)); end; with WizardForm do begin BorderStyle := bsDialog; Position := poScreenCenter; AutoScroll := False; ClientWidth := ScaleX(220); ClientHeight := ScaleY(50); Caption:='{#NAME}'; end; AutoRunFormNotebook := TNewNotebook.Create(WizardForm); with AutoRunFormNotebook do begin Parent := WizardForm; Left := ScaleX(0); Top := ScaleY(0); Width := ScaleX(220); Height := ScaleY(50); Align := alClient; end; AutoRunForm := TNewNotebookPage.Create(WizardForm); with AutoRunForm do begin Notebook := AutoRunFormNotebook; end; ResW:=GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value'); ResH:=GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value'); DisplayCombo := TNewComboBox.Create(WizardForm); with DisplayCombo do begin Parent := AutoRunFormNotebook; Left:=10; Top:=15; Width := 200; Text := ResW+'x'+ResH; OnChange:=@DisplayComboOnChange; //Style:=csOwnerDrawVariable; end; ModeIndex := 0; while EnumDisplaySettings('', ModeIndex, DisplaySettings) do begin with DisplaySettings do begin Inc(ModeIndex); ModeExists := False; for FilterIndex := 0 to GetArrayLength(DisplayModes) - 1 do begin if (DisplayModes[FilterIndex].Width = dmPelsWidth) and (DisplayModes[FilterIndex].Height = dmPelsHeight)then begin ModeExists := True; Break; end; end; if not ModeExists then begin SetArrayLength(DisplayModes, GetArrayLength(DisplayModes) + 1); with DisplayModes[GetArrayLength(DisplayModes) - 1] do begin Width := dmPelsWidth; Height := dmPelsHeight; DisplayCombo.Items.Add(Format('%dx%d', [Width,Height])); end; end; end; end; end; CheckResNotDynamic: Code:
#DEFINE NAME="CheckResNotDynamic" [Setup] AppName={#NAME} AppVersion=1.0 CreateAppDir=false OutputDir=. OutputBaseFilename={#NAME} [#Code] const SM_CXSCREEN = 0; SM_CYSCREEN = 1; var DisplayCombo: TNewComboBox; function GetSystemMetrics (nIndex: Integer): Integer; external '[email protected] stdcall setuponly'; function _MessageBoxW_(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer; external '[email protected] stdcall'; function SysMsgBox(const Caption, Message: String; const Flags: Integer): Integer; begin Result := _MessageBoxW_(StrToInt(ExpandConstant('{wizardhwnd}')), Message, Caption, Flags); end; procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean); begin Confirm:=False; Cancel:=True; end; function LoadValueFromXML(const AFileName, APath: string): string; var XMLNode: Variant; XMLDoc: Variant; begin Log('Get Xml text node: ' + AFileName); Result := ''; XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); Result := XMLNode.text; end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; function GetAttrValueFromXML(const AFileName, APath: string): string; var XMLNode: Variant; XMLDoc: Variant; begin Result := ''; XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); Result := XMLNode.NodeValue; end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure SaveValueToXML(const AFileName, APath, AValue: string); var XMLNode: Variant; XMLDoc: Variant; begin Log('Save Xml text node: ' + AFileName); XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); XMLNode.text := AValue; XMLDoc.save(AFileName); end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure SaveAttributeValueToXML(const AFileName, APath, AAttribute, AValue: string); var XMLNode: Variant; XMLDoc: Variant; begin Log('Save Xml attr: ' + AFileName); XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); XMLNode.setAttribute(AAttribute, AValue); XMLDoc.save(AFileName); end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure DisplayComboOnChange(Sender: TObject); var XMLFile: string; begin XMLFile := ExpandConstant('{src}\settings.xml'); case DisplayCombo.ItemIndex of 0:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','800'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','600'); end; 1:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1024'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','768'); end; 2:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1152'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','864'); end; 3:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1280'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','720'); end; 4:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1280'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','768'); end; 5:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1280'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','800'); end; 6:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1280'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','960'); end; 7:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1280'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','1024'); end; 8:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1360'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','768'); end; 9:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1366'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','768'); end; 10:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1600'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','900'); end; 11:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1600'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','1024'); end; 12:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1600'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','1200'); end; 13:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1680'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','1050'); end; 14:begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value','1920'); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value','1080'); end; end; end; procedure InitializeWizard; var xres,yres: integer; XMLFile,ResW,ResH: string; XMLDoc,NewNode,XMLNode,RootNode: Variant; AutoRunFormNotebook: TNewNotebook; AutoRunForm: TNewNotebookPage; begin xres := GetSystemMetrics(SM_CXSCREEN); yres := GetSystemMetrics(SM_CYSCREEN); XMLFile := ExpandConstant('{src}\settings.xml'); XMLDoc := CreateOleObject('MSXML2.DOMDocument'); XMLDoc.async := False; XMLDoc.resolveExternals := False; XMLDoc.load(XMLFile); XMLNode := XMLDoc.selectSingleNode('//Settings/FirstLaunch'); if ((XMLNode as IDispatch) = nil) then begin NewNode := XMLDoc.createElement('FirstLaunch'); RootNode := XMLDoc.documentElement; RootNode.appendChild(NewNode); RootNode.lastChild.text := '0'; XMLDoc.Save(XMLFile); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value',IntToStr(xres)); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value',IntToStr(yres)); end; with WizardForm do begin BorderStyle := bsDialog; Position := poScreenCenter; AutoScroll := False; ClientWidth := ScaleX(220); ClientHeight := ScaleY(50); Caption:='{#NAME}'; end; AutoRunFormNotebook := TNewNotebook.Create(WizardForm); with AutoRunFormNotebook do begin Parent := WizardForm; Left := ScaleX(0); Top := ScaleY(0); Width := ScaleX(220); Height := ScaleY(50); Align := alClient; end; AutoRunForm := TNewNotebookPage.Create(WizardForm); with AutoRunForm do begin Notebook := AutoRunFormNotebook; end; DisplayCombo := TNewComboBox.Create(WizardForm); with DisplayCombo do begin Parent := AutoRunFormNotebook; Left:=10; Top:=15; Width := 200; Style:=csOwnerDrawVariable; Items.Add('800x600'); Items.Add('1024x768'); Items.Add('1152x864'); Items.Add('1280x720'); Items.Add('1280x768'); Items.Add('1280x800'); Items.Add('1280x960'); Items.Add('1280x1024'); Items.Add('1360x768'); Items.Add('1366x768'); Items.Add('1600x900'); Items.Add('1600x1024'); Items.Add('1600x1200'); Items.Add('1680x1050'); Items.Add('1920x1080'); if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '800') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '600') then ItemIndex := 0; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1024') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '768') then ItemIndex := 1; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1152') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '864') then ItemIndex := 2; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1280') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '720') then ItemIndex := 3; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1280') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '768') then ItemIndex := 4; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1280') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '800') then ItemIndex := 5; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1280') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '960') then ItemIndex := 6; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1280') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '1024') then ItemIndex := 7; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1360') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '768') then ItemIndex := 8; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1366') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '768') then ItemIndex := 9; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1600') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '900') then ItemIndex := 10; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1600') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '1024') then ItemIndex := 11; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1600') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '1200') then ItemIndex := 12; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1600') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '1050') then ItemIndex := 13; if (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value') = '1920') and (GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value') = '1080') then ItemIndex := 14; OnChange:=@DisplayComboOnChange; end; end; Code:
ModeIndex := 0; while EnumDisplaySettings('', ModeIndex, DisplaySettings) do begin with DisplaySettings do begin Inc(ModeIndex); ModeExists := False; for FilterIndex := 0 to GetArrayLength(DisplayModes) - 1 do begin if (DisplayModes[FilterIndex].Width = dmPelsWidth) and (DisplayModes[FilterIndex].Height = dmPelsHeight)then begin ModeExists := True; Break; end; end; if not ModeExists then begin SetArrayLength(DisplayModes, GetArrayLength(DisplayModes) + 1); with DisplayModes[GetArrayLength(DisplayModes) - 1] do begin Width := dmPelsWidth; Height := dmPelsHeight; DisplayCombo.Items.Add(Format('%dx%d', [Width,Height])); SaveStringToFile(ExpandConstant('{userdocs}\Rockstar Games\GTA V\EnumDisplay.txt'), Format('%dx%d'+#13#10, [Width,Height]), True); end; end; end; end; Someone an idea? ![]() May be Code:
ModeIndex := 0; while EnumDisplaySettings('', ModeIndex, DisplaySettings) do begin with DisplaySettings do begin Inc(ModeIndex); ModeExists := False; for FilterIndex := 0 to GetArrayLength(DisplayModes) - 1 do begin if (DisplayModes[FilterIndex].Width = dmPelsWidth) and (DisplayModes[FilterIndex].Height = dmPelsHeight)then begin ModeExists := True; Break; end; end; if not ModeExists then begin SetArrayLength(DisplayModes, GetArrayLength(DisplayModes) + 1); with DisplayModes[GetArrayLength(DisplayModes) - 1] do begin Width := dmPelsWidth; Height := dmPelsHeight; SaveStringToFile(ExpandConstant('{userdocs}\Rockstar Games\GTA V\EnumDisplay.txt'), Format('%dx%d'+#13#10, [Width,Height]), True); LoadStringFromFile(ExpandConstant('{userdocs}\Rockstar Games\GTA V\EnumDisplay.txt'), ANSIStr); UnicodeStr := String(ANSIStr); DisplayCombo.Items.Add(AnsiString(UnicodeStr)); end; end; end; end; ![]() Thanks for your help Last edited by JRD!; 25-09-2015 at 12:38. |
The Following 2 Users Say Thank You to JRD! For This Useful Post: | ||
houcine80 (17-11-2015), RamiroCruzo (22-09-2015) |
Sponsored Links |
#2
|
||||
|
||||
Nice one
|
#3
|
||||
|
||||
Code:
#DEFINE NAME="CheckResDynamic" [Setup] AppName={#NAME} AppVersion=1.0 CreateAppDir=false OutputDir=. OutputBaseFilename={#NAME} [Code] #ifdef UNICODE #define AW "W" #else #define AW "A" #endif const CCHFORMNAME = 32; CCHDEVICENAME = 32; SM_CXSCREEN = 0; SM_CYSCREEN = 1; MB_ICONWARNING = 2; type TDeviceMode = record dmDeviceName: array[0..CCHDEVICENAME - 1] of Char; dmSpecVersion: Word; dmDriverVersion: Word; dmSize: Word; dmDriverExtra: Word; dmFields: DWORD; dmOrientation: Smallint; dmPaperSize: Smallint; dmPaperLength: Smallint; dmPaperWidth: Smallint; dmScale: Smallint; dmCopies: Smallint; dmDefaultSource: Smallint; dmPrintQuality: Smallint; dmColor: Smallint; dmDuplex: Smallint; dmYResolution: Smallint; dmTTOption: Smallint; dmCollate: Smallint; dmFormName: array[0..CCHFORMNAME - 1] of Char; dmLogPixels: Word; dmBitsPerPel: DWORD; dmPelsWidth: DWORD; dmPelsHeight: DWORD; dmDisplayFlags: DWORD; dmDisplayFrequency: DWORD; dmICMMethod: DWORD; dmICMIntent: DWORD; dmMediaType: DWORD; dmDitherType: DWORD; dmICCManufacturer: DWORD; dmICCModel: DWORD; dmPanningWidth: DWORD; dmPanningHeight: DWORD; end; TDeviceFilter = record Width: DWORD; Height: DWORD; end; var ModeIndex: DWORD; ModeExists: Boolean; FilterIndex: Integer; DisplayPage: TWizardPage; DisplayCombo: TNewComboBox; DisplayModes: array of TDeviceFilter; DisplaySettings: TDeviceMode; function EnumDisplaySettings(lpszDeviceName: string; iModeNum: DWORD; var lpDevMode: TDeviceMode): BOOL; external 'EnumDisplaySettings{#AW}@user32.dll stdcall'; function GetSystemMetrics (nIndex: Integer): Integer; external '[email protected] stdcall setuponly'; function _MessageBoxW_(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer; external '[email protected] stdcall'; function SysMsgBox(const Caption, Message: String; const Flags: Integer): Integer; begin Result := _MessageBoxW_(StrToInt(ExpandConstant('{wizardhwnd}')), Message, Caption, Flags); end; procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean); begin Confirm:=False; Cancel:=True; end; function LoadValueFromXML(const AFileName, APath: string): string; var XMLNode: Variant; XMLDoc: Variant; begin Log('Get Xml text node: ' + AFileName); Result := ''; XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); Result := XMLNode.text; end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; function GetAttrValueFromXML(const AFileName, APath: string): string; var XMLNode: Variant; XMLDoc: Variant; begin Result := ''; XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); Result := XMLNode.NodeValue; end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure SaveValueToXML(const AFileName, APath, AValue: string); var XMLNode: Variant; XMLDoc: Variant; begin Log('Save Xml text node: ' + AFileName); XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); XMLNode.text := AValue; XMLDoc.save(AFileName); end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure SaveAttributeValueToXML(const AFileName, APath, AAttribute, AValue: string); var XMLNode: Variant; XMLDoc: Variant; begin Log('Save Xml attr: ' + AFileName); XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0'); try XMLDoc.async := False; XMLDoc.load(AFileName); if (XMLDoc.parseError.errorCode <> 0) then SysMsgBox('{#NAME}', 'Le fichier "settings.xml" est introuvable.', MB_ICONWARNING) else begin XMLDoc.setProperty('SelectionLanguage', 'XPath'); XMLNode := XMLDoc.selectSingleNode(APath); XMLNode.setAttribute(AAttribute, AValue); XMLDoc.save(AFileName); end; except SysMsgBox('{#NAME}', 'Une erreur est survenue!' + #13#10 + GetExceptionMessage, MB_ICONWARNING); end; end; procedure DisplayComboOnChange(Sender: TObject); var ModeIndex: DWORD; ModeExists: Boolean; FilterIndex,ProgressBarPos,ProgressBarMax: Integer; DisplayModes: array of TDeviceFilter; DisplaySettings: TDeviceMode; XMLFile: string; begin XMLFile := ExpandConstant('{src}\settings.xml'); ModeIndex := 0; while EnumDisplaySettings('', ModeIndex, DisplaySettings) do begin with DisplaySettings do begin Inc(ModeIndex); ModeExists := False; for FilterIndex := 0 to GetArrayLength(DisplayModes) - 1 do begin if (DisplayModes[FilterIndex].Width = dmPelsWidth) and (DisplayModes[FilterIndex].Height = dmPelsHeight) then begin ModeExists := True; Break; end; end; if not ModeExists then begin SetArrayLength(DisplayModes, GetArrayLength(DisplayModes) + 1); with DisplayModes[GetArrayLength(DisplayModes) - 1] do begin Width := dmPelsWidth; Height := dmPelsHeight; if DisplayCombo.Text = Format('%dx%d', [Width,Height]) then begin SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value',IntToStr(Width)); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value',IntToStr(Height)); end; end; end; end; end; end; procedure InitializeWizard; var xres,yres: integer; XMLFile,ResW,ResH: string; XMLDoc,NewNode,XMLNode,RootNode: Variant; AutoRunFormNotebook: TNewNotebook; AutoRunForm: TNewNotebookPage; begin xres := GetSystemMetrics(SM_CXSCREEN); yres := GetSystemMetrics(SM_CYSCREEN); XMLFile := ExpandConstant('{src}\settings.xml'); XMLDoc := CreateOleObject('MSXML2.DOMDocument'); XMLDoc.async := False; XMLDoc.resolveExternals := False; XMLDoc.load(XMLFile); XMLNode := XMLDoc.selectSingleNode('//Settings/FirstLaunch'); {if ((XMLNode as IDispatch) = nil) then begin NewNode := XMLDoc.createElement('FirstLaunch'); RootNode := XMLDoc.documentElement; RootNode.appendChild(NewNode); RootNode.lastChild.text := '0'; XMLDoc.Save(XMLFile); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenWidth','value',IntToStr(xres)); SaveAttributeValueToXML(XMLFile, '//Settings/video/ScreenHeight','value',IntToStr(yres)); end;} with WizardForm do begin BorderStyle := bsDialog; Position := poScreenCenter; AutoScroll := False; ClientWidth := ScaleX(220); ClientHeight := ScaleY(50); Caption:='{#NAME}'; end; AutoRunFormNotebook := TNewNotebook.Create(WizardForm); with AutoRunFormNotebook do begin Parent := WizardForm; Left := ScaleX(0); Top := ScaleY(0); Width := ScaleX(220); Height := ScaleY(50); Align := alClient; end; AutoRunForm := TNewNotebookPage.Create(WizardForm); with AutoRunForm do begin Notebook := AutoRunFormNotebook; end; ResW:=GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenWidth/@value'); ResH:=GetAttrValueFromXML(XMLFile,'//Settings/video/ScreenHeight/@value'); DisplayCombo := TNewComboBox.Create(WizardForm); with DisplayCombo do begin Parent := AutoRunFormNotebook; Left:=10; Top:=15; Width := 200; Text := ResW+'x'+ResH; OnChange:=@DisplayComboOnChange; Style:=csOwnerDrawVariable; end; ModeIndex := 0; while EnumDisplaySettings('', ModeIndex, DisplaySettings) do begin with DisplaySettings do begin Inc(ModeIndex); ModeExists := False; for FilterIndex := 0 to GetArrayLength(DisplayModes) - 1 do begin if (DisplayModes[FilterIndex].Width = dmPelsWidth) and (DisplayModes[FilterIndex].Height = dmPelsHeight)then begin ModeExists := True; Break; end; end; if not ModeExists then begin SetArrayLength(DisplayModes, GetArrayLength(DisplayModes) + 1); with DisplayModes[GetArrayLength(DisplayModes) - 1] do begin Width := dmPelsWidth; Height := dmPelsHeight; DisplayCombo.Items.Add(Format('%dx%d', [Width,Height])); if (Width = xres) and (Height = yres) then DisplayCombo.ItemIndex:=DisplayCombo.Items.Count-1; end; end; end; end; end; |
#4
|
||||
|
||||
Thank you altef_4 !
Code:
if (Width = xres) and (Height = yres) then DisplayCombo.ItemIndex:=DisplayCombo.Items.Count-1; Code:
if (Width = StrToInt(ResW)) and (Height = StrToInt(ResH)) then DisplayCombo.ItemIndex:=DisplayCombo.Items.Count-1; If that little interest someone: Last edited by JRD!; 27-09-2015 at 14:41. |
The Following User Says Thank You to JRD! For This Useful Post: | ||
houcine80 (17-11-2015) |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
need help? TQ:IT no items | realguy88 | General Gaming | 2 | 16-03-2007 09:30 |
FFX and all key items | mitsos79b | General Gaming | 1 | 16-04-2004 07:20 |