|
Manmohan29 wrote: doesnot compile
And what does the compiler say? Be specific.
To add to it,
Manmohan29 wrote: UINT ThreadFunc(LPVOID pParam)
{
MessageBox("Thread Started"); //----> BAD idea!
return 0;
}
void CAppDlg::OnButtonClkRunThread()
{
AfxBeginThread(ThreadFunc, this);
}
Because if your main thread becomes busy into something, the newly spawned thread as well would block for displaying the message. This is because you are using a function (MessageBox from MFC) that would make use of the default message pump of your application.
In other words, if you add a Sleep(3000); after AfxBeginThread, the message from your thread would probably be displayed after this sleep period only!
I see you're just starting to learn, but threading has such "gotchas", that you'll learn along the way. Lesson learned today: It isn't a great idea to use something within a worker thread, that may in turn use the default message pump of the application (in a blocking fashion).
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
NEW CODE :-
UINT CThreadDlg::ThreadFunc(LPVOID pParam)
{
return 0;
}
void CThreadDlg::OnBnClickedBthread()
{
// TODO: Add your control notification handler code here
AfxBeginThread(ThreadFunc, this);
}
ERROR :-
------ Build started: Project: Thread, Configuration: Debug Win32 ------
Compiling...
ThreadDlg.cpp
d:\manmohan\visual c++\thread\thread\threaddlg.cpp(162) : error C3867: 'CThreadDlg::ThreadFunc': function call missing argument list; use '&CThreadDlg::ThreadFunc' to create a pointer to member
Build log was saved at "file://d:\Manmohan\Visual C++\Thread\Thread\Debug\BuildLog.htm"
Thread - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Manmohan Bishnoi
|
|
|
|
|
Manmohan29 wrote: UINT CThreadDlg::ThreadFunc(LPVOID pParam) //---> Here is the problem!
{
return 0;
}
void CThreadDlg::OnBnClickedBthread()
{
// TODO: Add your control notification handler code here
AfxBeginThread(ThreadFunc, this);
}
The thread function should be a global function (not a member function of any class), or it must be a static member function of any class. Try this instead:
in your header file:
static UINT CThreadDlg::ThreadFunc(LPVOID pParam);
in the source file:
UINT CThreadDlg::ThreadFunc(LPVOID pParam){
OutputDebugString(_T("*********** Entered thread function ***********\n"));
return false;
}
Watch the output window of your debugger to see the text printed from your thread.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Manmohan29 wrote:
UINT CThreadDlg::ThreadFunc(LPVOID pParam)
This member has to be declared as 'static'.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
My previous answer to you is updated after you edited your post to include the code. Check it.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Thanks, It works great.
Manmohan Bishnoi
|
|
|
|
|
I am creating a static library.
In that i am linking to a third pary lib named xyz.lib.
LNK1241: resource file xyz.lib(abc.res) already specified
How to resolve this error?
|
|
|
|
|
KASR1 wrote: How to resolve this error?
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all..
i need a help regarding editbox in MFC....
i've been trying to make a simple exe for entering some text and then save it in a text format...
The string size for member variable which i've given is around 1000... after entering 255 characters the cursor moves to the top of edit box and allows to enter there until it completes 1000 characters.. but then iam not able to select using cursor.. it jumps automatically to the start position...
iam very new to VC++ .. plz help out to solve this pblm..
thanks is advance.....
|
|
|
|
|
sonualex wrote: plz help out to solve this pblm..
This is not default behavior, so whatever code you've added for setting the cursor position within the edit control needs to be removed/changed.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanku so much David for the response..
actually i havnt written any code for edit box because all the data entered in edit box are assigned to the memeber variable of string type via class wizards..
so i dnt knw what to add for setting cursor and where..
Iam saving my data to a text file after also...
|
|
|
|
|
sonualex wrote: ...all the data entered in edit box are assigned to the memeber variable of string type via class wizards..
Use a CEdit member variable instead.
sonualex wrote: so i dnt knw what to add for setting cursor and where..
Your requirements do not indicate a need to set the cursor.
All you need to do is call m_edit.SetLimitText(1000) in the dialog's OnInitDialog() method. When you are ready to get the text to write to the file, just call m_edit.GetWindowText() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks again david..
lemme make it some more clear now.. i have already assigned the member variable to CString and iam appending the text to another CString...
i tried ur method but den realised the above mentioned pblm.. how can i solve that....
iam putting my piece of code for saving the text here.. plz do check...
void CNoteDlg::OnSave()
{
UpdateData(TRUE);
static char BASED_CODE szFilter[] = "Text files (*.txt)|*.txt||";
char nextline[3];
nextline[0] = 0x0D;
nextline[1] = 0x0A;
nextline[2] = 00;
CString S1;
CFile flEdit;
CFileDialog FileDlg(FALSE, ".txt","Prioritynotes",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
if( FileDlg.DoModal() == IDOK )
{
if( flEdit.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite) == FALSE )
return;
S1 += "Critical****";
S1 += nextline;
S1 += "--------------------------";
S1 += nextline;
S1 += m_sedit1;
S1 += nextline;
S1 += nextline;
S1 += "Important***";
S1 += nextline;
S1 += "--------------------------";
S1 += nextline;
S1 += m_sedit2;
S1 += nextline;
S1 += nextline;
S1 += "Less Important**";
S1 += nextline;
S1 += "--------------------------";
S1 += nextline;
S1 += m_sedit3;
S1 += nextline;
S1 += nextline;
S1 += "Normal*";
S1 += nextline;
S1 += "--------------------------";
S1 += nextline;
S1 += m_sedit4;
S1 += nextline;
flEdit.Write(S1.GetBuffer(S1.GetLength()), S1.GetLength());
flEdit.Close();
}
else
return;
}
|
|
|
|
|
sonualex wrote: i tried ur method but den realised the above mentioned pblm.. how can i solve that....
What problem?
sonualex wrote: CFile flEdit;
Should you be using CStdioFile instead?
sonualex wrote: flEdit.Write(S1.GetBuffer(S1.GetLength()), S1.GetLength());
What's wrong with just:
flEdit.Write(S1, S1.GetLength()); sonualex wrote: else
return;
Unnecessary.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hii david...
how can i assign the CEdit m_edit variable with the string which we add in edit box ??
With the previous code how can i modify and make it work....
|
|
|
|
|
sonualex wrote: how can i assign the CEdit m_edit variable with the string which we add in edit box ??
SetWindowText() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hi david..
i tried with SetWindowText too.. but i cant find any change ...
can u plz mention where exaclty i have to add these changes for making this work..
anythng to be changed in class wizards ?
thanku so much
|
|
|
|
|
sonualex wrote: can u plz mention where exaclty i have to add these changes for making this work..
You call SetWindowText() wherever you want the contents of the edit control changed.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks david for ur help...
SetLimitText is giving an assertion failure once i keep it in OnInitDialog()...
SetWindowText and GetwindowText as per my understanding should be kept where we change the text in edit box.. as i told earlier i have not created any function for editbox...
my understanding is the text we enter in editbox is
m_sedit1 = _T("") which is in
CNoteDlg::CNoteDlg(CWnd* pParent /*=NULL*/): CDialog(CNoteDlg::IDD, pParent)
and the ::DoDataExchange(pDx)
DDV_MaxChars(pDX, m_sedit1, 1000);
plz letme knw if im not giving u the correct picture of my code...
hope u wud continue helping me..
thanku so much
|
|
|
|
|
sonualex wrote: SetLimitText is giving an assertion failure once i keep it in OnInitDialog()...
What does the suspect code look like?
sonualex wrote: SetWindowText and GetwindowText as per my understanding should be kept where we change the text in edit box.. as i told earlier i have not created any function for editbox...
I'm not sure what a "function for editbox" is.
sonualex wrote: my understanding is the text we enter in editbox is
m_sedit1 = _T("") which is in
I indicated here that you should use a CEdit object instead.
sonualex wrote: plz letme knw if im not giving u the correct picture of my code...
I know exactly what you are doing, but you have to be willing to implement my suggestions.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi david ...
Iam following ur suggestions truely...thanku so much for ur patience...
Asserion faliure is showing in AFXWIN2.lnl line 881....
Dont know how to solve that...
OnInitDialog is not allowing to keep CEdit m_edit1;
m_edit1.SetLimitText (1000); in it....
What i meant by function is if we click on EN_CHANGE it will ask for add function OnChangeEdit1()..
Presently iam stuck with CEdit SetlimitText,SetWindowText and GetWindowText..
plz bear with me
|
|
|
|
|
sonualex wrote: Iam following ur suggestions truely...thanku so much for ur patience...
Asserion faliure is showing in AFXWIN2.lnl line 881....
Dont know how to solve that...
You should start by looking at line #881 of afxwin2.inl. It is asserting that a valid window handle exists, which obviously does not.
sonualex wrote: OnInitDialog is not allowing to keep CEdit m_edit1;
Are you declaring this variable in OnInitDialog() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hello david .. im in right track now.. thanks for ur immense support..
now im able to limit the text.. cursor pblm is solved..
but at the same time.. i have been using CString for saving and opening the contents in edit box now how can i do that using CEdit..
hope u remembr my piece of code for OnSave and OnOpen earlier posted ....
|
|
|
|
|
sonualex wrote: ...i have been using CString for saving and opening the contents in edit box now how can i do that using CEdit.
By using SetWindowText() and GetWindowText() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks a lot David... it worked perfectly...
thanku so much...
|
|
|
|