|
Viorel. wrote: The ms_instances array contains pointers to Ball objects
What happens when j = 0;
Ball * const ball = ms_instance[0];
Does this mean it has no pointers because ms_instance[0] ?
Do you need atleast j = 1 to create a pointer ........ like ms_instance[1] means 1 pointer
.... ms_instance[2] means array of two pointers......... so what does 0 mean?
ball->m_stateTimeInterval = timeInterval;
--------------------------------------------------------------------------------------------
So for each j value, there will be an array of pointers created?
|
|
|
|
|
Jay03 wrote: Ball * const ball = ms_instance[0];
Arrays in C/C++ are 0-based. This line will access the first element in the ms_instance array and cast it to a pointer-to-a-Ball.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
ms_instances is apparently an array of pointers to instances of some kind of object.
this code gets element 'j' (a pointer) out of the array, then casts that pointer to a pointer-to-a-Ball: "compiler, treat this pointer as if it was a pointer to a Ball, instead of a pointer to whatever it is actually pointing at. then it dereferences the pointer and sets the m_state* member variable of what we all hope is an actual Ball object.
|
|
|
|
|
It is nothing more than the equivalent of doing the following:
for (unsigned int j = 0; j < ms_numInstances; j++)
{
Ball* pBall = (Ball*)ms_instances[j];
pBall->m_stateTimeInterval = timeInterval;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I'm using the web browser active-x control in an MFC application to browse some web sites. If I need to click links within this site however, sometimes it opens up a new IE window. I need it to always open up within the same window. In other words always target _SELF.
I tried looking through MSDN and other sites, but everything is always so cryptic and the examples are scarce.
Write now I call Browser.Navigate(myURL,NULL,NULL,NULL,NULL); to open a site. The 2nd NULL is supposed to be for the target name. I have yet to see an example where these 4 NULL's are actually set to anything else.
Can anyone shed some light as to how to do what I am trying to do.
Thanks in advance!!
|
|
|
|
|
univega_r304 wrote: Write now I call Browser.Navigate(myURL,NULL,NULL,NULL,NULL); to open a site. The 2nd NULL is supposed to be for the target name.
So have you tried "_SELF" as the second parameter?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
If it were only that easy... That's the very first thing I did...
Here's what I got:
error C2664: 'CExplorer::Navigate' : cannot convert parameter 3 from 'const char [6]' to 'VARIANT *'
|
|
|
|
|
How about:
VARIANT vTarget;
vTarget.vt = VT_BYREF|VT_I1;
vTarget.pcVal = ("_SELF");
m_ctrlBrowser.Navigate(..., &vTarget, ...);
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Ok, that compiled. However my original problem still exists. When I navigate to the page and click a link within, it still opens a new IE window. Something tells me I have to intercept it with NewWindow2(), but when I tried setting up that event, nothing happened. I do have OnNavigateComplete and OnBeforeNavigate2 working, but when I tried adding OnNewWindow2 to the list of events, nothing happens when it spawns a new window.
Any other suggestions?? Much appreciated!
|
|
|
|
|
univega_r304 wrote: Something tells me I have to intercept it with NewWindow2(), but when I tried setting up that event, nothing happened.
I got notified with:
BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
ON_EVENT(CMyDlg, IDC_EXPLORER, 251 , OnNewWindow, VTS_DISPATCH VTS_PBOOL)
END_EVENTSINK_MAP()
void CMyDlg::OnNewWindow(LPDISPATCH pDisp, BOOL FAR* URL)
{
TRACE("New window opening\n");
}
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
OK, I got that to work too...
When I originally tried the event I used the number 254 vs 251 like you have. Being new to this, is there any documentation that shows how you came up with that number.
Anyhow, so now I added a line to your code:
void CMyDlg::OnNewWindow(LPDISPATCH pDisp, BOOL FAR* URL)
{
TRACE("New window no longer opening\n");
*URL = TRUE;
}
(that should probably have been named CANCEL but I stuck with what you had)
That no longer spawns a new IE window, but it's also preventing it from opening up at all *sigh*.
Now if I can only get the link to target my window I'll be set...
|
|
|
|
|
univega_r304 wrote: ...is there any documentation that shows how you came up with that number.
Look in afxhtml.h .
univega_r304 wrote: (that should probably have been named CANCEL but I stuck with what you had)
The old copy-and-paste bug is to blame!
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks
Just one more step and I'm done!
Obviously now that I can cancel it from spawning a new window, I need to still be able to open it within the same window. get_locationURL isn't going to work obviously since it can't establish the new URL yet. Do you know how to extract the URL from the link you click on so I can call it in a new Navigate() command?
|
|
|
|
|
univega_r304 wrote: Do you know how to extract the URL from the link you click on...
Wouldn't that be the BeforeNavigate2 event?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
If it is, I'm not able to get the URL the link is pointing to. It's probably something that would still be handled by NewWindow... My guess is there's a few more parameters available, one of which would contain the URL to the link. Then I could simply navigate to it after the *Cancel = TRUE; command is processed.
I've been looking at KB Article Q185538 which is basically ideal for this situation, but the sample is in VB. I'm sure it must be related somehow but I haven't got it to work yet.
|
|
|
|
|
univega_r304 wrote: If it is, I'm not able to get the URL the link is pointing to. It's probably something that would still be handled by NewWindow... My guess is there's a few more parameters available, one of which would contain the URL to the link.
Do you have:
BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
ON_EVENT(CMyDlg, IDC_EXPLORER, 250 , OnBeforeNavigate,
VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
END_EVENTSINK_MAP()
void CMyDlg::OnBeforeNavigate(LPDISPATCH pDisp, VARIANT *URL, VARIANT *Flags, VARIANT *Target,
VARIANT *PostData, VARIANT *Headers, BOOL *Cancel )
{
ASSERT(V_VT(URL) == VT_BSTR);
TRACE("Before navigating to %S\n", V_BSTR(URL));
}
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
If I put *Cancel = TRUE; in NewWindow to prevent it spawning a new window then BeforeNavigate never gets called. It works for anything that doesn't spawn, however. Any other ideas? I can't imagine why something like this would be so difficult. It'd make a useful article if we can get it working....
|
|
|
|
|
univega_r304 wrote: If I put *Cancel = TRUE; in NewWindow to prevent it spawning a new window then BeforeNavigate never gets called. It works for anything that doesn't spawn, however.
I would think that would be the case (i.e., BeforeNavigate() getting called) no matter what NewWindow() did to Cancel since BeforeNavigate() would not know about the new window.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Take a look at http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/dwebbrowserevents2/newwindow3.asp
NewWindow3 may be the better way to go?
|
|
|
|
|
I have a toolbar that when it is floating I can resize ( manually ).
The toolbar contains a combobox, a couple of static (CStatic derived ) controls and some normal standard buttons.
something like drawn in lousy ascii art, where | is the gripper and - is a separator.
<code>|</code>combobox static1 static2 <code>-</code> button1 <code>-</code> button2 <code>-</code> button3 <code>-</code> button4
after I resize I get something like :
<code>|</code>combobox static1
static2 <code>-</code> button1 <code>-</code> button2 <code>-</code> button3 <code>-</code> button4
if I resize further ( including some blank space beforre static2):
<code>|</code>combobox static1
static2 <code>-</code>
button1 <code>-</code> button2 <code>-</code> button3 <code>-</code> button4
It seems that there is no "break" between the combobox and the static1 controls.
What is the mechanism that controls that breaks in the toolbar ? is it the separator ?
I'm not certain what to google for to get an explanation.
Thanks for the help.
Max.
|
|
|
|
|
Hi all,
OK, this is my first multi-threaded program ever. It's more a proof of concept rather than anything really useful. The main problem is that it's not working as I intended.
Overwiev:
An m*n array (double**) is filled with random numbers from -5 to 5. After that a thread gets created for each row of the array (i.e. we know that exactly m threads will be created). That thread will add all entries in that row, write the result to a particular memory location (double *result), decremnt the threadcount and exit.
Problem:
I want main() to create m-threads and then wait until the last thread exits. Then main is supposed to print the result to the screen and exit. So far I can't get main to wait on the threads. It continues execution despite my best efforts.
The code:
See below. It compiles on Microsofts Visual C++ 6.0. I have a lot of
#ifdef Mutex2... in there 'cos I want it to port it to Unix as well. Any hints in that direction are very much appreciated.
Thanks much
Mike
/////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#include <process.h>
#endif
#ifdef SOLARIS
// ?????? POSIX threads maybe?
#endif
//////// definitions ///////////
#ifdef WIN32
#define MUTEX1 1
#define MUTEX2 0
#endif
#ifdef SOLARIS
#define MUTEX1 0
#define MUTEX2 1
#endif
//////// data struct ///////////
struct data{
int size;
int id;
double *row;
double *result;
};
//////// globals ///////////////
int threadcount;
#if MUTEX1
HANDLE hMutex;
HANDLE doneMutex;
#endif
#if MUTEX2
#endif
//////// functions /////////////
void sum(void*);
////////////////////////////////
int main(int argc, char *argv[])
{
if(argc != 3){
printf("useage: <exe> <# of rows > 0> <#of columns > 0>\n");
exit(0);
}
int i,j;
int row = atoi(argv[1]);
int col = atoi(argv[2]);
double **arr = NULL;
double *result;
struct data *list;
struct data *ptrlist;
#if MUTEX1
hMutex = CreateMutex(NULL, false, NULL);
doneMutex = CreateMutex(NULL, true, NULL);
#endif
#if MUTEX2
#endif
list = new data[row];
arr = new double*[row];
for(i = 0; i < row; i++){
arr[i] = new double[col];
}
result = new double[row];
for(i = 0; i < row; i++){
for(j = 0; j < col; j++){
arr[i][j] = -5 + rand() % 11;
}
}
list->size = col;
for(i = 0; i < row; i++){
result[i] = -99;
}
threadcount = row;
#if MUTEX1
WaitForSingleObject( doneMutex, INFINITE );
// I was hoping that main() would suspend execution when it hits the 2nd WaitForSingleObject( doneMutex, INFINITE )
// a few lines further down. It doesn't. Why?
#endif
#if MUTEX2
#endif
///////////////////////////
for(i = 0; i < row; i++){
list[i].size = col;
list[i].id = i;
list[i].row = arr[i];
list[i].result = result;
ptrlist = list+i;
#if MUTEX1
_beginthread(sum, 0, (void*)ptrlist);
#endif
#if MUTEX2
#endif
}
#if MUTEX1
WaitForSingleObject( doneMutex, INFINITE );
// I was hoping to lock the doneMutex and have the last thread (i.e. threadcount == 0) unlock it.
// ...that strategy doesn't do the job. main() does not wait until the last thread releases this mutex. Why?
#endif
#if MUTEX2
#endif
// This while-loop should never execute IF main() would wait for the doneMutex to be released by the last thread upon exit.
// Sadly it doesn't care.
while(threadcount > 0){
// while this appears to work, I really want main to wait until the last thread exits.
printf("threadcount = %i\n", threadcount);
}
for(i = 0; i < row; i++){
printf("%i. %f\n", i, result[i]);
}
#if MUTEX1
ReleaseMutex( doneMutex );
#endif
#if MUTEX2
#endif
for(i = 0; i < row; i++){
delete [] arr[i];
}
delete [] arr;
delete [] result;
delete [] list;
return(1);
}
//****************************************
void sum(void *arg)
{
double sum = 0;
int i;
struct data *list = (struct data*)arg;
for(i = 0; i < list->size; i++){
sum += list->row[i];
}
list->result[list->id] = sum;
#if MUTEX1
WaitForSingleObject( hMutex, INFINITE );
#endif
#if MUTEX2
#endif
threadcount--;
printf("ID = %i sum = %f\n", list->id, sum);
if(threadcount == 0){
ReleaseMutex( doneMutex );
// Here I figured the last thread exits and releases the Mutex for main().
// Anyway, main() dosn't appear to wait on this Mutex, it continues execution regardless
}
#if MUTEX1
ReleaseMutex( hMutex );
_endthread();
#endif
#if MUTEX2
#endif
}
//****************************************
|
|
|
|
|
so, it doesn't even stop at the first WaitForSingleObject(doneMutex,..) ?
|
|
|
|
|
Should it wait at the first WaitForSingleObject( doneMutex, INFINITE )?
I intended for main() to lock the mutex at the first call. Then create all threads and have the last thread release it. The 2nd WaitForSingleObject( doneMutex... is where main() is supposed to wait on the last thread to exit.
Obviously I am not doing it right, I am open to suggestions. I also tried semaphores, same problem.
|
|
|
|
|
you could try Events.
1. create an Event object (just like creating a Mutex) in your main
2. launch your threads
3. WaitForSingleEvent on the Event in main()
4. SetEvent from the worker thread, when done. that will let your Wait* return.
5. CloseHandle to clean up the Event
|
|
|
|
|
You might have better luck using WaitForMultipleObjects (MSDN). Make an array of your thread handles and pass that into WaitForMultipleObjects with the bWaitAll parameter set to TRUE.
That will be cleaner and much easier to debug than working with a Mutex in this case.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|