窗口互斥的问题,像QQ发送消息窗口那样,已打开则show它,发给其它好友的又可以新创建??
程序类似QQ发送消息的窗口:
1.若已经打开了发给好友A的窗口,再次点击的话则把它show到前面.
2.若是点击发给其它好友,则可以新创建一个窗口.
现在我的问题是,点发给A的话(已打开),可以show它,没有新建,点击发给B的话也可以新建,若回头再点A,就乱套了.代码如下:
互斥部分:
function createform(id:pchar):string;
procedure DestroyMutex;
implementation
var Mutex: hWnd;
{$R *.dfm}
procedure DestroyMutex;
begin
if Mutex <> 0 then
CloseHandle(Mutex);
end;
function createform(id:pchar):string;
var mUTEX:HWND;
begin
Mutex := Windows.CreateMutex(nil, False, id);
if (GetLastError = ERROR_ALREADY_EXISTS) or (Mutex = 0) then
begin
sendfm.Show;
if sendfm.WindowState<>wsNormal then sendfm.WindowState:=wsNormal;
Result:='Created';
end
else
begin
Result:='NoSame';
end;
end;
创建窗口部分:
button的name作为ID以创建不同的ID实例
if createform(pchar(pbutton.Name ))='NoSame' then CallCreateFrm(pButton.Name);
另当窗口关闭时,如果调用destroyMutex?
代码是放在main单元中,发送窗口sendunit已经uses了它,现在怎么调用main单元中的destroyMutex.打算用消息处理,请高手指点...