After restarting my project (I fixed my memory leakage problems), I need some more help. Does anyone know how to clear the contents of a edit box when someone wants to start a new project?
Thanks in advance
After restarting my project (I fixed my memory leakage problems), I need some more help. Does anyone know how to clear the contents of a edit box when someone wants to start a new project?
Thanks in advance
You can use SendMessage() to send the WM_SETTEXT message to the editbox. Just set the text to "".
- SeanAn application sends a WM_SETTEXT message to set the text of a window.
WM_SETTEXT
wParam = 0; // not used; must be zero
lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string
Parameters
lpsz
Value of lParam. Points to a null-terminated string that is the window text.
Return Values
The return value is TRUE if the text is set. It is FALSE (for an edit control), LB_ERRSPACE (for a list box), or CB_ERRSPACE (for a combo box) if insufficient space is available to set the text in the edit control. It is CB_ERR if this message is sent to a combo box without an edit control.
If cities were built like software is built, the first woodpecker to come along would level civilization.
Black Frog Studios
Thank you. I'll see what happensOriginally posted by sean345
You can use SendMessage() to send the WM_SETTEXT message to the editbox. Just set the text to "".
- Sean
Ok, I tried what you said (I think). Here's the code I did:
(IDM_NEW worked before [tested with a message box])....there's no errors, it just won't clear the edit box.Code:case IDM_NEW: //MessageBox(hwnd, "Option not in", NULL, NULL); SendMessage(hwnd, WM_SETTEXT, 0, 0); break;
I think it should be:
- SeanCode:SendMessage(hwnd, WM_SETTEXT, 0,(LPCTSTR)"");
If cities were built like software is built, the first woodpecker to come along would level civilization.
Black Frog Studios
Originally posted by sean345
I think it should be:
- SeanCode:SendMessage(hwnd, WM_SETTEXT, 0,(LPCTSTR)"");Tried what you had above, and that's the error I get (anyone know why it says long?)Code:C:\Program Files\Microsoft Visual Studio\MyProjects\Window Code Test\Window Code Test.cpp(40) : error C2664: 'SendMessageA' : cannot convert parameter 4 from 'char *' to 'long'
Because you are not sending the message to the right handle. You are just sending it to hwnd, your main window handle. You need to send the message to the editbox. like so:
Code:SendMessage(GetDlgItem(hwnd,ID_OF_YOUR_EDITBOX)),WM_SETTEXT,0,(LPARM)"");
Dohojar Moajbuj
Time is the greatest teacher, too bad it kills all its students
You got that error because the 4th parmater in SendMessage has to be cast to (LPARAM) not LPCTSTR
Dohojar Moajbuj
Time is the greatest teacher, too bad it kills all its students
Ok, thanks. That worked. While I'm on the edit box deal, how would you resize the edit box when someone maximizes it (or hwo do you make it fullscreen by default).Originally posted by Dohojar
Because you are not sending the message to the right handle. You are just sending it to hwnd, your main window handle. You need to send the message to the editbox. like so:
Code:SendMessage(GetDlgItem(hwnd,ID_OF_YOUR_EDITBOX)),WM_SETTEXT,0,(LPARM)"");
>>You got that error because the 4th parmater in SendMessage has to be cast to (LPARAM) not LPCTSTR
>>After reading the SendMessage() on MSDN, I kinda thought that that is why<<
Handle WM_SIZE message of the parent window. The lParam has the client dimensions of the parent window packed into it which can be used, if required, to position and size your control. Use LOWORD and HIWORD macros on the lParam value to retrieve these values. I believe that a search of this board should have explicit examples of how to use this message handler in this way if you need them.Originally posted by Quantrizi
how would you resize the edit box when someone maximizes it (or hwo do you make it fullscreen by default).
Last edited by Ken Fitlike; 08-10-2003 at 01:06 PM.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
Would that also resize the edit box also?Originally posted by Ken Fitlike
Handle WM_SIZE message of the parent window. The lParam has the client dimensions of the parent window packed into it which can be used, if required, to position and size your control. Use LOWORD and HIWORD macros on the lParam value to retrieve these values. I believe that a search of this board should have explicit examples of how to do this if you need them.
>>> or hwo do you make it fullscreen by default
You correct your design/UI so that it is not necessary.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
You could obviously alter the parameters to MoveWindow to adjust the size and position of your edit control. Some people prefer to use SetWindowPos instead of MoveWindow.Code:case WM_SIZE: { WORD cx,cy; cx=LOWORD(lParam); /*parent width*/ cy=HIWORD(lParam); /*parent height*/ /*move edit so that it fills parent's client area*/ /* hEdit is handle to your edit control*/ MoveWindow(hEdit, 0, 0, cx, cy, TRUE); return 0; }
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
Ok, thank you. That works perfectly, except that when I do, my status bar is like duplicated (it resizes correctly, but it sticks a copy of itself where it was before resize until I move the cursor down there.Originally posted by Ken Fitlike
You could obviously alter the parameters to MoveWindow to adjust the size and position of your edit control. Some people prefer to use SetWindowPos instead of MoveWindow.Code:case WM_SIZE: { WORD cx,cy; cx=LOWORD(lParam); /*parent width*/ cy=HIWORD(lParam); /*parent height*/ /*move edit so that it fills parent's client area*/ /* hEdit is handle to your edit control*/ MoveWindow(hEdit, 0, 0, cx, cy, TRUE); return 0; }
Also, if a user selects a button to insert something, I'd use WM_GETTEXT and WM_SETTEXT, wouldn't I (to add the text the user selected)?
>>my status bar is like duplicated (it resizes correctly, but it sticks a copy of itself where it was before resize until I move the cursor down there.<<
Then adjust the size/position of your edit control to take into consideration any other controls, including your status bar, that occupy the client area of the parent window. Use GetClientRect to get the dimensions of the statusbar control.
edit:
>> Also, if a user selects a button to insert something, I'd use WM_GETTEXT and WM_SETTEXT, wouldn't I (to add the text the user selected)?<<
Time to read up on edit controls.
Last edited by Ken Fitlike; 08-10-2003 at 01:43 PM.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.