1 registered members (AndrewAMD),
1,493
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
MessageBox Hooks, Callbacks, User Defined Buttons & Icons
#222119
08/18/08 04:33
08/18/08 04:33
|
Joined: Aug 2008
Posts: 17
PiLX
OP
Newbie
|
OP
Newbie
Joined: Aug 2008
Posts: 17
|
MessageBox Hooks, Callbacks, User Defined Buttons & Icons Example For Lite-C (Pure or Legacy) #define MAKELANGID(p, s) ((((WORD )(s)) << 10) | (WORD )(p))
#define PRIMARYLANGID(lgid) ((WORD )(lgid) & 0x3ff)
#define SUBLANGID(lgid) ((WORD )(lgid) >> 10)
#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
#define MAKEINTRESOURCE MAKEINTRESOURCEA
#define MB_USERICON 0x00000080L
typedef unsigned long ULONG_PTR;
typedef ULONG_PTR DWORD_PTR;
typedef void* MSGBOXCALLBACK;
typedef struct _MSGBOXPARAMS{
UINT cbSize;
HWND hwndOwner;
HINSTANCE hInstance;
LPCSTR lpszText;
LPCSTR lpszCaption;
DWORD dwStyle;
LPCSTR lpszIcon;
DWORD_PTR dwContextHelpId;
MSGBOXCALLBACK lpfnMsgBoxCallback;
DWORD dwLanguageId;
}MSGBOXPARAMS;
/*
...below is the id of the icon within the acknex.exe. its the only
way (and icon) you can display as a user defined icon unless you
build it yourself or do the resource hack they explain in the manual.
EDIT:
if you have an icon resource in a dll (see next post down)
*/
#define IDI_ICON 103
MSGBOXPARAMS mbp;
int _MessageBox(HWND hwndOwner, LPCSTR lpszText, LPCSTR lpszCaption, DWORD dwStyle, UINT lpszIcon)
{
mbp.cbSize = sizeof(MSGBOXPARAMS);
mbp.hwndOwner = hwndOwner;
mbp.hInstance = GetModuleHandle(NULL);
mbp.lpszText = lpszText;
mbp.lpszCaption = lpszCaption;
mbp.dwStyle = dwStyle | MB_USERICON;
mbp.lpszIcon = MAKEINTRESOURCE(lpszIcon);
mbp.dwContextHelpId = 0;
mbp.lpfnMsgBoxCallback = NULL;
mbp.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
return MessageBoxIndirect(&mbp);
} call it like this... _MessageBox(NULL,"MessageBox Hooks, Callbacks, User Defined Buttons & Icons", "Lite-C", MB_OK, IDI_ICON); nothing to exciting.
|
|
|
Re: _MessageBox. . .
[Re: PiLX]
#222201
08/18/08 12:22
08/18/08 12:22
|
Joined: Aug 2008
Posts: 17
PiLX
OP
Newbie
|
OP
Newbie
Joined: Aug 2008
Posts: 17
|
UPDATE: Icon Resource (.dll) now you can load the icon within your dll.(just edit the code above with these lines)
mbp.hInstance = GetModuleHandle("your_dll_name.dll");
or (you can use either one)
mbp.hInstance = LoadLibrary("your_dll_name.dll");
then...
/*
define the id of the icon within your dll.
below is just an example.. you will have to get the value.
*/
#define IDI_ICON 103
|
|
|
Re: _MessageBox. . .
[Re: PiLX]
#222216
08/18/08 14:12
08/18/08 14:12
|
Joined: Aug 2008
Posts: 17
PiLX
OP
Newbie
|
OP
Newbie
Joined: Aug 2008
Posts: 17
|
UPDATE: Callbacks & User Defined Button Text in order to use this you need to edit windows.h. im not sure why they did this but..
long WINAPI GetCurrentThreadId(long);
needs to be (it will crash if you dont change this)
long WINAPI GetCurrentThreadId(void);
then... the code.
typedef void *HHOOK;
HHOOK hHook;
#define WH_CBT 5
LPCSTR lpString = "Lite-C";
LRESULT CALLBACK CBT_Proc(int nCode, WPARAM wParam, LPARAM lParam)
{
HWND hButton;
switch(nCode)
{
case HCBT_ACTIVATE:
{
hWnd = (HWND)wParam;
hButton = GetDlgItem(hWnd, IDOK);
SetDlgItemText(hWnd, IDOK, lpString);
}
break;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
int _MessageBox_Hook(HWND hWnd, LPCSTR lpszText, LPCSTR lpszCaption, UINT uType)
{
hHook = SetWindowsHookEx(WH_CBT, CBT_Proc, NULL, GetCurrentThreadId());
int _cbt = _MessageBox(hWnd, lpszText, lpszCaption, uType | MB_USERICON, IDI_ICON);
// int _cbt = MessageBox(hWnd, lpszText, lpszCaption, uType); // if you want to use the regular messagebox.
UnhookWindowsHookEx(hHook);
return _cbt;
}
then call it. (use this instead of calling MessageBox or _MessageBox)
_MessageBox_Hook(NULL, "MessageBox Hooks, Callbacks, User Defined Buttons & Icons", "Lite-C", MB_OK);
|
|
|
|