|
|
Oh thanx exactly what I needed
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|
|
I have multiple user interface threads. I am trying to post a message using postmessage so that all of the threads (they are all the same class doing the same things) react to the message.
The problem is that only the thread that posts the message receives the message.
What combination of message declarations and message maps should I be using so that all of the threads receive the message?
|
|
|
|
|
Since all your threads are instances of the same class (let's call it CMyUIThread ) the simplest solution is maintaining a static list of all active threads and let a method multiplex message posting to all of them. Scheme follows:
class CMyUIThread: public CWinThread
{
public:
CMyUIThread()
{
activeThreads.insert(this);
}
~CMyUIThread()
{
activeThreads.erase(this);
}
protected:
static void BroadCastMessage(UINT Msg,WPARAM wParam,LPARAM lParam)
{
for(activeThreadsIterator it=activeThreads.begin();it!=activeThreads.end();++it){
it->PostThreadMessage(Msg,wParam,lParam);
}
}
private:
static std::set<CMyUIThread*> activeThreads;
typedef std::set<CMyUIThread*>::iterator activeThreadsIterator;
}; This code is merely an indication (it probably won't even compile), but hopefully you're getting the idea: when a thread wants to broadcast a message, it simply calls BroadCastMessage , which does the dirty job of posting to all threads one by one. Regards.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ok i see the theory. Initially I thought that I was doing something wrong and that was why only my posting thread got the message.
Would a postmessage in say the main application thread reach all of the gui threads?
Thanks for the quick response.
|
|
|
|
|
Would a postmessage in say the main application thread reach all of the gui threads?
No. Each invokation of PostMessage and similar functions will reach only one thread.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello All,
I am trying to delete the IE History completely, I have used the ClearHistory method (below), however, the History deletes, but the links are still present in the Address (dropdown) in IE6.0 ?
For example, I run my program (calling ClearHistory), after program execution completes, I open up a fresh browser (IE6), I click on the History button, and it displays nothing , but I click on the Address dropdown, and the sites visited still exist?? I don't understand how to delete the links in the Address dropdown , any guidance is appreciated. Thanks in Advance!!
================================================================
Method Signature;
================================================================
IUrlHistoryStg2::ClearHistory Method
Clears history on a per-user basis.
Syntax
HRESULT ClearHistory(VOID);
Return Value
Returns S_OK if successful, or an error value otherwise.
================================================================
Code Snippet (from Microsoft docs)
================================================================
include <shlguid.h> // Needed for CLSID_CUrlHistory
#include <urlhist.h> // Needed for IUrlHistoryStg2 and IID_IUrlHistoryStg2
IUrlHistoryStg2* pHistory; // We need this interface for clearing the
history.
HRESULT hr;
DWORD cRef;
CoInitialize(NULL);
// Load the correct Class and request IUrlHistoryStg2
hr = CoCreateInstance(CLSID_CUrlHistory,
NULL, CLSCTX_INPROC_SERVER,
IID_IUrlHistoryStg2,
reinterpret_cast<void **="">(&pHistory));
if (SUCCEEDED(hr))
{
// Clear the IE History
hr = pHistory->ClearHistory();
}
// Release our reference to the
cRef = pHistory->Release();
CoUninitialize();
==================================================
Soliant - soliant@yahoo.com
|
|
|
|
|
I am just learning VC++. I am trying to read from an Excel file using VC++ but I can't find any good help on how to do it. Does anyone have any ideas?
|
|
|
|
|
G'Day Havoc,
You should be able to find enough information in MSDN to get you going. Here is one link to a few articles
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno97ta/html/msoautovc.asp
failing that try searching with the key words 'excel' and 'autmation'
Good luck
Richard.
|
|
|
|
|
#ifndef _EXCELSPACE_H
#define _EXCELSPACE_H
#include "excel9.h"
class CExcelSpace : public CObject
{
public:
CExcelSpace();
~CExcelSpace();
BOOL OpenExcel(LPCTSTR lpszFileName,LPCTSTR lpszSheetName,
BOOL m_bReadOnly = TRUE, BOOL bNewFile = FALSE, BOOL bNewSheet = FALSE );
void Close();
void GetRowColCount(int &row, int &col);
COleVariant GetCellValue(int row, int col);
BOOL SetCellValue(int row, int col,COleVariant var);
BOOL DeleteRow(int row);
CString GetFileName() { return m_szFileName; };
BOOL IsReadOnly() { return m_bReadOnly; };
void PrepareFetchData();
void EndFetchData();
BOOL ActiveSheet(LPCTSTR lpszSheetName);
BOOL IsSheetExist(LPCTSTR lpszSheetName);
BOOL DeleteSheet(LPCTSTR lpszSheetName);
BOOL NewSheet(LPCTSTR lpszSheetName);
_Application GetApplication()
{
return excelApp;
}
protected:
CString m_szFileName;
CString m_szSheetName;
BOOL m_bNewFile;
BOOL m_bReadOnly;
BOOL m_bValidate;
BOOL m_bServiceStarted;
BOOL bPreparedFectch;
CStringArray fldNames;
_Application excelApp;
int rowCount, colCount;
int curRow;
COleSafeArray sa;
BOOL StartExcelService();
CString InnerGetColumnName(int col);
CString GetCellName(int row, int col);
int NameToIndex(LPCTSTR lpszFldName);
// Dataset function
public:
int GetRecordCount() { return rowCount; };
int GetColCount() { return colCount; };
BOOL AddColumn(LPCTSTR lpszColName, int nColType);
CString GetColumnName(int col);
int GetColumnType(int col);
BOOL Delete();
BOOL InsertRow(BOOL bAppend);
BOOL Update();
COleVariant GetFieldValue(int col);
COleVariant GetFieldValue(LPCTSTR lpszFldName);
void SetFieldValue(int col,COleVariant var);
void SetFieldValue(LPCTSTR lpszFldname,COleVariant var);
BOOL MoveFirst();
BOOL MoveNext();
BOOL MoveBefore();
BOOL IsEOF();
BOOL IsBOF();
public:
static BOOL NewExcelSheet(LPCTSTR lpszFilename, LPCTSTR lpszSheetName);
static BOOL IsSheetExist(LPCTSTR lpszFilename, LPCTSTR lpszSheetName);
static BOOL DeleteSheet(LPCTSTR lpszFilename, LPCTSTR lpszSheetName);
static CString OleVariantToStr( const COleVariant & Var);
};
#endif
-------------------------------------
CExcelSpace::CExcelSpace()
{
m_szFileName = "";
m_bReadOnly = TRUE;
m_bValidate = FALSE;
bPreparedFectch = FALSE;
curRow = -1;
rowCount = colCount = 0;
m_bServiceStarted = FALSE;
}
CExcelSpace::~CExcelSpace()
{
fldNames.RemoveAll();
Close();
}
void CExcelSpace::Close()
{
if( m_bServiceStarted )
{
TRY
COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
_Workbook workbook = excelApp.GetActiveWorkbook();
workbook.Close(COleVariant((short)FALSE), VOptional, VOptional);
excelApp.Quit();
CATCH_ALL(e)
e->Delete();
END_CATCH_ALL
m_bServiceStarted = FALSE;
}
if( m_bValidate )
{
EndFetchData();
m_bValidate = FALSE;
}
}
CString CExcelSpace::GetCellName(int row, int col)
{
col++;
int count = 0;
char szNum16[32],szTmp[32];
while( col > 0 )
{
int m = (col-1)%26;
col = (col-1)/26;
szTmp[count++] = (char)('A'+m);
}
for(int i=0; i<count; i++)
="" sznum16[i]="szTmp[count-1-i];
" sznum16[count]="0;
"
="" cstring="" s;="" s.format("%s%d",sznum16,row+2);
="" return="" s;
}
int="" cexcelspace::nametoindex(lpctstr="" lpszfldname)
{
="" for(int="" i="0;" i<fldnames.getsize();="" {
="" if(="" fldnames.getat(i).comparenocase(lpszfldname)="=" 0="" )
="" i;
="" }
="" -1;
}
bool="" cexcelspace::addcolumn(lpctstr="" lpszcolname,="" int="" ncoltype)
{
="" colevariant="" var(lpszcolname);
="" setcellvalue(-1,="" colcount-1,="" var)="" szcolname="lpszColName;
" fldnames.add(="" );
="" colcount++;
="" true;
="" else
="" false;
};
cstring="" cexcelspace::innergetcolumnname(int="" col)
{
="" var="GetCellValue(-1,col);
" olevarianttostr(var);
}
cstring="" cexcelspace::getcolumnname(int="" s(_t(""));
="" col="">=0 && col < fldNames.GetSize() )
s = fldNames.GetAt(col);
return s;
}
int CExcelSpace::GetColumnType(int col)
{
return 0;
}
void CExcelSpace::GetRowColCount(int &row, int &col)
{
row = col =0;
if( !m_bValidate )
return;
Range range = excelApp.GetActiveCell();
COleVariant Value((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
range = range.SpecialCells(11,Value);
Value = range.Select();
row = range.GetRow()-1;
col = range.GetColumn();
}
void CExcelSpace::PrepareFetchData()
{
if( !bPreparedFectch )
{
COleVariant cell1( GetCellName(-1,0) );
COleVariant cell2( GetCellName(rowCount,colCount) );
Range range = excelApp.GetRange( cell1,cell2);
VARIANT ret = range.GetValue();
sa.Attach(ret);
bPreparedFectch = TRUE;
}
}
void CExcelSpace::EndFetchData()
{
if( bPreparedFectch )
{
sa.Detach();
bPreparedFectch = FALSE;
}
}
COleVariant CExcelSpace::GetCellValue(int row, int col)
{
COleVariant var;
var.Clear();
if( m_bValidate && row >= -1 && col >= 0 && row < rowCount && col < colCount )
{
TRY
if( bPreparedFectch )
{
long index[2];
index[0] = row+2;
index[1] = col+1;
sa.GetElement(index, &var);
}
else
{
CString cellName = GetCellName(row,col);
COleVariant cell1( cellName );
//COleVariant cell2( cellName );
Range range = excelApp.GetRange( cell1,cell1);
var = range.GetValue();
}
CATCH_ALL(e)
e->ReportError();
e->Delete();
END_CATCH_ALL
}
return var;
}
|
|
|
|
|
I bumped into this sad example while working with a "professional" charting library that I am forced to use. This code (changed to protect the guilty) comes from the drawing code in one of the charting code's base classes
<br />
switch( dwSomeValue )<br />
{<br />
case SOME_CHARTTYPE1:<br />
case SOME_CHARTTYPE2:<br />
case SOME_CHARTTYPE3:<br />
case SOME_CHARTTYPE4:<br />
case SOME_CHARTTYPE5:<br />
{<br />
break;<br />
}<br />
default:<br />
case SOME_CHARTTYPE6:<br />
case SOME_CHARTTYPE7:<br />
case SOME_CHARTTYPE8:<br />
case SOME_CHARTTYPE9:<br />
case SOME_CHARTTYPE10:<br />
{<br />
}<br />
}<br />
So now when a custom value (chart) is added, for example "SOME_NEW_CHARTTYPE11", the "Some Other Code" code block always gets executed, because the "default:" was placed in the middle of the switch statement, with no "break;" after it!
Now, I may be wrong here, but I am pretty sure that this is a bug in the charting class' code. What I really want to know is, can anyone provide me with an example where (mis)using a "default" in the middle of a switch statement like this is a good idea?
Peace!
-=- James.
|
|
|
|
|
I have what I think is an example.
I used it in a PreTranslateMessage for keystrokes. I need only certain keys to get through to the target window, so the default would cover all those unknown keys that M$ would add in the future. I obviously don't want my control to handle them.
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
|
|
|
|
|
(Note that I am not asking about uses for the "default" clause...)
If I understand you correctly, I think your example can be implemented with a "default:" clause at the end of the switch statement, correct? For example:
<br />
switch( uiKey )<br />
{<br />
case VK_A:<br />
{<br />
break;<br />
}<br />
case VK_B:<br />
{<br />
break;<br />
}<br />
default:<br />
{<br />
break;<br />
}<br />
}<br />
My question specifically asks about a "default" clause in the middle of a switch, with no "break;", followed by other "case" values.
Peace!
-=- James.
|
|
|
|
|
That code is definitely an example of bad coding. The thing is that it is equivalent to the code where SOME_CHARTTYPE6, SOME_CHARTTYPE7, SOME_CHARTTYPE8, SOME_CHARTTYPE9, SOME_CHARTTYPE10
are ommited. I.e. the code can easily look like the following:
switch( dwSomeValue )
{
case SOME_CHARTTYPE1:
case SOME_CHARTTYPE2:
case SOME_CHARTTYPE3:
case SOME_CHARTTYPE4:
case SOME_CHARTTYPE5:
{
//
// Some Code...
//
break;
}
default:
{
//
// Some Other Code...
//
}
}
Igor Proskuriakov
|
|
|
|
|
Since there is code at the end of the switch statement, my thought was along the lines of "the programmer effed-up". Since that code is called in a base class, adding new CHARTTYPE values will always cause that code to be executed (which draws an unwanted graph component).
IMHO, the code was not originally designed for what it is now being used as. I am just suprised that it is still in the library.
Anyway...
Peace!
-=- James.
|
|
|
|
|
I agree, that's some bad coding.
Here's some questionable coding i found in a widely used TIFF reading library
#define REPEAT8(op) REPEAT4(op); REPEAT4(op)
#define REPEAT4(op) REPEAT2(op); REPEAT2(op)
#define REPEAT2(op) op; op
#define CASE8(x,op) \
switch (x) { \
case 7: op; case 6: op; case 5: op; \
case 4: op; case 3: op; case 2: op; \
case 1: op; \
}
#define UNROLL8(w, op1, op2) { \
uint32 _x; \
for (_x = w; _x >= 8; _x -= 8) { \
op1; \
REPEAT8(op2); \
} \
if (_x > 0) { \
op1; \
CASE8(_x,op2); \
} \
}
while (h-- > 0) {
uint32* bw;
UNROLL8(w, bw = PALmap[*pp++], *cp++ = *bw++);
cp += toskew;
pp += fromskew;
}
not only is this totally wierd, it is also a complete pain in the ass to debug (cause you can't step into a macro). those UNROLL8 things get expanded into loops of switch statements which are actually unrolled loops themselves, or into repetitions of statements. aahhhHH!!! i had to unroll this code to use it in another app. i almost went crazy.
this really crunches a lot of code into a few terse macros. but holy crap.. it's impossible to understand.
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Though I'm not recommending such exotic layouts, this is an example where having default in the middle of the switch block makes some sense:
switch( dwSomeValue )
{
case SOME_CHARTTYPE1:
case SOME_CHARTTYPE2:
case SOME_CHARTTYPE3:
case SOME_CHARTTYPE4:
case SOME_CHARTTYPE5:
{
break;
}
default:
OutputDebugString("warning: unexpected value; handling as if of the last block\n");
case SOME_CHARTTYPE6:
case SOME_CHARTTYPE7:
case SOME_CHARTTYPE8:
case SOME_CHARTTYPE9:
case SOME_CHARTTYPE10:
{
}
} This construct can help a programmer to detect dangerous default s while still doing something reasonable with them.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
How can I change the date of modification or creation of a file in my program
or in windows?
Mazy
|
|
|
|
|
CFile::SetStatus()
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
I am using string in my program.
I have the following lines in my code:(I am showing only relevant lines)
#include<string>
using namespace std;
........
.............
void main()
{
string myname("Stars");
string yourname;
yourname=myname;
cout<<myname;
}
i get="" compilation="" error="" for="" line..yourname="myname" (says="" "=" operator not defined stuff...)
also for line..cout<<myname (says " <<"="" not="" defined...)
how="" can="" i="" achieve="" what="" intend="" doing="" here?also="" how="" use="" cin="">>yourname?
Please help me.
|
|
|
|
|
The only thing your program is missing is an #include <iostream> to use cout . Apart from this, it compiles and works fine.
You may try stripping down your program to a twenty line file (i.e. removing the "irrelevant" lines). My guess is that in the process the bug will dissapear, and possibly this will shed some light.
As for the second question, yes you can use cin>>yuorname , but that only gets till the first whitespace. Use getline(cin,yourname) for retrieving entire lines.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello,
I would like to know if somebody has already implement
set of c++ macros that generate automatically class (constructor and destructor).
I yes can you send me few sample or links?
Thanks for help.
S.
|
|
|
|
|
#define STARTCLASS(classname) \
classname::classname(){} \
classname::~classname(){}
class CMYClass
{
STARTCLASS(CMYClass)
};
Hope this helps,
Bill
|
|
|
|
|
I've got an idea that's been rattling about my nearly vacant cranium for a while now, and I'd like to solicit some ideas here.
I have two locations, 10 km apart, running a text-based retail program using serial ports for communications. The two sites are run on separate serial concentrator chains. For the remote site, the signals leave the server at on a RS422 line at 1.5 Mbps, but are immediately throttled down to 56 kbps as they pass thru a DSU/CSU for transmission over a pair of wires to the remote DSU/CSU and into a concentrator for demultiplexing. The wires between periodically get dug up, which puts a bit of a kink into things at the other end.
Back at the main site, I have a separate WinNT server with a 2 Mbps wireless Internet connection and eight available serial ports. The thought is that I should be able to skip the wire connection completely by reading the serial data stream from the serial server with a port on the NT server, then construct a VPN over the Internet to the remote site, and from there out to the concentrator via a serial port on a machine there. It would immensely increase the speed of the data flow, and eliminate the risk from a drunken contractor on a backhoe. Plus it would save a bundle, since the wire between sites costs me $100/month, and the wireless connection is free (I trade roof space for antennas for service).
I think it would be an interesting project, but I'm curious whether anyone here has tried such a thing, or has any suggestions about how to approach it... One concern of mine is that the hardware approach we're using is, by design, near real-time, while an NT server is far from it. Would the latency be likely to make it fail? Is it a dumb idea from the getgo? Thoughts, anyone?
|
|
|
|
|
consider a for loop like that:
for(i=0;i<=Bound;i++)
In this loop i would like to do an "if" test which if the test succeed i would like to go to the next iteration and if not i do another thing. For example:
if(i>Max||i
|
|
|
|
|