flat assembler
Message board for the users of flat assembler.

Index > Windows > SetFocus Question

Author
Thread Post new topic Reply to topic
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
Hi Smile

In a dialog, i got 2 buttons, i want to set focus on the second button
i tried this
Code:
...
proc DialogProc,hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog                                    ; called before dialog box is displayed
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax                                         ; eax = 0
        jmp     finish

  wminitdialog:
        invoke  GetDlgItem,[hwnddlg],ID_BUTTON_QUIT
        invoke  SetFocus,eax
        invoke  UpdateWindow,[hwnddlg]
    

or this
Code:
...
  wminitdialog:
        invoke  SendMessage,\
                ID_BUTTON_QUIT, BM_SETSTATE, TRUE, NULL
    

but nothing changed, still the first button which received the focus Confused

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 09 May 2005, 23:52
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
give it the BS_DEFPUSHBUTTON style?
Post 10 May 2005, 00:36
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
Where ? Into the Resource section ?

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 10 May 2005, 11:02
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
yes give it that style, make sure the other button is a BS_PUSHBUTTON. that is a half solution though, i tried your code and dont see why it doesnt work. perhaps dialogs are updated/drawn differently

if youre using fasm's resource macros it would be something like
Code:
dialogitem 'BUTTON','OK',IDOK,85,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
dialogitem 'BUTTON','C&ancel',IDCANCEL,135,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
    
Post 10 May 2005, 11:29
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
thanks to have responded Wink

here's the src :

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

; *****************************************************************************
; ***** Const
; *****************************************************************************
ID_DIALOG          = 10
ID_GROUP_BOX       = 100

ID_LABEL_DATE      = 101
ID_LABEL_TIME      = 102
ID_LOCAL_TIME      = 103

ID_EDIT_DATE       = 104
ID_EDIT_TIME       = 105
ID_EDIT_LOCAL      = 106

ID_BUTTON_TIME     = 107
ID_BUTTON_QUIT     = 108

; *****************************************************************************
; ***** Datas
; *****************************************************************************
section '.data' data readable writeable

  hinstance        dd ?
  IsError          dd ?
  lpSystemTime     SYSTEMTIME                                   ; API struct

  _format_date     db '%02d/%02d/%4d',0
  _buffer_date     rb 11                                        ; 11 bytes reserved (xx/xx/xxxx0)

  _format_time     db '%02d:%02d:%02d',0
  _buffer_time     rb 9                                         ; 9 bytes reserved (xx:xx:xx0)
  _buffer_loc_time rb 9

; *****************************************************************************
; ***** Code
; *****************************************************************************
section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  DialogBoxParam,[hinstance],ID_DIALOG,HWND_DESKTOP,DialogProc,0
        invoke  ExitProcess,0

; ***** Procedures

proc DialogProc,hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog                                    ; called before dialog box is displayed
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax                                         ; eax = 0
        jmp     finish

  wminitdialog:
;        invoke  GetDlgItem,[hwnddlg],ID_BUTTON_QUIT
;        invoke  SetFocus,eax
;        invoke  UpdateWindow,[hwnddlg]
; or
;        invoke  SendMessage,\
;                ID_BUTTON_QUIT, BM_SETSTATE, TRUE, NULL         ; [wparam], 0

        stdcall sys_time,[hwnddlg]
        stdcall loc_time,[hwnddlg]
        stdcall sys_date,[hwnddlg]

        jmp     processed

  wmcommand:
        cmp     [wparam],ID_BUTTON_QUIT                         ; BN_CLICKED shl 16 + ID_BUTTON_QUIT
        je      wmclose                                         ; goto close if click on Cancel
        cmp     [wparam],ID_BUTTON_TIME                         ; BN_CLICKED shl 16 + ID_BUTTON_TIME
        jne     processed                                       ; <> Ok

        stdcall sys_time,[hwnddlg]                              ; Called when clicked on button 'Time'
        stdcall loc_time,[hwnddlg]
        jmp     processed

  wmclose:
        invoke  EndDialog,[hwnddlg],0

  processed:
        mov     eax,1

  finish:
        pop     edi esi ebx

        return
endp

proc sys_time,_hwnddlg
        invoke  GetSystemTime,lpSystemTime
        movsx   eax,[lpSystemTime.wHour]                        ; movsx (ou movzx) permet de
        movsx   ebx,[lpSystemTime.wMinute]                      ; convertir en DWORD signed (ou unsigned)
        movsx   edi,[lpSystemTime.wSecond]                      ; car wsprintf ne demande que du DWORD
        cinvoke wsprintf,_buffer_time,_format_time,eax,ebx,edi
        invoke  SetDlgItemText,[_hwnddlg],ID_EDIT_TIME,_buffer_time

        return
endp

proc loc_time,_hwnddlg
        invoke  GetLocalTime,lpSystemTime
        movsx   eax,[lpSystemTime.wHour]
        movsx   ebx,[lpSystemTime.wMinute]
        movsx   edi,[lpSystemTime.wSecond]
        cinvoke wsprintf,_buffer_loc_time,_format_time,eax,ebx,edi
        invoke  SetDlgItemText,[_hwnddlg],ID_EDIT_LOCAL,_buffer_loc_time

        return
endp

proc sys_date,_hwnddlg
        movsx   eax,[lpSystemTime.wDay]
        movsx   ebx,[lpSystemTime.wMonth]
        movsx   edi,[lpSystemTime.wYear]
        cinvoke wsprintf,_buffer_date,_format_date,eax,ebx,edi
        invoke  SetDlgItemText,[_hwnddlg],ID_EDIT_DATE,_buffer_date

        return
endp

; *****************************************************************************
; ***** Data Import
; *****************************************************************************
section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         GetSystemTime, 'GetSystemTime',\
         GetLocalTime, 'GetLocalTime',\
         ExitProcess,'ExitProcess'

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         UpdateWindow,'UpdateWindow',\
         SendMessage,'SendMessageA',\
         SetDlgItemText,'SetDlgItemTextA',\                     ; on peut aussi mettre SetDlgItemInt
         GetDlgItem,'GetDlgItem',\
         SetFocus,'SetFocus',\
         MessageBox,'MessageBoxA',\
         wsprintf,'wsprintfA',\
         EndDialog,'EndDialog'

; *****************************************************************************
; ***** Resources
; *****************************************************************************
section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           ID_DIALOG,LANG_NEUTRAL+SUBLANG_DEFAULT,datesysteme

  dialog datesysteme,"System Date & Time", 70, 70, 150, 110, DS_CENTER+DS_MODALFRAME+WS_POPUP+WS_VISIBLE+WS_CAPTION+WS_SYSMENU
    dialogitem 'STATIC','System date :', ID_LABEL_DATE , 10, 10, 45, 14, SS_RIGHT + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000000
    dialogitem 'STATIC','System Time :', ID_LABEL_TIME , 10, 30, 45, 14, SS_RIGHT + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000000
    dialogitem 'STATIC','Local Time :' , ID_LOCAL_TIME , 10, 50, 45, 14, SS_RIGHT + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000000
    dialogitem 'BUTTON',''             , ID_GROUP_BOX  , 60,  0, 85, 70, BS_GROUPBOX + WS_CHILD + WS_VISIBLE, 0x00000000
    dialogitem 'STATIC','__/__/____'   , ID_EDIT_DATE  , 70, 10, 65, 14, SS_CENTER + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000204
    dialogitem 'STATIC','__:__:__'     , ID_EDIT_TIME  , 70, 30, 65, 14, SS_CENTER + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000204
    dialogitem 'STATIC','__:__:__'     , ID_EDIT_LOCAL , 70, 50, 65, 14, SS_CENTER + SS_CENTERIMAGE + WS_CHILD + WS_VISIBLE + WS_GROUP, 0x00000204
    dialogitem 'BUTTON','&Time'        , ID_BUTTON_TIME, 10, 80, 60, 28, WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON;BS_PUSHBUTTON + BS_VCENTER + BS_CENTER + WS_CHILD + WS_VISIBLE + WS_TABSTOP
    dialogitem 'BUTTON','&Quit'        , ID_BUTTON_QUIT, 80, 80, 60, 28, WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON;BS_PUSHBUTTON + BS_VCENTER + BS_CENTER + WS_CHILD + WS_VISIBLE + WS_TABSTOP
  enddialog
    


I want the 'Quit' Button to be focused, but it's the 'time' button which is focused Confused

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 10 May 2005, 11:53
View user's profile Send private message Visit poster's website Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank
Swap the order of buttons in the resource section -- it works if the "Quit" button is declared before the "Time" button.
Post 10 May 2005, 13:50
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
yes, that's right thx Smile
in fact i'm looking to always set focus on the Quit button, even if i clicked on another one !

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 10 May 2005, 13:54
View user's profile Send private message Visit poster's website Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank
That's just a question of putting the available bits and pieces together.

Code:
; Changes to the code section:

  wmcommand:
        cmp     [wparam],ID_BUTTON_QUIT                         ; BN_CLICKED shl 16 + ID_BUTTON_QUIT
        je      wmclose                                         ; goto close if click on Cancel
        invoke  GetDlgItem,[hwnddlg],ID_BUTTON_QUIT
        invoke  SetFocus,eax
        cmp     [wparam],ID_BUTTON_TIME                         ; BN_CLICKED shl 16 + ID_BUTTON_TIME
        jne     processed                                       ; <> Ok


; Changes to the resource section:

    dialogitem 'BUTTON','&Quit'        , ID_BUTTON_QUIT, 80, 80, 60, 28, WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
    dialogitem 'BUTTON','&Time'        , ID_BUTTON_TIME, 10, 80, 60, 28, WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
    
Post 10 May 2005, 14:50
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
Mr. Green wow thank you very, very much Very Happy

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 10 May 2005, 15:02
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.