The MASM Forum Archive 2004 to 2012

Project Support Forums => IDE Development and Support => Easy Code => Topic started by: Bieb on December 24, 2004, 02:44:32 AM

Title: Messages to Controls
Post by: 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
Title: Re: Messages to Controls
Post by: 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

Title: Re: Messages to Controls
Post by: Maven on December 24, 2004, 02:53:42 AM
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
Title: Re: Messages to Controls
Post by: 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.
Title: Re: Messages to Controls
Post by: Maven on December 24, 2004, 05:00:15 AM
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..
Title: Re: Messages to Controls
Post by: Bieb on December 24, 2004, 02:34:31 PM
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?
Title: Re: Messages to Controls
Post by: John on December 24, 2004, 02:47:42 PM
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.
Title: Re: Messages to Controls
Post by: Bieb on December 24, 2004, 03:28:27 PM
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?
Title: Re: Messages to Controls
Post by: Ramon Sala on December 24, 2004, 05:39:25 PM
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
Title: Re: Messages to Controls
Post by: Bieb on December 25, 2004, 03:42:24 AM
Thanks.  I think I'm finally starting to get this :)
Title: Re: Messages to Controls
Post by: Ramon Sala on December 25, 2004, 09:12:25 AM
You are welcome Bieb. Have a look at the topic Easy Code tutorials.

Regards,

Ramon