Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi dynamisch den Text eines Labels ändern (https://www.delphipraxis.net/65725-dynamisch-den-text-eines-labels-aendern.html)

originalhanno 20. Mär 2006 16:29


dynamisch den Text eines Labels ändern
 
Hallo,
ich habe ein Problem mit dem folgenden Programm.
Ich würde gerne den Text meines Labels zur Laufzeit ändern, und habe auch schon gemerkt, dass es so wohl nicht geht.. :gruebel:
Hilft mir jemand?

Delphi-Quellcode:
program StaticText;

{$R resource.res}

uses
  Windows,
  Messages,
  SysUtils;

  const
  ClassName = 'WndClass';
  AppName = 'Label-Demo';
  WindowWidth = 200;
  WindowHeight = 130;
  Fontname = 'MS Sans Serif';
  FontSize = -12;

const
  IDC_LABEL1 = 1;
  IDC_LABEL2 = 2;

var
  hwndLabel1: DWORD;
  hwndLabel2: DWORD;
  MyFont: HFONT;

{Fensterfunktion}
function WndProc(hWnd: HWND; uMsg: UINT; wParam: wParam; lParam: LParam):
  lresult; stdcall;
 var
   i:integer;
   ausdruck:pchar;
  //x, y : integer;  //Variablen für Fensterposition
begin
  Result := 0;
  case uMsg of
    WM_CREATE:
      begin
        {Label erstellen}
        for i:=1 to 2 do
        if i=1 then ausdruck:='1';
        if i=2 then ausdruck:='2';
        begin
        hwndLabel1 := CreateWindowEx(0, 'STATIC', ausdruck,
          WS_VISIBLE or WS_CHILD, 15, 25, 160, 20, hWnd, IDC_LABEl1, hInstance,
          nil);
        end;

      end;
    WM_DESTROY: PostQuitMessage(0);
  else
    Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
  end;
end;

var
  {Struktur der Fensterklasse}
  wc: TWndClassEx = (
    cbSize         : SizeOf(TWndClassEx);
    Style          : CS_HREDRAW or CS_VREDRAW;
    lpfnWndProc    : @WndProc;
    cbClsExtra     : 0;
    cbWndExtra     : 0;
    hbrBackground  : COLOR_APPWORKSPACE;
    lpszMenuName   : nil;
    lpszClassName  : Classname;
    hIconSm        : 0;
  );
  msg: TMsg;

begin
  {Fenster registrieren}
  RegisterClassEx(wc);

  {Fenster anzeigen}
  CreateWindowEx(0, ClassName, AppName, WS_CAPTION or WS_VISIBLE or WS_SYSMENU,
    CW_USEDEFAULT, CW_USEDEFAULT, WindowWidth, WindowHeight, 0, 0, hInstance,
    nil);

  {Nachrichtenschleife starten}
  while GetMessage(msg,0,0,0) do
  begin
    TranslateMessage(msg);
    DispatchMessage(msg);
  end;

  ExitCode := msg.wParam;
end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:40 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