No i jest problem, bo jak tworze okno wtedy program się zatrzymuje, tak jakby przerywał tworzenie okna.
Jak zakomentuje "while GetMessage(msg, 0, 0, 0) do DispatchMessage(msg);"
wtedy wtyczka tworzy się normalnie lecz okno się nie ukazuje.
Ogólnie jest jeszcze chyba taka opcja żeby główny program odbierał komunikaty i jakoś żeby dll to odbierała?
Bo kod głównego programu posiadam, tylko jak to ogarnąć żeby działało tylko na te moduły?
Kopiuj
library in_midi;
uses
SysUtils,
Windows,
StdCtrls,
Graphics,
Messages,
CheckLst,
SyncObjs,
INIFiles,
Utils,
FileCtrl,
common in '..\common.pas';
{$R *.RES}
type
TMyEvent = Record
MidiMessage: Byte;
Data1: Byte;
Data2: Byte;
Control: Byte;
level : Tlevel;
end;
type
TDetails = class(TObject)
public
gbDetails: TGroupBox;
lbxInputDevices: TCheckListBox;
flbConfig: TFileListBox;
scheme: string;
lConfig, lScheme: TLabel;
output : array [1..64] of TSpectrum;
outEvent: array [1..64] of TMyEvent;
procedure lbxInputDevicesClickCheck(Sender: TObject);
procedure flbConfigClick(Sender: TObject);
procedure LoadFromINI;
private
fCriticalSection: TCriticalSection;
public
procedure DoMidiInData( const aDeviceIndex: integer; const aStatus, aData1, aData2: byte );
end;
var
Wnd: TWndClass;
Msg: TMsg;
procedure TDetails.lbxInputDevicesClickCheck(Sender: TObject);
begin
end;
procedure TDetails.LoadFromINI;
var INI : TINIFile;
i : integer;
begin
begin
INI := TINIFile.Create(getappdir + 'midi\' + ExtractFileName(flbConfig.FileName));
try
for i := 1 to 64 do begin
outevent[i].MidiMessage := INI.ReadInteger('Output'+ inttostr(i), 'Message', 144);
outevent[i].Data1 := INI.ReadInteger('Output'+ inttostr(i), 'Data1', 0);
outevent[i].Control := INI.ReadInteger('Output'+ inttostr(i), 'Control', 0);
end;
finally
INI.Free;
end;
end;
end;
procedure TDetails.flbConfigClick(Sender: TObject);
begin
if length(flbConfig.FileName) > 0 then
begin
LoadFromINI;
scheme:=flbConfig.FileName;
end;
end;
procedure TDetails.DoMidiInData(const aDeviceIndex: integer; const aStatus,
aData1, aData2: byte);
var
thisEvent: TMyEvent;
i: integer;
begin
if aStatus = $FE then Exit;
fCriticalSection.Acquire;
try
begin
thisEvent.MidiMessage :=aStatus;
thisEvent.Data1 :=aData1;
thisEvent.Data2 :=aData2;
for i:=1 to 64 do
begin
if (outevent[i].MidiMessage >= $90) and (outevent[i].MidiMessage <= $9F) then
if thisevent.MidiMessage = outevent[i].MidiMessage then
begin
if thisevent.Data1 = outevent[i].Data1 then
begin
if thisevent.Data2 > $00 then Createspectrum(Output[i],levelmax);
if thisevent.Data2 = $00 then Createspectrum(Output[i],levelmin);
end;
end else
if thisevent.MidiMessage = (outevent[i].MidiMessage - $10) then
if thisevent.Data1 = outevent[i].Data1 then
begin
Createspectrum(Output[i],levelmin);
end;
if (outevent[i].MidiMessage >= $B0) and (outevent[i].MidiMessage <= $BF) then
if thisevent.MidiMessage = outevent[i].MidiMessage then
if thisevent.Data1 = outevent[i].Data1 then
begin
case outevent[i].Control of
0,1: outevent[i].level := (thisevent.Data2 * 5119) div 127;
2: begin
if thisevent.Data2 > $40 then
if (outevent[i].level + thisevent.Data2) >= levelmax
then outevent[i].level := levelmax else
outevent[i].level := outevent[i].level + abs(thisevent.Data2-64);
if thisevent.Data2 < $40 then
if ((outevent[i].level - thisevent.Data2) <= levelmin) or
((outevent[i].level - thisevent.Data2) > levelmax)
then outevent[i].level := levelmin else
outevent[i].level := outevent[i].level - abs(thisevent.Data2-64);
end;
end;
Createspectrum(Output[i],outevent[i].level);
end;
if (outevent[i].MidiMessage >= $E0) and (outevent[i].MidiMessage <= $EF) then
if thisevent.MidiMessage = outevent[i].MidiMessage then
begin
outevent[i].level :=10 *(((thisevent.Data2 * 128) + thisevent.Data1) div 32);
Createspectrum(Output[i],outevent[i].level);
end;
end;
end;
finally
fCriticalSection.Leave;
end;
end;
function init(name: PChar; nameLength: DWORD): DWORD; cdecl;
begin
Result := return('IMidi1|Hardware', name, nameLength);
end;
function WndProc(Wnd: HWND; uMsg: UINT; wPar: WPARAM; lPar: LPARAM): LRESULT; stdcall;
begin
Result := 0;
case uMsg of
WM_DESTROY: PostQuitMessage(0);
else
Result := DefWindowProc(Wnd, uMsg, wPar, lPar);
end;
end;
function create(controlHandle: THandle): PLightningModule; cdecl;
var
myDetails: TDetails;
begin
New(Result);
with Result^ do
begin
handle := controlHandle;
title := 'Midi in';
settings := True;
width := -1;
height := -1;
inputTop := -1;
infoTop := -1;
outputTop := -1;
inputs := 0;
outputs := 6;
inputTooltip := '';
outputTooltip := '';
reserved := nil;
myDetails := TDetails.Create;
details := myDetails;
end;
with Wnd do
begin
lpfnWndProc := @WndProc;
hInstance := hInstance;
lpszClassName := 'My1stApp';
hbrBackground := COLOR_WINDOW;
end;
RegisterClass(Wnd);
CreateWindow('My1stApp', 'Pierwszy program w WinAPI',WS_VISIBLE,0, 0, 100, 100,
0, 0, hInstance, NIL);
while GetMessage(msg, 0, 0, 0) do DispatchMessage(msg);
end;
function action(lightningModule: PLightningModule; input, output: Integer; inputConnected, outputConnected: PChar; var bridge: TSpectrum): Boolean; cdecl;
var
details: TDetails;
begin
details := TDetails(lightningModule.details);
bridge := details.Output[output];
Result := true;
end;
procedure show(lightningModule: PLightningModule; handle: THandle); cdecl;
begin
with TDetails(lightningModule.details) do
begin
gbDetails := TGroupBox.Create(nil);
with gbDetails do
begin
Top := detailsTop;
Left := detailsLeft;
Width := detailsWidth;
Height := detailsHeight;
Ctl3D := True;
Color := clBtnFace;
Caption := 'Midi Settings';
end;
lConfig := TLabel.Create(gbDetails);
with lConfig do
begin
AutoSize := True;
Top := 20;
Left := 8;
Caption := 'Devices: Scheme:';
Parent := gbDetails;
end;
lScheme := TLabel.Create(gbDetails);
with lscheme do
begin
AutoSize := True;
Top := 20;
Left := 400;
Caption := Scheme;
Parent := gbDetails;
end;
lbxInputDevices := TCheckListBox.Create(gbDetails);
with lbxInputDevices do
begin
Top := 40;
Left := 8;
Width := 208;
Height := 126;
onClickCheck := lbxInputDevicesClickCheck;
Parent := gbDetails;
end;
flbConfig := TFileListBox.Create(gbDetails);
with flbConfig do
begin
Top := 40;
Left := 224;
width := 260;
height := 126;
mask := '*.ini';
OnClick := flbConfigClick;
Parent := gbDetails;
end;
gbDetails.ParentWindow := handle;
flbConfig.Directory:=getappdir+ 'midi\';
end;
end;
procedure hide(lightningModule: PLightningModule); cdecl;
begin
with TDetails(lightningModule^.details) do
begin
lbxInputDevices.Free;
gbDetails.Free;
end;
end;
procedure open(lightningModule: PLightningModule; settings: PChar); cdecl;
var
bString: string;
begin
bString := settings;
with TDetails(lightningModule^.details) do
end;
function save(lightningModule: PLightningModule; settings: PChar; settingsLength: DWORD): DWORD; cdecl;
begin
with TDetails(lightningModule^.details) do
end;
procedure destroy(lightningModule: PLightningModule); cdecl;
var
Details: TDetails;
begin
details :=TDetails(lightningModule.details);
FreeAndNil(details.fCriticalSection );
TDetails(lightningModule^.details).Free;
Dispose(lightningModule);
end;
exports
init, create, action, show, hide, open, save, destroy;
end.