Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#4

Re: NONVCL: Dialog und Accelerator

  Alt 6. Dez 2004, 01:21
So sollte das Hauptprogramm aussehen:
Delphi-Quellcode:
begin
  { tooltips }
  InitCommonControls;

  CreateDialog(hInstance, MAKEINTRESOURCE(100), 0, @dlgfunc);
  { load acceltable }
  hAccelTbl := LoadAccelerators(hInstance, MAKEINTRESOURCE(4000));

  while true do
  begin
    if not GetMessage(msg, 0, 0, 0) then
      break;
    { no accel was pressed, go ahead }
    if TranslateAccelerator(hApp, hAccelTbl, msg) = 0 then
    { it is no dialog message, go ahead }
      if IsDialogMessage(hApp, msg) = FALSE then
      begin
        TranslateMessage(msg);
        DispatchMessage(msg);
      end;
  end;
  ExitCode := msg.wParam;
end.
Die Shortcuts werden dabei aus einem Acceleratortable aus der Resource geladen.
WM_COMMAND dann entsprechend:
Delphi-Quellcode:
    WM_COMMAND:
      begin
      { accel for closing the dialog with ESC }
        if wParam = ID_CANCEL then
          SendMessage(hDlg, WM_CLOSE, 0, 0);
      { button and menu clicks }
        if hiword(wParam) = BN_CLICKED then
        begin
          case LoWord(wParam) of
            IDC_BTNABOUT: MyMessageBox(hDlg, APPNAME, INFO_TEXT, 2);
            IDC_BTNCLOSE: SendMessage(hDlg, WM_CLOSE, 0, 0);
          end;
        end;
      { accelerators }
        if hiword(wParam) = 1 then
        begin
          case loword(wParam) of
            ID_ACCEL_CLOSE: SendMessage(hDlg, WM_CLOSE, 0, 0);
          end;
        end;
      end
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat