P
peng_qs
Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,
我现在在做一个利用串口传送数据的托盘程序,经调试发现,在用户点击
托盘菜单时会导致主进程被挂起,无法正确处理接收到的数据,故此想在一个
独立的线程中实现POPUP MENU的弹出操作,但总是无法将菜单弹出,不知
哪位大侠可以提供高见.谢谢
procedure TPCDataLink.IconTray (var Msg: TMessage);
var
hHandle: THandle;
ThreadId1: DWORD;
retCode: DWORD;
p : Pointer;
begin
if (Msg.lParam = wm_rbuttondown) then
begin
if not bHasPopuped then
begin
retCode := 0;
bHasPopuped := True;
p := @PopupMenu1;
hHandle := CreateThread( nil, 0, @PCDataLink_ThreadFunc, p, 0, ThreadId1 );
if hHandle <> 0 then
begin
While Truedo
begin
if not GetExitCodeThread(hHandle,retCode) then
break;
If retCode <> STILL_ACTIVE then
Break;
Application.ProcessMessages;
end;
end;
bHasPopuped := False;
end;
end;
end;
function PCDataLink_ThreadFunc( pInfo : Pointer): Integer;
stdcall;
var
Pt: TPoint;
retCode : Integer;
begin
Try
GetCursorPos (Pt);
TPopupMenu(pInfo^).Popup (Pt.x, Pt.y);
retCode := 0;
except
retCode := 1;
end;
ExitThread( retCode );
Result := retCode;
end;
我现在在做一个利用串口传送数据的托盘程序,经调试发现,在用户点击
托盘菜单时会导致主进程被挂起,无法正确处理接收到的数据,故此想在一个
独立的线程中实现POPUP MENU的弹出操作,但总是无法将菜单弹出,不知
哪位大侠可以提供高见.谢谢
procedure TPCDataLink.IconTray (var Msg: TMessage);
var
hHandle: THandle;
ThreadId1: DWORD;
retCode: DWORD;
p : Pointer;
begin
if (Msg.lParam = wm_rbuttondown) then
begin
if not bHasPopuped then
begin
retCode := 0;
bHasPopuped := True;
p := @PopupMenu1;
hHandle := CreateThread( nil, 0, @PCDataLink_ThreadFunc, p, 0, ThreadId1 );
if hHandle <> 0 then
begin
While Truedo
begin
if not GetExitCodeThread(hHandle,retCode) then
break;
If retCode <> STILL_ACTIVE then
Break;
Application.ProcessMessages;
end;
end;
bHasPopuped := False;
end;
end;
end;
function PCDataLink_ThreadFunc( pInfo : Pointer): Integer;
stdcall;
var
Pt: TPoint;
retCode : Integer;
begin
Try
GetCursorPos (Pt);
TPopupMenu(pInfo^).Popup (Pt.x, Pt.y);
retCode := 0;
except
retCode := 1;
end;
ExitThread( retCode );
Result := retCode;
end;