Extragere date dintr-un Edit Box

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
carrera
Junior
Junior
Posts: 38
Joined: 23 Aug 2007, 12:06

Extragere date dintr-un Edit Box

Post by carrera » 22 Apr 2011, 17:21

Buna,

- Intr-o fereastra child am un form, iar in form un List Control de tip report (cu grid, ca-n excel).
- Cind dau click pe-o celula din grid, afisez un EditBox in jurul acelei celule si il setez cu valoarea acelei celule.
- Problema e ca setarea EditBox-ului se poate face fara probleme, dar de extras textul din el nu mai pot.
- As avea trei moduri:
1. Sa creez o variabila de control pentru EditBox folosind "GetWindowText" - dar nu vrea de nici o forma - Imi crapa la un assert.
2. Prin ::GetWindowText (hWndEdit, szText, TEXTLEN -1); - Nu merge nici asa, szText e gol.
3. Prin ::SendMessage (hWndEdit, WM_GETTEXT,(WPARAM) TEXTLEN - 1,(LPARAM) szText); - Aceeasi situatie ca la 2.

Ciudat e ca la 2 si 3 se poate face setarea textului, dar de extras nu pot sub nici o forma.Buffer-ul iese gol din ambele functii.

Aveti vreo idee?


PS: Totul se face in functia "OnEnUpdateEdit()" adica in functia care se apeleaza ori de cite ori se face o modificare asupra EditBox-ului.

IDC_LIST1 - ID-ul listei
IDC_EDIT11-ID-ul EditBox-ului

Code: Select all

void MyForm::OnEnUpdateEdit()
{
   char buffer[40];
   HWND hWnd1 =  ::GetDlgItem (m_hWnd,IDC_LIST1);
   LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR2;
   RECT rect;
   //get the row number
   nItem = temp->iItem;
   //get the column number
   nSubItem = temp->iSubItem;
   //if(nSubItem == 0 || nSubItem == -1 || nItem == -1) 
   //   return ;
   //Retrieve the text of the selected subItem from the list
   CString str = GetItemText(hWnd1,nItem ,nSubItem);

   RECT rect1,rect2;
   // this macro is used to retrieve the Rectanle of the selected SubItem
   ListView_GetSubItemRect(hWnd1,temp->iItem,temp->iSubItem,LVIR_BOUNDS,&rect);
   //Get the Rectange of the listControl
   ::GetWindowRect(temp->hdr.hwndFrom,&rect1);
   //Get the Rectange of the Dialog
   ::GetWindowRect(m_hWnd,&rect2);

   int x=rect1.left-rect2.left;
   int y=rect1.top-rect2.top;


   if(nItem != -1)   
   ::SetWindowPos(::GetDlgItem(m_hWnd,IDC_EDIT11),HWND_TOP,rect.left+x,rect.top+90 ,rect.right-rect.left ,rect.bottom-rect.top 2,NULL);
   ::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT11),SW_SHOW);
   ::SetFocus(::GetDlgItem(m_hWnd,IDC_EDIT11));
   //Draw a Rectangle around the SubItem
   ::Rectangle(::GetDC(temp->hdr.hwndFrom),rect.left,rect.top-1,rect.right,rect.bottom);
   //Set the listItem text in the EditBox
   ::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT11),str); 

 // Aici e pb. - In ambele situatii buffer e gol.
 // Metoda 1

    ::GetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT11), buffer,39);

// Metoda 2

     HWND hWnd7= ::GetDlgItem(m_hWnd, IDC_EDIT11);
     ::SendMessage(hWnd7, WM_GETTEXT,  0,(WPARAM) buffer);

     *pResult2 = 0;
}
Last edited by Ovidiu Cucu on 22 Apr 2011, 21:17, edited 1 time in total.
Reason: am adaugat taguri [CODE]



Dragos Cojocari
Membru++
Membru++
Posts: 789
Joined: 11 Jul 2007, 14:11

Re: Extragere date dintr-un Edit Box

Post by Dragos Cojocari » 22 Apr 2011, 20:56

Vezi ce intoarce GetWindowText si de asemenea GetLastError.

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Extragere date dintr-un Edit Box

Post by Ovidiu Cucu » 22 Apr 2011, 21:40

  1. Folosesti MFC?
  2. De unde l-ai scos pe pNMHDR2?

carrera
Junior
Junior
Posts: 38
Joined: 23 Aug 2007, 12:06

Re: Extragere date dintr-un Edit Box

Post by carrera » 23 Apr 2011, 11:19

-Ai sesizat bine Ovidiu, pNMHDR2 era problema, nu era initializat corect, am pierdut aproape doua zile cu prostia asta :(
Merci pentru timp Ovidiu, Dragos.

PS: Folosesc MFC.

Post Reply