|
What is the best threadsafe way to get a pointer to an MFC control on a form. I have been trying to use GetDlgItem() and it has not been working. It crashes when it calls isWindow ir something like that. BTW if I call GetDlgItem() from with in the formview class it works fine. I am using MFC7. Thanks.
Steve
|
|
|
|
|
You may be trying to use the returned CWnd pointer before the CWnd has had a chance to Create() itself. This is a common problem when you attempt to access a control using GetDlgItem() in a modeless dialog's OnInitDlg().
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
That is not the case here. The control has definetly been created.
|
|
|
|
|
Maybe I'm misunderstanding you. If you're trying to get at the control from OUTSIDE the formview, you need to call GetDlgItemu() on the formview. For example:
CFormView* pFormView = ...;
CWnd* pCtrl = pFormView->GetDlgItem (IDC_foo);
ASSERT (pCtrl != NULL);
pCtrl->Mumble();
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I'm not sure if there is abest threadsafe way. I never been able to get a pointer to a MFC control like that. Maybe someone can give us more info on that.
You can pass what you need to a function within your formview and let that function call GetDlgItem then update the DlgItem with that information; I'v done this sometimes with int or CStrings. Or make the class that your calling GetDlgItem() from a friend of the formview.
Jay
|
|
|
|
|
GetDlgItem() which returns a CWnd* pointer is an override of the API call
::GetDlgItem(HWND hwnd, UINT control_id) ;
For it to work, you need to have the handle (HWND) of the controls parent window (after all, your getting a dialog item).
It would work for a formview as it is the parent window. If you need to do it from some place else, you would need to get a pointer to the formview first. Something like:
POSITION pos = pDoc->GetFirstViewPosition() ;
CView* pView = pDoc->GetNextView(pos) ;
pView->GetDlgItem(control_id)....
If you were doing this from a worker thread, i have in the past, given it a pointer to the doc whos data it works on, and from there get a pointer to the view (as above) when I needed to update a control. I haven't paid any particular attention to how thread safe it is, but have yet to encounter any problems in this regard.
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
|
|
|
|
|
I'm afraid CWnd pointers - as returned by GetDlgItem() - are not thread safe, and cannot therefore be passed across thread boundaries.
Fortunately, the HWND to which the CWnd object is attached can.
What you will probably have to do is use the Platform SDK version of GetDlgItem() to give you the HWND or the control you're interested in, then create a local CWnd object in the thread you need to use it, and call CWnd::Attach() to associate it with the HWND .
Good luck
Andy Metcalfe - Sonardyne International Ltd
Trouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++
"I would be careful in separating your wierdness, a good quirky weirdness, from the disturbed wierdness of people who take pleasure from PVC sheep with fruit repositories."
- Paul Watson
|
|
|
|
|
Hi every body, I have a program that gets the data from a SQL server, the problem is how can I make a report for any queury or table to print it or view it.
the another thing is : how can i make a setup file for my program?
Best Regards
|
|
|
|
|
http://www.codeproject.com/database/dynamic_odbc_class.asp
would be one way to do this..
hope this helps
bernhard
Sometimes I think the surest sign for intelligent life elsewhere in
the universe is that none of them ever tried to contact us.
|
|
|
|
|
thank u , can I use Crystal Report with VC++?
Best Regards
|
|
|
|
|
crystal what???
i never used it.. i don't even know what this should be..
sorry guy (or girl.. i don't know what sex drawil is)
bernhard
(if you should use ado.. there is a similar tutorial in the ado section)
Sometimes I think the surest sign for intelligent life elsewhere in
the universe is that none of them ever tried to contact us.
|
|
|
|
|
Hi
I'm just wondering whether it is possible to draw both bold and regular text in a CToolTipCtrl.
I want to display a tooltip which looks like this:
----------------
| Button text | <- bold
| |
| some text | <- regular
----------------
how can I do this?
thanks in advance
modified 12-Sep-18 21:01pm.
|
|
|
|
|
int n;
CDatabase db;
db.OpenEx("DRIVER={SQL Server};Server=(local);DATABASE=database1;UID=sa;PWD=123;");
CRecordset rs(&db);
rs.Open(AFX_DB_USE_DEFAULT_TYPE, "select * From table1 where field1="+n+""); //this line error, why?
rs.Close();
db.Close();
//where filed1=variable, how to do that?
//field1 is int type.
|
|
|
|
|
what is the error? this script could crask if your connection string is bad or if your sql is bad.
the error will clarify this.
You should change this: "select * From table1 where field1="+n+""
to
CString Temp;
Temp.Format("select * From table1 where field1='%s'", n);
rs.Open(AFX_DB_USE_DEFAULT_TYPE, Temp);
this assumes n is a string, though. If it is a number (int), change it to
Temp.Format("select * From table1 where field1=%d", n);
If n is a string, dont forget to escape all single quotes (') to double single quotes (''). This prevents errors and expoits.
// Rock
|
|
|
|
|
I have an app that has a rebar with two toolbars in it. However there is a 3D line separating the two bars and i wish them to be seamless. Any ideas?
.NET or not .NET? MFC is the question......
|
|
|
|
|
Hello,
Wondering if anyone out there has run into this before.
I'm extracting a string from a file and it HAS to have the quote in the string too. I'm adding two strings together that I have extracted from a file to get the string I need to look up.
CString id;
CString str;
str.Format("a string plus "%s"", id);
Question is how can I keep the qoutes within the string itself? Thanks in advance.
Signatures wanted for 5000 rupees each!
|
|
|
|
|
Think I figured it out. lol
CString id;
CString str;
str.Format("a string plus \"%s\"", id);
Is that correct?
Signatures wanted for 5000 rupees each!
|
|
|
|
|
Ys, it's correct
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi there,
I have written a little package viewer/builder program to extract files from the file to any directory as well as add new files to the package.
Now it was no big problem to implement drag'n'drop functionality, so that you can add files via dragging file(s) from an Explorer window INTO the program.
However I am having big problems to implement the other way round, so that you can drag a file out of a program into an Explorer window.
Does anyone have some experiences with this and maybe can provide a little example code? If its of any importance, the program itself displays the files in a standard CListView. Oh and I am not interested in d+d operations INSIDE the program, only from Program->Explorer.
Thanks in advance for any response...
|
|
|
|
|
|
I am trying to send a file over a CAsyncSocket and for this i read the file from a CFile into a BYTE or a char. I tried writing the buffer back to a file and this worked for a char as well as a BYTE. But when i tried to send over the connection (the data gets segmented into packets) i needed to stick all the packets together. Now, i didn't know how to do this with a BYTE, so there's my first question, whats the equivalent of strcat() with a BYTE?? Cause i also tried to do this with a char and i used strcat() but it only got to the three first characters or so (might this have anything to do with when u open a binary (i used an .exe) in notepad u get to see empty spaces in some places and that strcat doesn't work with this??)
Again, if someone already knows how to send files over a tcp connection(with or without MFC) please let me know.
thanks
Kuniva
--------------------------------------------
God gave man a penis and a brain but not enough blood to make both of 'em work at the same time.
|
|
|
|
|
|
Hi everyone. I originally was developing a program on a Win95 (osr2) machine, and the code below originally worked fine to write a value to the registry. I think switched to developing on a Win2000 machine, and found something odd. The code below did write to the registry fine, and I verified this with regedit, but after I reboot the machine, whatever I wrote to the registry was gone. I traced through my program many times, and I was not at any point in code erasing what was written. When I first started the program, the registry data was re-written to the registry and was read out successfully when the program was run a second time. But for some reason, whenever I rebooted the machine, the data was gone. I verified this using regedit, and ran this test several times. The reboot caused the data to be erased. This does not happen to any apps I have purchased, so I assume it is my code.
And, is limited to Win2000/NT? It did work on my Win95 development machine, as well as a friend's Win98 machine, as a release build; that is, all data was written to the registry, and was still there after reboot, and was read out succesfully every time.
This code writes to the usual hkey_current_user/software folder in the registry.
The code below writes a string the registry, which is the only data type I am writing to the registry.
<br />
long CRegKey::Write(LPCTSTR pszKey, LPCTSTR pszData)<br />
{<br />
ASSERT(m_hKey);
ASSERT(pszKey);<br />
ASSERT(pszData);<br />
ASSERT(AfxIsValidAddress(pszData, strlen(pszData), FALSE));<br />
<br />
return RegSetValueEx(m_hKey, pszKey, 0L, REG_SZ, (CONST BYTE*) pszData, strlen(pszData)+1);<br />
}<br />
|
|
|
|
|
Sounds like the key is being created with the REG_OPTION_VOLATILE option. Change that to REG_OPTION_NON_VOLATILE.
--Mike--
"Why you keep calling me Jesús? I look Puerto Rican to you?"
-- Samuel L. Jackson in Die Hard 3
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
ok, i'm really new to c++
can someone help me ?!
i made a button and i want it to run a file.
how can i do ??
thanks in advance
|
|
|
|