Hello everyone. Is there any MFC function to get my own window handle? I'm creating window with Dialog box without title, so i can't use FindWindow(); Maybe there is something like AfxGetInstanceHandle() but i could get window handle?
Thank you
Hello everyone. Is there any MFC function to get my own window handle? I'm creating window with Dialog box without title, so i can't use FindWindow(); Maybe there is something like AfxGetInstanceHandle() but i could get window handle?
Thank you
Hello guys. How can i make my program start minimized to system tray? I'm using MFC. I managed to make it start hidden, but i can add sys tray icon... Any ideas?
Thank you
So i should try using GetWindowPlacement()?
But it will find window regerdless it's minimized or maximized. Am i correct?
But i guess it's possible to get Firefox status (minimized or maximized) and hide or show dialog box?
I don't need to make browser window. I just need Dialog box wich will be only on firefox. Not something like toolbar. Just Dialog Box...
I need to create a small window with a timer wich will be visible only in firefox and then i'll minimize firefox window will disappear. Hope i made myself clear? And by the way i need window to apear again then i'll maximize firefox
Hi. How can i make Dialog box visible only in one application window for examlpe only on firefox? I'm using MFC.
Thank you
I know how to read line by line till i'll find required line. But i was wondering if there is special function for that.
did you declare variable CStr?
CString Cstr;
Instead of that loop, just try this:CSt = str.c_str();
assuming CStr is of type CString.
Thank you. That worked :) And what about reading only one line wich is not first line in the file?
I need your help... Again...
How can i combine reading from file with std::getline(file, std::string);
and UpdateData(FALSE);
? UpdateData() accepts only CString and getline only std::string, and then i try to use it like that:
std::string readbuff;
int length;
std::ifstream file("file.txt");
while(getline(file, str))
{
length = str.length();
for(int i=0; i<length; i++)
CStr[i] = str[i]; //CStr is global CString variable used at DoDataExchange;
UpdateData(FALSE);
Sleep(5000);
}
i recieve following error:
error C2106: '=' : left operand must be l-value
I know fstream has something like file.read();
but then calling this function i have to give a number of symbols that i want to read. Am i right? And i don't know how to do that. So what can i do?
And also how can i read only one line, for example just 6th line?
Hello. Can someone tell me how can i add string to combo box? i tried
GetDlgItem(IDC_COMBO1)->Items->Add("Text");
but it didn't worked. and everything that i could find on google didn't helped :( so i'm asking you pros ;)
This class is for creating new button, but i'm creating window with dialog editor so i can't use this class to create new button on dialog...
Can you give me an example please? Because i didn't really undestood :(
By the way i'm using MFC.
Hello. I'm creating a program with dialog editor. How can i set bitmap on button? I set bitmap at properties to True. I tried to search on google but i could only find how to set bitmap on button created with CButton.
Thank you
I tried that. But i couldn't understand :(
Can you give code example? Countdown from 10 to 0 please. Thank you
Hello. How can i make count-down timer on MFC program?
Thank you
Hello. I know this is lame questinon but what is multi-if syntax? Like this:
if (a == 0)
doSometihng();
if (a == 1)
doSomething();
else
doElse();
Or like this:
if (a == 0)
doSometihng();
else if (a == 1)
doSomething();
else if (a == 2)
doSomething();
else
doElse();
I'm useing Microfot Visual C++ 08
Thank you :$
Ok i didn't really understood what is triple. Can you give me some output in my sequences? So i will understand what is that :)
1 2 3 6 9
1 2 3 5 8 9
9 10 19 29
Ok i think i have found something usefull. But i dont understand this :( Can any pro translate this and make it as simple as possible?
http://msdn.microsoft.com/en-us/magazine/bb985598.aspx
http://msdn.microsoft.com/en-us/magazine/cc301438.aspx
Thank you
Any ideas guys?
[IMG]http://img213.imageshack.us/img213/7063/editsv.png[/IMG]
I marked edits in this image ;) hope you'll understand.
Hello. I need your help. I need to write program wich will take numbers from other program's edit. I'm pretty sure that other program is writen with C++. Can you help me to write reading from edit part?
Can you post errors here?
void Kodavimas () { using namespace std; string ReadBuff; int ReadBuffDydis; char ReadBuffSimbolis; int FailoSimbolioASCII; int SifroRaktoIlgis; int SifroRaktoSimbolis; int SifroRaktoASCII; int SifroRaktoIndex = 0; int ASCIIiFaila; char SimbolisIfaila; ifstream ReadFile(OpenFileName); ofstream WriteFile(SaveFileName); SifroRaktoIlgis = SifroRaktas.GetLength(); while (getline(ReadFile, ReadBuff)) { ReadBuffDydis = ReadBuff.length(); for (int i2=0; i2<ReadBuffDydis; i2++) { ReadBuffSimbolis = ReadBuff[i2]; FailoSimbolioASCII = int(ReadBuffSimbolis); SifroRaktoSimbolis = SifroRaktas[SifroRaktoIndex]; SifroRaktoIndex+=1; if (SifroRaktoIndex = SifroRaktoIlgis) SifroRaktoIndex = 0; SifroRaktoASCII = int(SifroRaktoSimbolis); ASCIIiFaila = FailoSimbolioASCII + SifroRaktoASCII; if (ASCIIiFaila > 255) ASCIIiFaila-=255; SimbolisIfaila = char(ASCIIiFaila); WriteFile << SimbolisIfaila; } WriteFile << "\n"; } }
Most variables name are in my language. If you need i can translate them
OpenFileName and SaveFileName are CString variables and i recieve them from CFileDialog.
SifroRaktas is a cipher key variable.
I just added ios::binary openmodes at all fstreams. First try was successful, but second not... [IMG]http://img255.imageshack.us/img255/5564/codeingfail.png[/IMG]
Original picture at the left and uncoded picture at the right. Any ideas?
It seems that it's same with all .jpg pictures
.bmp files are binary files, not ascii text files. You have to open the file with ios::binary flag and then use ifstream's read() method to read the binary data. getline() will not work. And you will have to read the file into a character array, not a std::string object
char readbuf[255]; ifsteam in("filename.bmp", ios::binary); if( in.is_open() ) { while( in.read(readbuf, sizeof(readbuf)) ) { int bytesRead = in.gcount(); // get number of bytes read // blabla } }
Thank you. Opening file as binary helped. but i cant use char array because it can store too little chars. However i can't use std::string too, because picture was a mess :D any ideas?
I tried to open coded .bmp file with notepad. It seems that my program only reads very little part of picture symbols. I don't know why. Pls help me someone! :(
void Kodavimas () {
using namespace std;
string ReadBuff;
int ReadBuffDydis;
char ReadBuffSimbolis;
int FailoSimbolioASCII;
int SifroRaktoIlgis;
int SifroRaktoSimbolis;
int SifroRaktoASCII;
int SifroRaktoIndex = 0;
int ASCIIiFaila;
char SimbolisIfaila;
ifstream ReadFile(OpenFileName);
ofstream WriteFile(SaveFileName);
SifroRaktoIlgis = SifroRaktas.GetLength();
while (getline(ReadFile, ReadBuff)) {
ReadBuffDydis = ReadBuff.length();
for (int i2=0; i2<ReadBuffDydis; i2++) {
ReadBuffSimbolis = ReadBuff[i2];
FailoSimbolioASCII = int(ReadBuffSimbolis);
SifroRaktoSimbolis = SifroRaktas[SifroRaktoIndex];
SifroRaktoIndex+=1;
if (SifroRaktoIndex = SifroRaktoIlgis)
SifroRaktoIndex = 0;
SifroRaktoASCII = int(SifroRaktoSimbolis);
ASCIIiFaila = FailoSimbolioASCII + SifroRaktoASCII;
if (ASCIIiFaila > 255)
ASCIIiFaila-=255;
SimbolisIfaila = char(ASCIIiFaila);
WriteFile << SimbolisIfaila;
}
WriteFile << "\n";
}
}
Most variables name are in my language. If you need i can translate them
OpenFileName and SaveFileName are CString variables and i recieve them from CFileDialog.
SifroRaktas is a cipher key variable.
Hello. I'm writing codeing progam. It reads from file using fstream and then converts simbols to ascii, changes ascii, converts ascii to symbols and writes them to file. I tried to code .txt file with it. It worked perfect. But then i tried to convert .bmp file and then i decoded .bmp file and tried to watch pic i windows picture viewer showed me following error: "Drawing failed". I think i did something wrong. but i'm not sure... So i'm asking you is this possible to code and decode all files using fstream and converting symbols to ascii? Please answer me.
P.s sorry for my bad english. If you didn't understood me just ask.
false is a boolean type, so you can just check it with
if( !getline(file1, str1) ) { //EOF }
Thank you it's working perfect .
Of course catching an EOF exception is better...
I have never tried that before but I checked forum and i think i should use it like this:
for (!file1.eof()) {
getline (file1, str1); /* file1 is file from wich i read and str1 is string*/
file << str1;
}
Am i doing it right? And will this work on MFC project?
P.S. I'm not too lazy to check it but i want to be sure that my program will work fine... ;)
I tried to check return value but i couldn't find right variable type... I tried intiger, string.... always error... maybe you know wich type i need?
Hello. I'm writing program wich reads from file line by line and then rewrites everything to other file. This is simplifyied part of code:
for (int i=0; i<=5;) {
getline (file1, str1); /* file1 is file from wich i read and str1 is string*/
file << str1;
}
No i'm not copying file :) Between reading and writing i'm working with lines and rewriting to other file reformed text. But the problem is that i don't know how many lines are in file. So i need to catch file end to break loop. Please help me to catch file end. Thank you :)
You need to use append openmode if you want to add.
ofstream file ("file.txt", ios::app)
Seperate openmodes with |
No i don't have MSN messenger if you were talking about it.
Add these lines:
string str3;
After line 7 and these
if (str == str3)
break;
str3 = str;
after line 11. Sorry i'm a beginner and that the best what i could work out.
That's because there is no lines after line 5. That means program will search in line 5 again and again...
If program will not exit it will not return any value :P
In this line
ifstream file ("file.txt");
replace file.txt with any other file. Just don't forget to put file name in ""
I'm sure the OP will thank you for doing his homework for him, even though it's not 100% correct. But I'll give you a B+ for good effort.
>.> i didn't knew that this was his homework... and why is this not correct? for me it's working perfect
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string str;
string str2 = "hate";
int i;
ifstream file ("file.txt");
for (int index=1; index<=4; index++) {
getline (file, str);
i = str.find(str2);
cout << "Line " << index << ": ";
if(i != string::npos)
cout << "Word found\n";
else cout << "Word not found\n";
}
cin.get();
file.close();
}
Try this. You can change searching word for by changing str2 value. If you want to check more lines in file just change 10 line with for example this:
for (int index=1; index<=8; index++) {
This will check 8 lines. Hope you undestood ;)
I'm using this:
WinExec("C:\\WINDOWS\\notepad.exe", SW_SHOWNORMAL);
Anyway thanks for answer
Hi. I need program wich will start other program (for example notepad.exe) and if notepad.exe will exit my program will start it again. How can i get info about process state and put it into variable to use with if? I'm beginner at C++ so please write all headers witch i need to include and code example with explanation. Thank you.
You need WIN32 application or console application?
2.How can i read from file line by line and get all sentence with spaces? Using fstream?
And how can i read from file line by line and put text from file to dynamic array?
Ok, You have encountered the cin fail that most of us encountered as we started.
consider the following
int x; cin>>x;
The "problem" with cin in this case is that cin is a stream(big buffer) so it accumulates everything. you asked for an int it gave you one, but what is left on the buffer still exists, your program goes to a second cin there is still some thing on the buffer so it gives you that and your program evaluates it.
So if you want keyboard input at various stages it is good to clear the input stream between reads to make sure its not holding data. I usually stick it in before a call to cin. Narue has an exellent post about how to do this if you check the main forum area. "how to flush the input stream" or something to that effect is the name.
Hope this helps you.
Thank you. It helped and it's working fine. But now i'm not sure am i doing it correctly. I should put
cin.clear()
before using cin? and do i need to put anything else? like
cin.sync()
?
here is your problem
if (repeat == 't' || repeat == 'n') break; else cout << "Wrong symbol\n";
you put 't' instead of 'y'
Oh yes :). But i corrected it to:
if (repeat == 'y' || repeat == 'n')
break;
else
cout << "Wrong symbol\n";
And still same. Maybe something wrong with syntax? I'm using Microsoft Visual Studio 2005.
Hello.
I have some problems.
1.With for cycle. This is my code:
#include <iostream>
#include <fstream>
int main () {
int i;
int i2;
char sentence [200];
char repeat;
ofstream file ("file.txt", ios::app);
for (i=0; i<1;) {
cout << "Enter sentence (max. 200 symbols)\n";
cin >> sentence;
if (!file) {
cout << "File opening error\n";
return 1;
}
file << sentence;
for (i2=0; i2<1;) {
cout << "Do you want to write another sentence? (y/n)\n";
cin >> repeat;
if (repeat == 't' || repeat == 'n')
break;
else
cout << "Wrong symbol\n";
}
if (repeat == 'n')
break;
}
file.close();
return 0;
}
The problem is that when i input sentence program writes to file only first word. After that porgram asks me if i want to repeat, writes "wrong symbol" and then ask again if i want to repeat and asks me to write symbol (y or n). Program is asking me twice. First time i can't write y or no so it writes "Wrong symbol". What am i doing wrong?
2.How can i read from file line by line and get all sentence with spaces? Using fstream?
3.How can i check if array index is clean?
#include <iostream>
using namespace std;
int main () {
char mas [16], *a;
cout << "Enter word\n";
cin >> mas;
a = &mas [7];
if (a == NULL)
cout << "Word is shorter than 7 symbols\n";
else cout << "Word is longer than 6 symbols\n";
cin.get(); …