贴出主要代码吧
全局变量:
[b]var[/b]
hMsgBox: HHOOK;
[b]function[/b] HMSGBOXProc(Msg, wParam, lParam: Integer): Integer; [b]stdcall[/b];
[b]var[/b]
hWindow: HWND;
hMainIcon: HICON;
[b]begin[/b]
[b]if[/b] Msg < 0 [b]then[/b]
Result := CallNextHookEx(hMsgBox, Msg, wParam, lParam);
[b]if[/b] Msg = HCBT_ACTIVATE [b]then[/b]
[b]begin[/b]
hWindow := HWND(wParam);
hMainIcon := LoadIcon(Sysinit.HInstance, 'MAINICON'); //需要什么图标在这里改,默认是程序图标
SendMessage(hWindow, WM_SETICON, ICON_SMALL, hMainIcon);
Result := 0;
[b]end[/b];
Result := CallNextHookEx(hMsgBox, Msg, wParam, lParam);
[b]end[/b];
//MsgBoxEx替代了MessageBox
[b]function[/b] MsgBoxEx(AHWND: HWND; AText, ACaption: [b]String[/b];
AStyle: LongWord): Cardinal;
[b]var[/b]
ret: Integer;
[b]begin[/b]
hMsgBox := SetWindowsHookEx(WH_CBT, @HMSGBOXProc, GetModuleHandle([b]nil[/b]), 0);
ret := MessageBox(AHWND, PChar(AText), PChar(ACaption), AStyle);
UnhookWindowsHookEx(hMsgBox);
Result := ret;
[b]end[/b];
执行:
MsgBoxEx(Handle, 'This is a MessageBox', 'Title', MB_ICONQUESTION [b]or[/b] MB_YESNOCANCEL);