News:

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

Messages to Controls

Started by Bieb, December 24, 2004, 02:44:32 AM

Previous topic - Next topic

Bieb

Alright, I think I've finally got down how message handling with controls works, and I've got a message handling routine like this for a button

Window1Button1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
.If uMsg == WM_LBUTTONDOWN
Mov LeftDown, 1
.ElseIf uMsg == WM_LBUTTONUP
.If LeftDown == 1
Mov LeftDown, 0
Invoke MessageBox, hWnd, Addr MsgBoxTest, Addr MsgBoxTest, MB_OK
.EndIf
.EndIf
Return FALSE
Window1Button1 EndP

I know there must be some way to simplify that, but how?  Sorry if I sound like a complete and total n00b :red

Maven

Quote from: Bieb on December 24, 2004, 02:44:32 AM
Alright, I think I've finally got down how message handling with controls works, and I've got a message handling routine like this for a button

Window1Button1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
.If uMsg == WM_LBUTTONDOWN
Mov LeftDown, 1
.ElseIf uMsg == WM_LBUTTONUP
.If LeftDown == 1
Mov LeftDown, 0
Invoke MessageBox, hWnd, Addr MsgBoxTest, Addr MsgBoxTest, MB_OK
.EndIf
.EndIf
Return FALSE
Window1Button1 EndP

I know there must be some way to simplify that, but how?  Sorry if I sound like a complete and total n00b :red

Just change all of that to this:

.If uMsg == WM_LBUTTONDOWN
Invoke MessageBox, hWnd, Addr MsgBoxTest, Addr MsgBoxTest, MB_OK
.EndIf


Maven

Quote from: Maven on December 24, 2004, 02:51:48 AM
Quote from: Bieb on December 24, 2004, 02:44:32 AM
Alright, I think I've finally got down how message handling with controls works, and I've got a message handling routine like this for a button

Window1Button1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
.If uMsg == WM_LBUTTONDOWN
Mov LeftDown, 1
.ElseIf uMsg == WM_LBUTTONUP
.If LeftDown == 1
Mov LeftDown, 0
Invoke MessageBox, hWnd, Addr MsgBoxTest, Addr MsgBoxTest, MB_OK
.EndIf
.EndIf
Return FALSE
Window1Button1 EndP

I know there must be some way to simplify that, but how?  Sorry if I sound like a complete and total n00b :red

Just change all of that to this:

.If uMsg == WM_LBUTTONDOWN
Invoke MessageBox, hWnd, Addr MsgBoxTest, Addr MsgBoxTest, MB_OK
.EndIf



or if you want the code to execute after they left off the mouse buttong, change to this:
.If uMsg == WM_LBUTTONUP
Invoke MessageBox, hWnd, Addr MsgBoxTest, Addr MsgBoxTest, MB_OK
.EndIf

Bieb

That first code snippet you gave me is what I tried originally, and it ends up locking the app up in a never ending sequence of message boxes.  The second one worked very nicely, thank you.

Maven

Quote from: Bieb on December 24, 2004, 03:14:42 AM
That first code snippet you gave me is what I tried originally, and it ends up locking the app up in a never ending sequence of message boxes.  The second one worked very nicely, thank you.

That should have worked either way. It sounds like you may have WM_LBUTTONDOWN set to an incorrect number. The number that variable is suppose to correspond with is 201h.

IE: WM_LBUTTONDOWN equ 201h

make sure the h is there lol..

Bieb

I've now found how I can use a controls handle to access it's properties, but I only know how to get the handle from inside that controls' message loop.  How do I get it outside of that?

John

You should save the handle to the control when you create it. CreateWindowEx will leave the handle to the control in eax when it returns.

Bieb

Ahh, I see.  Problem is, I'm using Easy Code, and all that gets hidden from me.  Is there a way I can see and edit that part of the code?

Ramon Sala

#8
Hi Bieb,

When you want to get the handle of a control, use the Easy Code method GetWindowItem. Here is its declaration:

GetWindowItem Proto hWnd:HWND, lItemID:ULONG

Where hWnd is the handle to the owner window (the window where the control is) and lItemID is the control IDentifier. The control IDentifier is all upper case and is formed by 'IDC_', plus the name of the owner window, plus '_', plus the control object name. For example, for a Static control named Static1 placed inside a Window object named Window1, the control ID will be:

IDC_WINDOW1_STATIC1

As you can see, the control ID has to be always uppercase even though its name is lowercase. Then, you can always get the handle of that control by calling GetWindowItem:

Invoke GetWindowItem, hWnd, IDC_WINDOW1_STATIC1

When returning, register Eax contains the handle for the specified control.


Best regards,

Ramon
Greetings from Catalonia

Bieb

Thanks.  I think I'm finally starting to get this :)

Ramon Sala

You are welcome Bieb. Have a look at the topic Easy Code tutorials.

Regards,

Ramon
Greetings from Catalonia