|
Thanks for your help, but shoudn't DoDataExchange() be in some way involved in this?
I have an array CButton btns[10] that need to be 'connected' to 10 buttons on a dialog form. If I use ClassWizard (Member Variables) I can map each button with a single CButton variable, but it doesn't allow me to use btns[0], for example, as a name of a variable.
|
|
|
|
|
You can bypass ClassWizard and code assignments in DoDataExchange by hand. Just leave your 'manual' assignments out of the special code section delimited by
//{{AFX_DATA_MAP(<dialogclassname>)
//}}AFX_DATA_MAP
I do this all the time for custom DDV routines not built into ClassWizard or to make special assignment like you need.
You can try:
//{{AFX_DATA_MAP(<dialogclassname>)
//}}AFX_DATA_MAP
DDX_Control(pDX, ID_BTN_0, btns[0]);
DDX_Control(pDX, ID_BTN_1, btns[1]);
...
And that should work.
ClassWizard is the only thing that requires each button variable to be a separate member variable, the DDX_Control function does not care.
|
|
|
|
|
thanx for your help. I appreciate it.
|
|
|
|
|
That's a good start, but I need to know how then do I map all of the buttons in the array to call a single function when clicked that can tell which button was pressed.
Basically, my problem is this: I am writing a little program for testing very simple math. The program puts up a simple math problem such as "2 + 1 =", and the user is to press a button with the correct number as the answer, in this case "3". There are several of these buttons. Each should call essentially the same routine which just checks to see if the number on the button is the correct answer or not. How do I set these up as an array such that pressing any of them calls this one function with an Index in the array so that I know which one was pressed?
I'd sure like to avoid having a separate function for each of these buttons because I'm planning on having about 20 of them.
Thanks.
|
|
|
|
|
OK, I figured out how to map the buttons all to the same function. Here's the code:
BEGIN_MESSAGE_MAP(CButtonArrayTestDlg, CDialog)
//{{AFX_MSG_MAP(CButtonArrayTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, OnButtonArray)
ON_BN_CLICKED(IDC_BUTTON2, OnButtonArray)
ON_BN_CLICKED(IDC_BUTTON3, OnButtonArray)
END_MESSAGE_MAP()
Now, when each of the buttons is pressed, it does call the correct function. But now how do I know which button was pressed?
|
|
|
|
|
Maybe you need to try this instead:
ON_CONTROL_RANGE(BN_CLICKED, IDC_BUTTON1, IDC_BUTTON3, OnButtonArray)
Note: The range of command IDs must be contiguous.
Handler functions for single commands normally take no parameters. With the exception of update handler functions, handler functions for message-map ranges require an extra parameter, nID, of type UINT. This parameter is the first parameter. The extra parameter accommodates the extra command ID needed to specify which command the user actually chose.
afx_msg void OnButtonArray( UINT nID );
When called, nID will be the ID of the button pressed.
|
|
|
|
|
|
I misunderstood your initial question. I think Blake Miller has given you the correct answer.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
[View Image]
asdf.zip file is a zip file.
But, it can browsed in Explorer just like a folder.
How can I make this?
|
|
|
|
|
it is a shell extension, but i dunno exactly how it works... maybe michael dunn is the right one for this question
Don't try it, just do it!
|
|
|
|
|
hi everybody,
i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the WM_RBUTTONDOWN an i associated to it the following code :
<font style="color:blue;">void </font>CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
<font style="color:blue;">this</font>->OnClose();
CDialog::OnRButtonDown(nFlags, point);
} Unfortunately, it doesn't work
i've been obliged to create a "OK" button which i hide, and instead of calling OnClose (), i call OnOk () :
<font style="color:blue;">void </font>CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
<font style="color:blue;">this</font>->OnOk();
CDialog::OnRButtonDown(nFlags, point);
} It now works, but i don't like this way of contourning the problem.
can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?
TOXCCT >>> GEII power
|
|
|
|
|
Why not call EndDialog()
Ant.
|
|
|
|
|
work fine thank you
anyway, do you have an idea of the reasons OnClose () doesn't work ?
would the virtual BOOL CWnd::DestroyWindow(void); have work better too ?
TOXCCT >>> GEII power
|
|
|
|
|
You would use DestroyWindow() for a modeless dialog and EndDialog() for a modal dialog.
OnClose() will call DestroyWindow() anyway IIRC. However without looking I can not recall why they are done differently. Now I will have to look and find out
Ant.
|
|
|
|
|
From MSDN CDialog::OnOK
"If you implement the OK button in a modeless dialog box, you must override the OnOK method and call DestroyWindow from within it. Do not call the base-class method, because it calls EndDialog, which makes the dialog box invisible but does not destroy it."
Had to look this up so here for your benefit too.
Ant.
|
|
|
|
|
thx very much
TOXCCT >>> GEII power
|
|
|
|
|
You can do it like this:
<br />
void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) <br />
{<br />
SendMessage(WM_CLOSE);<br />
<br />
CDialog::OnRButtonDown(nFlags, point);<br />
}<br />
and then in OnClose(), you can do the cleanup. OnClose() is called after WM_CLOSE is processed, I guess. So it doesn't actually close the window.
|
|
|
|
|
ok. yes, i was calling OnClose () to close, but it is called when the windows is about to be closed... thx
TOXCCT >>> GEII power
|
|
|
|
|
Any reason why OnRButtonDown() is calling OnLButtonDown() ?
toxcct wrote:
Unfortunately, it doesn't work
Because EndDialog() is not being called. Take a look at CDialog::OnOK() and CDialog::OnCancel() . Notice how they both call EndDialog() .
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
Any reason why OnRButtonDown() is calling OnLButtonDown()?
Nop, mistake from my own. fixed now. thanks for the directions to see.
TOXCCT >>> GEII power
|
|
|
|
|
|
thank you but repost.
no need to overload the servers...
TOXCCT >>> GEII power
|
|
|
|
|
I am working on an SDI application with 3 different views(CFormView). There are 3-4 variables that are shared between those views. These variables should be saved in a file, so each time user starts the app its sees the interface as it was when he exited.
I don't need to use CDocument, because I need just one file to store the settings for the app. Therefore, my questions are:
1) Where should I put those variables (CwinApp, CDocument or somewhere else)?
2) What other changes do I need to make, in order to have the app load the settings' file, when it starts, and save changes to the file when it exits?
3) How to 'turn off' support for creating new, opening and saving documents, since I don't need it?
Any help would be appreciated.
|
|
|
|
|
Yes, I recommend CDocument. The concept of SDI utilizes CDocument. Access CDocument through the view.
Kuphryn
|
|
|
|
|
If you don´t necessarily need a file, what about the registry, otherwise you could use the applications´ ini file.
1) If the Views are using the same CDocument and you don´t need these variables anywhere else than in these view, you might as well put them in CDocumen, otherwise in CWinApp
2) The CWinApp object gives a halfway decent support to write an read from the ini file
CWinApp::WriteProfileInt
CWinApp::GetProfileInt
CWinApp::GetProfileString
CWinApp::GetProfileString...
when the app quits, you can write your stuff within the
virtual CWinApp::ExitInstance()...
3) Easiest thing to do is to throw out the resources directly from the menu.
|
|
|
|