Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetDlgItemText and MessageBox

Status
Not open for further replies.

xorl

Programmer
Aug 8, 2006
10
SE
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);
}

}
}
 
Why don't you just create your own form with a label and 2 buttons rather than trying to hack the MS one?
 
Hey

Sure i could do that with the form and stuff but i wanted to try out this method. Gets boring doing the stuff so i want to try out this functionality.
 
Allright then. i'll do the labels and stuff but thats not what i really want so ill have to turn somewhere else for help with api.

thanks anyway

regards
/xorl

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top