|
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hey Thanx David.
I see the Solution you have suggested, but the problem is the solution is for MFC Application while I am using Win32 API .
Can You help me with this. ???
I have tried somthing like this. but the Same thing. Errors,
I have Taken the Global Boolean flag First . But dont know where to initialize it to True. So I have initialize it in WM_INITDIALOG.
case WM_WINDOWPOSCHANGING:
if(First)
{
if ( ! ShowWindow(hWndDlg,SW_HIDE) )
dError = GetLastError();
First = FALSE;
}
break;
case WM_INITDIALOG :
First = TRUE;
...
...
break;
|
|
|
|
|
GauranG33 wrote: I have tried somthing like this. but the Same thing. Errors,
Because you did not remove the SWP_SHOWWINDOW flag.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have got the Idea to do do this.
I am using the timer in WM_INIT for about 100 msec. and in the WM_TIMER I am using ShowWinow() to hide the Dialog.
Currently It is working fine. But I just want to know will this work all the time. Or there will be the case it can fail.
the Code I am using is as follows
case WM_TIMER:
ShowWindow(hWndDlg, FALSE);
KillTimer(hWndDlg,0);
break;
case WM_INITDIALOG:
...
...
SetTimer(hWndDlg,0,100,0);
break;
|
|
|
|
|
I'm still wondering why this has to be so complicated.
If you never show the window to begin with then there's
no reason to go through all of this to hide it.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have created a dynamic list box control in my dialog based application.
This list shows threes item but does not response to button click or selection change.
Using Wizard, I can not add any handler function for this because it does not exist before program run.
How Can I add handler for this dynamic control so that I can respond to button click or selection change.
Do I need to use derived class to do this? Is there any way without using derived class.
Simple code example will be great. I am new in VC++.
Thank you.
msc
|
|
|
|
|
How did you make it can you show your code?
|
|
|
|
|
simple,
1.create a static listbox control,
2.add the event handler to that listbox control,
3.then observe dodataexchange and(or) beginmessagemap sections in your dialog.
4.what ever lines of code are added newly related to your static control,
5.duplicate them and alter the duplicated lines as per your dynamic control.
the above suggestions only give you a overview of how to do it.
you may have to put some efort and your own intelligense there, to sort it out.
and after that, you may get some more doubts like,
if i create the dynamic controls as an array, then how?
try to solve them yourself or post back.
gud luck.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
Hi Chandu
Thank you for your nice suggession. I tried to follow what you said. I have a member variable of CListBox pointer and I have created dynamic listbox in OnInitDialog() but I think DoDataExchange called before calling OnInitDialog and does not find the window handle and crushes.
Here is what I did: Please let me know if I did anything wrong based on your suggesstion. ====================
1.declared in header file
protected:
<br />
<br />
HICON m_hIcon;<br />
CListBox* m_dynalist;
virtual BOOL OnInitDialog();<br />
afx_msg void OnPaint();<br />
afx_msg HCURSOR OnQueryDragIcon();<br />
afx_msg void OnButton1();<br />
afx_msg void OnSelchangeList();
afx_msg void OnSelchangeDynaList();
<br />
<br />
DECLARE_MESSAGE_MAP()<br />
<br />
2. In .cpp file<br />
void CTestdynDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
CDialog::DoDataExchange(pDX);<br />
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_LISTTEST, *m_dynalist);
DDX_Control(pDX, IDC_EDIT, m_edit);<br />
DDX_Text(pDX, IDC_EDIT, m_editstr);<br />
<br />
}<br />
<br />
BEGIN_MESSAGE_MAP(CTestdynDlg, CDialog)<br />
ON_WM_PAINT()<br />
ON_WM_QUERYDRAGICON()<br />
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)<br />
ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)
ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeDynaList)
<br />
<br />
END_MESSAGE_MAP()<br />
<br />
void CTestdynDlg::OnSelchangeDynaList() <br />
{<br />
CString str;<br />
int isel = m_dynalist->GetCurSel();<br />
m_dynalist->GetText(isel,str);<br />
m_editstr = str;<br />
m_edit.SetWindowText(str);<br />
<br />
}<br />
msc
|
|
|
|
|
wait for some time may be 30 minutes,
i shall have my dinner, refer my backups and reply exactly.
meanwhile try it ur self.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
s196675m wrote: I think DoDataExchange called before calling OnInitDialog
It's called BY CDialog::OnInitDialog().
You need to do your creation before calling the base class
OnInitDialog(), and also check for a valid pointer in your
DoDataExchange() override...
void CTestdynDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST, m_list);
<font color="Red">if (m_dynalist)</font>
<font color="Red">{
</font> <font color="Red">
<font color="Red">}</font>
DDX_Control(pDX, IDC_EDIT, m_edit);
DDX_Text(pDX, IDC_EDIT, m_editstr);
}
BOOL CTestdynDlg::OnInitDialog()
{
<font color="Red">
<font color="Red">
CDialog::OnInitDialog();
}
Last modified: 55mins after originally posted --
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
if mark's suggestion, worked for you, then its fine.
byt in my application, i have not taken a pointer *m_dynalist, instead, i took normal variable(in my case, array).it worked quite comfortably for me.
s196675m wrote: DDX_Control(pDX, IDC_LISTTEST, *m_dynalist);//dynamic listbox
s196675m wrote: ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeDynaList)// dynamic listbox
in both the above cases, instead of IDC_LISTTEST, i have used some unique number like, for example, 10001
and i have used the same number while creation in the initdialog.
what i observe in your case is, you are declaring it as pointer and you are not creating memory for it using new.
if iam right, try creaitng the memory and see or use normal variable instead of pointer.
any more clarifications required?
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
Hi
I tried mark's suggession but still no luck.
Yes I have create memeory using new and I also used unique number defined for IDC_LISTTEST. I am scratching my head for last two days even can not make it work. I will be glad if you can help me to make it work
I need to understand this concept, otherwise I can not go forward.
Here is updated code:
<br />
void CTestdynDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
CDialog::DoDataExchange(pDX);<br />
DDX_Control(pDX, IDC_LIST, m_list);<br />
if (m_dynalist){<br />
DDX_Control(pDX, IDC_LISTTEST, *m_dynalist);<br />
}<br />
DDX_Control(pDX, IDC_EDIT, m_edit);<br />
DDX_Text(pDX, IDC_EDIT, m_editstr);<br />
<br />
}<br />
<br />
BEGIN_MESSAGE_MAP(CTestdynDlg, CDialog)<br />
ON_WM_PAINT()<br />
ON_WM_QUERYDRAGICON()<br />
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)<br />
ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)<br />
ON_LBN_SELCHANGE(IDC_LISTTEST, OnSelchangeDynaList)<br />
<br />
<br />
END_MESSAGE_MAP()<br />
<br />
BOOL CTestdynDlg::OnInitDialog()<br />
{<br />
<br />
m_dynalist = new CListBox;<br />
<br />
m_dynalist->CreateEx( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_TOOLWINDOW,<br />
_T("LISTBOX"),<br />
NULL,<br />
WS_CHILD | WS_BORDER,<br />
CRect(0, 0, 100, 70),<br />
this,<br />
IDC_LISTTEST,<br />
NULL);<br />
CDialog::OnInitDialog();<br />
<br />
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
<br />
m_dynalist->MoveWindow(130,200, 110, 100);<br />
<br />
m_dynalist->AddString("oone");<br />
m_dynalist->AddString("TTwo");<br />
<br />
m_dynalist->UpdateData(FALSE);
m_dynalist->ShowWindow(SW_SHOW);<br />
<br />
m_list.InsertString(0,"one");<br />
m_list.InsertString(1,"two");<br />
m_list.InsertString(2,"three");<br />
<br />
<br />
return TRUE;
}<br />
void CTestdynDlg::OnSelchangeDynaList() <br />
{<br />
CString str;<br />
<br />
int isel = m_dynalist->GetCurSel();<br />
m_dynalist->GetText(isel,str);<br />
m_editstr = str;<br />
m_edit.SetWindowText(str);<br />
<br />
}<br />
<br />
<br />
msc
|
|
|
|
|
What's not working?
Check out my previous post....I changed a line...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
do as mark said, or otherwise, if your application is light weighted, means, no dependencies like database etc,
and if it is in visual c++ 6.0, then mail me i shall see it.
chandu004@yahoo.com.
after mailing please indicate it here.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
I have sent my project files to you. Please have a look. I am using VC++6.0
I really appreciate you help.
|
|
|
|
|
received your source code.
but it is still downloading.
you would have deleted teh debug folder and zipped it.
any way,
i will go through it and come back.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
s196675m wrote: m_dynalist->UpdateData(FALSE);// false true both same effect here
It may be true that it has the same effect in this case but that's not true in general.
First, you should be passing FALSE when calling UpdateData() from OnInitDialog.
Second, CDialog::OnInitDialog() Calls UpdateData(FALSE) for you....it's redundant to call
it again unless you've actually made a modification that effects DDE - you haven't here.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark
If you want I can send you the source file.
Thank you and appreciate your help
|
|
|
|
|
Sure. Without the object code (delete the debug folder)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Fixed.
I sent back one file - search for "//MARK" to see the changes I made.
One change was the one I modified in my first reply - the DDX_Control() call isn't
necessary since the control is already subclassed.
Second change: LBS_NOTIFY style added to the listbox control so you
get your selchange notifications.
Third change: m_dynalist->UpdateData() call removed. That's useless,
and does nothing
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi mark
Thank you for your big help.
Your three line comment is more than my two days of work.
I appreciate your help.
Thank you again.
-- modified at 17:14 Saturday 13th October, 2007
|
|
|
|
|
s196675m wrote: Thank you
You're welcome
I sent another email in reply to the other topic...
Cheers,
MArk
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
you are very dynamic sir.
by the time i downloaded it, copied it onto other system, and unzipped it, you fired the answer.
hats off.
|
|
|
|
|
Heh. Well (s)he sent me a project that built fist try (after conversion to
VS2005 format) so that made it easy.
Plus there wasn't thousands of lines of code to weed through.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|