News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Button refusing to be disabled

Started by Landsfiskalen, January 16, 2015, 09:35:20 PM

Previous topic - Next topic

Landsfiskalen

Ok, I set up a procedure to disable the controls I want. But there's a weird problem, one of the buttons refuse to be disabled.


EnableCtrls proc dwEnabledOrDisable:DWORD
invoke EnableWindow,hUnpackButton,dwEnabledOrDisable ; <---------------------- This one refuses to be disabled.
invoke EnableWindow,hPackButton,dwEnabledOrDisable
invoke EnableWindow,hBackupCheckbox,dwEnabledOrDisable
invoke EnableWindow,hBrowseButton,dwEnabledOrDisable
invoke EnableWindow,hProfileComboBox,dwEnabledOrDisable
invoke UpdateWindow,hWindow
ret
EnableCtrls endp


Anyone have ANY idea why this might happen?

vogelsang

Try to update it with UpdateWindow.

hth.

Landsfiskalen

Hi!
I do an UpdateWindow at the end of that proc, on the main window. Should I do one on the specific button perhaps? Cheers!

Quote from: vogelsang on January 16, 2015, 10:08:04 PM
Try to update it with UpdateWindow.

hth.

vogelsang

I see that you updating hWindow - main window as you say. Try to update hUnpackButton and see what will happen.
And what exactly means "refusing". According to MSDN EnableWindow returns:
Quote
Return value

Type: BOOL

If the window was previously disabled, the return value is nonzero.

If the window was not previously disabled, the return value is zero.

I guess it doesn't changed its state to other?

Maybe this helps:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646291%28v=vs.85%29.aspx

hutch--

Get a handle for each control, then use EnableWindow().

dedndave

perhaps the control has keyboard focus
if it's stubborn, try removing focus and also try de-activating it

http://blogs.msdn.com/b/oldnewthing/archive/2004/08/04/208005.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646311%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646312%28v=vs.85%29.aspx

if all else fails, try SetWindowPos with appropriate flags

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx

you can use SWP_NOMOVE and SWP_NOSIZE - no need to set the position arguments
flags are OR'ed together, for example...
SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE

Landsfiskalen

Quote from: hutch-- on January 16, 2015, 11:13:46 PM
Get a handle for each control, then use EnableWindow().

Hi!
That's what I'm doing, but this one button refuse to gt disabled when I do invoke EnableWindow,hButton,FALSE.  :icon_confused:

I checked the return value, and it is 0, ie. it was not disabled before.

Will see if dedndave:s input might help.

Cheers!

fearless

Might be handy to see the code where you assign the handle hUnpackButton - just to make sure there arent any typos or maybe a wrong const value used for IDC_UNPACKBUTTON or whatever its named in your resources.

jj2007

If after two nights of bugchasing you still haven't found it, here is a top secret information for you:
QuoteTo get extended error information, call GetLastError.

ragdog

Hello

I use this in my code to enable or disable many Controls

invoke   EnableControl,hWnd,1001,TRUE

or

invoke   EnableControl,hWnd,1001,FALSE


EnableControl proc uses ebx hWnd:HWND,_ID:DWORD,_bool:BYTE
invoke GetDlgItem,hWnd,_ID
mov ebx,eax
invoke EnableWindow,ebx,_bool
ret
EnableControl endp


Greets,

Landsfiskalen

Hi!
I don't user resources, I create them using CreateWindowsEx. Looks like this:


invoke CreateWindowEx,0,ADDR ButtonClass,ADDR szPackButton,WS_CHILD or WS_VISIBLE or WS_TABSTOP or WS_DISABLED,350,169,75,24,hWindow,NULL,hInst,NULL
mov hPackButton,eax


Quote from: fearless on January 17, 2015, 02:19:46 AM
Might be handy to see the code where you assign the handle hUnpackButton - just to make sure there arent any typos or maybe a wrong const value used for IDC_UNPACKBUTTON or whatever its named in your resources.

sinsi

Do you get a valid window handle from CreateWindowEx?
Tá fuinneoga a haon déag níos fearr :biggrin:

Landsfiskalen

Hi!
Yes, I get a valid windows handle. But it looks like the EnableCtrls procedure is called twice. So I think there's something wrong in my main WindowProc.

Right now I do:


.elseif uMsg == WM_COMMAND
        .if eax == hPackButton
...


But I seem to recall dedndave telling me once that I should use wParam and check the hi and lo word. So looking in to that.

Quote from: sinsi on January 19, 2015, 07:50:43 PM
Do you get a valid window handle from CreateWindowEx?

Landsfiskalen

Ok, so now I got this:


.elseif uMsg == WM_COMMAND
mov edx,[wParam]
movzx eax,dx
shr edx,16
.if edx == BN_CLICKED


So now it should only execute on BN_CLICKED? Do I just put lParam in to eax then and get the handle? What's best practice in this case?

fearless

I use the wNotifyCode mainly for comboboxes and other controls sometimes. You can still specify a control id when creating it using CreateWindowEx - its the third last parameter: hMenu - which can be a control id, like iDC_BtnPack or IDC_BtnUnpack or whatever.

.CONST
IDC_BtnPack EQU 1001
IDC_BtnUnpack EQU 1002

.DATA
ButtonClass db 'button',0
szPackButton db 'Pack',0
szUnpackButton db 'Unpack',0

.DATA?
hUnpackButton dd ?
hPackButton dd ?

.CODE
WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

    LOCAL wNotifyCode:DWORD

    mov eax, uMsg
    .IF eax==WM_INITDIALOG
        ; do init stuff here, including possibly creating our btn controls here (or somewhere else perhaps, assuming we have hInstance already stored)
        invoke CreateWindowEx,0,ADDR ButtonClass,ADDR szPackButton,WS_CHILD or WS_VISIBLE or WS_TABSTOP or WS_DISABLED,350,169,75,24,hWin,IDC_BtnPack,hInstance,NULL
        mov hPackButton,eax
        invoke CreateWindowEx,0,ADDR ButtonClass,ADDR szUnpackButton,WS_CHILD or WS_VISIBLE or WS_TABSTOP or WS_DISABLED,350,169,75,24,hWin,IDC_BtnUnpack,hInstance,NULL
        mov hUnpackButton,eax


    .ELSEIF eax == WM_COMMAND
        mov eax, wParam
        shr eax, 16
        mov wNotifyCode, eax
        mov    eax,wParam
        and    eax,0FFFFh
        .IF eax==IDC_BtnUnpack
                ; do something here

        .ELSEIF eax==IDC_BtnPack
                ; do something else here

        .ELSEIF eax==IDC_SomeOtherControl
                ; maybe we check to enable disable controls here, like if user has succesfully opened a file - allow unpack button?

        .ENDIF
         
        ; other code here onwards