Caglar said:
I have been reading Ruminations on C++, a very interesting book. They
are going into handles. I think what they are doing is very intersting
and very confusing. I have to read each paragraph several times to
understand.
I would like to understnad hgandles and find good uses for them or
better understand how they can make my programs better.
Hello,
I think you are talking about handles in Windows
[snip]
the short version:
handles are "like pointers" to objects like a window, button or something
else.
you need them to modify for example the caption of a button or resize a
window.
We are off-topic here, nonetheless I'd like to add a remark:
Yes, in Windows a handle is something like a pointer, however there's
one
important difference:
In Windows a pointer refers to locked, unmovable (physical) memory,
a handle is a reference to memory managed by Windows which will move
the
real memory location if needed; you may consider a handle an index into
a lookup table that is managed by the OS (Windows).
That's why 2 group of functions are associated with handles:
the first one allows to lock and unlock the memory "behind" a handle,
something like (I don't remember the API exactly):
Window* lockWindow(HWND wnd);
the second ground copies the content of the handle's memory into a
local
variable (again it's too long ago I've been programming with Windows):
void getWindow(Window& dest, HWND wnd)
{
// pseudo implementation
Window* w = lockWindow(wnd);
dest = *w;
unlockWindow(wnd);
}
handles are a must for programming gui windows application,
because the Windows API was definded this way ...
so you should look for some tutorials using google.
BTW: also look at the memory allocation functions (other than new())
in the API, some of them return handles.
I hope you now understand it better
regards
Stephan Brönnimann
(e-mail address removed)
Open source rating and billing engine for communication networks.