man,vc++ is no fun =(
how do i take the text from an 'edit box' and put it into a string?
i'm basically trying to copy the contents of a text box to the clipboard...
please tell me everything i'll need to do including the include files
Printable View
man,vc++ is no fun =(
how do i take the text from an 'edit box' and put it into a string?
i'm basically trying to copy the contents of a text box to the clipboard...
please tell me everything i'll need to do including the include files
If you are using a dialog then:
if you are not using a dialog:Code:char *buffer = new char[255];
GetDlgItemText(hwndofdialog,IDI_EDIT1,buffer,255];
You can also send the WM_GETTEXT message (it also retrieves asteriks (passswords)).:cool:Code:char *buffer = new char[255];
GetWindowText(hwndofedit,buffer,255);
To place the text to the clipboard use the
Code:SetClipboardData
The SetClipboardData function places data on the clipboard in a specified clipboard format. The window must be the current clipboard owner, and the application must have called the OpenClipboard function. (When responding to the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages, the clipboard owner must not call OpenClipboard before calling SetClipboardData.)
HANDLE SetClipboardData(
UINT uFormat, // clipboard format
HANDLE hMem // data handle
);
Parameters
uFormat
Specifies a clipboard format. This parameter can be a registered format or any of the standard clipboard formats. For more information, see Registered Clipboard Formats and Standard Clipboard Formats.
hMem
Handle to the data in the specified format. This parameter can be NULL, indicating that the window provides data in the specified clipboard format (renders the format) upon request. If a window delays rendering, it must process the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages.
After SetClipboardData is called, the system owns the object identified by the hMem parameter. The application can read the data, but must not free the handle or leave it locked. If the hMem parameter identifies a memory object, the object must have been allocated using the GlobalAlloc function with the GMEM_MOVEABLE and GMEM_DDESHARE flags.
Return Values
If the function succeeds, the return value is the handle of the data.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Remarks
The uFormat parameter can identify a registered clipboard format, or it can be one of the standard clipboard formats. For more information, see Registered Clipboard Formats and Standard Clipboard Formats.
The system performs implicit data format conversions between certain clipboard formats when an application calls the GetClipboardData function. For example, if the CF_OEMTEXT format is on the clipboard, a window can retrieve data in the CF_TEXT format. The format on the clipboard is converted to the requested format on demand. For more information, see Synthesized Clipboard Formats.
Windows CE: The data to be set into the clipboard should be allocated using the LocalAlloc function.
Windows CE does not support the following uFormat values:
CF_GDIOBJFIRST through CF_GDIOBJLAST
CF_DSPBITMAP
CF_DSPENHMETAFILE
CF_DSPMETAFILEPICT
CF_DSPTEXT
CF_HDROP
CF_LOCALE
CF_OWNERDISPLAY
CF_PRIVATEFIRST through CF_PRIVATELAST
No, the limit cna be other than 255. To get the whole text use:
Code:long textlen = SendMessage(edithwnd,WM_GETTEXTLENGTH,0,0);
TCHAR *buffer = new TCHAR[textlen+1];
SendMessage(edithwnd,WM_GETTEXT,textlen,(LPARAM)buffer);
//now buffer contains the whole text that is in the edit box
hmm
error C2065: 'edithwnd' : undeclared identifier
looks like you use hwnds a lot up there but you don't tell me how to get them
If you make the editbox yourself with APIs, your CreateWindow, or CreateWindowEX will return the hWnd for the edit box.
k, so how do i make it myself with apis
You can do it with Dialogs also. How do you have it right now? Some code would help.
ya, some code would help, care to offer some?
i just have an edit box, clicked the lil edit box thing, then drew it,
the end
can you zip a sample project that just has an edit box and
changes the contents then puts the contents into a string then
displays the string in a message box?
sucks going from being able to code vb in my sleep, to being
more lost than i was when i first taught myself qbasic =\
I meant code from you would help :D
I am guessing by your response you are trying to apply VB ideas to a VC++ project and you cant really do that.
First thing first, how familure are you just plan C/C++?
If your answer is your not then you need to learn that stuff first. Becuase your are going to drown in the Visual side if you dont understand classess, pointers, and other basic C/C++ functions. You need to start with console (DOS) apps first then move up.
If you are familure with C/C++ then you should try to break yourself from using the Dialog creation tools and MFC until you learn how to do that stuff using API and manualy doing everything by hand. Its a pain at first but you learn how everything works a lot better that way. Then you can move on to MFC and using the Dialog creation tools.
If you are lucky Vlatko or parksie will come a long and give you their links (You might try the FAQ) to their info
If you have done all the above and you just needed info on how to get info from an edit box on a Dialog box I can help you, if thats what you need.
Get used to being slapped down by VC++. I used to be a GOD when it came to VB, then I move to VC++ an now I feel like a bug. Its hard work to learn VC++, and no where close to as easy as VB.
blablabla, can you zip a sample project that does the things i
asked for above or no?
all i want to do is make one program, i have no books and no
classes teach it here, i'd rather learn it like i've learned all the
other languages i know
Fine be that way. Dont say I did not warn you.
No I dont have anything I can give you.
[code]
cwm i see that you are asking how to make an edit box with API. How did you make this one. I assume you are using MFC.(did you draw the edit box on the form). When using MFC you assign a variable to each control. (in the classwizard). In that case to get the text just use the variable (m_eVar (variable) contains the text).
For your other question to get the hwnd use the FindWindow API.
Here is an example of MFC:Code:HWND handle = FindWindow(classname,caption)
People, play nicely. I assume that if he wants to learn he's not going to use MFC ;)
http://www.parksie.net/Raw.zip
http://www.parksie.net/RawDlg.zip
Those assume the Platform SDK headers are installed, so otherwise change LONG_PTR to LRESULT, and INT_PTR to int.
o_O
is it me or did neither of those two zips you just posted even have a text box?
Bugger it, you're right. Ooops...I think they're a different version to the one I had before, probably because someone complained it was too complicated/useful (despite excessive comments).
Okay, originally when you pressed the button it displayed the editbox's contents in a message box.