Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: non-Vcl Programm mit Listbox

  Alt 14. Mai 2018, 20:27
Ich habe es nun umgestellt, von .res direkt in den Hauptcode.

So sieht es bis jetzt aus:
Delphi-Quellcode:
program DStart;

uses
  SysUtils, Windows, Messages, ShellApi, Vcl.Dialogs;

const
  ClassName = 'WndClass';
  AppName = 'DStart';
  WindowWidth = 450;
  WindowHeight =450;

  FontName = 'Verdana';
  FontSize = -12;

const
  IDC_BUTTON = 1;
  IDC_LBITEMS = 2;

var
  hWndListBox: DWORD;
  StdFont: hFont;

function WndProc(hWnd: HWND; uMsg: UINT; wParam: wParam; lParam: LParam):
  lresult; stdcall;
var
  x, y : integer;
  dwEntriesRead: DWORD;
  i: integer;
begin
  Result := 0;
  case uMsg of
    WM_CREATE:
      begin
        x := GetSystemMetrics(SM_CXSCREEN);
        y := GetSystemMetrics(SM_CYSCREEN);
        MoveWindow(hWnd, (x div 2) - (WindowWidth div 2),
          (y div 2) - (WindowHeight div 2),
          WindowWidth, WindowHeight, true);

       hWndListBox := CreateWindowEx(WS_EX_CLIENTEDGE, 'ListBox', 'ListBox',
          WS_VISIBLE or WS_CHILD or LBS_SORT or LBS_STANDARD,150, 75, 180, 100, hWnd, IDC_LBITEMS, hInstance,
          nil);

        StdFont := CreateFont(FontSize, 0, 0, 0, 0, 0, 0, 0, ANSI_CHARSET,
          OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
          DEFAULT_PITCH, FontName);
        if StdFont <> 0 then begin
          SendMessage(hWndListBox, WM_SETFONT, Integer(StdFont), Integer(true));
        end;

      end;
    WM_DESTROY:
      PostQuitMessage(0);
    WM_COMMAND:
      begin
        if hiword(wParam) = BN_CLICKED then
          case loword(wParam) of
            IDC_BUTTON:
              begin
                // do
              end;
          end;
      end;
  else
    Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
  end;
end;

var
  wc: TWndClassEx = (
    cbSize : SizeOf(TWndClassEx);
    Style : CS_HREDRAW or CS_VREDRAW;
    lpfnWndProc : @WndProc;
    cbClsExtra : 0;
    cbWndExtra : 0;
    hbrBackground : COLOR_BTNFACE+1;
    lpszMenuName : nil;
    lpszClassName : ClassName;
    hIconSm : 0;
  );
  msg: TMsg;

begin
  wc.hInstance := hInstance;
  wc.hIcon := LoadIcon(hInstance, MAKEINTRESOURCE(100));
  wc.hCursor := LoadCursor(0, IDC_ARROW);
  RegisterClassEx(wc);
  CreateWindowEx(0, ClassName, AppName, WS_CAPTION or WS_VISIBLE or WS_SYSMENU
    or WS_MINIMIZEBOX, integer(CW_USEDEFAULT),
    integer(CW_USEDEFAULT), WindowWidth, WindowHeight, 0, 0, hInstance, nil);
  while GetMessage(msg,0,0,0) do
  begin
    TranslateMessage(msg);
    DispatchMessage(msg);
  end;
  ExitCode := msg.wParam;
end.
Doch wie fülle ich Listbox, und wie werden daraus 2 Columns?
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat