|
Hello, and thanks for reading my post hopefully you can help me.
My problem is i need code or a control that is native with low-overhead using Microsoft Visual C++ .NET that allows a user to add images and text. Exactly like a wordpad, however, it needs to also be able to display (and edit). It seems quite simple but i need to display HTML code. I took a look at the
RichTextBox control and choked, it seemed to have a complicated format for storeing the images and text formatting.. I was hopeing to be able to write
a function that takes a argument of HTML code and convert this into some
cordinates for the text and images (supporting only basic HTML) and use the
System::Drawing2D to draw the text but i run into a problem.
I can not figure out a way to tell how long in pixels or whatever how
long the string will be when it is written out onto the picturebox or form.
Graphics * g = this->CreateGraphics();
g->DrawString( ... blah .. blah , 10, 10 );
No, way i can know where to start drawing my image if for instance i had something like.
"blah blah blah [img src=...]"
btw: This is for the compose form of my mail application. So user can write their email, insert images, and view emails.
|
|
|
|
|
nm; I figured out how to do it.
Using label and picture box controls.
I convert HTML into my own structored format of
text, image, and tag classes linked together then
the main class displays these onto a surface and using
autoscrolling - *magic* it looks just like a webpage..
Well, almost. With a little work it would.
----------------------------------------------------------------------------
<br />
#pragma once<br />
<br />
using namespace System;<br />
using namespace System::Drawing;<br />
using namespace System::Drawing::Drawing2D;<br />
using namespace System::Windows::Forms;<br />
<br />
__gc class mlr_lb {<br />
public:<br />
mlr_lb();<br />
~mlr_lb();<br />
};<br />
__gc class mlr_txt {<br />
public:<br />
mlr_txt();<br />
~mlr_txt();<br />
<br />
Drawing::Color color;<br />
Drawing::Font * font;<br />
String * txt;<br />
};<br />
__gc class mlr_img {<br />
public:<br />
mlr_img();<br />
~mlr_img();<br />
<br />
PictureBoxSizeMode sizemode;<br />
String * path;<br />
Int32 width;<br />
Int32 height;<br />
};<br />
__gc struct mlr_lnk {<br />
Object * obj;<br />
mlr_lnk * next;<br />
};<br />
__gc class mlr {<br />
public:<br />
mlr(void);<br />
~mlr(void);<br />
Int32 x;<br />
Int32 y;<br />
mlr_lnk * lnk;<br />
Boolean RemovePrevCtrls( Form * f );<br />
Boolean Render( Form * f, Graphics * g, Int32 x, Int32 y, Int32 w, Int32 h );<br />
};<br />
<br />
#include "StdAfx.h"<br />
#include ".\mlr.h"<br />
#using <mscorlib.dll><br />
<br />
String * JoinStrAr( String * s[], Int32 x, Int32 l, String * d )<br />
{<br />
String * str = S"";<br />
for( Int32 index = x; index < x+l; index++ )<br />
{<br />
str = S""->Concat( str->Trim(), d, s[index]->Trim(), d);<br />
}<br />
if(str->Length < 1)<br />
return str;<br />
return str->Substring( 0, str->Length - d->Length );<br />
}<br />
String * MakeWidthFit( String * s, System::Windows::Forms::Label * l, Int32 w )<br />
{<br />
l->Text = s;<br />
if( l->Width > w )<br />
{<br />
String * ls[] = s->Trim()->Split( S" "->ToCharArray() );<br />
for( Int32 index = ls->Length; index > -1; index-- )<br />
{<br />
l->Text = JoinStrAr( ls, 0, index, " " )->Trim();<br />
if( l->Width <= w )<br />
{<br />
return JoinStrAr( ls, index, ls->Count - index, " " );<br />
}<br />
}<br />
return s; <br />
}<br />
return NULL;<br />
}<br />
mlr::mlr(void) { }<br />
mlr::~mlr(void) { }<br />
Boolean mlr::RemovePrevCtrls( Form * f )<br />
{<br />
Int32 cnt;<br />
start:;<br />
cnt = f->Controls->Count;<br />
for( Int32 index = 1; index < cnt; index++ )<br />
if( f->Controls->get_Item( index )->Tag->ToString()->CompareTo( S"MLR_CTRL" ) == 0 )<br />
{<br />
f->Controls->RemoveAt( index );<br />
goto start;<br />
}<br />
return true;<br />
}<br />
Boolean mlr::Render( Form * f, Graphics * g, Int32 x, Int32 y, Int32 w, Int32 h )<br />
{<br />
String * str;<br />
Int32 cx = x;<br />
Int32 cy = y;<br />
Int32 clh = 0;<br />
mlr_lnk * l = lnk;<br />
<br />
RemovePrevCtrls( f );<br />
f->Update();<br />
<br />
while( lnk != NULL )<br />
{<br />
if( lnk->obj->GetType()->FullName->CompareTo( "mlr_txt" ) == 0 )<br />
{<br />
mlr_txt * txt = static_cast<mlr_txt*>( lnk->obj );<br />
str = static_cast<mlr_txt*>( lnk->obj )->txt;<br />
while( str != NULL )<br />
{<br />
<br />
System::Windows::Forms::Label * newl = new System::Windows::Forms::Label();<br />
newl->Tag = S"MLR_CTRL"; <br />
newl->AutoSize = true;<br />
newl->Location = Point( cx, cy );<br />
newl->Font = txt->font;<br />
str = MakeWidthFit( str, newl, w - (cx - x) );<br />
if( str != NULL )<br />
{<br />
<br />
cx = x;<br />
if( newl->Height > clh )<br />
clh = newl->Height;<br />
cy = cy + clh;<br />
clh = 0;<br />
}else {<br />
clh = newl->Height;<br />
cx += newl->Width;<br />
}<br />
f->Controls->Add( newl );<br />
}<br />
<br />
}<br />
if( lnk->obj->GetType()->FullName->CompareTo( "mlr_lb" ) == 0 )<br />
{<br />
cx = x;<br />
cy = cy + clh;<br />
clh = 0;<br />
}<br />
if( lnk->obj->GetType()->FullName->CompareTo( "mlr_img" ) == 0 )<br />
{<br />
mlr_img * img = static_cast<mlr_img*>( lnk->obj );<br />
System::Windows::Forms::PictureBox * newpb = new System::Windows::Forms::PictureBox();<br />
newpb->Tag = S"MLR_CTRL";<br />
newpb->Width = img->width;<br />
newpb->Height = img->height;<br />
newpb->BackColor = Color::AliceBlue;<br />
newpb->Image = Image::FromFile( img->path );<br />
newpb->SizeMode = img->sizemode;<br />
<br />
if( cx == x ) <br />
{<br />
imgnochoice:;<br />
newpb->Location = Point( cx, cy );<br />
} else {<br />
if( w - (cx - x) >= img->height ) <br />
{<br />
newpb->Location = Point( cx, cy );<br />
cx += img->width;<br />
if( img->height > clh )<br />
clh = img->height;<br />
}else{<br />
<br />
cx = x;<br />
cy = cy + clh;<br />
goto imgnochoice;<br />
}<br />
}<br />
f->Controls->Add( newpb );<br />
}<br />
lnk = lnk->next;<br />
}<br />
return true;<br />
}<br />
mlr_txt::mlr_txt(void) { }<br />
mlr_txt::~mlr_txt(void) { }<br />
mlr_img::mlr_img(void) { }<br />
mlr_img::~mlr_img(void) { }<br />
mlr_lb::mlr_lb(void) { }<br />
mlr_lb::~mlr_lb(void) { }<br />
<br />
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)<br />
{<br />
mlr * m = new mlr();<br />
mlr_txt * txt1 = new mlr_txt();<br />
mlr_txt * txt2 = new mlr_txt();<br />
mlr_img * img1 = new mlr_img();<br />
mlr_lb * lb1 = new mlr_lb();<br />
txt1->font = new Drawing::Font( "Arial", 15 );<br />
txt1->color = Color::Red;<br />
txt1->txt = S"Hello, my name is kevin. I am writting this long lone for a reason can you guess what the reason is?";<br />
m->lnk = new mlr_lnk;<br />
m->lnk->obj = txt1;<br />
m->lnk->next = new mlr_lnk;<br />
img1->width = 250;<br />
img1->height = 250;<br />
img1->path = "c:\\b.jpg";<br />
img1->sizemode = PictureBoxSizeMode::StretchImage;<br />
m->lnk->next->obj = img1;<br />
m->lnk->next->next = new mlr_lnk;<br />
m->lnk->next->next->obj = lb1;<br />
m->lnk->next->next->next = new mlr_lnk;<br />
txt2->font = new Drawing::Font( "Arial", 10 );<br />
txt2->color = Color::Red;<br />
txt2->txt = S"Alright, im just going to start talking about some apples that fell off a tree and landed into a truck then got driven towards the town and a bird pecked one off and fly over the river back to it's next and feed its babys while it watch a hunter track a deer!";<br />
m->lnk->next->next->next->obj = txt2;<br />
m->lnk->next->next->next->next = NULL;<br />
m->Render( this, this->CreateGraphics(), 10, 10, this->Width - 10, this->Height - 10 );<br />
}<br />
|
|
|
|
|
Hi,
I incorporated a PLK for my VSPackage. I followed the exact instructions for the PLK implementation as mentioned in the VSIP help (including registering it in the registry). I also verified the PLK info.
When I attempt to run the package (by running project in debug mode – F5, using /noVSIP switch), it gives me an error message “Package XX has failed to load properly…”. Half the time the spawned app just goes blank and hangs and does not even give the pakage load failure message.
However, it does not give any clue as to why the package load failed or what the problem is. Is there any way (any log or anything else) in which I can find out why the package is not loading properly? It does not even produce any trace messages to indicate till what point the load went through.
When I run the app in debug mode (using F5) but without the /noVSIP switch, it runs fine and I can trace through it.
Any help will be greatly appreciated.
Thanks.
ManSus.
|
|
|
|
|
I need a method to find out All paths from a node( such as I) to another node (Such as J) in a digraph. the digraph is represented by adjacency matrix!
|
|
|
|
|
First off, you need to reduce the problem. You cannot necessarily determine all paths from I to J if there is a cycle in the graph, because there are (potentially) infinite paths.
Detecting graph cycles is fairly simple. Search on Google for how.
Now, if you are willing to reduce the problem to only Directed Acyclic Graphs, you simply start at I and traverse every possible path. The simplest implementation is to store a representation of the path (possibly just a list of vertex pointers). Every time you come to a point where you could traverse down two different edges, copy the list and traverse down both. (Of course, if there are more than two possible edges, make additional copies and traverse for each.) Since the graph is acyclic, the paths will either run into J (at which point they record/print themselves somewhere) or they will end unsuccessfully (at which point they do nothing else).
This same logic (with minor modifications) will also work on cyclic graphs, but checking for cycles becomes necessary. e.g. Is vertex Q already in the path? If so, don't bother going there again, because it's a cycle. And of course, if there is actually a cycle in valid path (e.g. I->Q->Z->Q->J), it's impossible to return all the paths, because there really will be an infinite number of them. (e.g. I->Q->Z->Q->Z->Q->Z->...Q->J)
|
|
|
|
|
how to set send & recv timeout for TCP?
|
|
|
|
|
|
Try changing the Socket.Blocking Property to false. That way when you call the connect method you can go into you're own loop counting the amount of time you want to wait, but, make sure the socket is on a seperate thread if it has to be or something to keep it working while you loop is working.
You could also try putting you're loop to sleep a number of milli-seconds or seconds to allow the socket to make its connection or not.
while( [it hasnt been 10 seconds] )
{
/* time code */
Threading::Thread::CurrentThread->Sleep( 1000 );
}
|
|
|
|
|
Use the appropriate WSAxxxxxx functions... FD_SETs and so on. Using threads and while loops is non-efficient in my opinion. And what do you exactly want to do ?? Is it a serving socket or a client one ? Why 10 seconds ? I can help more if you clarify your question.
|
|
|
|
|
Hi,
i need a high resolution timer for catching some packages on about every 20 msec.I already have working class which start multimedia timer with 1 msec. precision.And now,the problem: how to sen quit message to my Timer class,or is there any other way to stop the timer from main program in which Timer is started?
Generally, i would like to see some messaging issues in console app's, but with class approach and not classical c++.
many thanks
|
|
|
|
|
Has any body goten the new .net compiler in the toolkit to work with the VC++6 IDE??
How did you do it??
Thanks
|
|
|
|
|
I have a Windows Form Application (.NET), I am having trouble calling a procedure within the namespace from outside the namespace. I have the procedure displaychar outside the namespace which is a wrapper to be called from another programming language. The procedure showchar is within the namespace.
The code:
void displaychar(int mychar) //outside the namespace
{
//showchar(mychar);
formoutput::Form1::showchar(mychar);
}
--results in:
error C2653: 'formoutput' : is not a class or namespace name
Anyone have any ideas??
-Don
|
|
|
|
|
Mabye, formoutput really is not a namespace. I am figuring it may well be.
<br />
void displaychar(int mychar)
{<br />
Form1::showchar(mychar);<br />
}<br />
OR, You may not be including the header file ".\form1.h" witch should define the namespace <quote>formoutput. Use #include ".\form1.h" at the top of the source.
Then call it, however i bet you might get the error.
c:\Documents and Settings\default user.JOSH\My Documents\Visual Studio Projects\Tmle\mlr.cpp(105): error C2352: 'System::Windows::Forms::Form::showchar' : illegal call of non-static member function or something. If so, it means you must first create the class Form1 or gain a pointer to it when it is created from
<br />
Application::Run(new Form1());<br />
|
|
|
|
|
The subject basically says the gist of it.
I'm trying to write a program in C++ where it waits for input for up to 2 seconds but if nothing happens in 2 seconds, it stops looking for input and goes off to do something else.
I know this may touch on stuff that you need multi-threading for but I think I remember reading somewhere that there's a simpler way for something as simple as I'm looking to do.
Does anyone have any code snippets or any ideas?
Thanks in advance for your help.
MaKuTu t3h n00b
|
|
|
|
|
Probably more elegant to do this in a multithreaded fashion, but yes, it's possible to do what you want without multithreading.
First, you're going to need non-blocking input. If you don't have that, I think you're pretty much SOL.
Assuming you have non-blocking input, the basic logic is:
int granularity = 100;
int attempt = 2000;
int attempted = 0;
while (attempted < attempt)
{
if (inputIsAvailable())
{
doSomething();
}
else
{
Sleep(granularity);
attempted += granularity;
}
}
doSomethingElse();
|
|
|
|
|
I guess I don't know whether or not I have non-blocking input.
Do you know any examples of what a function like that might be called/what header file you need?
Thx
|
|
|
|
|
Not really. That would be entirely dependent on what libraries you ae using for input. Perhaps whatever library you are using provides a function (with a name such as bytes_available()) which returns the number of bytes currently available for access. I've used libraries (e.g. JNetLib) which has this type of functionality, but many libraries do not. It is possible to wrap an asynchronous APi and achieve this kind of functionality (which is what JNetLib does), but this wrapping will require threading.
It really depends on what you are trying to do, where this input is coming from, and what libraries you are using.
|
|
|
|
|
hi
i am kind of new in programming and am still learning c++ , and so far i know about functions arrays pointers and a little about file processing but no knowledge of object and classes...
anyway , i've been encountering some annoying problems , and i found out that they're all about the difference between the .h header files and the new ones with the 'using' and namespaces.
and here's some of the problems i found :
- when i use <iostream.h> and for example i store 025 in an integer with cin and then output it with cout i'll get a different value but with <iostream> and using namespace std; i dont have this problem
- while outouting and inputing to a file with <fstream> and using namespace std; and then passing this file to a recursive function as follows :
void func ( ifstream dd )
{ ..bla bla func(dd) bla bla.. }
...
ifstream file ("ff.txt");
func (file);
...
I get errors but with <fstream.h> i dont get these kind of errors
So if anybody would explain to me (in a simplified way) why i get these errors and if there's a way to do the same job with the new header files cause as you know in early courses they dont explain such things
And thanks
==<< ormax3 >>==
|
|
|
|
|
<br />
#include <iostream><br />
using namespace std;<br />
char a = 'a';<br />
int b = 38273;<br />
double c = 9382;<br />
char * d = "hello";<br />
cout << a << " " << b << " " << c << d << endl;<br />
---------------------------------------------------------------------------
<br />
#include "stdafx.h"<br />
#include <windows.h><br />
#include <iostream><br />
using namespace std;<br />
int main(int argc, _TCHAR* argv[])<br />
{<br />
char * OurBuffer = new char[2048];<br />
FILE * FileHandle;<br />
cout << "Reading from C:\\BOOT.INI, using a " <br />
<< ( sizeof(char) * 2048 ) <br />
<< " byte buffer." <br />
<< endl;<br />
cout << "Now displaying the file as it is read line by line." <br />
<< endl;<br />
FileHandle = fopen( "c:\\boot.ini", "r" );<br />
while( OurBuffer[0] != 0 )<br />
{<br />
OurBuffer[0] = 0;<br />
fgets( OurBuffer, 2048 * sizeof(char), FileHandle );<br />
cout << OurBuffer;<br />
}<br />
return 0;<br />
}<br />
---------------------------------------------------------------------------
<br />
Get a string from a stream.<br />
<br />
char *fgets( <br />
char *string,<br />
int n,<br />
FILE *stream <br />
);<br />
wchar_t *fgetws( <br />
wchar_t *string,<br />
int n,<br />
FILE *stream <br />
);<br />
Parameters<br />
string <br />
Storage location for data. <br />
n <br />
Maximum number of characters to read. <br />
stream <br />
Pointer to FILE structure. <br />
Return Value<br />
Each of these functions returns string. NULL is returned to indicate an error or an end-of-file condition. Use feof or ferror to determine whether an error occurred.<br />
---------------------------------------------------------------------------
<br />
Open a file.<br />
<br />
FILE *fopen( <br />
const char *filename,<br />
const char *mode <br />
);<br />
FILE *_wfopen( <br />
const wchar_t *filename,<br />
const wchar_t *mode <br />
);<br />
Parameters<br />
filename <br />
Filename. <br />
mode <br />
Type of access permitted. <br />
Return Value<br />
Each of these functions returns a pointer to the open file. A null pointer value indicates an error. <br />
----------------------------------------------------------------------------------------<br />
|
|
|
|
|
helloo...
this is my first post....
i wonder the differences between borland c++builder with c++ in general???
may you tell me where can i download trial version of borland c++ 6 enterprise edition??
thank's
any suggestion n answer is appreciated..........
|
|
|
|
|
I am trying to print from a richTextBox in Managed C++, but I can't figure out how to pront the formatting with the text. I tried making a streamreader and inputting the text, but I got an error that the streamreader can't be over 240 chars or something. I am also affraid that if I get this to work, it won't take into account all of the formatting. Hopefully someone can help.
James Meade
vLT(jg) vUSN
vOPSOFF VAQ-140
|
|
|
|
|
Hi Dear...
I struck in a problem & I know you can help me..
I've a pro-merchant account in amazon..& I want to upload Inventory to amazon.. but getting problem..File Error..even from site upload...
Can you send me Execl file you used for that uploading...
+ if possible some coding snippet of uploading invenorty. I want to upload through coding.. send me at:
sumit_kapoor1980@hotmail.com
or chat with me at hotmail account or yahoo: sumit_kapoor1980@yahoo.com
I hope you will help me..
Thanks
Have a Nice Life..
Sumit Kapoor.
---Sumit Kapoor---
|
|
|
|
|
Can any one tell me how can I detect keyboard whenever it is unplugged?
Any hint !!!
|
|
|
|
|
I need a good compiler... Preferably for Win32... I am noob..
|
|
|
|
|
|