Q&A

  • SendMessage 질문 드립니다.

안녕하세요.  고수님들 질문이 있는데요. 답변 꼭 부탁 드립니다.

메인 폼 스타일을 fsMDIForm 하고 서브 폼 fsMDIChild 으로 해서 DLL Form 으로 SendMessage 보내면

응답을 하지 않습니다. 속성을 fsNormal 폼으로 하면 응답을 하는데요. 왜 그럴까요.

고수님들 한수 부탁 드립니다.

 

// 전송

procedure Tfrm_Main.Button1Click(Sender: TObject);
begin
  SendMessage(FindWindow('frmProduction_Insert', nil), WM_User, 0, 0);
end;

procedure Tfrm_Main.N2Click(Sender: TObject);
var
  hDllShowForm : THandle;
  DllFunc : procedure; stdcall;
begin
  hDllShowForm := LoadLibrary(PChar('Production_Insert.dll'));
  if(hDllShowForm <= 32)then
      ShowMessage('Production_Insert.dll DLL Error')
  else begin
      @DllFunc := GetProcAddress(hDllShowForm, 'ShowForm');
      if @DllFunc <> Nil then
          DllFunc;
  end;
end;

 

// DLL Form 응답

unit unitProduction_Insert;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FormSize;

type
  TfrmProduction_Insert = class(TForm)
  private
    { Private declarations }
    procedure doWM_User(var Msg: TMessage); message WM_User;
  public
    { Public declarations }
  end;

var
  frmProduction_Insert: TfrmProduction_Insert;

implementation

{$R *.dfm}

{ TfrmProduction_Insert }

procedure TfrmProduction_Insert.doWM_User(var Msg: TMessage);
begin
  ShowMessage('성공');
end;

 

library Production_Insert;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  Forms,
  Controls,
  Dialogs,
  unitProduction_Insert in 'unitProduction_Insert.pas' {frmProduction_Insert};

{$R *.res}

procedure ShowForm; export;
begin
  frmProduction_Insert := TfrmProduction_Insert.Create(Application);
  frmProduction_Insert.Show;
end;

exports
  ShowForm;

begin
end.

end.

1  COMMENTS
  • Profile
    리틀종 2012.11.14 18:12

    찾았습니다.^^

    function FindMIDFormHandle(FindFormName : String): THandle;
    var
      i : Integer;
    begin
      for i := 0 to Screen.CustomFormCount-1 do
      begin
          if LowerCase(Screen.CustomForms[i].Name) = LowerCase(FindFormName) then
          begin
              if(Screen.CustomForms[i].WindowState = wsMinimized)then
              begin
                  Screen.CustomForms[i].WindowState := wsNormal;
              end;
              Result := Screen.CustomForms[i].Handle;
          end;
      end;
    end;