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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Initialize Controls in a Dialog Box!

Status
Not open for further replies.

atoledo

Programmer
Oct 14, 2002
16
ES
Hi! I need some help from you....

I am opening a dialog box with the dialogBox() function and calling this procedure to catch some messages:

BOOL CALLBACK ReceivedVolanteProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch (message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
if (!GetDlgItemText(hwndDlg, ID_ITEMNAME,
szItemName, 80))
*szItemName=0;

// Fall through.

case IDCANCEL:
EndDialog(hwndDlg, wParam);
return TRUE;
}
break;
case WM_INITDIALOG:

// Get the owner window and dialog box rectangles.

if ((hwndOwner = GetParent(hwndDlg)) == NULL)
{
hwndOwner = GetDesktopWindow();
}

GetWindowRect(hwndOwner, &rcOwner);
GetWindowRect(hwndDlg, &rcDlg);
CopyRect(&rc, &rcOwner);

// Offset the owner and dialog box rectangles so that
// right and bottom values represent the width and
// height, and then offset the owner again to discard
// space taken up by the dialog box.

OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
OffsetRect(&rc, -rc.left, -rc.top);
OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);

// The new position is the sum of half the remaining
// space and the owner's original position.

SetWindowPos(hwndDlg,
HWND_TOP,
rcOwner.left + (rc.right / 2),
rcOwner.top + (rc.bottom / 2),
0, 0, // ignores size arguments
SWP_NOSIZE);
char buffer[256];
sprintf(buffer,"Volante %d Inválido. Favor Introduzca un nuevo código:",volantesCounter-1);
SetDlgItemText(hwndDlg,IDC_VOLANTE_NUMBER,buffer);
if (GetDlgCtrlID((HWND) wParam) != ID_ITEMNAME)
{
HWND prueba=GetDlgItem((HWND) wParam, ID_ITEMNAME);
SetFocus(prueba);
((CEdit*)prueba)->SetLimitText(2);
return FALSE;
}


}
return FALSE;
}

I would like to know how can I set the limit text of my CEdit control wich is in the dialog box.It seems that doesn't find the parent window but I don´t know what to do

Thank you for your help!
 
HWND prueba=GetDlgItem((HWND) wParam, ID_ITEMNAME);
SetFocus(prueba);
((CEdit*)prueba)->SetLimitText(2);


you can't cast a HWND
HWND prueba
to a CEdit pointer. They are not the same thing.
((CEdit*)prueba)

-pete


 
By your use of CEdit makes me wonder, Are you using MFC?

• If so, then you don't need to write a dialog box procedure. You will handle WM_INITDIALOG in a virtual function of your dialog class, and you can use CWnd::GetDlgItem to obtain the CWnd pointer you need.

• If not, then you can't use the CEdit wrapper. Check out EM_LIMITTEXT.

Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top