|
I wrote a demo project for demonstrates the problem. Maby the project file is bigger than the permit post in the forum .IF you would like,I will E-mail the demo to you!My E-mail:wmc0860@sina.com
There is a problem.I debugger it many times,I knew the problem produce in the Function -void CTestDlg::OnChooseOriI(UINT nID) .but has no good methods to solved it.Maybe some VC++ specialist can find the pivotal reason.Can you help me ?If required the the CMyButton Class,PLS tell me!
The scene is follows://see the Attachment
Scene1:
Scene2:
Scene3:
Scene4:
my purpose is if switch the destination and the follow source signal status can be load.
and select source signal button interlock!
So far the destination select can be interlock,and the source select can be interlock!
but if I choose previously destination button ,this destionation load the source button
status is my have selected the source status all,not is my want is the latest select .but if
I select the source button again,it can be interlock.
For saving source select button status,In codes ,I create a *.ini file ,and make the source button
status worte in the *.ini file! each select the destination button ,can read the source button status
form the *.ini file.
see my follows code(one part )
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
.....
iniFile.Open("testDlgconfig.ini" ,CFile::modeCreate|CFile::modeNoTruncate|CFile::mo
deReadWrite|CFile::shareDenyWrite);
m_pAr=new CArchive(&iniFile,CArchive::load);//create the ini file pointer
if(iniFile.GetLength()!=0)
{
//read the status from the ini file!
for(int i=0;i<4;i++)
for(int j=0;j<16;j++)
{
(*m_pAr)>>m_byStatus[i][j];//BYTE m_byStatus[4][16],the array variable saved the source button select status
}
}
//read finish,destroy the pointer
m_pAr->Close();
delete m_pAr;
}
//Define the destination and source button select event
BOOL CTestDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
UINT nID=LOWORD(wParam);
HWND hWndCtrl=(HWND)lParam;
int nCode=HIWORD(wParam);
//
if((nID>=IDC_CHOOSEDES1)&&(nID<=IDC_CHOOSEDES4))
{
if(nCode==BN_CLICKED)
{
OnChooseDesI(nID-IDC_CHOOSEDES1);
}
}
if((nID>=IDC_CHOOSEORI1)&&(nID<=IDC_CHOOSEORI16))
{
if(nCode==BN_CLICKED)
OnChooseOriI(nID);
}
return CDialog::OnCommand(wParam, lParam);
}
//destination button select function,nSel parameter is the what destination button select!
void CTestDlg::OnChooseDesI(int nSel)
{
for(int i=0;i<4;i++)
{
if(i==nSel)
{
m_buChooseDes[i].m_nFlag=1;//m_nFlag =1,means the button be pressed status;m_buChooseDes[4],is the object array of the class CMyButton .
m_buChooseDes[i].RedrawWindow();
for(int j=0;j<16;j++)
{
m_buChooseOri[j].m_nFlag=m_byStatus[i][j];//m_buChooseOri[16],is the object array of the class CMyButton.
m_buChooseOri[j].RedrawWindow();
}
continue;
}
if(m_buChooseDes[i].m_nFlag==1)
{
m_buChooseDes[i].m_nFlag=0;
m_buChooseDes[i].RedrawWindow();
}
}
}
// select the source button ,the nID parameter means the button's ID what soucre button selected
void CTestDlg::OnChooseOriI(UINT nID)
{
//find the destination selected button nSel
int nSel;
for(int i=0;i<4;i++)
{
if(m_buChooseDes[i].m_nFlag==1)
{
nSel=i;
break;
}
}
if(i==4) return;
//select source button select function implement
int m=nID-IDC_CHOOSEORI1;
for(int j=0;j<16;j++)
{
if(j==m)
{
m_buChooseOri[j].m_nFlag=1;
m_buChooseOri[j].RedrawWindow();
continue;
}
if(m_buChooseOri[j].m_nFlag==1)
{
m_buChooseOri[j].m_nFlag=0;
m_buChooseOri[j].RedrawWindow();
}
}
// save the source select button status
m_byStatus[nSel][nID-IDC_CHOOSEORI1]=m_buChooseOri[nID-IDC_CHOOSEORI1].m_nFlag;
m_buChooseOri[nID-IDC_CHOOSEORI1].RedrawWindow();
}
|
|
|
|
|
bit OADM_Disconnect(void)
{
bit bDropOADS=0, bAddOADS=0;
int i=0, iPortValue=0, iPorts=pMsg[0], j=0;
//sbit SetBit=0;
//if(iPorts>PORT_SWITCH_MAX) return;
if(iPorts>PORT_SWITCH_MAX) return false; //every call can only set up to 8 ports/mirrors
for(i=0; i<iports; i++)=""
="" {
="" iportvalue="pMsg[i+1];
" if(iportvalue="">0 && iPortValue<9)
{
j=iPortValue-1;
if (j==0)
{SetBit10=pCardStatus[STATUS_DROP_BYTE]^0; SetBit10=0;}
if (j==1)
{SetBit11=pCardStatus[STATUS_DROP_BYTE]^1; SetBit11=0;}
if (j==2)
{SetBit12=pCardStatus[STATUS_DROP_BYTE]^2; SetBit12=0;}
if (j==3)
{SetBit13=pCardStatus[STATUS_DROP_BYTE]^3; SetBit13=0;}
if (j==4)
{SetBit14=pCardStatus[STATUS_DROP_BYTE]^4; SetBit14=0;}
if (j==5)
{SetBit15=pCardStatus[STATUS_DROP_BYTE]^5; SetBit15=0;}
if (j==6)
{SetBit16=pCardStatus[STATUS_DROP_BYTE]^6; SetBit16=0;}
if (j==7)
{SetBit17=pCardStatus[STATUS_DROP_BYTE]^7; SetBit17=0;}
//SetBit=pCardStatus[STATUS_DROP_BYTE]^(iPortValue-1);
//SetBit=0;
bDropOADS=true;
}
else
{
if(iPortValue>64 && iPortValue<73)
{
j=iPortValue-65;//was -57-1=-58
if (j==7)
{SetBit00=pCardStatus[STATUS_ADD_BYTE]^0; SetBit00=0;} // start with bit 8
if (j==6)
{SetBit01=pCardStatus[STATUS_ADD_BYTE]^1; SetBit01=0;}
if (j==5)
{SetBit02=pCardStatus[STATUS_ADD_BYTE]^2; SetBit02=0;}
if (j==4)
{SetBit03=pCardStatus[STATUS_ADD_BYTE]^3; SetBit03=0;}
if (j==3)
{SetBit04=pCardStatus[STATUS_ADD_BYTE]^4; SetBit04=0;}
if (j==2)
{SetBit05=pCardStatus[STATUS_ADD_BYTE]^5; SetBit05=0;}
if (j==1)
{SetBit06=pCardStatus[STATUS_ADD_BYTE]^6; SetBit06=0;}
if (j==0)
{SetBit07=pCardStatus[STATUS_ADD_BYTE]^7; SetBit07=0;}
//SetBit=pCardStatus[STATUS_ADD_BYTE]^(iPortValue-58); // start with bit 8
//SetBit=0;
bAddOADS=true;
}
}
}
// determine which hardware function to call
if(bDropOADS)
{
DROP_CHAN = pCardStatus[STATUS_DROP_BYTE];
DROP_OADS();
//////////testing//////////////
ACC='K';
TX_BYTE();
ACC='K';
TX_BYTE();
ACC=DROP_CHAN;
TX_BYTE();
ACC='K';
TX_BYTE();
ACC='K';
TX_BYTE();
/////////////////////////////////
}
if(bAddOADS)
{
ADD_CHAN = pCardStatus[STATUS_ADD_BYTE];
ADD_OADS();
//////////testing//////////////
ACC='K';
TX_BYTE();
ACC='K';
TX_BYTE();
ACC=ADD_CHAN;
TX_BYTE();
ACC='K';
TX_BYTE();
ACC='K';
TX_BYTE();
/////////////////////////////////
}
OADM_ReportStatus(false);
INIT_I2C();
return true; //added
}
I was given the above the code, but don't really understand how the function behave and how it works. This code is used to control a device hardware. The SWITCH_MAX is defined as 8.Can somebody advise me? Thank you very much.
|
|
|
|
|
...let two or more users connect (one being a server?) and have the users draw on the same canvas (possibly w/ a specified background picture)
kind of like a collective drawing (one person draws a line, everyone else sees it)
i made a program like this but it's crap.. so i wanted to know if there was a popular free utility that could do that
thanks
Roman Nurik
|
|
|
|
|
|
take a look at this link: http://www.realvnc.com/[^] you'll find a program that is used to monitor and control other PC's like Symantec's PC Anywhere, the good point is that you can find the sourcecodes there as it is opensource, and that you could do this app by yourself...
Hope this helps...
|
|
|
|
|
I have MFC MDI app with number of child windows all "maximized", i.e. (max when activated) ....
When single window is "restored" MDI shows rest of the windows in "restored" state....
Is there any way to alter framework to allow restored child displayed over maximized window?
Thanks,
Brian
|
|
|
|
|
It looks like Opera does just that.... Is opera MDI app?
|
|
|
|
|
I would like to write an application, having MANY classes. Each class needs access to a common (application-wide) global variable, say, int nVAR.
One of the classes would "set" nVAR, the rest of the classes would "get" nVAR.
Could someone please provide a simple sample code showing how to do this (or provide references to applicable samples).
Also, according to several sources I read "global variables" should NOT be used. Then WHAT should be used?
|
|
|
|
|
look for the singleton pattern, it's a class that can be instanciated only once, and can live everywhere,
for example ( taken from Design Patter, by Gamma, Helm, Johnson and Vlissides):
class Singleton {
public:
static Singleton* Instance();
protected:
Singleton();
private:
static Singleton* _instance;
};
The corresponding implementation is
Singleton* Singleton::_instance = 0;
Singleton* Singleton::Instance () {
if (_instance == 0) {
_instance = new Singleton;
}
return _instance;
}
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
There are no iron-cast, inviolable laws of programming.
Every program usually has at least a few things that are global and creating global variables for them is fine. It's the excessive, unnecessary use of global variables that causes problems.
Using a Singleton class is fine in itself but you want to be careful not to put a whole lot of stuff in place that ends up with you having a really complicated global variable
The situation you describe is a good case for *not* using a global variable since it introduces a coupling between your classes that can be hard to detect. Better if you make it a static member variable of the setting class and provide a static "get" method. That way, the coupling is obvious.
Software is everything. It also sucks. Charles Fishman [^]
Awasu 1.0.3 (beta)[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Gabor Kalman wrote:
Then WHAT should be used?
Static variables inside a class visible to everywhere, or inside a namespace, or globals in an unnamed namespace. Anything else is a nightmare, although obviously one global is not going to bring your project to your knees, I usually regard a long list of glabals as evidence that people have elsewhere used bad practices out of ignorance or laziness. It's better to do things right ALL the time than to make allowances where you can't be bothered.
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
Hi there,
I just finished compiling a static library with Dev-C++ 5.0. I tried to use the library in VC++ 6.0, but this brings up the error LNK1136 while trying to link...How can I get that to work? Does anybody have an idea? Is there a free compiler which can be used to produce static libraries that are compatible to VC++ 6.0 ??
thanks in advance...
jason
|
|
|
|
|
I experienced the most bizzare thing with SetPaneText
Some application of mine has a CStatusBar with 3 panes.
It's created properly, and SetPaneText() calls are successful for pane 1, but not for pane 2.
My indicators were declared as follows :
static UINT indicators[] =
{
ID_SEPARATOR,
ID_PANE1,
ID_PANE2
}
If I swap positions of ID_PANE1 and ID_PANE2 in indicators declaration, then SetPaneText works for pane 2, but not 1.
So I checked the declaration of ID_PANE1 and ID_PANE2 in the resource header file. Nothing unsual, besides ID_PANE1 shows up as hexadecimal when all other strings are decimal.
Deleting ID_PANE2 and re-inserting it from the string resources did the trick. But I'm still confused about why a simple string declaration has been able to block SetPaneText.
JC
|
|
|
|
|
Ok, I have a class called CComboBox2. Lets assume there's not much to it other than the declaration. It is derived from CComboBox(public)
I put the CComboBox2 in my afx message map.
Windows is not dunningmy dialog-level handler.
It does call the class's own OnSelchange():
void CComboBox2::OnSelchange()
{
m_bChanged = true;
CEdit2::SetChange(true);
}
It is used on a dialog where a CMyDialog::OnSelchangeCombo1() is defined.
What must I do to get the dialog's OnSelchangeCombo1() to run?
Many thanks in advance!
|
|
|
|
|
First of all, your question is confusing. It sounds as if you are trying to implement a custom message map, but not. If you used the class wizard, the message map is generated automagically. If not, you need to do it by hand. i.e.:
in your MyDialog.cpp:
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_NOTIFY(NM_DBLCLK, IDC_SOMECONTROL, OnDblclkSomeControl)
END_MESSAGE_MAP()
void CMyDialog::OnDblclkSomeControl(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int item_clicked = pNMListView->iItem;
if(item_clicked != -1)
{
DoSomething();
}
*pResult = 0;
}
and in MyDialog.h:
afx_msg void OnDblclkSomeControl(NMHDR* pNMHDR, LRESULT* pResult);
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Ok. I have a Drop-List style combo box control. It is declared as a CComboBox2. CComboBox2's base class is CComboBox.
I want a CBN_SELCHANGE handler for a control IDC_COMBO1 in a dialog IDD_DIALOG1
When the control is a CComboBox2, the dialog never gets the message. It never calls the dialog's handler for that control for that message. It does run the CComnoBox2's CBN_SELCHANGE handler though.
|
|
|
|
|
I'm working on an MFC project. When I went to add an MFC class via the wizard it tells me I can only add an MFC class to an MFC project. Anyone know how to tell it that it is an MFC project? Or how this information is kept so I can fix the project?
Cross posted on VS thread too..
ed
Regulation is the substitution of error for chance.
|
|
|
|
|
Best way is probably to start a new fresh MFC project and transfer your files there.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
If you created an MFC application from the AppWizard (I'm assuming you are using VC6 and not VC7 since you mention Class Wizard), you shouldn't have any problems. Did you try to convert a console app to an MFC app or something like that? Have you ever had problems making MFC apps before?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Are you sure that it is an MFC project and not a console application, or just a simple application? Did you use the application wizard to create the project?
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
I overrode the CBN_SELCHANGE event so I have a OnSelChangeControl event for my dialog. (In MFC, via ClassWizard)
When the user changes the selection, the code doesn't get called. If I do a close-up event on the same control it works, but I need it to run on selection change and not just close-up.
I'm using a break point in the debugger to see if it'd getting called.
What am I forgetting?
|
|
|
|
|
This is odd. I made a new project, and did what I did above. It works. But it refuses to work on this project.
Does anyone have any ideas?
|
|
|
|
|
Compare your message map calls between the two projects and see if they match. Your event may not have gotten hooked up for some reason. I've had issues with that before (though not usually on a combo box) that were fixed by hooking up the message map manually.
I did a test app to see if I could duplicate your problem and mine worked fine. Heres the code that classwizard generated.
void CSelChangeTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STATIC_LABEL, m_label);
DDX_Control(pDX, IDC_COMBO1, m_combo1);
}
BEGIN_MESSAGE_MAP(CSelChangeTestDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
END_MESSAGE_MAP()
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I did verify that I have:
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
So it is wired up right.
I also checked for duplicate nmumonics and control IDs. No such luck. It's like windows isn't sending (or is swallowing) the event.
I even went into PreTranslateMessage() and did:
if (m_cmbCombo1.m_hWnd==pMsg->hWnd) {
TRACE ("%d %d %d\n",pMsg->message,pMsg->wParam,pMsg->lParam);
}
and no CBN_SELCHANGE messages are comming in!
Arg!
|
|
|
|
|
Someone (not me) made it a CComboBox2
CComboBox2 publicly inherits CCombobox, be it looks like this isn't good enough.
How do I use a derived class like this, while still being able to use the CComboBox's events?
|
|
|
|