Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,493 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
MessageBox Hooks, Callbacks, User Defined Buttons & Icons #222119
08/18/08 04:33
08/18/08 04:33
Joined: Aug 2008
Posts: 17
P
PiLX Offline OP
Newbie
PiLX  Offline OP
Newbie
P

Joined: Aug 2008
Posts: 17
MessageBox Hooks, Callbacks, User Defined Buttons & Icons Example For Lite-C (Pure or Legacy)


Code:
#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...


Code:
 _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
P
PiLX Offline OP
Newbie
PiLX  Offline OP
Newbie
P

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)

Code:
mbp.hInstance = GetModuleHandle("your_dll_name.dll"); 


or (you can use either one)


Code:
mbp.hInstance = LoadLibrary("your_dll_name.dll");  


then...

Code:
/* 
           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
P
PiLX Offline OP
Newbie
PiLX  Offline OP
Newbie
P

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..

Code:
long WINAPI GetCurrentThreadId(long);


needs to be (it will crash if you dont change this)

Code:
 
long WINAPI GetCurrentThreadId(void);



then... the code.


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)

Code:
_MessageBox_Hook(NULL, "MessageBox Hooks, Callbacks, User Defined Buttons & Icons", "Lite-C", MB_OK);



Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1