![]() |
Constant expression expected
Mein Problem ist folgendes
Ich schicke von außen also aus der Anwendung eine ID für meine Combobox. Innerhalb der DLL möchte ich diese nun in einer Case Anweisung auswerten. Nun kommt oben genannter Fehler! Wie kann ich diese trotzdem als Constante übergeben ? In der Anwendung..
Delphi-Quellcode:
ID_COLORPICK = WM_APP + 119; // ColorPicker auf TAB 1
Delphi-Quellcode:
DlgItemID ist dann die Constante.. Die will die Case Anweisung aber nicht!
HCombo := CreateWindowEx(0, 'COMBOBOX', PWideChar(ColorLabel), LStyle,
Width - 24, 0, 1, 152, FHColorPicker, DlgItemID, SkinEngine.skInstance, nil); gruss |
AW: Constant expression expected
Hallo,
die Konstante wird ja durch die Übergabe als Variable ja zu eben dieser, also zu einer Variable. Es klappt also nur if statt case. |
AW: Constant expression expected
Zitat:
gruss |
AW: Constant expression expected
Zitat:
Delphi-Quellcode:
funktioniert auf jeden Fall. Falls Du versucht haben solltest, DlgItemID als einen der Selektoren zu verwenden brauchst Du definitiv mehr Schlaf, das wäre ein übler neuronaler Kurzschluß :).
case DlgItemID of
ID_COLORPICK: .... end; |
AW: Constant expression expected
Delphi-Quellcode:
funktioniert nicht!
case DlgItemID of
DlgItemID wird aus der Anwendung an die DLL geschickt und dann wird aus DlgItemID eine Variable. So wie @hoika schon sagte. so geht's.
Delphi-Quellcode:
property DlgItemID: Integer read GetDlgItemID write SetDlgItemID;
Delphi-Quellcode:
so war es vorher
if (PDis^.CtlID = DWORD(SkinColorPicker.DlgItemID)) then
begin case PDis^.itemAction of ODA_DRAWENTIRE: begin if (PDis.itemAction and ODA_DRAWENTIRE) = ODA_DRAWENTIRE then begin
Delphi-Quellcode:
gruss
case PDis^.CtlID of
SkinColorPicker.DlgItemID: // error weil Variable Constant expression expected begin case PDis^.itemAction of ODA_DRAWENTIRE: begin if (PDis.itemAction and ODA_DRAWENTIRE) = ODA_DRAWENTIRE then begin |
AW: Constant expression expected
Zitat:
|
AW: Constant expression expected
Zitat:
Und wie schon gesagt die DLL kennt die Konstante ID_COLORPICK: nicht! Die wird in der Anwendung erstellt. Und DlgItemID = ID_COLORPICK wird zur DLL geschickt. gruss |
AW: Constant expression expected
Zitat:
|
AW: Constant expression expected
Zitat:
Das Problem ist bereits behoben. Du siehst die DLL weis sehr wohl was DlgItemID darstellt. Aber extra nochmal für dich! ANWENDUNG
Delphi-Quellcode:
{$REGION 'Interface ISkinColorPicker'}
ISkinColorPicker = interface ['{EF99A6D4-16F9-4675-B006-CF7D0AAA0065}'] {$REGION 'Getter+Setter'} function GetHandle: HWND; function GetHeight: Integer; procedure SetHeight(const Value: Integer); function GetLeft: Integer; procedure SetLeft(const Value: Integer); function GetTop: Integer; procedure SetTop(const Value: Integer); function GetWidth: Integer; procedure SetWidth(const Value: Integer); function GetDlgItemID: DWord; procedure SetDlgItemID(const Value: DWord); function GetColorLabel: string; procedure SetColorLabel(const Value: string); function GetUseColor: string; procedure SetUseColor(const Value: string); function GetDropDownImg: WideString; procedure SetDropDownImg(const Value: WideString); function GetColorImg: WideString; procedure SetColorImg(const Value: WideString); function GetPipetteCursor: WideString; procedure SetPipetteCursor(const Value: WideString); {$ENDREGION} function CreateWindow(ParentHandle: hWnd): HWND; procedure DestroyWindow; property Handle: HWND read GetHandle; property Left: Integer read GetLeft write SetLeft; property Top: Integer read GetTop write SetTop; property Width: Integer read GetWidth write SetWidth; property Height: Integer read GetHeight write SetHeight; property DlgItemID: DWord read GetDlgItemID write SetDlgItemID; property ColorLabel: string read GetColorLabel write SetColorLabel; property UseColor: string read GetUseColor write SetUseColor; property DropDownImg: WideString read GetDropDownImg write SetDropDownImg; property ColorImg: WideString read GetColorImg write SetColorImg; property PipetteCursor: WideString read GetPipetteCursor write SetPipetteCursor; end; {$ENDREGION}
Delphi-Quellcode:
// ColorPicker
function CTRL_ColorPickerCreate(): ISkinColorPicker; stdcall; external dllfile;
Delphi-Quellcode:
DLL
ColorPicker := CTRL_ColorPickerCreate;
ColorPicker.ColorLabel := SKAERO_COLORLABEL; ColorPicker.Left := 20; ColorPicker.Top := 130; ColorPicker.Width := 200; ColorPicker.Height := 21; ColorPicker.DlgItemID := ID_COLORPICK; // SIEHE hier! SKAERO_SplitColorARGB(SKAERO_AEROCOLOR, Alpha, Red, Green, Blue); ColorPicker.UseColor := SKAERO_RGBtoHex(RGB(Red, Green, Blue)); ColorPicker.DropDownImg := SKAERO_FOLDER + 'ColorPicker\BTN_DropDown.png'; ColorPicker.ColorImg := SKAERO_FOLDER + 'ColorPicker\Color190.png'; ColorPicker.PipetteCursor := SKAERO_FOLDER + 'ColorPicker\pipette.cur'; ColorPicker.CreateWindow(TabHandle); SKAERO_SetAnchorMode(ColorPicker.Handle, ANCHOR_CENTER_HORZ_BOTTOM); SKAERO_SetZorder(ColorPicker.Handle, HWND_TOP);
Delphi-Quellcode:
function TSkinColorPicker.CreateWindow(ParentHandle: HWND): HWND;
var Font: HFont; SetItem, K: Integer; R, G, B, R1, G1, B1: Byte; Count: Integer; CLName, Color: string; Parse, ColorName: TSplitStrArray; begin FHColorPicker := CreateWindowX(0, '/', WS_CHILD or WS_VISIBLE, Left, Top, Width, Height, ParentHandle, @ColorProc, DlgItemID); FParentHandle := ParentHandle; if FHColorPicker <> 0 then begin Img := SkinEngine.AddResource(ParentHandle, PWideChar(FColorImg)); LStyle := WS_CHILD {or WS_VISIBLE} or WS_TABSTOP or CBS_DROPDOWNLIST or CBS_HASSTRINGS or CBS_DISABLENOSCROLL or CBS_OWNERDRAWFIXED or WS_VSCROLL or CBS_NOINTEGRALHEIGHT; HCombo := CreateWindowEx(0, 'COMBOBOX', PWideChar(ColorLabel), LStyle, Width - 24, 0, 1, 152, FHColorPicker, DlgItemID, SkinEngine.skInstance, nil); Font := GetStockObject(ANSI_VAR_FONT); SendMessage(HCombo, WM_SETFONT, Font, 0); SkinColorPicker := self; if ColorLabel > '' then begin SetItem := -1; Parse := Split(ColorLabel, '_'); Count := High(Parse); SkinEngine.SplitColorARGB(SkinEngine.SK_AEROCOLOR, Alpha, Red, Green, Blue); R1 := Red; G1 := Green; B1 := Blue; for K := 0 to Count - 1 do begin // Get Color Name ColorName := Split(Parse[K], ','); CLName := ColorName[Low(ColorName)]; // Remove first ' " ' char if K = 0 then CLName := MidStr(CLName, 2, Length(CLName)); SendMessage(HCombo, CB_ADDSTRING, 0, LParam(CLName)); // Get Color Value Color := Trim(ColorName[High(ColorName)]); R := StrToInt('$' + Copy(Color, 2, 2)); G := StrToInt('$' + Copy(Color, 4, 2)); B := StrToInt('$' + Copy(Color, 6, 2)); SendMessage(HCombo, CB_SETITEMDATA, K, LParam(RGB(R, G, B))); if (R = R1) and (G = G1) and (B = B1) then SetItem := K; end; if SetItem > -1 then SendMessage(HCombo, CB_SETCURSEL, SetItem, 0); end; if UseColor > '' then begin R := Byte(StrToInt('$' + Copy(UseColor, 2, 2))); G := Byte(StrToInt('$' + Copy(UseColor, 4, 2))); B := Byte(StrToInt('$' + Copy(UseColor, 6, 2))); end else begin R := 255; G := 255; B := 255; end; SkinEngine.SetProperty(FHColorPicker, COLORPICK_COLOR, SkinEngine.ColorARGB (255, RGB(R, G, B))); SkinEngine.SetProperty(FHColorPicker, COLORPICK_COMBO, HCombo); btnDropDown := TSkinPushButton.Create(); btnDropDown.ImagePath := DropDownImg; btnDropDown.Text := ''; btnDropDown.Left := FWidth - 24; btnDropDown.Top := 0; btnDropDown.Width := 24; btnDropDown.Height := Max(FHeight, 24);; btnDropDown.DlgItemID := ID_COLORPICKBUTTON; btnDropDown.TextCol := SKAERO_BTNTEXTCOLOR; btnDropDown.Label3D := 1; btnDropDown.TextAlligment := Center; btnDropDown.ImageStateMax := 0; btnDropDown.CreateWindow(FHColorPicker); SkinEngine.SetAnchorMode(btnDropDown.Handle, ANCHOR_NONE); SkinEngine.SetZorder(btnDropDown.Handle, HWND_TOP); end; Result := FHColorPicker; end;
Delphi-Quellcode:
function ColorProc(WinHandle: HWND; Msg: UINT; wP: WParam; lP: LParam)
: LRESULT; stdcall; var PMis: PMeasureItemStruct absolute lP; PDis: PDrawItemStruct absolute lP; ClassName: array [0 .. 128] of Char; ps: TPaintstruct; hDCpaint, DC: HDC; wText: WideString; rc: TRect; imgW, imgH: Cardinal; p1, p2: TGPPoint; p: TPoint; strItem: string; Item: Integer; RGBcolor, Color: ColorRef; begin FillChar(ClassName, SizeOf(ClassName), 0); case Msg of WM_MEASUREITEM: begin PMis := Pointer(lP); if PMis.CtlType = ODT_COMBOBOX then begin PMis.itemHeight := 16; Result := 1; Exit; end; end; WM_DRAWITEM: begin PDis := Pointer(lP); case PDis^.CtlType of ODT_COMBOBOX: begin SetBkMode(PDis.HDC, TRANSPARENT); if (PDis^.CtlID = SkinColorPicker.DlgItemID) then // Problem behoben! Was gibt es nun noch zu diskutieren? Oh und Wunder es funktioniert sogar! gruss |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:23 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz