在開(kāi)發(fā) PC 端項(xiàng)目時(shí),有時(shí)我們需要提醒用戶進(jìn)行相關(guān)操作 / 提示用戶下一步該如何操作
那么我們就需要與 Windows 進(jìn)行交互,來(lái)告訴 Windows 彈個(gè)框出來(lái)
去提醒用戶,確認(rèn)/取消 是/否?
這里有兩種方法:
1.調(diào)用User32.dll外部庫(kù),實(shí)現(xiàn)彈框
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-641735.html
2.調(diào)用System.Windows.Forms.dll 外部庫(kù),實(shí)現(xiàn)彈框
?

?
//-----------------------
// @Author GarFey
// @date 20190612
// @version 1.0
//-----------------------
using System;
using System.Runtime.InteropServices;//調(diào)用外部庫(kù),需要引用命名空間
///
/// 為了調(diào)用外部庫(kù)腳本
///
public class ChinarMessage
{
? ? [DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
? ? public static extern int MessageBox(IntPtr handle, String message, String title, int type);
//具體方法
}
returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-0:返回值均:1", "確認(rèn)", 0);
? ? ? ? ? ? ? ? print(returnNumber);
?2.2
returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-1:確認(rèn):1,取消:2", "確認(rèn)|取消", 1);
print(returnNumber);
?2.3
returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-2:中止:3,重試:4,忽略:5", "中止|重試|忽略", 2);
? ? ? ? ? ? ? ? print(returnNumber);
?2.4
returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-3:是:6,否:7,取消:2", "是 | 否 | 取消", 3);
? ? ? ? ? ? ? ? print(returnNumber);
?2.5
returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-4:是:6,否:7", "是 | 否", 4);
? ? ? ? ? ? ? ? print(returnNumber);
2.6
returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-5:重試:4,取消:2", "重試 | 取消", 5);
? ? ? ? ? ? ? ? print(returnNumber);
?2.7
returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-6:取消:2,重試:10,繼續(xù):11", "取消 | 重試 | 繼續(xù)", 6);
? ? ? ? ? ? ? ? print(returnNumber);
?

?
//Asterisk:包含一個(gè)符號(hào),該符號(hào)在圓圈中包含小寫(xiě)字母 i。
//OK:OK按鈕
MsgBoxBase.Show("Chinar,OK按鈕,燈泡圖標(biāo)", GetType().Name, WinForms.MessageBoxButtons.OK, WinForms.MessageBoxIcon.Asterisk);
2.2
//Error:包含一個(gè)符號(hào),該符號(hào)包含一個(gè)紅色背景圓圈,圓圈中為白色 X 符號(hào)。
//AbortRetryIgnore:包含中止、 重試和忽略按鈕。
MsgBoxBase.Show("Chinar,中止|重試|忽略,錯(cuò)誤圖標(biāo)", GetType().Name, WinForms.MessageBoxButtons.AbortRetryIgnore, WinForms.MessageBoxIcon.Error);
?2.3
//Exclamation:包含一個(gè)符號(hào),該符號(hào)包含一個(gè)黃色背景三角形,三角形中為感嘆號(hào)。
//OKCancel:中包含確定和取消按鈕。
MsgBoxBase.Show("Chinar,確定|取消,三角感嘆號(hào)", GetType().Name, WinForms.MessageBoxButtons.OKCancel, WinForms.MessageBoxIcon.Exclamation);
?2.4
//Hand: 包含一個(gè)符號(hào),該符號(hào)包含一個(gè)紅色背景圓圈,圓圈中為白色 X 符號(hào)。
//RetryCancel:重試和取消按鈕
MsgBoxBase.Show("Chinar,重試 | 取消,(同錯(cuò)誤圖標(biāo))", GetType().Name, WinForms.MessageBoxButtons.RetryCancel, WinForms.MessageBoxIcon.Hand);
?2.5
//Information:包含一個(gè)符號(hào),該符號(hào)在圓圈中包含小寫(xiě)字母 i。
//YesNo:是和否按鈕
switch (MsgBoxBase.Show("Chinar,是 | 否,燈泡", GetType().Name, WinForms.MessageBoxButtons.YesNo, WinForms.MessageBoxIcon.Information))
{
case WinForms.DialogResult.Yes:
? ? ? ? ?print("對(duì)");
? ? ? ? ?break;
? ? case WinForms.DialogResult.No:
? ? ? ? ?print("錯(cuò)");
? ? ? ? ?break;
? ? case WinForms.DialogResult.None:
? ? ? ? ?print("無(wú)");
? ? ? ? ?break;
?}
?2.6
//None:未包含符號(hào)。
//YesNoCancel:是、否、取消按鈕
MsgBoxBase.Show("Chinar,是 | 否 | 取消,無(wú)圖標(biāo)", GetType().Name, WinForms.MessageBoxButtons.YesNoCancel, WinForms.MessageBoxIcon.None);
?2.7
//Question:包含一個(gè)符號(hào),該符號(hào)包含一個(gè)圓圈,圓圈中為問(wèn)號(hào)。 不再建議使用問(wèn)號(hào)消息圖標(biāo),因?yàn)檫@種圖標(biāo)無(wú)法清楚地表示特定類(lèi)型的消息,并且作為問(wèn)題的消息表述可應(yīng)用于任何消息類(lèi)型。 此外,用戶可能會(huì)將問(wèn)號(hào)消息符號(hào)與幫助信息混淆。 因此,不要在中使用問(wèn)號(hào)消息符號(hào)。 系統(tǒng)繼續(xù)支持它包含的內(nèi)容,只為滿足反向兼容性。
MsgBoxBase.Show("Chinar,OK按鈕,問(wèn)號(hào)?", GetType().Name, WinForms.MessageBoxButtons.OK, WinForms.MessageBoxIcon.Question);
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-641735.html
?
到了這里,關(guān)于Unity調(diào)用Windows彈框(User32.dll/System.Windows.Forms.dll)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!