Einzelnen Beitrag anzeigen

Olli
(Gast)

n/a Beiträge
 
#2

Re: [Non VCL] - Button erscheint nicht...

  Alt 11. Okt 2005, 10:19
Bei mir erscheint er ...
Zeilen in denen ich rumgespielt habe sind rot. Denk mal nach, du hast bei WM_CREATE versucht einen Button zu erstellen, doch zu diesem Zeitpunkt war CreateWindowEx für das Hauptfenster noch garnicht zurückgekehrt und ergo die entsprechende Variable (hWndMain) nicht zugewiesen. Du hast also deinem Button NULL als Elternfenster übergeben ... da kann nichts angezeigt werden.
Code:
uses
  Windows,
  Messages;

var
  WndMain,
  WndAbout: TWndClassEx;
  //Fensterhandles
  hWndAbout: HWND;

  //Buttonhandles
  hBtnAbout: HWND;
  msg: TMSG;

[color=red]function CreateButtons(parent: HWND): Boolean;[/color]
begin
[color=red] hBtnAbout := CreateWindow('BUTTON', 'About',[/color]
                            WS_CHILD or WS_VISIBLE,
                            350, 270, 40, 24,
                            parent, 0, 0, nil);
[color=red] Result := IsWindow(hBtnAbout);[/color]
end;

function WndMainProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM;
                     lParam: LPARAM): LRESULT; stdcall;
begin
  case uMsg of
[color=red]   WM_CREATE: if not CreateButtons(hwnd) then[/color]
                 PostQuitMessage(0);
  end;
  Result := DefWindowProc(hwnd, uMsg, wParam, lParam);
end;

function WndAboutProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM;
                      lParam: LPARAM): LRESULT; stdcall;
begin
  Result := DefWindowProc(hwnd, uMsg, wParam, lParam);
end;

function RegisterWindowClasses: Boolean;
begin

  WndMain.cbSize := SizeOf(TWndClassEx);
  WndMain.style := CS_OWNDC;
  WndMain.lpfnWndProc := @WndMainProc;
  WndMain.cbClsExtra := 0;
  WndMain.cbWndExtra := 0;
  WndMain.hInstance := hInstance;
  WndMain.hCursor := LoadCursor(0, IDC_ARROW);
  WndMain.hbrBackground := COLOR_WINDOW;
  WndMain.lpszMenuName := nil;
  WndMain.lpszClassName := 'wnd_Root';
  RegisterClassEx(WndMain);

  WndAbout.cbSize := SizeOf(TWndClassEx);
  WndAbout.style := CS_OWNDC;
  WndAbout.lpfnWndProc := @WndAboutProc;
  WndAbout.cbClsExtra := 0;
  WndAbout.cbWndExtra := 0;
  WndAbout.hInstance := hInstance;
  WndAbout.hCursor := LoadCursor(0, IDC_ARROW);
  WndAbout.hbrBackground := COLOR_WINDOW;
  WndAbout.lpszMenuName := nil;
  WndAbout.lpszClassName := 'wnd_About';
  RegisterClassEx(WndAbout);

  Result := True;

end;

begin

  if not RegisterWindowClasses then
    Exit;

[color=red] CreateWindowEx(WS_EX_APPWINDOW,[/color]
                             'wnd_Root', 'Haupt Fenster',
                             WS_OVERLAPPED or WS_VISIBLE,
                             200, 300,
                             400, 400,
                             0, 0, hInstance, nil);

  while True do
  begin
    if not GetMessage(msg, 0, 0, 0) then
      Break;
    TranslateMessage(msg);
    DispatchMessage(msg);
  end;

end.
Nochmal die color-Tags angepaßt.
  Mit Zitat antworten Zitat