Jump to content
Tuts 4 You

Strange handle problem using ComboBoxEx32 class!


LCF-AT

Recommended Posts

Posted

Hi guys,

need some quick help again.I try to get the handle of controls where the mouse pointer is and used some APIs for this...

GetCursorPos,WindowFromPoint at WM_NOTIFY message.So on first check it seems to work but now the problem I have.I use three controls which I wanna catch if mouse does move over these controls to set the focus on them.I use 2 Listviews and one ComboBoxEx32.Its works to compare the handles of both diffrent LVs to check whether foucs is already set or not but it does fail on the ComboBoxEx32 handle so this strange.My code for this looks so...

IDC_LISTVIEW  equ	1005
IDC_LISTVIEW2 equ	1006 
IDC_COMBOBOX  equ	1002
-------------------------------



.elseif	uMsg == WM_INITDIALOG
invoke GetDlgItem,hWnd,IDC_LISTVIEW
mov LISTVIEW,eax
invoke GetDlgItem,hWnd,IDC_LISTVIEW2
mov LISTVIEW2,eax
invoke GetDlgItem,hWnd,IDC_COMBOBOX
mov COMBOBOX_HANDLE, eax


.elseif uMsg == WM_NOTIFY
invoke GetCursorPos,addr LP
invoke WindowFromPoint, LP.x, LP.y
.if eax != 0h
   mov edi, eax
   .if  edi == LISTVIEW || edi == LISTVIEW2 || edi == COMBOBOX_HANDLE
        invoke GetFocus
        .if eax != edi
         invoke SetFocus,edi
        .endif
   .endif
.endif

...so it works just for both LISTVIEW handles but not for the COMBOBOX_HANDLE and I dont know why.The handle seems to be else I get from WindowFromPoint which is not same as the handle I got from GetDlgItem API.Has anyone a idea what the problem is and how to fix it?As I said I only wanna check & set focus on these three controls if the mouse is over one of them.

EDIT: Ok I found something out.So if I remname the combox control class from ComboBoxEx32 to ComboBox then it works!?!But now I dont get icons anymore into the combobox.Have I to enable any another style or something etc?

And another thing...if I do check at hwndFrom at WM_NOTIFY then it gets the handle of my COMBOBOX_HANDLE and there I can also set the focus on it.....

.elseif uMsg == WM_NOTIFY
mov edi, lParam
mov eax,(NMHDR ptr [edi]).hwndFrom
.if eax == COMBOBOX_HANDLE
invoke SetFocus,eax
.endif

...so why is it working there but not with the code I did post above just if I use ComboBoxEx32 class instead of ComboBox.Maybe you have any idea or maybe you have any idea how to write the code better and correctly for this So I see I get also problems if a messagebox popups and move over one of these 3 controls then they get again the focus.So is there maybe any other smarter solution for this?

Thank you

Posted

The normal combobox is made up of the combo control, a list control and an edit control. Each have their own handles, which can be obtained with the GetComboBoxInfo function (https://msdn.microsoft.com/en-us/library/windows/desktop/bb775939(v=vs.85).aspx)

Not sure if the ComboBoxEx32 version has something similar, but if it does, then if you use this function (or the equivalent for it) to get the handles of all the controls that the combobox is comprised of, then you can check to see if the current handle is equal to one of them.

So hopefully that helps or points you in the right direction.

  • Like 1
Posted

Hi,

thanks for your answer.So I tried this API you did suggest with the struct but the API just always fails ONLY if I do use ComboBoxEx32 class.If I change it to ComboBox then the API get successfully called and struct gets filled.So the problem is really the class name I do use ComboBoxEx32.Something must be strange with it or maybe WinASM makes any trouble or something.Just a example,I did add a combobox control in WinASM resources window (didnt use CreateWindowEx API this time) and now I let show the style window then I can see almost all style infos I can enable / disable but I need to use this ComboBoxEx32 class and if I enter this class name into the resources....

CONTROL "",IDC_COMBOBOX,"ComboBox",0x52210003,37,306,300,46,0x00000000
change to
CONTROL "",IDC_COMBOBOX,"ComboBoxEx32",0x52210003,37,306,300,46,0x00000000

....and open now again the style window to see all styles then I only see just a few from WS_CHILD til WS_TABSTOP and all others below have no names anymore...

A1.png

...not sure whether this could be a problem later on compiling the file.Somehow this class is not registered maybe or whatever / no idea.

So as I said I need to use the EX32 version to use COMBOBOXEXITEMA struct in my code and now I found that strange handle issue if I use EX32 combo class.WindowFromPoint dosent return the same combox handle I get from GetDlgItem API & from WM_NOTIFY (hwndFrom).Thats the strange thing.

So till now I wrote the code to this to get it work what I want....

.elseif uMsg == WM_NOTIFY 		
	        
mov edi, lParam
mov eax,(NMHDR ptr [edi]).hwndFrom

	        .if eax == COMBOBOX_HANDLE && DISABLE_FOCUS == 0h
	            mov edi, eax
	            invoke GetFocus
	            .if eax != edi
	             invoke SetFocus,edi
	            .endif
	        .endif	


           .if DISABLE_FOCUS == 0h
	       invoke GetCursorPos,addr LP
	       invoke WindowFromPoint, LP.x, LP.y
	       .if eax != 0h
	       mov edi, eax
	       .if  edi == LISTVIEW || edi == LISTVIEW2
               invoke GetFocus
	           .if eax != edi
	            invoke SetFocus,edi
	           .endif
	       .endif
	       .endif	       
	       .endif

...looks a little stupid but its working.Just need to disable focus if any messagebox is called / shown and on WM_SIZE too.

greetz

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...