View Full Version : آیکن سفارشی در messagebox
حمیدرضاصادقیان
یک شنبه 18 آذر 1386, 13:29 عصر
سلام دوستان.آیا امکانش هست در messagebox که خودمون می نویسیم نوع آیکن رو هم خودمون انتخاب کنیم.مثلا از فایلهایی که داخل سیستم هست استفاده بشه.
ICEMAN
یک شنبه 18 آذر 1386, 14:32 عصر
این و یه نگاه بنداز
The following shows how you can use the MessgeBoxIndirect API function. It takes as its parameter a structure which contais the description of the messagebox to build. I encapsulated this API function in a procedure called MyAboutBox, which will show a MessageBox with the application main icon:
{--snip--}
procedure MyAboutBox(Text: String);
var
MsgPars: TMsgBoxParams;
begin
with MsgPars do
begin
cbSize := SizeOf(MsgPars);
hwndOwner := Sysinit.HInstance;
hInstance := Sysinit.hInstance; //where to find resources
lpszText := PChar(Text); //if using Delphi 1, must use StrPCopy.
lpszCaption := 'About';
dwStyle := MB_OK or MB_USERICON;
lpszIcon := 'MAINICON'; //app's main icon, icluded in the *.exe
dwContextHelpId := 0; //help context
lpfnMsgBoxCallback := nil;
dwLanguageId := LANG_NEUTRAL;
end; //with
MessageBoxIndirect(MsgPars);
end;
{--snip--}
Then, you could use it in a event handler, like this:
{--snip--}
procedure TForm1.Button1Click(Sender: TObject);
begin
MyAboutBox('Example of changing the default MessageBox icons'#13 +
'by Odilon Nelson - odilon.nelson@usa.net');
end;
{--snip--}
Note that, in the MyAboutBox proc, I used the following:
{--snip--}
hwndOwner := Sysinit.HInstance;
hInstance := Sysinit.hInstance;
{--snip--}
Well, I did this to avoid confusion between the two hinstance variables, since I'm using a *with* statement. One is the hinstance member of the TMsgBoxParams record, the other is the handle of the app, defined (and initialized) in the Sysinit unit
(remember that ObjectPascal is NOT case sensitive: hInstance and HInstance mean the same).
The lpszIcon member of the TMsgBoxParams record represents the resource name of the compiled icon. Hence, you could reference any resource icon in your app. I used the main app icon just as a convenience.
The advantage of this approach is quite obvious: you have an about box, with no need to include an extra form in your project.
Hamid_PaK
یک شنبه 18 آذر 1386, 17:28 عصر
حمید جان اگر از ابتدا جستجو می کردید سریعتر به نتیجه می رسیدید.
لینک موضوع (http://barnamenevis.org/forum/showthread.php?t=63825)
یا حق ...
حمیدرضاصادقیان
یک شنبه 18 آذر 1386, 21:21 عصر
حالا حمید خان امکانش هست درمورد کدت بیشتر توضیح بدی.آیا امکانش هست در قسمت آیکن مسیر فایلی رو که میخوایم بدیم؟حتما باید پسوندش ico باشد ؟
حمیدرضاصادقیان
دوشنبه 19 آذر 1386, 20:22 عصر
سلام.همچنان منتظر جوابتون هستم
Hamid_PaK
سه شنبه 20 آذر 1386, 16:04 عصر
آیا امکانش هست در قسمت آیکن مسیر فایلی رو که میخوایم بدیم؟
در این مورد بهترین گزینه این هست که شما از ریسورسهای DLL استفاده کنید.
begin
tmsg.cbSize := sizeof(tmsg);
tmsg.hInstance := MainInstance; // LoadLibrary
tmsg.lpszText := 'ÂÒãÇíÔ í˜ íÇã ÈÇ äãÇÏ ÓÝÇÑÔí ...'+#13#13+
'code by Hamid_PaK [PRAISER] - TEST'#9;
tmsg.lpszCaption := 'ÂÒãæÏä ...';
tmsg.dwStyle := MB_RTLREADING+MB_RIGHT+MB_USERICON;
tmsg.lpszIcon := MakeIntResource(102);
tmsg.lpfnMsgBoxCallback := MsgCallBack;
MessageBox(0, pChar(Format('Result of Message: %s',
[MsgRslt[MessageBoxIndirectEx(tmsg)]])), '', 0);
end.
The LoadLibrary function maps the specified executable module into the address space of the calling process.
HINSTANCE LoadLibrary(
LPCTSTR lpLibFileName // address of filename of executable module
);
قسمتهای ضخیم برای فراخوانی آیکون از یک DLL نیازمند تعریفند که اولی را با دریافت Handle کتابخانه و دومی را با شناسه ریسورس مقدار دهی خواهید کرد.
یا حق ...
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.