|
how to use:
SetFolderImageList(const int folder, CImageList * pImageList, int nImageList)?
how to set multi-outlookbar folder image?
|
|
|
|
|
I have code like this
<br />
fun1(){<br />
CEdit* pEdit=new CEdit;<br />
pEdit->Create(...);<br />
}<br />
fun2(){<br />
CEdit* pEdit=new CEdit;<br />
}<br />
fun3(){<br />
pEdit->SetWindowText("Bla Bla");<br />
}<br />
But I have problems in fun3() because sometimes the pEdit object isn't created.
What function I could use, to test pEdit, in fun2 to know if the object is created or not?
Thanks
|
|
|
|
|
( I assume that what you wrote in your question is what you have in your real code )
Well, you should go back to to your C++ books ...
in fun1 you create a local variable pEdit which will leak memory when the function ends; same thing in fun2
in fun3 you access a variable that is not allocated yet, so it will crash.
NOW, assuming that what you wrote is not actually your real code and that you pass pEdit as a parameeter to fun3 , check to see if pEdit is NULL before trying to access it :
fun3( CEdit* pEdit )
{
if ( pEdit )
pEdit->SetWindowText("...");
}
If when calling fun3 your not certain that pEdit is Create ed, you can check with CWnd::GetSafeHwnd ( or something similar ).
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
SORRY.
Of course, the sintax wasn't correct.
This probally is better.
<br />
CEdit* pEdit=NULL;<br />
InitType1(){<br />
pEdit=new CEdit;<br />
pEdit->Create(...);<br />
}<br />
InitType2(){<br />
pEdit=new CEdit;<br />
}<br />
DoSomething(){<br />
pEdit->SetWindowText("Bla Bla");<br />
}<br />
Now.
if(pEdit) pEdit->SetWindowText("Bla Bla");
doesn't work because we could think that pEdit is always !=NULL.
if(pEdit->GetSafeHwnd()!=NULL) pEdit->SetWindowText("Bla Bla");
Looks interesting, and I think that could work.
So, Thank you
-- modified at 7:50 Wednesday 16th November, 2005
|
|
|
|
|
Matteo_78 wrote: if(pEdit) pEdit->SetWindowText("Bla Bla");
doesn't work because we could think that pEdit is always !=NULL.
Well, we would not... and checking the pointer validity is always a good thing, either with ASSERT or by if
...
BTW, why do you new pEdit twice ? is pEdit a class member variable ? in DoSomething , which pEdit are you referencing ? the one allocated in InitType1 or in InitType2 ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
The code that I've posted was only an example, in my program the situation isn't so simple.
Yes, I'm checking pEdit before entering in this instructions.
About InitType1 and InitType2 and the doubled 'new': these are 2 different type of initalization functions of pEdit. And you could be sure that only one of InitType* was runned before DoSomething .
Thank you for your help;)
|
|
|
|
|
I use something like
if( ::IsWindow(pEdit->m_hWnd) ){
to verify that the window that the object references has been created and still exists.
GetSafeHwnd() will protect against the NULL this pointer and return the m_hWnd, but it won't let you knwo if the window exists, prior to sending a message.
Maybe you want soemthing like this:
if( pEdit && ::IsWindow(pEdit->m_hWnd) ){
|
|
|
|
|
did you look into the MSDN[^] ?
MSDN tells us :
CEdit::Create()
Creates the Windows edit control and attaches it to the CEdit object.
Return Value
Nonzero if initialization is successful; otherwise 0.
i think you'll find you hapinness there, won't you ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
CEdit* pEdit=NULL;
pEdit = new CEdit();
fun3()
{
if(pEdit!=NULL)
pEdit->SetWindowsText("Bla Bla");
}
Bye
Cool Ju
Vote for Cool Ju
|
|
|
|
|
how to indicate sorting icon in the list control on clicking column header.
knarasimharao
|
|
|
|
|
Check this[^]...
In CP one C# atricle is there on this ....
See this[^]....
Hope this will help you....
|
|
|
|
|
I have to write a program which shows a dialog when click on a button. After that, when click outside this dialog, it will be closed.
I've tried to use OnKillFocus function to check whether this dialog should be closed or not but it doesn't work.
Could u suggest me another solution to to this task?
Thanks in advance.
THE_TIME
|
|
|
|
|
OnActivate? (assuming you use MFC)
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I don't know how to use OnActivate function, could u tell me more detail?
Many thanks to your help.
Trunghd
|
|
|
|
|
trunghd wrote: I don't know how to use OnActivate function
MSDN[^] is your friend buddy...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I just tested this, OnActivate won't work for you. Since it's a modal dialog (which I assume it is) it won't receive OnActivate messages when you click outside the dialog. Similarly, you won't get any WM_LBUTTONDOWN or the likes when the user clicks outside your dialog. Instead, you must handle the WM_NCACTIVATE message:
In your dialog class header, put
<br />
afx_msg BOOL OnNcActivate(BOOL bActive);<br />
and put
<br />
ON_WM_NCACTIVATE()<br />
in the dialog class' message map.
in CYourDialog::OnNcActivate handle the case bActive==FALSE, this is when the user clicks outside the client area. Dismiss your dialog in whatever way is appropriate.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
trunghd wrote: but it doesn't work
What does not work ? You do not catch the WM_KILLFOCUS message, or does the message not get send when you click outside the dialog ?
Three possibilities here (from the best to the least good, IMO):
1- Catch the WM_ACTIVATE message( MFC using afx_msg void OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized ); and WA_INACTIVE as nState). In the message handler, dismiss your dialog.
2- Catch WM_KILLFOCUS, i still do not understand why this should not work
3- Handle WM_LBUTTONDOWN and WM_RBUTTONDOWN, check if the clicked position is inside the area of your dialog, if not, dismiss the dialog.
Hope this helps
~RaGE();
|
|
|
|
|
This program I have to write is very similar to the Undo button in MS Visual C++ 6.0. When click on a button, a new dialog which have a listbox within it appears. We can choose item in listbox. When we click outside the dialog, it will be closed.
I use Create()& SetWindowPos functions to put the new dialog at the bottom of this button.
Firstly, I've tried to use OnKillFocus to check when the dialog lost focus but I always get WM_KILLFOCUS message immediately after SetWindowPos function. So the dialog disappear immediately after appear.
Second, I've tried to catch WM_ACTIVATE message but I don't know how to check WA_INACTIVE or WA_ACTIVE in the WM_ACTIVATE message. Do I have to override OnActivate function to handle WM_ACTIVATE message.
Could u tell me more detail?
Many thanks for your help. It's very precious.
Trunghd
|
|
|
|
|
trunghd wrote: I use Create()& SetWindowPos functions to put the new dialog at the bottom of this button.
Firstly, I've tried to use OnKillFocus to check when the dialog lost focus but I always get WM_KILLFOCUS message immediately after SetWindowPos function. So the dialog disappear immediately after appear.
Ok, this explains why OnKillFocus is not our solution here.
trunghd wrote: I've tried to catch WM_ACTIVATE
I still do not know if you are using MFC, but I will assume it. If not, post back and i'll give you the plain Win32 code.
So override the WM_ACTIVATE message (I guess you know how to do, if not : Right-click on your dlg class in the class borwser, [Add Windows MEssage Handler], Set [Filter for messages available to class] (on the bottom right) combo box on [Window], Select WM_ACTIVATE in the left listctrl and Click Add Handler button).
Then
void CYourDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
if ((WM_INACTIVE == nState ) && (pWndOther == FromHandle(m_hWnd))
{
}
else
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
}
}
~RaGE();
-- modified at 7:56 Wednesday 16th November, 2005
|
|
|
|
|
hi all, i am new to VC++. i want to write the out put of VC++ code in a notepad file, at a specific destination or alternative is that i want to write the output of a function in database.
kindly help me to achieve the task.
|
|
|
|
|
toufiq_raja wrote: hi all, i am new to VC++. i want to write the out put of VC++ code in a notepad file, at a specific destination
Your question is a little short on specifics, if you are using MFC then you can use the CFile class to write output to a text-file.
toufiq_raja wrote: alternative is that i want to write the output of a function in database.
What kind of database? SQL? Access? Oracle? MySql?
Michael
CP Blog [^] Development Blog [^]
|
|
|
|
|
i am using the Oracle database. i need to write the out put in oracle database
|
|
|
|
|
that's very easy when you know how to use the standard library... (i consider you're using pure standard C++)
ofstream MyFile("C:\\myDir\\myFile.txt");
MyFile << "Hello world !!!";
MyFile.close();
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
sir i don't know the proper use of VC++.
i am a oracle developer. can u kindly send me an example of the code to write the out put in text file. what steps i have to follow.
which header files i need to include in the file.
regards
toufiq
|
|
|
|
|
ok, i already provided you a sample but if you don't know where to start, do this :
#include <iostream>
void main(void) {
std::ofstream MyFile("C:\\myDir\\myFile.txt");
MyFile << "Hello world !!!" << '\n';
int i = 5+4;
MyFile << "i = " << i << endl;
MyFile.close();
}
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 8:36 Thursday 17th November, 2005
|
|
|
|