Hello. I'm wondering how I could convert a string that I got from GetWindowText into a variable so I can use it in non-string functions.
What I'm trying to do is get the window text from an editbox which only allows numbers to be inputted and convert it into a variable so I can use it in SetCursorPos function. Right now, it gets the string from the window but SetCursorPos only allows numbers to be inputted.
If you could post an example of how to do it, it would be great.
@Shacktar Yes, I'm trying to convert it to numerical. Also, will that code work in a Win32 application? I'm building my program as a Win32 program not console.
Yes, the code will work, as long as you #include <sstream> . Of course your Win32 application would not start with int main() and you wouldn't be couting the results.
Seriously, if you don't understand the difference between console and windowed applications, you should probably start with the more basic of the two which are console applications. It's better to start off simple when learning a new language.
I already know I should start off with the basics with C++ which is the console apps. But that isn't why I posted this. All I wanted was to know how to convert a string from GetWindowText into a numerical number so that SetCursorPos would be able to use it.
We've given you code that will work whether or not it is in a Win32 project. If you understand how to make windowed applications but can't understand how to use the code we gave you, then you've probably skipped a huge learning step and are in way over your head.
All I wanted to know was, how could I convert a string that I got from GetWindowText command into a numerical number. I know I should be doing console programming and not Win32 right now, but that isn't what I asked. Is it impossible for you to even tell me part of what need to do? Telling me something I already know doesn't help. All I wanted was a little help, is that really that hard to do? Wasting 3 hours to be told to go back to something that I already know is no help.
stringstreams have nothing to do with console programming, you just have to include the right header.
But knowing this is part of the basics that you need to know before attempting anything more complex.
The above WndProc is for some window that has two edit boxes. It is part of "fail.cpp" which may contain more code. When the user clicks the left mouse button, it will attempt to get the text from each of the edit boxes, and attempt to use the text as coordinates for SetCursorPos. The code should work just fine, except for one thing: stringstream is not defined anywhere!. The coder of the above forgot to put #include <sstream> under #include <windows.h> . This code will compile fine after that.
I don't know how I can be more clear than this. As stated before, if you're having trouble with the concept of header files, then you should start off with easier problems before tackling Win32. Besides the program entry points and the fact that Win32 programs run as threads waiting for messages, there is no lack of interchangability for code between console and Win32 GUI apps.