Thanx a lot for the tips! Really helpful :D
Thanx a lot for the tips! Really helpful :D
is it possible to insert a character say " " (space) after every 2 characters in a string?
using this doesnt seem to work :
Dim s As String
s = "010001000100"
s = Mid(s, 1, 2) & " " & Mid(s, 4)
MsgBox s
it adds space only after first two chars
ok, but you can give me some ideas to operate strings faster. It takes insanely high time (never ending some times) with large chunks of text.
OK, This is The Main Project. I apologize for it is roughly written. :$
Actually the buttons have to be pressed one after the other in the manner they are arranged, i.e., the sequence to do it right should be, save - load image - replace - load rtf file
You'll find out what it does, and For load rtf file - write "input.txt" for the file source
PS : I hope you have winrar or any other archiver with rar support :S
I have written a program, it uses a lot of replace funtions with huge amounts of texts.
Resultingly, It takes hell lot of time to operate.
Is there any way I can increase its speed?
COOOOOOOL!!!!
Many Thanx For your Reply!
Now its working perfect!
I want to capture the text in a textbox to a picturebox and I am trying to use bitbit function.
But everytime i use it, the image is not captured of the textbox but of some other area.
Can you explain me how can I use this function correctly?
pic.Visible = True
pic.Height = Text1.Height
pic.Width = Text1.Width
nRet = BitBlt(pic.hDC, 0, 0, Text1.Width - 2, Text1.Height - 2, Me.hDC, Text1.Left + 1, Text1.Top + 1, _ SRCCOPY)
pic.Picture = pic.Image
SavePicture pic.Image, "text.bmp"
pic.Visible = True
Is there any way through which I can split a single string into substrings with 20 characters each.
The first string should contain first 20 characters.
The seconds string should contain the next set of 20 characters and so on.
Is it possible to do what I'm thinking?
I see. Here's a Q&D solution:
Private Function HexString(EvalString As String) As String Dim intStrLen As Integer Dim intLoop As Integer Dim strHex As String EvalString = Trim(EvalString) intStrLen = Len(EvalString) For intLoop = 1 To intStrLen strHex = strHex & " " & Left$("0" & Hex(Asc(Mid(EvalString, intLoop, 1))), 2) Next HexString = strHex End Function
There's one problem with this, now it adds zero to every single pair of digits, Like ff is now 0f, a1 is now 01.... and so on!
well, its printing 0 instead of 00, 1 instead of 01, 2 instead of 02......and so on
i wonder why?
May be Picture1.TextHeight() and Picture1.TextWidth() help you to predict the font size
One last problem. I swear its the last one now!
Well, there is a block of text on the textbox but only the first line is being printed on the picturebox, and I dont want to increae the width of that box.
what should i do then to solve this?
Now, I just discovered a problem in this thing.
The PictureBox is not printing the whole block of text, but only the first line of it.
And I dont want to increase its width anymore.
What should I do then?
I am using the following function to convert ascii to hex, but it is not working properly.
Private Function HexString(EvalString As String) As String
Dim intStrLen As Integer
Dim intLoop As Integer
Dim strHex As String
EvalString = Trim(EvalString)
intStrLen = Len(EvalString)
For intLoop = 1 To intStrLen
strHex = strHex & " " & Hex(Asc(Mid(EvalString, intLoop, 1)))
Next
HexString = strHex
End Function
What am I doing wrong here?
one more question, is replace function case sensitive?
I am trying to replace a string with another string in a string, but it is just not happeneing and is driving me crazy :@ and I am really confused :confused:
Here is the snippet :
Dim strHex2 As String
strHex2 = strHex.Text
Dim Mystring2 As String
Dim GG As Integer
GG = FreeFile()
Open ("d:\ImageHex.dat") For Binary As GG
'For a string, do this:
Mystring2 = Space(LOF(GG))
Get GG, , Mystring2
txthex.Text = Mystring2
Close GG
Dim strRTF As String
Dim strIMHex As String
strRTF = rtfTxt.Text
Dim Mystring3 As String
Dim strHex3 As String
Mystring3 = Replace(Mystring2, Chr(32), "")
strHex3 = Replace(strHex2, Chr(32), "")
Dim strResult As String
strResult = Replace(strRTF, Mystring3, strHex3)
so, strResult is the same as strRTF with no changes, and i dont know why?
Please HELP!!!!
sorry, i should have told that I am still a beginner in this. :?:
Carry on reading the documentation for rtflib perhaps?
Or create an RTF file how you want, then write a program to "dump" the RTF file so you know what the structure is, then repeat that in your program.
I wish that would have been easy, but it isn't. the only way i can think of creating an rtf file like that is by using ms word. but it adds thousands of lines of hectic codes to the simple rtf file making it almost impossible to understand.
Moreover, I do not know how to do the "dump" procedure you talked about and i doubt if it would be helpful as the program is not intended to take a particular image file but different file every time.Any ideas then?
I am develping a program to create an rtf file.The rtf file will be having images in it that will form a border around the page.
Here is the code so far:
#include "rtflib.h"
#include "globals.h"
#include "errors.h"
void main()
{
// Set RTF document font and color table
char font_list[] = "Times New Roman;Arial;";
char color_list[] = "0;0;0;255;0;0;192;192;192;255;255;255";
// Open RTF file
rtf_open( "Sample2.rtf", font_list, color_list );
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_load_image("Picture.jpg", 50, 50);
rtf_close();
}
However instead of forming a border, the images are at the center of the page one after the other.
Is there any way by which i can make them form a border? something like allignment?
no answers? is there no way i can do it?
I am trying to embed an image into an rtf file using VB. Well, I tried using the clipboard method but it doesn't wield any good results, I have to embed it and align it and copy it so that the images form a border.
Ideas anyone?
Problem Solved! Thanx for Helping
Do you mean ? When you give large amount of text, Its font size should be adjusted to fit into it?
Yeah, that should do
And also if i give small text the picture box should adjust its size according to the text so to fit it.
Ok, I give an example.
In a form
> Draw a Picture box (Picture1)
> Draw a Command Button (Command1)Private Sub Command1_Click() Picture1.AutoRedraw = True Picture1.Print "Welcome" Picture1.Print "To" Picture1.Print "VB6" SavePicture Picture1.Image,"C:\Test.jpg" End Sub
Thanx!!!!!!!! That just solved my problem. But there is one last thing :)
I want to put a lot of text in the textbox which is supposed to be captured. But the textbox does not resize to the text, Although it can show scrollbars. I want it to grow as big to fit the whole text on the screen no matter how big the text is.
Is there any way it can resize itself automatically to fit the whole text?
Hi, Instead of using BitBlt() function,you can directly print inside the picture box (using pic.print method) when you reading from the file. Also set AutoRedraw property to true.
Okay, Can you tell me how am I supposed to do that? :?:
HI,
Kindly Furnish the error Details...
-venkat
There are no errors. Its just that I want to capture the details in the textbox and it is capturing the portion of the screen somewhere out of it.
I have written a program that reads a text file and then saves it as an image file.Although the program is reading the file but its having errors saving it as an image file. Please Help!
Option Explicit
Private Const SRCCOPY = &HCC0020
Private Const MERGEPAINT = &HBB0226
Private Const SRCAND = &H8800C6
Private Const DIB_RGB_COLORS = 0
Private Const DIB_PAL_COLORS = 1
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Dim nRet As Long
Private Sub Command1_Click()
'Outline:- Asks the user for a file.
'- Reads all the data into Text1.
Dim FilePath As String
Dim Data As String
FilePath = InputBox("Enter the path for a text file", "The Two R's", _
"D:\address.txt")
'Asks the user for some input via an inp
' ut box.
Open FilePath For Input As #1
'Opens the file given by the user.
Do Until EOF(1)
'Does this loop until ' f>End Of File(' >EOF) for file number 1.
Line Input #1, Data
'Read one line and puts it into the vari
' ble Data.
Text1.Text = Text1.Text & vbCrLf & Data
'Adds the read line into Text1.
MsgBox EOF(1)
Loop
Close #1
'Closes this file.
End Sub
Private Sub Command2_Click()
pic.Visible = True
pic.Height = Text1.Height
pic.Width = Text1.Width
nRet = BitBlt(pic.hDC, 0, …
A simple screen capture would do the trick.
Alt-print screen, paste into your image editor to remove extraneous bits.
Sorry But I have to do this with the help of a C or C++ Program
Till now I have been able to come up with this code:
#include <windows.h>
#include <windowsx.h>
#include <vicdefs.h>
#include <string.h>
int text_to_image(char far *fname, imgdes *resimg)
{
#define FONT_SIZE 12
static LOGFONT lf = { // Use font described by LOGFONT struct
0, 0, 0, 0, FW_NORMAL, 0, 0, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "ARIAL"
};
HFONT hFont, hOldFont;
HBITMAP hOldBitmap;
HWND hWnd;
HDC hDC, hMemDC;
RECT rc;
imgdes tmptext;
int rcode = NO_ERROR, captionHt, captionWd;
char *caption;
HANDLE fhandle;
DWORD filesize, dwBytsRd;
fhandle = CreateFile(fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
filesize = SetFilePointer(fhandle, 0L, NULL, FILE_END);
SetFilePointer(fhandle, 0L, NULL, FILE_BEGIN);
filesize++;
if((caption = (UCHAR near *)calloc(filesize,1)) == NULL)
return(BAD_MEM); // If area not allocated
// Read the file
ReadFile(fhandle, (LPSTR)caption, (unsigned)filesize, &dwBytsRd, NULL);
CloseHandle(fhandle);
hDC = GetDC(GetActiveWindow());
hMemDC = CreateCompatibleDC(hDC);
// Set the font point size
lf.lfHeight= - MulDiv(FONT_SIZE, GetDeviceCaps(hDC,LOGPIXELSY), 72);
//Set lfEscapement and lfOrientation to 10 * angle to rotate text
//for example, to rotate 45 degrees set the values to 450
hFont = CreateFontIndirect(&lf); // Create our font
SetBkMode(hMemDC, TRANSPARENT);
hOldFont = SelectObject(hMemDC, hFont); // Select font into DC
// Don't write any text, just fill rc with text dimensions
DrawText(hMemDC, caption, -1, &rc, DT_CALCRECT | DT_LEFT | DT_EXPANDTABS | DT_NOPREFIX);
// Calculate the text …
I am doing a project on steganography ( I hope you know what it is :) ) I have to convert a text file (if possible a RTF File) to an image file like jpg or gif etc. But I do not seem to get around this problem and I'm stuck in it.
Please can anybody help me with this? :-/
Thanks for using code tags on your first post :) its not often that happends. Some of your indentation is a bit strange so I will fix that up, I also removed one warning to do with signed / unsigned comparisons.
#include <iostream> #include <string> #include <iomanip> #include <string.h> #include <fstream> using namespace std; void displayBinary(unsigned); int main() { string str; fstream file_op("c:\\test_file.txt", ios::in); while (file_op >> str) { for (size_t i = 0; i < str.length(); i++) { displayBinary((unsigned)str.at(i)); } } cout << endl; cout << endl; file_op.close(); return 0; } void displayBinary(unsigned u) { register int b; for (b = 128; b > 0; b = b/2) { (u & b) ? (cout << '1') : (cout << '0'); } cout << " "; }
Now that its easier to read, try reading from the file byte by byte.
Heres how you would do that and pass it to your function displayBinary.ifstream in("test_file.txt", ios::in); char ch; // Assign each byte to ch // and then pass it to the function displayBinary while (in.get(ch)) { displayBinary(ch); } in.close();
To save it back to a file you do basically the same thing, except this time use the ofstream and use ofstream::put to write it to the file.
Try modifying the displayBinary function like this.
ofstream out("output.txt", ios::out); void displayBinary(unsigned u) { register int b; char bit; for (b = 128; b > 0; b = b/2) { (u & b) ? (bit = '1') : (bit = '0'); cout << …
I am still very new to C++ and I'm a bit :confused: too.
I am trying to make a program which takes the ascii string from a text file and converts it into binary.
I have been able to come up with this code so far:
#include <iostream>
#include <string>
#include <iomanip>
#include <string.h>
#include<fstream>
using namespace std;
void displayBinary(unsigned);
int main()
{
string str;
fstream file_op("c:\\test_file.txt",ios::in);
while(file_op >> str)
for(int i =0; i < str.length(); i++)
{
displayBinary((unsigned)str.at(i));
}
cout << endl;
cout << endl ;
file_op.close();
return 0;
}
void displayBinary(unsigned u)
{
register int b;
for(b = 128; b > 0; b = b/2)
{
(u & b)?(cout << '1'):(cout << '0');
}
cout << " ";
}
Everything seems to work fine. I just have one problem. I want to save the output to a text file. But I dont seem to get that done.
Any ideas how will I be able to do that?