|
HI,
I've to set values in combo of 1 dialog box.
Then i've to call that value in the function in another class.
The function is defined in another class.
Dialogbox//
void settings::OnOK()
{
CString strTemp;
UpdateData();
nreturn=((CComboBox*)GetDlgItem(baudrate))->SetCurSel(m_dcb.BaudRate);
n2return=((CComboBox*)GetDlgItem(paritybits))->SetCurSel(m_dcb.Parity);
n3return=((CComboBox*)GetDlgItem(stopbits))->SetCurSel(m_dcb.StopBits);
strTemp.Format("%d", m_dcb.ByteSize);
n1return=((CComboBox*)GetDlgItem(databits))->SelectString(0,strTemp);
UpdateData(FALSE);
CDialog::OnOK();
}
class// fn definition:
BOOL serial::ConfigurePort(int BaudRate, int ByteSize,int fParity, int Parity, int StopBits)
{
if((m_bportready=GetCommState(m_hcom,&m_dcb))==0)
{
MessageBox("GetCommState error","Error",MB_OK+MB_ICONERROR);
CloseHandle(m_hcom);
return false;
}
m_dcb.ByteSize=ByteSize;
m_dcb.Parity=Parity;
m_dcb.StopBits=StopBits;
m_dcb.fBinary=TRUE;
m_dcb.fDsrSensitivity=false;
m_dcb.fParity=fParity;
m_dcb.fOutX=false;
m_dcb.fInX=false;
m_dcb.fNull=false;
m_dcb.fAbortOnError=TRUE;
m_dcb.fOutxCtsFlow=FALSE;
m_dcb.fOutxDsrFlow=false;
m_dcb.fDtrControl=DTR_CONTROL_DISABLE;
m_dcb.fDsrSensitivity=false;
m_dcb.fRtsControl=RTS_CONTROL_DISABLE;
m_dcb.fOutxCtsFlow=false;
m_dcb.fOutxCtsFlow=false;
m_bportready = SetCommState(m_hcom,&m_dcb);
if(m_bportready ==0)
{
MessageBox("SetCommState Error","Error",MB_OK+MB_ICONERROR);
CloseHandle(m_hcom);
return false;
}
return true;
}
In main class// this fn is called as
void CComDlg::Onreceive()
{
//if(!(port.ConfigurePort(115200,8,0,NOPARITY,ONESTOPBIT)))
if(!(port.ConfigurePort(comb.nreturn,comb.n1return,0,comb.n2return,comb.n3return)))
// if(!(port.ConfigurePort(comb.m_baudrate,comb.m_databits,0,comb.m_paritybits,comb.m_stopbits)))
{
MessageBox("Cannot Configure Communication Port","Error",MB_OK+MB_ICONERROR);
port.ClosePort();
}
My Question is in void CComDlg::Onreceive() ,
while using first if condition, it executes well.
But while using 2nd or 3rd if condn,
It gives " Set Comm state Error" and "Cannot Configure COmmn Port".
What's the problem there?
mithila
|
|
|
|
|
Check whether the combo items are properly populated.
Get the CComboBox item of the parent by using GetParent() function, fill the combo by the value from the popup dialog say in ur case settings.
|
|
|
|
|
anuchelvi wrote:
//if(!(port.ConfigurePort(115200,8,0,NOPARITY,ONESTOPBIT)))
if(!(port.ConfigurePort(comb.nreturn,comb.n1return,0,comb.n2return,comb.n3return)))
At this point, what are the values of comb.nreturn , comb.n1return , comb.n2return , and comb.n3return ? If they are not the same as those used by the call to ConfigurePort() that uses hard-coded values, it shouldn't surprise you that the results would be different.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ok...I solved my previous questions.
This question deals with a deleteItem function that is to delete an item from an array. And I am passing a sorted array, its size, and the target element...this is what I have so far...
<br />
<br />
<br />
<br />
<br />
#include <iostream><br />
#include <string><br />
using namespace std;<br />
<br />
template<typename T><br />
void sortArray(T arr[], int size);<br />
<br />
template<typename T><br />
void searchArray(T arr[], int size, T target);<br />
<br />
template <typename T><br />
void deleteItem(T arr[], int &size, T target);<br />
<br />
template<typename T><br />
void printArray(T arr[], int size);<br />
<br />
int main()<br />
{<br />
<br />
int size;<br />
int target;<br />
int arr[10] = {9,8,7,6,5,1,2,3,0,4};<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
system ("pause");<br />
}<br />
<br />
template<typename T><br />
void sortArray(T arr[], int size)<br />
{<br />
int smallest;<br />
T temp;<br />
for(int i=0; i<size-1; i++)<br />
{<br />
smallest = i;<br />
<br />
for(int j =i+1; j<size; j++)<br />
{<br />
if(arr[j] < arr[j-1])<br />
smallest = j;<br />
}<br />
<br />
temp = arr[j];<br />
arr[j] = arr[j-1];<br />
arr[j-1] = temp;<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
template<typename T><br />
void searchArray(T arr[], int size, T target)<br />
{ <br />
int size;<br />
int low = 0;<br />
int high = size -1;<br />
int mid = (low + high)/2;<br />
int target;<br />
<br />
bool found = flase;<br />
do<br />
{<br />
if(target == arr[mid])<br />
found = true;<br />
<br />
else if(target < arry[mid])<br />
high = mid-1;
<br />
else <br />
low = mid +1;<br />
<br />
if(!found)<br />
{<br />
mid = (low + high)/2;<br />
}<br />
<br />
}while (high >= low && !found)<br />
<br />
<br />
<br />
}<br />
<br />
<br />
template <typename T><br />
void deleteItem(T arr[], int &size, T target)
{<br />
<br />
<br />
<br />
}<br />
<br />
<br />
<br />
template<typename T><br />
void printArray(T arr[], int size)<br />
{<br />
for(int i=0; i<size; i++)<br />
{<br />
cout << arr[i] << " ";<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Can anybody help me with the delete item method...I'M SO LOST!!!!!
THANK YOU FOR YOUR TIME!
Jason
|
|
|
|
|
If we can view a 10-item array as:
+-+-+-+-+-+---+-+
|0|1|2|3|4|...|9|
+-+-+-+-+-+---+-+ then to delete the item at position 3, items 4-9 must be moved one position to the left. In other words, item 4 becomes item 3, item 5 becomes item 4, etc. Make sense? What to do with the empty spot that results from moving item 9 depends on how you want the array to behave. It can be removed, or it can be left intact so that the next addition does not have to allocate any new memory.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Well, Im better able to define the question.
How can I change the system-defined default printer?
I can change the default printer for a specific
application, but how can I change it for the system?
Please, any response any one can give me will be greatly
appreciated.
Sincerely,
Danielle Brina (an overworked graduate student)
|
|
|
|
|
|
DanYELL wrote:
I can change the default printer for a specific
application, but how can I change it for the system?
Are you sure you want to do this? If a user has set their default to be printer A, and, after running your application, the default is changed to printer B, they aren't going to be too happy. Do you agree?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
how do i uncheck a menu item after i check it with CheckMenuItem(). How do i find whether a menu item is checked or unchecked?
|
|
|
|
|
MSDN:
BOOL GetMenuItemInfo(
HMENU hMenu, // handle to menu
UINT uItem, // menu item
BOOL fByPosition, // meaning of uItem
LPMENUITEMINFO lpmii // menu item information
);
MENUITEMINFO structure contains a flags(fState) which will specify whether the item is checked/unchecked.
|
|
|
|
|
You can use this on Udate_Command_UI Handler, which will be called just b4 showing the toolbar items
|
|
|
|
|
Hi All,
I would like to add a button to Outlook Express toolbar and perform some action when the users click it.
However, I cannot find any sample from the web on how to program outlook express. I found someone asked this question here before but got no answer...
I sure this can be done as I see some product is doing the same thing...
Does anyone did this before and could you show me the direction of doing this? Like ... what kind of programming should I focus to? COM or anything else?
It would be best if you could provide me a sample...
If you know any books are talking about this, please let me know too...
Help! I need somebody help!
Would you please help me?
|
|
|
|
|
Please have a loot at http://www.mindcracker.com/mindcracker/c_cafe/atl/BuildingOffice2KCOMAddInAD.asp.
In internet search for Com Addin you can get enough resource related to this
|
|
|
|
|
Thanks Sujan.
However, the link you provided seems only work for microsoft outlook but not outlook express.
In fact, i have written the addin for microsoft outlook already with VB. But I need to implement the same function for Outlook Express.
Help! I need somebody help!
Would you please help me?
|
|
|
|
|
I am looking for a good article or a discussion, which tells when to use C++ exception, when to return error codes vs. throwing exceptions. Can someone please provide any tips/article in this regard?
|
|
|
|
|
buddy12345 wrote:
when to return error codes vs. throwing exceptions.
That would be more of a religious war. I doubt you'll find much discussion that advocates a mix of both.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
hey guys,
OK! I"m really in a JAM! I have a template function called sortArray and I need to sort it in ascending order using "<" comparison).
I am passing the arrary and its size inside a template function of sortArray. And I want to use selection sort, where it arrages the array from smallest to biggest with numbers
i.e. myArray[10] = {4,3,5,1,2,6,7,8,9,0};
This is what I have so far...
<br />
<br />
template<typename T><br />
void sortArray(T arr[], int size);<br />
<br />
int main()<br />
{<br />
<br />
int arr[10] = {9,8,7,6,5,1,2,3,0,4};<br />
<br />
<br />
<br />
<br />
}<br />
<br />
template<typename T><br />
void sortArray(T arr[], int size)<br />
{<br />
int smallest;<br />
<br />
for(int i=0; i<size-1; i++)<br />
{<br />
smallest = i;<br />
for(int j =i+1; j<size; j++)<br />
{<br />
}<br />
}<br />
<br />
} <br />
<br />
I don't know how to find small where the comment is..i don't know the code or nor do I know how to swap them Please Help!
thanks much!
~Jason
|
|
|
|
|
well I came up with this
template<typename T><br />
void sortArray(T arr[], int size);<br />
<br />
int main()<br />
{<br />
int arr[10] = {9,8,7,6,5,1,2,3,0,4};<br />
<br />
<br />
<br />
sortArray(arr, 5);<br />
<br />
<br />
<br />
<br />
system ("pause");<br />
return 0;<br />
}<br />
<br />
<br />
template<typename T><br />
void sortArray(T arr[], int size)<br />
{<br />
int smallest;<br />
<br />
for(int i=0; i<size-1; i++)<br />
{<br />
smallest = i;<br />
for(int j =i+1; j<size; j++)<br />
{<br />
if(arr[j] < arr[smallest])<br />
smallest = j;<br />
}<br />
int temp;<br />
temp = arr[i];<br />
arr[i] = arr[smallest];<br />
arr[smallest] = temp;<br />
}<br />
<br />
}
Does that sounds right?
|
|
|
|
|
I have written a C++ program that converts a string to its integer value. If the string is only alphanumeric chars, then 0 is returned. If the string is like "12dssd", then only the integer portion is considered. The program works fine except when the string is assigned value like "2147483648". Since this value exceeds INT_MAX ( assuming 4 byte integers), overfloow occurs, and the integer returned is -2147483647. How can take care of overflow and underflow in this function?
what to do if I want to throw an exception when this is happening?
int strtoint(const char* str)
{
if (str == NULL)
return 0;
if (*str == '\0')
return 0;
int i=0,temp=0;bool isneg = false;
while (str[i] != '\0')
{
if (str[i] == '-')
{
i++;
isneg = true;
continue;
}
if (str[i] >='0' && str[i] <='9')
{
temp = temp* 10 + (str[i] -'0');
}
cout<
|
|
|
|
|
Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs.
i hardly ever use a class unless im doing something with MFC.
So can anyone give me some examples of when it would be better to use a class?
|
|
|
|
|
Archer282 wrote:
So can anyone give me some examples of when it would be better to use a class?
When you have more than 20 lines of code, you should be using classes. Either you're writing incredibly small and simple programs, or your code is a complete nightmare from a maintenence standpoint.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
After writing and erasing two lengthy replies (covering the history and philosophy of OO design) i see the merit in your reply. You are very wise.
Although, i personally would have said 42 lines ... 42 being THE answer and all.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
ROTFL - brilliant. I can't wait to hear the new HHGTTG episodes.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I've been given this fantasitc new 13mm wrench.
I know how to use it, but have only done so with 13mm nuts.
How do i use it to build a car ?
I don't mean to be flipant, but the question begs a reply that covers the whole of the object oriented design paradigm. A topic too large to fit in a reply.
Start by reading up on object oriented design.
Follow up by taking some small procedural programs you may have written and see if you can port some of the code into classes.
The trick is to start seeing your program designs as the interaction of objects, as opposed to the paths of code execution. Wherever you see an 'object', you have a class waiting to be born.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
When to use Classess? What type of classes do u want to use.
Ok whenever u want to do some socket programming then u have to derive it from socket class.
Everything is depend on the situation. Thats is a other matter that u want to go for classes or not. But OO provides the class concept which is one of the beautiful thing.
Neelesh Jain.
Work Hard and A Bit of LUCK is KEY to SUCCESS.
|
|
|
|
|