|
The other thing I would recommend you look at is MapDialogRect[^], so you can use dialog box units, just like you would if you're doing a resource driven layout, and get them transformed to pixels like CreateWindow uses.
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Hi All,
Can anybody tell me how to retreive IP address of a server pc from client pc.
Regards,
Abinash
|
|
|
|
|
Just refer [^]
Величие не Бога может быть недооценена.
|
|
|
|
|
Hi
How to print content of a txt file using VC++.
Thanks in advance
|
|
|
|
|
|
Hi can anybody give a sample for WritePrinter function , i am confused about getting handle to the printer ,which is obtained by using OpenPrinter function.
OpenPrinter("Printer_Name" ,&pHandle ,NULL )
From the above code ,I am confused about getting printer name, 'cos
suppose I am using more than one printers ,it is not possible to hardcode the printer name.How to get selected printer name?
thanks 
|
|
|
|
|
Use GetDefaultPrinter() to get the name of the default printer. If you want the user to select a different printer, use PrintDlg() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks 
|
|
|
|
|
The steps:
1. StartDocPrinter
2. StartPagePrinter
3. WritePrinter
4. EndPagePrinter
5. repeat 2, 3, 4 for as many pages as necessary
6. EndDocPrinter
When you are trying to print a text file directly to a printer, there will be no format information such as font, color, etc sent to the printer. The printer will use its default font to print the text file in its natural text flow. The result is not pretty.
|
|
|
|
|
Hi
How to format data before printing ?
thanks
|
|
|
|
|
To format text you have to print it in graphics mode. Get the printer DC and output to that DC. That way you can choose your font, size, etc. and arrange text to appropriate locations.
|
|
|
|
|
One way would be to use ShellExecute(hWnd, "name of txt file", "print", ...) .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks 
|
|
|
|
|
Hi All,
Is there any spl reason to use CSingleLock and CDoubleLock objects and give the reference of a sync objects , whereas we can directly lock the resource by using CCriticalSection Lock and UnLock methods...
Please clarify me on this ..............
Thanks,
Hari
|
|
|
|
|
Hi all,
My code is like this:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream f;
char strMsg[512];
char buf[512];
while(1)
{
f.open("c:\\1.txt", ios::in|ios::out|ios::app );
if(f.is_open())
{
int i=0;
char s[512];
memcpy(s,"hello",512);
i = strlen(s);
f<<s<<std::endl;
f.seekg(0, ios::beg);
while(f.getline(strMsg, 512))
{
int i=0;
char s[512] = "";
memcpy(s,"hello",512);
i = strlen(s);
f <<s <<std::endl;
}
f.close();
}
}
}
starting, the file database.txt is empty.
The first "f<
|
|
|
|
|
Hi.
Some comments:
1.) I see an infinite while loop without any conditional breakage. Why do you need this?
2.) You are calling strlen on a char array without a NULL terminator. You should probably use strcpy instead of memcpy.
xbottle wrote: but the second "f<<s<<std::endl" can="" not="" write="" database="" to="" the="" 1.txt="" file.<="" blockquote="">
Your second while loop will never be true on the second pass because you are at the end of the file after you write to the file. However if you fix this it will cause an infinite loop. I would suggest that you redesign your logic flow.
Update your code and come back for a second analysis.
Best Wishes,
-David Delaune
modified on Thursday, October 29, 2009 1:16 AM
|
|
|
|
|
thanks for your answer.
1.)This is a part of my code.In my code ,it’s a thread code.So I use an infinite while loop.
2.)you let me use strcpy instead of memcpy ,I have used strcpy instead of memcpy.But I think it’s not the reason that I can’t write the file.
3.) My second while loop is really true on the second pass.
I’m not sure the reason. Before my second while loop, “f.seekg(0, ios::beg)”seek the begin of the file,maybe that’s why I’m not at the end of the file after I write to the file.
|
|
|
|
|
xbottle wrote: 1.)This is a part of my code.In my code ,it’s a thread code.So I use an infinite while loop.
Ok, but how do you plan to end the thread?
xbottle wrote: 2.)you let me use strcpy instead of memcpy ,I have used strcpy instead of memcpy.But I think it’s not the reason that I can’t write the file.
It could cause the application to crash. Always NULL terminate your char arrays before calling CRT functions such as strlen.
xbottle wrote: 3.) My second while loop is really true on the second pass.
I’m not sure the reason. Before my second while loop, “f.seekg(0, ios::beg)”seek the begin of the file,maybe that’s why I’m not at the end of the file after I write to the file.
Ok, I understand you now. The EOF bit has probably been set. Add this at the bottom of your second while loop:
if(f.eof())
f.clear();
Best Wishes,
-David Delaune
|
|
|
|
|
thx.
I probably found the reason.
<br />
#include <iostream><br />
#include <fstream><br />
using namespace std;<br />
int main()<br />
{ <br />
fstream f; <br />
char strMsg[512];<br />
char buf[512];<br />
while(1)<br />
{<br />
f.open("c:\\1.txt", ios::in|ios::out|ios::app );<br />
if(f.is_open()) <br />
{ <br />
int i=0; <br />
char s[512]; <br />
memcpy(s,"hello",512); <br />
i = strlen(s); <br />
f.seekp( 0, ios_base::end );<br />
f<<s<<std::endl; <br />
f.seekg(0, ios::beg); <br />
while(f.getline(strMsg, 512)) <br />
{ <br />
int i=0; <br />
char s[512] = ""; <br />
memcpy(s,"hello",512); <br />
i = strlen(s); <br />
f.seekp( 0, ios_base::end );<br />
f <<s <<std::endl; <br />
} <br />
f.close(); <br />
} <br />
}<br />
}<br />
I add "f.seekp( 0, ios_base::end );" before I write the data.
The code find the end of the file,then "f <<s <<std::endl; "can write the data successful.
|
|
|
|
|
Goodness me, what makes you think that the file pointer will get reset to the start of the file after each write?
Seriously, have a good hard look at your code - it's making my eyes sore and your logic is hurting me.
1. f.seekg(0, ios::beg);
2. while(f.getline(strMsg, 512))
3. {
4. int i=0;
5. char s[512] = "";
6. memcpy(s,"hello",512);
7. i = strlen(s);
8. f << s << std::endl;
9. }
Quick desk-check:
1. - seek to start of file
2. - strMsg = next line of file (max of 512 chars)
3. -
4. - declare and initialize i = 0 (initialization unnecessary)
5. - s[512] = "\0" (+511 more nulls)
6. - s[512] = "hello\0" (+ 506 more unknown chars)
7. - i = 5
8. - output "hello" + "\n" to the file. File pointer points to end of file
2. - strMsg = next line of text (we're at the end of the file, so there's no more text to read)
10.
|
|
|
|
|
xbottle wrote: In my code ,it’s a thread code.
At this stage of the game, you should not be doing any multithreading. That's an intermediate/advanced topic.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
xbottle wrote: memcpy(s,"hello",512);
What exactly are you expecting this to do? After it copies the 6 characters from the string literal, its going to copy 506 more characters from elsewhere. Is that intentional?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I have been programming for about 3 years. I found that if I try to speedup the program, it often entails more expense of memory. And for a particular algorithm, if more thresholds, predicates and parameters which needs users to tweak manually, the program implementing this algorithm tends to run faster.
In this sense, all programs if designed according to the common practise, even it is always on the edge of the same kind. Optimization is trivial modifications and equivalent to shifting the fulcrum of lever from time to memory or reversely, also the support of the lever of presumption to automation.
Thus, we cannot attain the savings of time and space at the same time. Why don't just choose one end and assent with one program or one algorithm for a particular problem? Why bother trouble to reproduce so many programs with approximately the same behavior taking both time and memory into account?
|
|
|
|
|
If i understand you correctly you are wondered why a program optimized for speed uses more memory and a program optimized for size is mostly slower.
I think there are 3 ways to optimize a program:
1. Get rid of all unneeded code. Classic examples are:
- the programmer lost oversight of variables resulting in several variables holding the same value
- He's insecure what value is in a variable resulting in too many conditions asking the same question
- Using the wrong algorithm to solve a problem
This kind of optimizing is for free: you will end with a program that uses less memory and less CPU
2. If your program does not contain any unneeded code, the only thing left is trade between memory, CPU and time. Your program says: i need this number of sourcode lines to solve the problem. Thus you only can restate lines, change computation into memory usage. This kind of optimizing has its costs: less CPU is more memory and v.v.
3. Sometimes you can divide a CPU-consuming piece in several parts that can be done when the program waits for the user. This kind of optimizing essentially does nothing (it still consumes the same time) but changes the feeling of the user. (actually you are not manipulating the program but the user).
I think a more interresting question would be: how can you garantuee that your program does not contain any needless code....
Rozis
|
|
|
|
|
Thank you very much for your explanation! I am clearer now.
|
|
|
|