Author Topic: Obtaining a control handle..  (Read 9860 times)

K_F

  • Member
  • *****
  • Posts: 1505
  • Anybody out there?
Obtaining a control handle..
« on: December 18, 2012, 07:07:00 PM »
Hi Ramon, just a thought on obtaining control handles, correct me if I'm wrong here..

If I have a control named edtEDIT in the wndMAIN, and edtEDT has it's own window proc, can I not extract the handle of edtEDIT with it's WM_Create (or any other) message
instead of using a GetWindowItem, or is the hWnd here, still the parent window handle ?

wndMainedtEdit Proc hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
                 .If uMsg == WM_CREATE
                       mov     hedtEDIT, hWnd



Thanks
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

rsala

  • Moderator
  • Member
  • *****
  • Posts: 296
    • Easy Code
Re: Obtaining a control handle..
« Reply #1 on: December 18, 2012, 11:30:32 PM »
Hi K_F,

Thanks for using Easy Code!

The WM_CREATE message is only sent when a window object is created (Window, MDIWindow or DialogBox), but not for child controls since their window procedures are subclassed once the controls have been created. So the answer is no, you can not get the handle of the edtEDT control on its WM_CREATE message because it is never received. You should get the handle in the WM_CREATE message of the parent window by using the GetWindowItem method (also you can use the GetDlgItem API function).

Regards,

Ramon
EC coder

K_F

  • Member
  • *****
  • Posts: 1505
  • Anybody out there?
Re: Obtaining a control handle..
« Reply #2 on: December 20, 2012, 04:32:49 PM »
Thanks Ramon.
I'm trying to clarify the value of hWnd in the (subclass) proc below..

wndMainedtEdit Proc hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

Would hWnd be the parent handle, or the edtEdit handle. ?
I'm thinking along the line that if it is the control handle, one could use it.

My easycodeV18 help file has 'bombed' under Win7,  so I cannot readup on it.
:icon_cool:
« Last Edit: December 21, 2012, 12:12:36 AM by K_F »
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Obtaining a control handle..
« Reply #3 on: December 20, 2012, 10:11:49 PM »
what you re going to find is that, under windows 7, these controls have a different hierarchy
particularly if you use the glass theme
some controls are even affected by using xp themes with common controls v 6.0
simple buttons come to mind - hard to set the background color on an xp theme button   :P

you may want to try using Spy++ to see how they are put together   :t
i use v 8.0

http://mdb-blog.blogspot.com/2010/11/microsoft-spy-or-spyxx-for-download.html

a while back, i was playing with the GetOpenFileName dialog and ran into the same thing
i wrote some code to detect the window hierarchy and sub-class accordingly
i guess we lost interest in that or something - i don't think it ever got tested under windows 7

http://www.masmforum.com/board/index.php?topic=16931.msg154917#msg154917

there is an attachment on that post - give it a shot

K_F

  • Member
  • *****
  • Posts: 1505
  • Anybody out there?
Re: Obtaining a control handle..
« Reply #4 on: December 21, 2012, 12:17:18 AM »
Thanks
 :t
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

rsala

  • Moderator
  • Member
  • *****
  • Posts: 296
    • Easy Code
Re: Obtaining a control handle..
« Reply #5 on: December 22, 2012, 11:55:51 PM »
Hi K_F,

wndMainedtEdit Proc hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

Yes, it is the edtEdit handle and, of course, you can use it. However, child controls send most of their events (click, focus, etc.)  to their parent through the WM_COMMAND and WM_NOTIFY messages. So it is easier and faster managing those events in the parent window, except if you are going to control something that WM_COMMAND or WM_NOTIFY messages do not control.

Regards,

Ramon
EC coder

K_F

  • Member
  • *****
  • Posts: 1505
  • Anybody out there?
Re: Obtaining a control handle..
« Reply #6 on: December 25, 2012, 04:50:56 AM »
Thanks Ramon,
This is what I was thinking, as the control is made with CreateWindow(Ex), according to the API 'bible'.

I was making a plan to pick up the control handle on the WM_Create message, instead of using the GetWindowItem proc - thus saving a lot of code lines when I have a 'gazillion' controls on a window.
It'll make the code neater.

Maybe if I do  not handle the WM_Create message in the parent window, will it pass it on to the child window (edtEDT) proc, or I can just pass on the create message from parent to child proc !!  :biggrin:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Obtaining a control handle..
« Reply #7 on: December 25, 2012, 05:10:03 AM »
the WM_CREATE messages are sent to windows as they are created
actually, during execution of the CreateWindow(Ex) call
the CreateWindow call does not return until WM_CREATE has returned

controls fall into the catagory of windows - so they get the message, as well

the question is - how are you creating the edit control

if you are using a system pre-defined class ('Edit',0) then that class provides WndProc
this includes edit controls created in resource
if you sub-class the edit control, your WndProc will not receive the WM_CREATE message
that is because, when the control is created, the system pre-defined WndProc is in use
when you sub-class it, too late - it's already been created   :P

if you are using your own class that is like an edit control, then you can save the handle during WM_CREATE
i doubt this is the case   :P

however, if you create the edit control with CreateWindow(Ex), that function returns a handle
so - if that happens during WM_CREATE of the parent, you can store the handle when it returns

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Obtaining a control handle..
« Reply #8 on: December 25, 2012, 05:41:57 AM »
here is a method i use that might interest you

i use tables for creating multiple controls
then, i call a loop that creates everything from the parms in the table(s)
the handles are stored sequentially into a handle structure

attached is some text to describe how i do it
you may want to come up with your own   :P

in your case, you might even add a parm to the table or something
and modify the loop code to subclass controls for you

in this one, i modified it to set the font for some control types
you could do a similar mod
add a parm to the table that is a pointer to the WndProc for sub-classing
if it is NULL, that control isn't sub-classed
pretty easy, really   :P

jj2007

  • Member
  • *****
  • Posts: 9689
  • Assembler is fun ;-)
    • MasmBasic
Re: Obtaining a control handle..
« Reply #9 on: December 25, 2012, 06:54:52 AM »
the handles are stored sequentially into a handle structure

I hope you are not using stosd for doing that :eusa_naughty:
First, it's old-fashioned, second, I have the copyleft :icon_mrgreen:

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Obtaining a control handle..
« Reply #10 on: December 25, 2012, 08:33:20 AM »
as a a matter of fact, i am
Hutch won't like it at all - lol
i use LODSD to get the parms from the table and STOSD to store the handles
if the output handle pointer is 0, it does not store the handles

copyleft - i don't think so - lol
this is a fairly recent version
you can see how eariler versions have evolved over time   :P

the NULL handle pointer is one improvement
but, also, i pass a pointer to the parent handle, rather than the parent handle, itself
that way, the first window in the table can be the main window
it will be created with a parent handle of 0
once it has been created, the parent handle for the rest is now non-zero
tricky, eh ?

i have used this on projects with many windows and controls - complex hierarchy
it works great   :biggrin:

i also have a loop function for positioning windows/controls
and, i have written a similar routine for registering window classes
i only use the later if i have several classes to register

i had considered making one for creating menus
but, there is little advantage over using the resource file for that if you use unicorn strings
i had in mind using a recursive routine for that
the OS does a pretty good job, already

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Obtaining a control handle..
« Reply #11 on: December 25, 2012, 06:45:43 PM »
Quote from: dedndave link=topic=1109.msg10973#msg10973
but, there is little advantage over using the resource file for that if you use unicorn strings

Unicorn strings?

Well Microsoft, here’s another nice mess you’ve gotten us into.

jj2007

  • Member
  • *****
  • Posts: 9689
  • Assembler is fun ;-)
    • MasmBasic
Re: Obtaining a control handle..
« Reply #12 on: December 25, 2012, 07:51:11 PM »
Quote from: dedndave link=topic=1109.msg10973#msg10973
but, there is little advantage over using the resource file for that if you use unicorn strings

Unicorn strings?

Check \Masm32\include\windows.inc:

      IFDEF __UNICODE__
        echo     
        echo *************
        echo UNICODE Build
        echo *************
        echo     
      ELSEIF SIXPACKS GT 1
        echo     
        echo ***********
        echo UNICORN build
        echo ***********
        echo     
      ELSE
        echo     
        echo ***********
        echo ASCII build
        echo ***********
        echo     
      ENDIF

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6665
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Obtaining a control handle..
« Reply #13 on: December 25, 2012, 08:43:17 PM »
You can tell its a ring in, only beer drinkers think in terms of six packs.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Obtaining a control handle..
« Reply #14 on: December 26, 2012, 01:23:35 AM »
he's German - lol - nuff said

"unicorn strings" sounds a lot more interesting than "unicode strings", eh ?
it's actually the name of a company   :P