|
I must be doing something wrong but i don't know what. So here's all of it..
Thanks for the patience.
<br />
<br />
#include "MyButton.h"<br />
class CTstButtonView : public CView<br />
{<br />
protected:
CTstButtonView();<br />
DECLARE_DYNCREATE(CTstButtonView)<br />
<br />
public:<br />
CTstButtonDoc* GetDocument();<br />
MyButton* myButton;<br />
public:<br />
virtual void OnDraw(CDC* pDC);
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);<br />
virtual void OnInitialUpdate();<br />
<br />
public:<br />
virtual ~CTstButtonView();<br />
#ifdef _DEBUG<br />
virtual void AssertValid() const;<br />
virtual void Dump(CDumpContext& dc) const;<br />
#endif<br />
<br />
protected:<br />
<br />
protected:<br />
DECLARE_MESSAGE_MAP()<br />
};<br />
<br />
<br />
void CTstButtonView::OnInitialUpdate() <br />
{<br />
CView::OnInitialUpdate();<br />
<br />
myButton = new MyButton;<br />
myButton->Create("Test", WS_CHILD, CRect(0,0,50,50), AfxGetMainWnd(), WM_USER+1);<br />
myButton->ShowWindow(SW_SHOW);<br />
}<br />
<br />
class MyButton : public CButton<br />
{<br />
public:<br />
MyButton();<br />
<br />
<br />
public:<br />
virtual ~MyButton();<br />
<br />
protected:<br />
afx_msg void OnMyButton();<br />
<br />
DECLARE_MESSAGE_MAP()<br />
};<br />
<br />
<br />
<br />
MyButton::MyButton()<br />
{<br />
}<br />
<br />
MyButton::~MyButton()<br />
{<br />
}<br />
<br />
<br />
BEGIN_MESSAGE_MAP(MyButton, CButton)<br />
ON_BN_CLICKED(WM_USER+1, OnMyButton)<br />
END_MESSAGE_MAP()<br />
<br />
void MyButton::OnMyButton()<br />
{<br />
AfxMessageBox("My Function!");<br />
}<br />
<br />
|
|
|
|
|
You dont need to inherit from CButton to handle the click event of your button
All you have to do is to add a button notification handler in the view class for the id of your button, and ensure that the button's id is unique in order not to conflict with other controls. This code should explain it:
class CTstButtonView : public CView
{
.
.
CButton m_btn;
afx_msg void MyButtonHandler();
.
.
};
BEGIN_MESSAGE_MAP(CTstButtonView , CView)
.
.
ON_BN_CLICKED(ID_MYBUTTON, MyButtonHandler)
.
.
END_MESSAGE_MAP()
void CTstButtonView::OnInitialUpdate()
{
CView::OnInitialUpdate();
if(!m_btn.GetSafeHwnd())
m_btn.Create("TEST", WS_CHILD|WS_VISIBLE, CRect(0,0, 200, 100), this, ID_MYBUTTON);
}
void MyButtonHandler()
{
AfxMessageBox("My Function!");
}
note that in your code you made the parent window of the button is the main window which is the CMainFrame class, if you want it this way you may need to move the handler function and handler message map to the CMainFrame instead of the CView
|
|
|
|
|
Another note concerning the code of you derived CButton class. The code did not work becuase the BN_CLICKED message is not sent to the button, this message is sent to the parent of the button. Therefore the message is not sent to the button in the first place.
|
|
|
|
|
Right, i'd actually alread tried that method too... and it didn't work. I tried swapping the mapping from my custom class, to the view and still didn't work. The problem was...
<br />
m_btn.Create("TEST", WS_CHILD|WS_VISIBLE, CRect(0,0, 200, 100), this, <br />
ID_MYBUTTON)<br />
<br />
as opposed to my<br />
<br />
m_btn.Create("TEST", WS_CHILD|WS_VISIBLE, CRect(0,0, 200, 100), AfxGetMainWnd(), <br />
ID_MYBUTTON)<br />
should have seen this.
Thanks for the help everyone.
|
|
|
|
|
We do a lot of user interface software, often small applications.
In order to speed up design is it possible to add to the palette in the dialgoue editor ? The one where the edit box, list control etc. appear ?
Either in VC++6.0 or VS.NET.
Thanks.
Elaine
The tigress is here
|
|
|
|
|
Well, not to the dialog editor.
But try to use the component gallery.
G. Steudtel
|
|
|
|
|
Hi,
DLL's OCX's... must be registered with that regsvr32 ( if they are COM servers...), but the TLB files, can they ( or should they) be registered as well ?, I think not, but I'm not 100 % sure, what is the right answer ?
Thanks in advance, greetings
Braulio
|
|
|
|
|
tlb type libraries describe the entry points into the ocx dll's
they are only necessary when you are importing them into your source code so that you can call the ocx functions. you can not / do not register them with regsvr32.
regsvr32 registers your COM CLSID's with the OLE / COM subsystem so that it can create the appropriate class factories / classes at runtime.
hope this is reasonable clear explanation
|
|
|
|
|
I want to query the last modified time on a file before I download it from the Internet. Unfortunately I'm connected via an MS proxy server which requires the domain name as well as username and password. I've successfully got a response code by using the following WinINet functions:
InternetOpen()<br />
InternetConnect()<br />
HttpOpenRequest()<br />
HttpSendRequest()<br />
HttpQueryInfo()
where HttpQueryInfo() looks something like this:
HttpQueryInfo(hResourceHandle, HTTP_QUERY_FLAG_NUMBER |
HTTP_QUERY_STATUS_CODE, &dwStatus, &dwStatusSize, NULL))
Note that I set my internet options for using the proxy using the handle returned from HttpOpenRequest().
HttpSendRequest() returned a response code of 200 - OK.
So now I want to get the last modified details, so I change the HttpQueryInfo() call to something like this:
char szLastModified[32];
DWORD dwLengthLastModified = sizeof(szLastModified);
HttpQueryInfo(hResourceHandle, HTTP_QUERY_LAST_MODIFIED,
szLastModified, &dwLengthLastModified, NULL))
Unfortunately, it fails and GetLastError() reports an error code of 12150 - "requested header could not be located".
Can anyone spot what I'm doing wrong?
"The folly of man is that he dreams of what he can never achieve rather than dream of what he can."
"If you think education is expensive, try ignorance."
|
|
|
|
|
Hi,
I am still learning programming in C. I have tried to write down a piece of code and i get many errors.
Could someone help me to correct those? Hope i am not asking too much
Thx
/*******************************************************************************************
this code shows the Trl_values calculation. it is going to help determining the histogram
********************************************************************************************/
#include <stdio.h>
#include <math.h>
double tailing = NULL;
double trl_values = NULL;
double y_int_1 = NULL;
double rest = NULL;
double leading = NULL;
double Duration;
const double slice_level = 53.9998;
double histogram_ram = NULL;
double i_index;
double Trl_values;
void trl_calculation(int amount, unsigned char*pData)
{
for (int i=1; i <= amount; i++)
{
if ((y_int_1) - slice_level <0) & (y_int - slice_level > 0)
tailing = 1 - (y_int-slice_level)/(y_int-y_int_1);
Trl_values(length(Trl_values)+1) = tailing + leading + rest;
leading = 1 - tailing;
rest = 0;
else if ((y_int_1-slice_level>0)&(y_int-slice_level<0))
tailing = 1 - (y_int-slice_level)/(y_int-y_int_1);
Trl_values(length(Trl_values)+1) = tailing + leading + rest;
leading = 1 - tailing;
rest = 0;
else
rest = rest + 1;
y_int_1 = y_int;
}
}
void histogram(int amount, unsigned char*pData)
{
for (int i=1; i <= amount; i++)
{
i_index=round(Trl_values(i)/Duration)+1;
histogram_ram(i_index)=histogram_ram(i_index)+1;
}
}
P.S: How do i express the "round" function in C?
F.K
|
|
|
|
|
I don't know if this will help, but i was tying to rewrite into C code, my program in Matlab.
I used the Matlab compiler to run my code in C, but it does not generate a proper C code as i want.
That'i is why at some points the syntax may look weird.
F.K
|
|
|
|
|
Well, it helps to understand the queer syntax.
First of all, if you want to initialize a variable, use 0(zero) instaed of NULL. NULL should only be used for pointers, meaning not available memory. It may or may not coincide with being zero.
A variable is not a function. in your sample trl_value was used as a function trl_value(length(.....)), this function was then given a value, and never stored. Two errors at once.
A function cannot assigned a value, it is returning one! And a variable cannot be a function.
You may of course have a function with the same name like a variable, but this is bad manners, and not shown in your sample code.
So I think the best is, you just make clear what the code should perform. and write a plain simple text(file) in your local language, and try to translate this one into C.
Rounding in C/C++:
One of many methods
<br />
VariableRounded = (long)(VariableToBeRounded+0.5);<br />
Works mathematically correct only for positive values.
So try to use the floor or ceiling finctions instead. Still issues with signs.
G. Steudtel
|
|
|
|
|
Be more specific. What errors are you talking about (i.e., compiler, linker, run-time)?
There are different ways of rounding a number, depending on the intent. You can use ceil(), floor(), or you can add 0.5 to the number and cast away the exponent, leaving just the mantissa.
|
|
|
|
|
2nd question first...
double d,e = 5.731;
d = floor (e); // = 5
d = ceil (e); // = 6
d = fmod (e, 1.0); // = 0.731
d = fmod (e, 2.0); // = 1.731
As for the 1st question:
a) You don't give us the error messages. If there are loads, the first few will do.
Chances are, error 10-99 are follow ons from errors 1 - 9.
b) You have two '#include's at the beginning, but you don't give the preprocessor
and filenames to actually include...
c) There are a LOT of file scope (global) variables here. Not the best programming
example. If it works, then OK, but don't take too many tips from it.
Iain.
|
|
|
|
|
I have a dialog with 6 spin controls on it. The controls are populated with a random number in the OnInitDialog method. Once one of the spin controls is increased I would like to turn off the other 5 so that they can't be changed. If the original control was then later decreased then I need to turn on the all of the controls again so that they may be changed.
I have tried to do this the VScroll message handler but it seems that the buddy window is updated before or independant of this message handler.
Thanks for the help,
-Eric
|
|
|
|
|
You might be able to lock out the buddy changing by looking at EN_UPDATE (or is it EN_CHANGE...)
Alternatively, turn off the buddying on the other controls with UDM_SETBUDDY (NULL) and re-
connect them when your changed spinner goes back to its initial value.
Iain.
|
|
|
|
|
Iain,
Thanks for the help. I have used the EN_CHANGE message for each edit control and then I turned off the other spin controls if one was increased. The problem is that when the user clicks up again it will turn them all back on again. Here is a snippet of my code. Any ideas? I want to be able to only increase one of the 6 spin controls then turn off the rest. If the users then decreases the one spin control by one then it needs to turn the other controls back on again.
<br />
void CMyDialog::OnChangeEditOne()<br />
{<br />
if(!bFirstRun)<br />
{<br />
if(!bOne)<br />
{<br />
m_cTwo.EnableWindow(FALSE);<br />
m_cThree.EnableWindow(FALSE);<br />
m_cFour.EnableWindow(FALSE);<br />
m_cFive.EnableWindow(FALSE);<br />
m_cSix.EnableWindow(FALSE);<br />
m_cOk.EnableWindow(TRUE);<br />
bOne = TRUE;<br />
}<br />
else<br />
{<br />
m_cTwo.EnableWindow(TRUE);<br />
m_cThree.EnableWindow(TRUE);<br />
m_cFour.EnableWindow(TRUE);<br />
m_cFive.EnableWindow(TRUE);<br />
m_cSix.EnableWindow(TRUE);<br />
m_cOk.EnableWindow(FALSE);<br />
bOne = FALSE;<br />
}<br />
}<br />
else<br />
bFirstRun = FALSE;<br />
}<br />
Thanks again.
-Eric
|
|
|
|
|
Iain,
Thanks for the help. I have used the EN_CHANGE message for each edit control and then I turned off the other spin controls if one was increased. The problem is that when the user clicks up again it will turn them all back on again. Here is a snippet of my code. Any ideas? I want to be able to only increase one of the 6 spin controls then turn off the rest. If the users then decreases the one spin control by one then it needs to turn the other controls back on again.
<br />
void CMyDialog::OnChangeEditOne()<br />
{ <br />
if(!bFirstRun)<br />
{<br />
if(!bOne)<br />
{<br />
m_cTwo.EnableWindow(FALSE);<br />
m_cThree.EnableWindow(FALSE);<br />
m_cFour.EnableWindow(FALSE);<br />
m_cFive.EnableWindow(FALSE);<br />
m_cSix.EnableWindow(FALSE);<br />
m_cOk.EnableWindow(TRUE);<br />
bOne = TRUE;<br />
}<br />
else<br />
{<br />
m_cTwo.EnableWindow(TRUE);<br />
m_cThree.EnableWindow(TRUE);<br />
m_cFour.EnableWindow(TRUE);<br />
m_cFive.EnableWindow(TRUE);<br />
m_cSix.EnableWindow(TRUE);<br />
m_cOk.EnableWindow(FALSE);<br />
bOne = FALSE;<br />
}<br />
}<br />
else<br />
bFirstRun = FALSE;<br />
}<br />
Thanks again.
-Eric
|
|
|
|
|
Hi
I want to dynamic load # buttons.
Like if i have one employee, i only show 1 'Remove' button next to his information.
But when there are 10 employees, i want to see 10 buttons at the correct place.
How can i make a copy of that button and place it somewhere else?
Greetings
jens
|
|
|
|
|
|
Hi David
Ok but the ID given to that CButton needs to be changing, i would make it something like
IDC_BUTTONREMOVENR1
IDC_BUTTONREMOVENR2
...
How can i now use the same code for IDC_BUTTONREMOVENR1 & the others?
Let's assume i have written the correct code for the 1st button on click. But can i use that code now for the other buttons too and how so?
Greetings
Jens
|
|
|
|
|
I don't know what your design is, but I would think an acceptable solution would be to put the employees in a list control with checkboxes in the first "column." Then you would only require one Remove button. Does that make sense?
If that violates your design, you can use something like:
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(IDC_BUTTONBASE, IDC_BUTTONBASE + 4, OnRemove)
END_MESSAGE_MAP()
CButton *pRemoveButtons[5];
for (int x = 0; x < 5; x++)
{
pRemoveButtons[x] = new CButton;
pRemoveButtons[x]->Create(..., IDC_BUTTONBASE + x);
}
void CMyDlg::OnRemove(UINT nID)
{
TRACE("You clicked on Remove button #%d\n", nID - IDC_BUTTONBASE);
}
|
|
|
|
|
I think that ON_CONTROL_RANGE would probably be a little simpler to use here, rather than ON_COMMAND_RANGE.
|
|
|
|
|
Whether you provide the BN_CLICKED notification code in the macro or the handler function, I don't see that one is any easier to use than the other.
|
|
|
|
|
Does any one know how to access the help button on a property sheet? I'm trying to use the resource editor, but all it lets me access are the individual pages. Thanks,
Ralf.
ralf.riedel@usm.edu
|
|
|
|
|