|
Yes, I agree -- it's quick, dirty, ugly... I get the feeling though that going into something like templates would not have been understood if the above could not have been done without help from this board (no offense meant to anyone).
I try to approach these things from the standpoint that a less elegant but easier to understand solution might better serve beginners. Then, at a later time, the better way to do something can be learned when the supporting knowledge is available. A fine line has to be drawn however, as the easy code might be a terrible way to do things. I suppose I should have added a disclaimer saying that there are better ways of doing things. With that said, I hadn't even thought about templates at the time
--Dean
|
|
|
|
|
|
What's wrong with templates?
template<class T> void MyFunction(T* start, T* end)
{
for(T* iter=start; iter <= end; iter++)
{
cout << *iter;
}
}
char temp [100];
MyFunction(temp, &temp[99]);
The beauty of this approach is that it works with things that provide iterators such as std::vector, as well as standard arrays. Untested code, so YMMV.
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
template <typename ForwardIter> void MyFunction(ForwardIter start, ForwardIter end)
{
while(start != end) {
doSomething(*start);
++start;
}
}
char temp[100];
MyFunction(temp, temp + 100); Would be a cleaner solution, as your will only work with std::vector . This'll work with any iterator.
--
Gnnnnmmmpppppppfffffhhh!
|
|
|
|
|
Like I said, untested code, and I'm a little rusty on C++ templates, but I figured it was essentially ok, and certainly illustrated what I wanted to suggest.
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
[EDIT]
Sorry did not read all the posts, but this problem screams for a template approach...
[/EDIT]
template<class T>myFunction(T* data)
{
}
int main()
{
char tmp[100];
float fTmp[1000];
myFunction<char>(tmp);
myFunction<float>(fTmp);
}
John
|
|
|
|
|
Hi,
I use the function ShellExecute to open a PDF-file from my c++-programm (ActiveXControl). I want to highlight one word on the pdf-file. Can I do this with ShellExecute or have you another idea how I can realize that.
Julia
|
|
|
|
|
In my SDI application , I have a ToolBar with 10 buttons .
I am unable to Change the text displayed in this Button .
I named the button ID_NEWBUTTON and have a event handler in CMainFrame.
I tried to change the text in the Toolbar button using
m_wndToolBar.SetButtonText(m_wndToolBar.CommandToIndex(ID_NEWBUTTON),"Please change text");
Still nothing seems to be happenning ?
|
|
|
|
|
How can I programatically change the Color of a ToolBar ?
|
|
|
|
|
Hi,
try this
<br />
SetClassLong(m_wndToolBar.m_hWnd, GCL_HBRBACKGROUND, (LONG)::GetStockObject(WHITE_BRUSH));<br />
Regards
|
|
|
|
|
I have an SDI framework where my Chidlview creates many Dialogs within itself .
I want to trap a keyboard entry in one of the dialogs . For this I went to ClassView and added the event Handler with a dummy AfxMessageBox
This event is not getting fired ? Suggestions are needed .
|
|
|
|
|
Hello,
Where did you add the event handler? The OnChar() handler should be added to the dialog in which you want to trap a keyboard entry!
hope this helps a bit...
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Sorry the subject was hard to summerize.
I have created a function that I thought was type independent, meaning that it didn't matter what type of an array was passed to the function. It would just write the data with a comma seperation.
I have 2 structure in a class called RFMAccess:
struct TSimHeader
{
char Name[47][21];
char Unit[47][21];
double Min[47];
double Max[47];
int SignalCount;
int SimStatus;
}static TSimHeader_arr[10];
struct TSimSignal
{
double Value[47];
double TimeStamp;
}static TSimSignal_arr[10];
The data in these structures gets updated 2x a second.
I also want to write the data to a file 2x a second so, I created a function that I thought would do this without having to declare the array type. I want to be able to use this later in other projects.
Here is my function.
I am doing something incorrect here, but just not sure what it is.
ofstream fout ("test.txt");
bool firstTime = true;
int passes = 1;
void LogData::writeData(void *data){
int count;
if(firstTime){
fout<<"flight_data,";
for(int i=0; i<RFMAccess::TSimHeader_arr[0].SignalCount; i++){
if(i == 0){
fout<<data[i]<<endl;
passes++;
if(passes == 2)
writeData(RFMAccess::TSimHeader_arr[0].Unit);
else if(passes == 3)
writeData(RFMAccess::TSimHeader_arr[0].Min);
else if(passes == 4)
writeData(RFMAccess::TSimHeader_arr[0].Max);
else if(passes == 5){
firstTime = false;
writeData(RFMAccess::TSimSignal_arr[0].Value);
}
}
else
fout<<data[i]<<",";
}
}
if(!firstTime &&(flight_data->log == true)){
if(i == 0){
fout<<data[i]<<endl;
writeData(RFMAccess::TSimSignal_arr[0].Value);
}
else
fout<<data[i]<<",";
}
}
Thnaks for the help,
Steven
|
|
|
|
|
What is the actual problem your getting?
Regards,
Brian Dela
|
|
|
|
|
It's saying that the type of void is unknown or zero.
thanks
steven
|
|
|
|
|
Anyone have a link to a good resource explaining how to use CDialogBar ?
|
|
|
|
|
Hi, all
I am experiencing a problem, when I change an edit box into readonly/lock state the backgroundcolor of control changes into the buttonface system color. How can I prevent this or choose a different color?
Thanks in advance
Aidman » over and out
We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.
|
|
|
|
|
u have to trap the OnCtlColor() event but as i recall edit boxes dont play nice and repaint themselves in a few places so it can be a bit of a b*itch
"penguins have no bill" biz stuff about me
|
|
|
|
|
return a White Brush in OnCtlColor()
|
|
|
|
|
Ok, Thanks mates
I will try that out
Aidman » over and out
We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.
|
|
|
|
|
This is the default windows behavior. Unless it is absolutly necissary I would not change it because it will confuse your users who will expect to be able to edit the box.
John
|
|
|
|
|
Hey! I'm trying to get a child dialog to show up in a pure Win32 app.
What I want to do is use the dialog as half of the UI and use a simple ListBox (created with CreateWindowEx) as the other half.
Here's what I'm trying:
hCtrls = CreateDialog( hInst, (LPCTSTR)IDD_GAMEINFO, hWnd, (DLGPROC)DlgGameInfo );
The line of code works for all non-child dialogs (like my About and Options dialogs), however as soon as I specify in the resource editor that my IDD_GAMEINFO should be a child it doesn't work.
Any help is appreciated! Thanks
./[tiller]
|
|
|
|
|
|
The hWnd is the HWND variable that the main window's WndProc message handler recieves.
In the switch statement for the various windows messages I basically have the following to create my UI:
case WM_CREATE:
HWND hCtrls;
// Listbox works
hCtrls = CreateWindowEx( WS_EX_CLIENTEDGE, "LISTBOX", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL,
5, 5, 200, 340, hWnd, (HMENU)IDC_GAMELISTBOX,
GetModuleHandle(NULL), NULL);
// Static frame works
hCtrls = CreateWindowEx( WS_EX_CLIENTEDGE, "STATIC", "",
WS_CHILD | ~WS_VISIBLE | SS_GRAYFRAME,
210, 5, 250, 340, hWnd, (HMENU)IDC_GAMEINFOFRAME,
GetModuleHandle(NULL), NULL);
// CreateDialog returns a NULL (IDD_GAMEINFO is my dialog resource)
hCtrls = CreateDialog( hInst, (LPCTSTR)IDD_GAMEINFO, hWnd,
(DLGPROC)DlgGameInfo );
// I also added this later to try it...but it didn't help:
ShowWindow( hCtrls, SW_SHOWNORMAL );
UpdateWindow( hCtrls );
I experimented a bit...the code with no modification works if I specify in the resource editor that the dialog is a regular popup with a border, etc. But of course then it's a popup...and I want it a part of the actually window. (Like a common control would be)
Thanks,
./[tiller]
|
|
|
|
|
Not sure that this is your case, but for child dialogs you have to ensure that the WS_VISIBLE style attribute is set in the resource.
|
|
|
|