Hottest Forum Q&A on CodeGuru for the Week of April 18th, 2004


Lots of hot topics are covered in the Discussion Forums on CodeGuru. If you missed the forums this week, you missed some interesting ways to solve a problem. Some of the hot topics this week include:

What is the difference between ASSERT and VERIFY? (top)  


MikeB, a senior member of CodeGuru, needs to know the difference between ASSERT and VERIFY.

What is the difference between VERIFY and ASSERT?
Which should I use, and why not the other?

The ASSERT expression is used only in the debug version of your application. It does not work in release mode. The VERIFY expression can be used in both modes, but it does not check the result in release mode. Let's consider the following example:

ASSERT(pPointer = pPassedPointer);

Here, we are checking pPointer to determine whether or not it is non-zero. For debug builds, this will be work, but in release mode, the pPointer = pPassedPointer is not compiled at all. So, further down in your code if you have something relying on pPointer, you see that it is not valid because the statement within ASSERT did not get executed because it was not even a statement during compile time. Thanks to Kirants, who supplied the great reply.

Besides that, you should look at the following articles:

How do I implement a popup menu that opens on a mousemove when the cursor is on a specific region of a client window? (top)  


Emster needs to implement the following:

I am trying to implement a popup menu that opens on a
mousemove message rather than a right mouse click. When the
cursor is in a particular region of the client window, the
popup menu should be displayed. If the mouse moves to a
different region, the original popup menu should 'disappear'
and a modified menu should appear that is specific to that region.

I am finding this quite difficult to get working. Does anyone
have any ideas for me? This has been my approach so far:

In the OnMouseMove handler, I check the cursor coordinates and
create/load the popup menu specific to the region. Because I am
using TrackPopupMenu to display the popup menu, no other mouse
move messages were getting through until I closed that menu or
select an item from it.

My attempt at a solution (after searching on CodeGuru) was to use
a thread specific hook to catch the mousemove message. To do this,
I used:
SetWindowsHookEx(WH_MOUSE, MouseHook, NULL, GetCurrentThreadId());
The MouseHook function is declared as:
LRESULT CALLBACK MouseHook(int nCode, WPARAM wParam,
                           LPARAM lParam)
In this function I check if it is a mousemove message and then
call the same code to check the region and create a new popup menu.

My problem is that the popup menu will display the first time and then
will remain on the screen until I close it or select an item from it.
If I step into the code, the MouseHook function is being called and
sometimes fires the code to create a new menu, but it doesn't seem to
work. I am not sure if my problem lies in how I am implementing the
creation of the menu or how I am trying to create and use the windows

Sorry for the lengthy explanation, but can anyone shed some light on
this problem? Or perhaps suggest a better way to achieve the same

Well, the problem is that you need to dismiss the first open menu before you can pop up the next one. There are different ways to dismiss the menu:

Now, are you wondering whether or not this worked? Take a look at the thread and you will know the answer.

Can I use WaitForSingleObject on windows rather than processes? (top)  


drm15 wants to use WaitForSingleObject on Windows. Do you know whether or not that is possible?

Does anyone know if you can use WaitForSingleObject on a window?
I have a handle to the window (HWND) and I want to know when the
user closes the window. WaitForSingleObject seems to only work on
processes and not on windows.

The only solution if you only have a window handle would be to use GetWindowThreadProcessId. This will get the thread identifier and process identifier. After that, you can use the retrieved value to terminate the process. Something like this:

DWORD dwProcessID = 0;
DWORD dwThreadID = ::GetWindowThreadProcessId(hWnd, &dwProcessID);
if(0 != dwThreadID)
   HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, NULL, dwProcessID);
   if(NULL != hProcess)
      ::TerminateProcess(hProcess, 0);

Why does this constructor-usage not compile? (top)  


highhead is working on a simple structure, but unfortunaly it does not work correctly. Please take a look.

Assume a simple class like this (string-header has been included
and "using namespace std" has been used):
class someclass
      string m_string;

      someclass(string& str){m_string = str;}
now I want to use this class in a programm like this:
someclass* cinst = new someclass(string("test"));
But, this doesn't compile without error. Have you got any idea why?
The compiler-error occures at the line in the program where I want
to instantiate "someclass."

If I use the following everything works fine:
string str       = "test";
someclass* cinst = new someclass(str);

The above code compiles without any error on VC6, but gives an error on Borland and Comeau. So what can be the problem? The problem is that your constructor (string &str) would take a reference of a non-constant temporary and hence it's disallowed. You don't use that reference later, but it's still wrong. Change the your constructor to the following and it should work:

someclass(const string& str){m_string = str;}

As a side note: You should not specify using namespace std in the header file. Thanks to YvesM for his support.

About the Author

Sonu Kapoor

Sonu Kapoor is an ASP.NET MVP and MCAD. He is the owner of the popular .net website DotNetSlackers publishs the latest .net news and articles - it contains forums and blogs as well. His blog can be seen at:


  • how to create a form dynamically

    Posted by raviraj on 04/27/2004 10:51am


    • Re:

      Posted by Sonu Kapoor on 04/28/2004 04:54pm

      What do you mean ? sonu

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Protect Your Business against Today's Rapidly Growing Threats Your business, employees, partners, and customers are depending more and more on network connectivity, and protecting data and infrastructure has moved to the top of the IT agenda. You can't arm yourself against today's rapidly increasing threats unless you understand how they work. Read this ebook to learn more about the top 10 DNS attacks that can target your external and internal DNS infrastructure, the impact they can have on the DNS server …

  • Today's enterprise datacenter can be one of the most complex business environments with dozens (for smaller business), hundreds (for larger and midsize business), even thousands (for hyperscale businesses) of servers that must be managed and monitored. At this level, just managing the cords can be challenging — let alone keeping up with the growing need for more agility and scalability within the datacenter. Simply put, companies are aggressively looking for less complexity and more agility from their …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date