为什么如果我MessageBox()在我的消息循环中调用看似同步的Windows函数,循环本身不会像我调用Sleep()(或类似函数)那样冻结?为了说明我的观点,请采用以下骨架WndProc:
int counter = 0;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
SetTimer(hwnd, 1, 1000, NULL); //start a 1 second timer
break;
case WM_PAINT:
// paint/display counter variable onto window
break;
case WM_TIMER: //occurs every second
counter++;
InvalidateRect(hwnd, NULL, TRUE); //force window to repaint itself
break;
case WM_LBUTTONDOWN: //someone clicks the window
MessageBox(hwnd, "", "", 0);
MessageBeep(MB_OK); //play a sound after MessageBox returns
break;
//default …Run Code Online (Sandbox Code Playgroud) 我有两种"无模式"形式:
你可以看到:
从这种无模式的形式,我想展示一个模态:
的模态形式被构造为:
var
frmExchangeConfirm: TfrmExchangeConfirm;
begin
frmExchangeConfirm := TfrmExchangeConfirm.Create(Application);
try
//Setting popupMode and popupParent still makes the MainForm disabled
// frmExchangeConfirm.PopupMode := pmExplicit;
// frmExchangeConfirm.PopupParent := Self; //owned by us
frmExchangeConfirm.OwnerForm := Self; //tell the form which owner to use
frmExchangeConfirm.ShowModal;
finally
frmExchangeConfirm.Free;
end;
Run Code Online (Sandbox Code Playgroud)
模态表单被告知通过新OwnerForm属性使用哪个所有者:
protected
procedure SetOwnerForm(const Value: TForm);
public
property OwnerForm: TForm read GetOwnerForm write SetOwnerForm;
end;
Run Code Online (Sandbox Code Playgroud)
这迫使手柄娱乐:
procedure TfrmExchangeConfirm.SetOwnerForm(const Value: …Run Code Online (Sandbox Code Playgroud) 如果我在显示消息时使用delphi ShowMessage或MessageDlg,程序会等待按钮中的单击,我不希望程序阻止自己.我需要显示一条消息,我写的程序正在搜索,但只要显示消息,搜索就无法启动..我该怎么办?
谢谢,杰克
ShowMessage('Sto ricercando . . .');
if (cartellaSorgente[Length(cartellaSorgente)] <> '\') then
begin
// do the research
end;
Run Code Online (Sandbox Code Playgroud)