|
First, if you're going to use a synhcronization object to
protect a flag, use the synchronization object as the flag.
i.e. Use an Event whose state is checked as a condition to exit
the thread. (better yet use two events.. one to signal work to
be done, the other to exit. wait (WaitForMultipleObjects) on both
and then react appropriately.. that way your work thread won't
waste cycles running through loops pointlessly.)
Second, yes. Even access to resources should be protected (generally)
since you want to ensure that the resource is not being modified while
you are reading it. (or whatever)
That said, some types of resources (small register-sized variables
generally) can be read/written without the need of a protecting
synchronization object. Check out the Interlocked_______ functions
in win32.
|
|
|
|
|
Thanks Scott
I am sorry for the anonymous that was an error.
Rui
|
|
|
|
|
Here's a code sample:
HANDLE hWorkToBeDone=CreateEvent(0,FALSE,FALSE,0);
HANDLE hTimeToQuit=CreateEvent(0,TRUE,FALSE,0);
HANDLE Waitables[]={hTimeToQuit,hWorkToBeDone};
for (DWORD W=~WAIT_OBJECT_0;W!=WAIT_OBJECT_0;)
{
switch (W=WaitForMultipleObjects(2,Waitables,FALSE,INFINITE))
{
case WAIT_FAILED:
break;
case WAIT_OBJECT_0:
break;
case WAIT_OBJECT_0+1:
;
break;
case WAIT_TIMEOUT:
default:
ASSERT(FALSE);
}
}
|
|
|
|
|
|
I have an animation control on a dialog box that displays an AVI file while some processing is taking place. I create the animation control and play it from my WM_INITDIALOG handler. However, sometimes I notice that the animation takes a second or two to start playing. Any suggestions on what I can do to make sure this animation comes up all the time?
Brigg Thorp
Software Engineer
Timex Corporation
|
|
|
|
|
Hmm, never used that control before.
Can you create the hosting dialog as a hidden
modeless dialog (some time before ever
needed) and just pop it up, disabling
the main window, when needed? (Call animation
control's Seek method when creating dialog,
and Play in you OnShowWindow handler)
That way, hopefully the animation is ready to
play when you need it.
|
|
|
|
|
Hello all,
This is a basic question in MFC, but for some odd reason I can't figure out how to do it. I want to be able to specify the size of the main window when it comes up, and would like to be able to save this information (via .ini file I suppose). I thought that by modifying the CreateStruct in the OnCreate or the OnPreCreate would handle this setting the initiail size of the main window, but it does not work. Any suggestions on how to do this, and could anyone point me in the right direction to "save" this window information so when it comes up again I can use the last position/size information.
Thank you in advance.
Dan
|
|
|
|
|
There are some articles on how to do this somewhere on this very site...
When I am king, you will be first against the wall.
|
|
|
|
|
|
add this in CMainFrame::OnCreate() :
SetWindowPos(NULL, 0,0, 600,350,SWP_NOZORDER|SWP_NOMOVE);
|
|
|
|
|
In addition to S.Rod.'s answer you can also use
MoveWindow(200,100,450,300,TRUE);
This will change the size and move it around the screen
Also,
GetClientRect(&rcClient); // get size of client area
m_cyClient = rcClient.bottom-rcClient.top; // only the 'y' length
Will get the size of the window.
To get the left and right sides you can rcClient.Right-rcClien.Right
Jeff Patterson
Programmers speak in Code.
www.anti-dmca.org
|
|
|
|
|
Hello all
I have a VC7 dialog based application.
Basically one dialog with
an edit box
IDC_EDIT
and 2 buttons
IDC_READ_MYFILE
IDC_CANCEL
when I press the IDC_READ_MYFILE button i want to open a standard File Open Dialog, managed by the message_map entry, something like this:
ON_BN_CLICKED(IDC_READ_MYFILE, OnReadMyfile)
...
void CMyAppDlg::OnReadMyfile()
{
// TODO: Add your control notification handler code here
static CString szFilter = "DXF Files (*.dxf)|*.dxf||";
CFileDialog fileDialog(TRUE, "dxf", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL );
if(fileDialog.DoModal() == IDOK)
{
CString sDXF_FileName;
sDXF_FileName = fileDialog.GetPathName();
... do some processing on this file
UpdateData(FALSE);
}
}
Tested under windows XP it *works fine* (opening the File Dialog and processing the selected file as needed) but under windows 98 it works but when pressing on the IDC_READ_MYFILE button nothing happens (the File Open dialog is not open) while the close button works and also the about message box works (called inside the dialog top left System menu)
By the way I have checked the resources IDs and there isn't any conflict
any help/tips will be greatly appreciated
thanks in advance!
best regards
|
|
|
|
|
This is an MFC7 bug I'm afraid. There is an MSDN article on this I think (you'll get the same problem on Win95 and older versions of NT4).
The fix is to pass zero as the last param, e.g.:
CFileDialog fileDialog(TRUE, "dxf", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL, 0);
When I am king, you will be first against the wall.
|
|
|
|
|
thank you very much!
i was getting crazy finding out which reasons could be causing that strange behaviour
best regards
|
|
|
|
|
Hi, i am making a MDI application and i am trying to add some splitters to it.
I want two splitters to divide the Frame/MDICLIENT window into tree panes/views and i want all views to show the same view-class.
Below is a clip of my code where i make the splitters :
if (!m_wndSplitter.CreateStatic(this,2,1))
{
TRACE(_T("failed to create the splitter"));
return FALSE;
}
if (!m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CAPecc2View),CSize(200, 200), pContext))
{
TRACE(_T("failed to create view in second pane"));
return FALSE;
}
// add the second splitter pane - which is a nested splitter with 2 rows
if (!m_wndSplitter2.CreateStatic(&m_wndSplitter,1,2))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
if (!m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CAPecc2View),CSize(200, 200), pContext))
{
TRACE(_T("failed to create view in second pane"));
return FALSE;
}
if (!m_wndSplitter2.CreateView(0,1,RUNTIME_CLASS(CAPecc2View),CSize(200, 200), pContext))
{
TRACE(_T("failed to create view in second pane"));
return FALSE;
}
the problem i get is an assert in the following code :
CAPecc2Doc* CAPecc2View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAPecc2Doc))); //NB, HERE is the problem???
return (CAPecc2Doc*)m_pDocument;
}
I did the same for a SDI application and i worked fine there, so i don't have a clue why it doesen't work for this application.
I hope there is someone who can help me, cause i am really stucked .
best regards
Bjørnar Skogseth
|
|
|
|
|
I'm not sure, maybe CDocument::AddView will help you. Try to add your views to document manually.
Dmitry Timin
|
|
|
|
|
Try this for a start: www.sockets.com
|
|
|
|
|
I need to use a CTreeCtrl in a CDialogBar window but
I have problems when I try to perform any operation
in the tree control. All operation fails so I have found
that the m_hWnd related to the TreeCtrl is 0x00000000.
Does someone knows which is the problem ??
Can the CTreeCtrl be used in a CDialogBar ??
|
|
|
|
|
Anthiny B. wrote:
Can the CTreeCtrl be used in a CDialogBar ??
Of course!
1) Check the block of code, which creates your TreeCtrl. What value is returned with Create function? What about GetLastError?
2) It may be a "race condition" - you might use a TreeCtrl when it has not been created yet. For example, it may be a WM_SIZE handler of your DialogBar
|
|
|
|
|
I don't create the TreeCtrl with the Create method !!!
I have created a class derived from CDialogBar and I manage
the TreeCtrl in that class using a CTreeCtrl member variable
created through Class Wizard. I'm sure to don't use that
variable before the window creation but I don not know how to
verify the creation of the Tree control !!!
|
|
|
|
|
Override OnCreate (+OnInitDialog for guarantee) in your DialogBar. Set breakpoints at end of functions. Make sure that your TreeCtrl has been created (m_hWnd!=NULL). Just in case try to use GetDlgItem to obtain CTreeCtrl* pointer and check its m_hWnd.
If ASSERT or exception raises earlier than you rich these breakpoints, you, it seems, have raise conditions
Show us a fragment of code which refuses to run
After all, try to rebuild all
|
|
|
|
|
I've got an EditView, and want to show Row/Col in the Status bar. I can get the Row, but Column isn't quite right.
int nCol = LOWORD(GetEditCtrl().CharFromPos(ptCaret))
- (GetEditCtrl().LineIndex(nRow-1));
This works until the caret isn't visible anymore. (ie. user scrolls right/left w/o updating caret pos.) When this happens I get some bogus value in the 65000 range.
Is their a better way to get this info?
BW
"I'm coming with you! I got you fired, it's the least I can do. Well, the least I could do is absolutely nothing, but I'll go you one better and come along!"
- Homer J. Simpson
|
|
|
|
|
Are you intend to show position of caret? For current position it will look like that
//for retrieve nCharPos use EM_GETSEL
nLine = SendMessage(xxx, EM_LINEFROMCHAR, nCharPos, 0);
nCol = nCharPos - SendMessage(xxxx, EM_LINEINDEX, -1, 0);
I don't remember whether respective wrapper functions exist in MFC therefore I wrote it in API
|
|
|
|
|
Iam writing a connection-oriented sockets to write a simple client/server application. The objective of is to develop a client which inputs a string, sends it to a server program, the server program calculates character statistics on the inputted text, sends these back to the client and the client displays these results.
I have the client, server ,threads protocol wirtten in java and its working fine but i have to convert that into C++.
I was just wondering how to you create sockets and threads in C++
|
|
|
|
|
I assume you are developing the application for Windows.
Consider Winsock. I recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.
For Windows multithreading applications, I recommend Programming Applications for Microsoft Windows by Jeffrey Richter.
Kuphryn
|
|
|
|
|