I'm currently evaluating VC.NET as the new platform for the company I work
for and things are looking grim... We're up against another IDE which took
me about 5 minutes to master and I've been bitching at .NET for the whole
day now not being able to do something as simple as showing a textbox's
content in a damn MessageBox...
The TextBox.Text is a String... MessageBox takes a LPCSTR (plain single byte
char*)... All our current code base is NOT unicode and there is no way in
hell we're converting to unicode. We can live with the fact the interface
will be unicode, as long as the conversions aren't too much of a problem
since we're only using the GUI options for debugging purposes... Our "real"
interfaces will be VB.NET (with occasional C/C++ using plain Win32).
Anyways... I simply want to use the plain ascii version of MessageBox to
show the contents of a TextBox I've put on a form... Should be simple...
I've tried everything from ASCIIEncoding, casting, PtrStringsomething,
StringToHGlobal, etc and nothing works. While we're at it, I'll most likely
need to do the opposite (putting a plain char string into a String)...
Any help would be greatly appreciated....
Thanks alot!!!
Alex (chewing his keyboard!). 3 7399
Hi,
I'm not clear why do you need to output .Text in
win32 MessageBox? If you're already using Winforms
why not use MessageBox::Show(textBox1.Text,"");
Converting from String:
IntPtr ptr = Marshal::StringToCoTaskMemAnsi(textBox1->Text);
::MessageBox(NULL, (char*)ptr.ToPointer(), "", MB_OK);
Marshal::FreeCoTaskMem(ptr);
Converting to String:
char* pStr = "test";
String* str = pStr;
//String* str = new String(pStr);
//String* str = Marshal::PtrToStringAnsi(pStr);
MessageBox::Show(str,"");
Hope that helps
"Sin" <br****@hotmail.com> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl... I'm currently evaluating VC.NET as the new platform for the company I work for and things are looking grim... We're up against another IDE which took me about 5 minutes to master and I've been bitching at .NET for the whole day now not being able to do something as simple as showing a textbox's content in a damn MessageBox...
The TextBox.Text is a String... MessageBox takes a LPCSTR (plain single
byte char*)... All our current code base is NOT unicode and there is no way in hell we're converting to unicode. We can live with the fact the interface will be unicode, as long as the conversions aren't too much of a problem since we're only using the GUI options for debugging purposes... Our
"real" interfaces will be VB.NET (with occasional C/C++ using plain Win32).
Anyways... I simply want to use the plain ascii version of MessageBox to show the contents of a TextBox I've put on a form... Should be simple... I've tried everything from ASCIIEncoding, casting, PtrStringsomething, StringToHGlobal, etc and nothing works. While we're at it, I'll most
likely need to do the opposite (putting a plain char string into a String)...
Any help would be greatly appreciated....
Thanks alot!!!
Alex (chewing his keyboard!).
> I'm not clear why do you need to output .Text in win32 MessageBox? If you're already using Winforms
The real reason was just to try and convert the ->Text member to a plain
ascii single byte char array... We have a huge MSVC6 codebase which is all,
without exception, using plain ascii chars. Most of this code is
crosscompiled into QNX, which is a real-time OS that is somewhat of a unix
clone. Most of these applications do not have a user interface and when they
do they are remote VB screens using OPC to communicate with the control
apps. We're currently looking at .NET for our new Windows dev environement
and even though most of our interfaces are deported, we sometimes have a
need to make a local debug interface. I'm currently evaluating .NET as this
GUI platform. It needs to be simple, cause we're up against National
Instruments CVI which is simple (but on the other hand it's plain C, which
is it's biggest drawback).
In other words, we do not wish to dive in the .NET framework. We want to use
the .NET windows forms as an addtional tool which will be somewhat detached
from our existing (and new) code. MFC is out of the question and win32 is
just too much trouble for the kind of stuff we need to do. I'm a win32
programmer myself, but many here are used to a VB style environment where
you drop a button, double click on it, then write the code. I'm guessing
..NET can be used for this, and I'm currently verifying it.
why not use MessageBox::Show(textBox1.Text,"");
Well I tried but I get errors which I coudln't fix :
MainForm.h(98): error C2039: 'MessageBoxA' : is not a member of
'System::Windows::Forms'
MainForm.h(98): error C2660: 'System::Windows::Forms::Control::Show' :
function does not take 2 arguments
My code :
....
using namespace System::Windows::Forms;
....
private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
MessageBox::Show(textBox1->Text,"");
}
....
It looks to me like it's expanding MessageBox:: to MessagBoxA:: because of
the windows.h define or something... I do have windows.h included but it's
in (another) cpp file (and nowhere in any .h file)
I'm confused...
Converting from String: IntPtr ptr = Marshal::StringToCoTaskMemAnsi(textBox1->Text); ::MessageBox(NULL, (char*)ptr.ToPointer(), "", MB_OK); Marshal::FreeCoTaskMem(ptr);
Converting to String:
char* pStr = "test"; String* str = pStr; //String* str = new String(pStr); //String* str = Marshal::PtrToStringAnsi(pStr); MessageBox::Show(str,"");
Hope that helps
Thanks alot, it's exactly what I was looking for!
Alex.
Yes, compiler is expanding the MessageBox macro and it
conflicts with MessageBox in Winforms.
Simple way to work around it is:
#undef MessageBox
MessageBox::Show(textBox1->Text,"");
If you want to save/restore the MessageBox macro, you can use
push_macro/pop_macro.
After MessageBox macro is #undef'ed you can refer to the actual
MessageBoxA/MessageBoxW by name if needed. why not use MessageBox::Show(textBox1.Text,"");
Well I tried but I get errors which I coudln't fix :
MainForm.h(98): error C2039: 'MessageBoxA' : is not a member of 'System::Windows::Forms' MainForm.h(98): error C2660: 'System::Windows::Forms::Control::Show' : function does not take 2 arguments
My code :
... using namespace System::Windows::Forms; ... private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { MessageBox::Show(textBox1->Text,""); } ...
It looks to me like it's expanding MessageBox:: to MessagBoxA:: because of the windows.h define or something... I do have windows.h included but it's in (another) cpp file (and nowhere in any .h file) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Claudia Fong |
last post by:
Hi,
I have a MessageBox showing a message that the data has been added. It's
a messageBox containing a MessageBoxButtons.OK. I would like to after
the messagebox show and I click on button OK,...
|
by: wASP |
last post by:
Hello everyone,
I'm new to C# and ASP.NET, so pardon my stupidity on this one.
I'm having a problem with referencing methods/functions external
to a class member function.
My code is as...
|
by: MounilK |
last post by:
Hi all,
I have a form which has a TabControl and a Button. At runtime, on the
TabControl, I create a TabPage with a TextBoxes. Now, when I click the
button after entering some text in the textbox,...
|
by: ItNerd |
last post by:
Someone PLEASE HELP ME!!!!!
All I want to do is a simple postback and grab the value from a textbox
on clicking a linkbutton like below, but the value is not writing to the
screen. I am...
|
by: Debbie Carter |
last post by:
Can XML files be easily encrypted?
|
by: RSH |
last post by:
Hi,
i have a situation where I have a VB .Net Module built that contains all of
the functions I need. I now need to add a form to the project and i need
the form to sdisplay and the module code...
|
by: Tony Johansson |
last post by:
Hello!
I have a modal dialog lets call it TestDialog that is shown by using method
showDialog().
This TestDialog has three controls it's one richtextbox and two buttons.
The buttons is one Ok...
|
by: shane |
last post by:
I am trying to get values from a WMI Query in my textbox, txtResults I don't
think I am understand what I need to do to move the value from the for each
statement in the quary into the textbox, as...
|
by: Markus |
last post by:
Ok, so I'm just messing around with c# at the moment, learning some stuff -- it is surprisingly similar to JavaScript :S -- and I hit a snag: I'm grabbing the value of a texbox and then setting the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |