News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help on basic win32 programming

Started by Technomancer, April 14, 2006, 12:21:08 PM

Previous topic - Next topic

Technomancer

I am just starting to pick up win32 programming.

This is how a basic messagebox looks like

invoke MessageBox, NULL, ADDR MsgText, ADDR MsgTitle, MB_OK


The last parameter pushed before the call to messagebox is supposed to be "Handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window."

Can anyone explains to me what handle means basically? In this case, is it supposed to be an address or something?
Can someone provide to me an example code (in masm) what it looks like if i dont use NULL as the parameter.

Thank you for your time.

hutch--

Hi techno,

Welcome on board. A handle is just a unique ID and with a function like MessageBox, the handle is usually the parent window that calls the message box. When you use handle "0" it defaults to the desktop which in effect means it has no parent.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Technomancer

Thanks hutch for the help.

A handle is a unique ID? Can you show me some code examples where the handle is not 0 / NULL. All the messagebox examples i have seen so far uses NULL for its handle. Much thanks.

Mark Jones

#3
Hello Technomancer. A handle is simply a DWORD or four bytes. It can be any value. You get a handle by querying a window (or control, file, device etc) for a handle value. Here's an example of how a window handle is obtained:


MyProc PROC  uses esi  hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    mov eax,hWin
    mov MyWindowHandle,eax
    ...
MyProc ENDP


Now MyWindowHandle contains the proper value (handle) of the MyProc window. When you plug MyWindowHandle into MessageBox, the messagebox becomes a "child" of MyWindowHandle. With a NULL it has no parent so is treated like a separate program window.

Some handles must be freed, like GlobalAlloc. These are different in that the "handle" returned is actually a pointer to the reserved memory location. Here's one way to allocate and free 256kB of RAM:


    invoke GlobalAlloc,GPTR,262144
    mov MyMemHandle,eax
    ... do something with the memory...
    invoke GlobalFree,MyMemHandle
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

asmfan

Correct me if i'm wrong but as i know most of the handles are unique only for the calling process while IDs are globally unique for all processes.
Russia is a weird place

donkey

Hi asmfan,

Handles are global in nature, pseudo-handles (ie hProcess) are local to your process. Many people do not distinguish between the two but they are treated differently at MSDN. Memory handles are always local.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

asmfan

Russia is a weird place