Using Handles.

E

enki

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.
 
C

Caglar Cakan

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

I found a very good explenation in the web:

"Handles are numbers which identify objects used by the operating system.
Windows, controls and menu items all have handles. Many of the WinFun
functions require you to pass a handle as a parameter to identify the
object on which you want to operate.

Handles are usually obtained using one of the following functions:
rnFindWindowByName, rnFindWindowByClass, rnGetButtonHandle,
rnGetMainMenuHandle or rnGetSubMenuHandle. Or if you are using COOL:Gen
and the object you want to operate on is a window or control in the
current procedure, you can use the COOL:Gen built in function GetHandle.
Other application development tools also offer handles as window and
control properties."

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.

handles are a must for programming gui windows application, so you should
look
for some tutorials using google.

I hope you now understand it better

regards
 
?

=?iso-8859-1?q?Stephan_Br=F6nnimann?=

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.
 
H

Howard

Caglar Cakan said:
Hello,

I think you are talking about handles in Windows

I found a very good explenation in the web:

"Handles are numbers which identify objects used by the operating system.
Windows, controls and menu items all have handles. Many of the WinFun
functions require you to pass a handle as a parameter to identify the
object on which you want to operate.

That's fine if he's talking about Windows handles, although I see nothing in
the post to suggest that (not having read the book).

On the Mac (at least in the older operating systems), a handle was a pointer
to a pointer. Like the indexing/lookup system used in Windows, this allowed
the operating system to move the location of the memory, because the handle
pointed to a pointer which the OS could update when it relocated the memory
block.

But I think that "handle" also has a somewhat more generic meaning, meaning
an object which holds some form of reference or pointer to another object.
But without reading the book, I'd be hard-pressed explaining what the author
meant by any of it. :)

(As far as I know, "handle" isn't defined by the C++ language.)

-Howard
 
C

Chris Dearlove

Caglar Cakan ([email protected]) wrote:

: > I have been reading Ruminations on C++, a very interesting book. They
: > are going into handles.

: I think you are talking about handles in Windows

I don't, and I have read the book.
 
M

Mr. Blackwell

Caglar said:
I think you are talking about handles in Windows

No, the book is by Koenig/Moo before they completly changed their mind
and became STL devotees. IIRC, handles mean something similar to what
is nowadays toutet as smart pointers.
 
M

Mr. Blackwell

Mr. Blackwell said:
No, the book is by Koenig/Moo before they completly changed their mind
and became STL devotees. IIRC, handles mean something similar to what
is nowadays toutet as smart pointers.

After skimming the book again I must partly rectify my memory (I
remembered it as OO book in contrast to the later 'Accelerated C++'
which is a STL book). 'Ruminations on C++' already contains many STL
concepts. See also: http://homepages.kcbbs.gen.nz/nbree/ruminant.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top