-
August 21st, 2013, 12:11 AM
#1
Edit box closing problem
Hi all,
I am doing a win32 application,In that iam creating a dialog box and inside the dialog box one list control also,using resource editor.
For Editing the items and subitem of list control i created a edit box also(When user double click on control).My problem is, after enter the text on edit box if user pressing Enter key,the dialog box itself closing(Actually i need to delete the edit box only).How to do that.Relevent parts of code given below.Please help me
Code:
//Dialog procedure
HWND hEdit=NULL;
LRESULT CALLBACK DlgtProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG://setting the items & subitem values
break;
case WM_NOTIFY:
switch(LOWORD(wParam))
{
case IDC_LISTVIEW:
switch(((LPNMHDR)lParam)->code)
{
case NM_DBLCLK:
if(hEdit!=NULL)
SendMessage(hEdit,WM_KILLFOCUS,0,0);
RECT SubItemRect;
if(ListView_GetSubItemRect(hwnd,ItemClicked.iItem,ItemClicked.iSubItem,LVIR_BOUNDS,&SubItemRect))
{ int iHieght=SubItemRect.bottom-SubItemRect.top;
int iWidth=SubItemRect.right-SubItemRect.left;
iWidth=iWidth/3;
//creating edit box when user double click hEdit= CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""), WS_CHILD | WS_VISIBLE|ES_WANTRETURN |ES_UPPERCASE ,
SubItemRect.left, SubItemRect.top,iWidth,1.5* iHieght,hwnd,0, GetModuleHandle(NULL), NULL);
SetFocus(hEdit);
wphEditProc=(WNDPROC)SetWindowLong(hEdit,GWL_WNDPROC,(LONG)hEditProc);
break;
}
break;
}
break;
}
}
Edit box procedure:
LRESULT CALLBACK hEditProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_KILLFOCUS:
{
LV_DISPINFO lvDispInfo;
ZeroMemory(&lvDispInfo,sizeof(lvDispInfo));
lvDispInfo.hdr.hwndFrom=hwnd;
lvDispInfo.hdr.idFrom=GetDlgCtrlID(hwnd);
lvDispInfo.hdr.code=LVN_ENDLABELEDIT;
lvDispInfo.item.mask=LVIF_TEXT;
lvDispInfo.item.iItem=iItem;
lvDispInfo.item.iSubItem=iSubItem;
lvDispInfo.item.pszText=NULL;
char szedtTxt[100];
GetWindowText(hwnd,(LPWSTR)szedtTxt,100);
lvDispInfo.item.pszText=(LPWSTR)szedtTxt;
lvDispInfo.item.cchTextMax=lstrlen((LPWSTR)szedtTxt);
SendMessage(GetParent(GetDlgItem(hwnd,IDC_LIST1)),WM_NOTIFY,(WPARAM)IDC_LIST1,(WPARAM)&lvDispInfo);
DestroyWindow(hwnd);
break;
}
break;
case WM_KEYDOWN: Handler for keybord events
switch(wParam)
{
case VK_RETURN://Control is not going here.
break;
}
break;
}
return CallWindowProc(wphEditProc, hwnd, uMsg, wParam, lParam);
}
Last edited by manjut19; August 21st, 2013 at 12:16 AM.
-
August 21st, 2013, 12:55 AM
#2
Re: Edit box closing problem
This is a good explanation, what happens when Esc key is pressed in Win32 modal dialog:
http://www.williamwilling.com/blog/?p=28
When Esc is pressed, WM_COMMAND with wParam = IDCANCEL is sent.
When Enter key is pressed, WM_COMMAND with wParam = IDOK is sent (see also http://support.microsoft.com/kb/102589). Try to ignore these commands, at least when edit box is active,
-
August 21st, 2013, 02:17 AM
#3
Re: Edit box closing problem
Originally Posted by Alex F
Thank you very much.I solved my problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|