473,513 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

An easy way to convert printf's to TextBox->Append's?

In converting a console app to windows, I'd like to emulate the console
(stdout) output into a textbox. I am wondering how I can easily
translate the c style format strings into .NET format strings. It looks
like one can do it by an ICustomFormatter interface, but I'm wondering
if there is a quick a dirty way of doing it, as I'm not sure I will want
to keep it in the long run.

Or is there something already implemented that I just don't know about?

Thanks.

Steve
Nov 17 '05 #1
2 1816
On Wed, 13 Apr 2005 18:27:10 -0400, "Steve N."
<St****@discussions.microsoft.com> wrote:
In converting a console app to windows, I'd like to emulate the console
(stdout) output into a textbox. I am wondering how I can easily
translate the c style format strings into .NET format strings. It looks
like one can do it by an ICustomFormatter interface, but I'm wondering
if there is a quick a dirty way of doing it, as I'm not sure I will want
to keep it in the long run.

Or is there something already implemented that I just don't know about?


Using C or C++ and the Win32 API, it's quite easy; vsprintf() to a
string and append that to an editbox, static or listbox. Sorry, I
don't know what's involved in calling this from managed code.

Untested example, using the safe TCHAR version of vsprintf and output
to an edit box.

#include <windows.h>
#include <tchar.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

int SevEditPrintf(HWND hedit, LPCTSTR fmt, ...)
{
int n;
TCHAR buf[1000];
va_list vargs;

va_start(vargs, fmt);
n = _vsntprintf(buf, sizeof buf, fmt, vargs);
/* Move caret to end of text, no selection */
SendMessage(hedit, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
/* Append the new data */
SendMessage(hedit, EM_REPLACESEL, FALSE, (LPARAM)buf);
/* Be sure it's scrolled into view */
SendMessage(hedit, EM_SCROLLCARET, 0, 0);
return n;
}

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real
Nov 17 '05 #2
Thank you Severian.

Severian [MVP] wrote:
Using C or C++ and the Win32 API, it's quite easy; vsprintf() to a
string and append that to an editbox, static or listbox. Sorry, I
don't know what's involved in calling this from managed code.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
24061
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
2
5225
by: John | last post by:
Hi - I am trying to perform a simple append query, with no luck. I have a table (MktPrices) that has the following fields: BondID, PriceDate, Price. The objective is to allow the user to input a...
5
3132
by: Steven C | last post by:
Hello: I am trying to append a dataset that draws its data from a MSDE instance, and I keep getting the exception: Can't create a child list for field tblCustomers. conn = new...
4
2879
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
4
1519
by: George Durzi | last post by:
I'm trying to set focus on an asp:textbox. I'm running this code after my page_load StringBuilder sb = new StringBuilder(); sb.Append(@"<script language=javascript>"); sb.Append(@"<!--");...
6
1523
by: Rob Shorney | last post by:
Hi, I have a number of text boxes on my web form. when the text is change the serverside event TextChanged gets raised and I do some server side validation. This is fine. However, when the...
13
9197
by: Jason | last post by:
Could someone here show me how I would write a vb program to convert decimal ip address to binary? For example a small form with a convert button and a label for the result and a textbox for the...
2
2035
by: alanliang | last post by:
I want to be able to populate an asp textbox with logitude and lattitude values whenever a user selects a point or creates a marker on google maps. Simply, how do I change an asp's textbox value...
4
9372
by: Brad | last post by:
I am trying to convert an XML Stream received from a web api call into a DataSet to use in the rest of the app. The issue I am running into is that it will not convert the stream to a dataset and...
5
3409
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, It's been a while, I've got a small problem that I could do with your expertise on. As you know (I Think) I build websites for recruitment agencies, part of the website includes a job...
0
7158
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...
0
7535
jinu1996
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...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
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,...
1
5085
isladogs
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.