|
FindWindow should find both visible and not-visible windows. I believe you are destroying the dialog each time and not just show/hide flipping it.
Anyway you'd be better off, using a mutex. Read Joe Newcomer's article on avoiding multiple instances.
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Hi,
I have to communicate with a slow device over the serial port.In order to preserve responsivness, the device is called from worker threads.
Problem:
Is it safe to access a BOOL CWinApp::m_bConnected from several worker threads at a time?
Since I am that familiar with mutexes and critical sections, how to achieve this?
Thanks
Pepe
|
|
|
|
|
Create a critical section and enter it every time you're going to use the BOOL. Then leave it right away. That way if one thread is accessing the BOOL, others will stop and wait for it to finish.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
A BOOL is atomic (only needs 1 processor instructor to read/write) and therefore does not need synchronising.
|
|
|
|
|
How can I get the coordination of clientdc?
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
BOOL GetClientRect(
HWND hWnd, // handle to window
LPRECT lpRect // client coordinates
);
For the cleint Area
|
|
|
|
|
I new to using VC++ but have experience with C and Visual Basic. I'm looking for a simple function to Read from a text file.
Something like in VB:
Set fs = CreateObject("Scripting.FileSystemObject")
set filename = fs.GetFile("Text.txt")
Set ts = filename.OpenAsTextStream(ForReading, TristateUseDefault)
Buffer = ts.Readline
Any example info I've found so far about File I/O in VC++ is exceedingly difficult. I'm writing an simple MFC dialog app.
Thanks.
|
|
|
|
|
try this:
FILE *fp;
fp = fopen(filename, "r");
ASSERT(fp!=NULL);
char * buffer[MAX_LINE_SIZE];
fgets(buffer, MAX_LINE_SIZE, fp);
// here, buffer contains one line from your file.
|
|
|
|
|
CStdioFile f;
if (f.Open(filename, CFile::modeRead)==0)
{
...error
}
CString csText;
if (!f.ReadString(csText))
{
....error
}
Smaller Animals Software, Inc.
You're the icing - on the cake - on the table - at my wake. Modest Mouse
|
|
|
|
|
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
using std::copy;
using std::vector;
using std::string;
using std::ifstream;
using std::ostream_iterator;
using std::cout;
using std::back_inserter;
using std::getline;
using std::ostringstream;
using std::istream_iterator;
int main(int argc, char* argv[])
{
string currentLine;
ifstream str("c:\\winzip.log");
if (!str.is_open())
{
cout << "It's stuffed\n";
return -1;
}
vector<string> file_contents;
copy(istream_iterator<string>(str),istream_iterator<string>(), back_inserter(file_contents));
// Now print out the results
copy(file_contents.begin(), file_contents.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
This example reads a file in and prints the output to the console. However, the pertinent point is that you can create an fstream, which is bidirectional, or just an ifstream or ofstream, and then if you know the file format, you can, for example, do this:
myFile >> nMyNumber >> szMyString >> etc.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Hey! The guy is coming from VB. Are you going to make him afraid of C++?
I vote pro drink
|
|
|
|
|
|
MDR ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
MDR == Mort De Rire in French visit Irc Channel
|
|
|
|
|
I donno what that means but apparently people would call you a "damn STL MDR" if you start pushing STL down VB coders' throats
Nish
p.s. What's MDR anyway???
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Nemanja Trifunovic wrote:
Hey! The guy is coming from VB. Are you going to make him afraid of C++?
VB and C I thought he said. Admittedly the sample code is more complex than it needed to be in order to make the point ( it's a copy & paste from an earlier question ), but from memory the MFC classes for file IO use the shift operators as well, so why not point someone to the proper way to do things ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian Graus wrote:
VB and C I thought he said.
Yes, he said, but if he really knew C, he would have simply used the lucy's solution (fopen).
I vote pro drink
|
|
|
|
|
Nemanja Trifunovic wrote:
Yes, he said, but if he really knew C, he would have simply used the lucy's solution (fopen).
Actually, you're right, and that had occured to me when I read lucy's response, but then I saw Chris' MFC reliant post, so I felt obliged to defend the standard (which IMO equates to 'proper') way of doing things.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
CG
You sure are an STL warrior warring against the ruling MFCians.
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Nish [BusterBoy] wrote:
You sure are an STL warrior warring against the ruling MFCians.
And proud of it. Bring them on.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Look up CFile in MSDN.
Click here and use the menu on the left side to navigate thought the members functions etc.
Sprudling
|
|
|
|
|
What does CFile do that IOStreams do not ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
What does IOStreams do that fopen etc doesn't?
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I'm not sure, but let me hazard some guesses.
IOStreams are C++ based, and a file stream will always close the file in it's destructor, even if an exception is raised, as soon is it goes out of scope.
IOStreams can be extended to allow one step reading/writing of custom file types, as well as custom modifiers that need only be written once and work with every type to be streamed.
Once the code is written, output can be streamed to any other stream type ( the console, a custom stream type, etc. ), simply by changing the type of the stream, all the other code will remain valid.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I just thought that since he's using MFC he might as well use CFile.
Sprudling
|
|
|
|