|
the only two ways of doing this, (that I know of)
are , creating the check box at runtime as child of the listctrl and show/hide them on top of the item when nedded, or use a CImageList with icons to fake the checkboxes.
Dont know any outher way but the topic is interesting (I will do some testing )
Casa.Sapo.pt
|
|
|
|
|
Hi,
I have a design/OOP question. I am trying to find the most elegant solution or design of the object. I want to create several instances of an object, and then have each of those objects perform the same function at the same time when called upon to do that task. An example of what my question is this: for instance you wanted to create a bunch of door objects and you want them to open simultaneously at the appropriate time.
How would one design something like that? A real life example is in a horse race and the gates the horses are kept in. You want all the gates to open at once at the start of the race instead of having one person walk to each of them and open them manually. I’ve tried several ideas with the static keyword, but unfortunately, my design skills are not up to par.
If there is anyone who could show me a c++ example of how to design such an object, you would have helped me a lot.
|
|
|
|
|
Use a static member variable or (more generally) forward to a static member function, just like this:
class gate
{
public:
void open(){static_open();}
bool is_open(){return static_is_open();}
private:
static bool m_open;
static void static_open();
static bool static_is_open();
};
bool gate::m_open=false;
void gate::static_open()
{
m_open=true;
}
bool gate::static_is_open()
{
return m_open;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
So how would I use this?
int main(){<br />
<br />
gate x;<br />
gate y;<br />
gate z;<br />
<br />
bool gate::m_open = true;<br />
<br />
return 0;<br />
}
??? Thanks in advance for your help!
|
|
|
|
|
In Joaquín's example you would do this:
<br />
int main(){<br />
<br />
gate x;<br />
gate y;<br />
gate z;<br />
<br />
x.open();<br />
<br />
return 0;<br />
}<br />
I personally would remove the member functions and the gate class would look like this:
<br />
class gate{<br />
public: <br />
static void static_open(); <br />
static bool static_is_open();<br />
private:<br />
static bool m_open; <br />
};<br />
bool gate::m_open=false;<br />
void gate::static_open()<br />
{<br />
m_open=true;<br />
}<br />
<br />
bool gate::static_is_open()<br />
{<br />
return m_open;<br />
}<br />
Then your program could use it like this:
<br />
int main(){<br />
<br />
gate x;<br />
gate y;<br />
gate z;<br />
<br />
gate::open();<br />
<br />
return 0;<br />
}<br />
This is closer to what is really happening design-wise.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Is this weird?
I have an array with some entries I want to suppress from showing in the CListCtrl. WIthout thinking about index mismatch and conflict(and all I reallly need here is to populate the ctrl), I did:
for (int i3 = 0; i3 < pDoc->m_nNumItems; i3++)
{
fClearAllForList1 = TRUE;
if(pDoc->m_docFldHolder[i3] == "CDE")continue;
if(pDoc->m_docFldHolder[i3] == "XYZ")continue;
int nItem = m_list1.InsertItem(i3,pDoc->m_docFldHolder[i3]);
}
The entries all show up with no blank rows where the item was suppressed. SO if I didnt put in element # 3 of the arrray, the fourth element shows up where the third one shhould have been though if you look at the indices above, technically it should have skipped a row...
Is this safe or should I put use two indices, one for the rows and one for the array? AgainI really need to populate it only. I'm not doing any processing with the item number in the ctrl.
Appreciate your help,
ns
|
|
|
|
|
Why not insert void rows for the "hidden" items?
for (int i3 = 0; i3 < pDoc->m_nNumItems; i3++)
{
fClearAllForList1 = TRUE;
if(pDoc->m_docFldHolder[i3] == "CDE"||
pDoc->m_docFldHolder[i3] == "XYZ"||
pDoc->m_docFldHolder[i3] == "_"){
m_list1.InsertItem(i3,"");
}
int nItem = m_list1.InsertItem(i3,pDoc->m_docFldHolder[i3]);
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
And these void rows wont show ?
Appreciate your help,
ns
|
|
|
|
|
I have a SDI type app with 2 rich edit controls in the view (One for receiving text, and one for sending text).. How can I tell which edit control has the focus so when I do a "ctrl + c" to copy data to the clipboard MainFrame knows which edit control to copy the data from? GetFocus doesn't seem to work.
Any ideas?
|
|
|
|
|
Doesn't the richedit handle the clipboard stuff automatically??
--
Please state the nature of your medical emergency.
|
|
|
|
|
Doesn't seem to.. Unless when I create it I need to add something.. Here is how I create the controls..
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
if( !m_wndMonitor.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_READONLY, CRect(), this, 100) )
return -1;
if(!m_wndSendText.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE, CRect(), this, 101))
return -1;
m_wndMonitor.ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
m_wndMonitor.SendMessage(WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FIXED_FONT));
unsigned mask = m_wndMonitor.SendMessage(EM_GETEVENTMASK,0,0);
m_wndMonitor.SendMessage(EM_SETEVENTMASK,0,mask | ENM_LINK);
m_wndMonitor.SendMessage(m_wndMonitor.SetEventMask(ENM_LINK)) ;
m_wndMonitor.SendMessage(EM_AUTOURLDETECT,TRUE,0);
m_wndSendText.ModifyStyleEx(0, WS_EX_STATICEDGE);
m_wndSendText.SendMessage(WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FIXED_FONT));
return 0;
m_wndMonitor is one rich edit control
m_wndSendText is the other
|
|
|
|
|
Hi,
I am trying to convert a small piece of c++ code to c# however I am not familiar with c++.
I have a BSTR called sToChange, and an unsigned int called i
the string sToChange is "ZYX123".
in c++ when i is set to sToEncode[0] (which is 90, the char code for Z) it equals 12:
i = sToEncode[0]
//i now equals 12
in c# the same code i equals 90.
What is happening in the c++ code?
Thanks,
John
|
|
|
|
|
90 is ASCII for 'Z'.
IIRC, BSTR's are unicode, right? And they don't necessarily map one to one on ASCII. Have you tried converting the BSTR to a char*? It may also be the case that your BSTR string does not contain what you think it contains.
Do a CString str; str.Format("%S", bstrString); and check the contents of str. I'm assuming you are using MFC or ATL7. If you're using ATL7, try ATLTRACE("%S\n", bstrString); to see what the string contains. And if you're not using MFC, ATL nor ATL7, then use WideCharToMultiByte to convert the BSTR to char*.
--
Please state the nature of your medical emergency.
|
|
|
|
|
I am sending a command out my serial port and waiting for a reply. All replies end with '\r'. I am using WaitCommEvent() with EV_RXFLAG as the event, to wait for a '\r' received.
But with the serial port receive queue, if a '\r' has already been received and is in the queue before I call WaitCommEvent(), will it still return that the event has happened? Or will it timeout? Anyone know?
Thanks,
dan.
|
|
|
|
|
I'd say the event will be triggered for buffered characters --otherwise the function is nearly unusable in non-overlapped mode. To make sure, try the following:- Issue the command.
- Wait for a sufficiently long time (say 10 sec.) with
Sleep to make sure the '\r' has been received by the time Sleep returns.
- Call
WaitCommEvent and see what happens. If WaitCommEvent works the bad way (it doesn't set the event), come back here and we'll try to search for a solution.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I'm trying to plot a non linear graph using MSChart. I set up the array and val stores the result of the calculation. However, the graph I plot appears linear and it's plotted val vs val whereas I want index[0] vs val?
double val=0;
double step=0.5;
DWORD numElements[] = {10, 2}
saRet.Create(VT_VARIANT, 2, numElements);
long index[2];
for(index[0]=0; index[0]<10; index[0]++) {
for(index[1]=0; index[1]<2; index[1]++) {
val = index[0]*index[0];
saRet.PutElement(index, COleVariant( val ));
val += step;
}
}
m_chart.SetChartData(saRet.Detach());
m_chart.Refresh();
}
Any ideas?
Cheers
|
|
|
|
|
i have an SDI Application with a single view and i need to create new view, that would be a tool modeless window. what should i do?
|
|
|
|
|
An easy solution would be a simple dialog box. Another solution is to create a new window and then show and/or hide it.
Kuphryn
|
|
|
|
|
Is there a way of checking what versions of controls I am using in my application so I know what to distribute? I selected controls from the toolbox but am not sure which ones they are on my hard disk.
Hopefully, there is something like depends.exe which shows you the control name, location, version, etc. for everything your application is using.
Meanwhile, I have been looking up the CLSIDs in the header file and searching the registry and using OLE/COM object viewer to correlate the files needed.
The reason I'm asking is that even though I have packaged the rich text control, Richtx32.OCX, into my installation program and have registered the control, I am still having problems with my application's release build -- the rich edit control is not visible. I am running Windows 2000 and have tried running the program on Win98 and NT4 but no success.
Are there any other files I need with the richtext control, the flexgrid control, and the tab control besides their OCX counterparts? BTW, I'm a little confused here, I thought I selected a rich edit control (Edit box) into my form view but the CLSID is coming up with RichTx32.ocx.
|
|
|
|
|
Have you called AfxInitRichEdit at the beginning of your app?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes. Thank you. I've gotten further.
Does anyone know if there are some incompatabilities or limitations with the tab control, flex grid control, or rich text control with Win98 or other OS's???
|
|
|
|
|
I think my question was answered today. Someone asked about some problem he/she was having with the MSFlexgrid control and somebody responded that he needed a runtime license for it.
|
|
|
|
|
Hi,
I am trying to use ADO and ADOX, and I have included the following #import statements in the stdafx.h file,
#pragma warning(push)
#pragma warning(disable:4146)
#import "C:\Program Files\Common Files\System\ADO\MSADO15.dll" \
rename ("EOF", "EndOfFile")
#import "C:\Program Files\Common Files\System\ADO\msadox.dll"
#pragma warning(pop)
But, when I use the various objects in both the ADO and ADOX package, I need specify ADODB:: and ADOX:: respectively. If I do not specify this then it gives me an error saying that the class is not defined. Can Some one let me know why I am getting such an error.
Thanks,
Arthi
|
|
|
|
|
Having to prefix the names from these libraries is not a bad thing per se, but if you want to get rid of this obligation, include the following just after the the imports:
using namespace ADODB;
using namespace ADOX; This will pose problems if there are coincident names in the libraries: in those cases, you will have to include the prefix anyway.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|