|
-
Jun 1st, 2001, 02:32 AM
#1
Thread Starter
Addicted Member
textbox -> string
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
-
Jun 1st, 2001, 04:38 AM
#2
Frenzied Member
If you are using a dialog then:
Code:
char *buffer = new char[255];
GetDlgItemText(hwndofdialog,IDI_EDIT1,buffer,255];
if you are not using a dialog:
Code:
char *buffer = new char[255];
GetWindowText(hwndofedit,buffer,255);
You can also send the WM_GETTEXT message (it also retrieves asteriks (passswords)).
-
Jun 1st, 2001, 04:39 AM
#3
Frenzied Member
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
-
Jun 1st, 2001, 08:22 AM
#4
Frenzied Member
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
-
Jun 1st, 2001, 10:33 AM
#5
Thread Starter
Addicted Member
hmm
error C2065: 'edithwnd' : undeclared identifier
Generic vb 5
Private Sub WakeMyAssUp(  As Boolean)
If  Then  :  = False
End Sub
-
Jun 1st, 2001, 10:41 AM
#6
Thread Starter
Addicted Member
looks like you use hwnds a lot up there but you don't tell me how to get them
-
Jun 1st, 2001, 11:21 AM
#7
Frenzied Member
If you make the editbox yourself with APIs, your CreateWindow, or CreateWindowEX will return the hWnd for the edit box.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 11:31 AM
#8
Thread Starter
Addicted Member
k, so how do i make it myself with apis
-
Jun 1st, 2001, 11:33 AM
#9
Frenzied Member
You can do it with Dialogs also. How do you have it right now? Some code would help.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 11:47 AM
#10
Thread Starter
Addicted Member
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 =\
Generic vb 5
Private Sub WakeMyAssUp(  As Boolean)
If  Then  :  = False
End Sub
-
Jun 1st, 2001, 12:04 PM
#11
Frenzied Member
I meant code from you would help
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.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 12:08 PM
#12
Thread Starter
Addicted Member
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
-
Jun 1st, 2001, 12:16 PM
#13
Frenzied Member
Fine be that way. Dont say I did not warn you.
No I dont have anything I can give you.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 1st, 2001, 12:45 PM
#14
Frenzied Member
[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.
Code:
HWND handle = FindWindow(classname,caption)
Here is an example of MFC:
-
Jun 1st, 2001, 03:44 PM
#15
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 3rd, 2001, 07:01 AM
#16
Thread Starter
Addicted Member
o_O
is it me or did neither of those two zips you just posted even have a text box?
-
Jun 3rd, 2001, 07:17 AM
#17
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
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
|