I have a problem which i dont know how to resolve..
At program startup its showing a messagebox with two buttons. yes and no. But i dont want yes/no text on the captions. I want a custom text on the buttons. So i resolved to SetDlgItemText. Now it only shows the "yes" and "no" captions. I want to show "server" and "client" instead. How can i do that?
This is my class:
public class ExMsgBox
{
[DllImport("user32.dll")]
private static extern int MessageBoxA(int hwnd, string lptext, string lpcaption, int wtype);
[DllImport("user32.dll")]
private static extern bool SetDlgItemTextA(int hDlg, int npdlg, string lptext);
[DllImport("user32.dll")]
private static extern int SetWindowsHookExA(int nID, Callback lpfn, int hMod, int dwThread);
[DllImport("user32.dll")]
private static extern int UnHookWindowsEx(int hHook);
private delegate int Callback(int uMsg, int wParam, int lParam);
private event Callback msgboxevent;
//variables
private const int MB_YESNO = 0x00000004;
private const int MB_ICONINFORMATION = 0x00000040;
private const int MB_TASKMODAL = 0x00002000;
private int CBT = 5;
private int WH_CBT_ACTIVATE = 5;
private int hook;
public const int IDYES = 6;
public const int IDNO = 7;
public ExMsgBox()
{
}
private int MsgBoxProc(int uMsg, int wParam, int lParam)
{
if (uMsg == WH_CBT_ACTIVATE)
{
SetDlgItemTextA(wParam, IDYES, "Server"); /* i want both
SetDlgItemTextA(wParam, IDNO, "Client"); IDYES and
UnHookWindowsEx(hook); IDNO to show
} the values
return 0; written */
}
private static void Thread_Init()
{
return;
}
public int MsgBox(int hwnd)
{
Thread managedThread = new Thread(new ThreadStart(Thread_Init));
msgboxevent += new Callback(this.MsgBoxProc);
hook = SetWindowsHookExA(CBT, msgboxevent, 0, managedThread.ManagedThreadId);
return MessageBoxA(hwnd, "test1", "test", MB_YESNO | MB_ICONINFORMATION | MB_TASKMODAL);
}
}
}
At program startup its showing a messagebox with two buttons. yes and no. But i dont want yes/no text on the captions. I want a custom text on the buttons. So i resolved to SetDlgItemText. Now it only shows the "yes" and "no" captions. I want to show "server" and "client" instead. How can i do that?
This is my class:
public class ExMsgBox
{
[DllImport("user32.dll")]
private static extern int MessageBoxA(int hwnd, string lptext, string lpcaption, int wtype);
[DllImport("user32.dll")]
private static extern bool SetDlgItemTextA(int hDlg, int npdlg, string lptext);
[DllImport("user32.dll")]
private static extern int SetWindowsHookExA(int nID, Callback lpfn, int hMod, int dwThread);
[DllImport("user32.dll")]
private static extern int UnHookWindowsEx(int hHook);
private delegate int Callback(int uMsg, int wParam, int lParam);
private event Callback msgboxevent;
//variables
private const int MB_YESNO = 0x00000004;
private const int MB_ICONINFORMATION = 0x00000040;
private const int MB_TASKMODAL = 0x00002000;
private int CBT = 5;
private int WH_CBT_ACTIVATE = 5;
private int hook;
public const int IDYES = 6;
public const int IDNO = 7;
public ExMsgBox()
{
}
private int MsgBoxProc(int uMsg, int wParam, int lParam)
{
if (uMsg == WH_CBT_ACTIVATE)
{
SetDlgItemTextA(wParam, IDYES, "Server"); /* i want both
SetDlgItemTextA(wParam, IDNO, "Client"); IDYES and
UnHookWindowsEx(hook); IDNO to show
} the values
return 0; written */
}
private static void Thread_Init()
{
return;
}
public int MsgBox(int hwnd)
{
Thread managedThread = new Thread(new ThreadStart(Thread_Init));
msgboxevent += new Callback(this.MsgBoxProc);
hook = SetWindowsHookExA(CBT, msgboxevent, 0, managedThread.ManagedThreadId);
return MessageBoxA(hwnd, "test1", "test", MB_YESNO | MB_ICONINFORMATION | MB_TASKMODAL);
}
}
}