flat assembler
Message board for the users of flat assembler.

Index > Windows > SetDlgItemText

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 05 Jun 2011, 13:52

The problem is that the only one "EN_CHANGE" is sent before the end of "SetDlgItemText" ... so "EM_SETSEL,-1,0" is sent too early! ... and "EM_SETSEL,-1,0" has no effect.

Code:
.initdialog:   invoke  SetDlgItemText,[hwnd_dlg],ID_CMDLINE,only_cmd_line
          bts     [hl_off],0

              .....
               .....

.command:      cmp     [wparam],ID_CMDLINE + EN_CHANGE shl 16
              jne     @F

              btr     [hl_off],0 ;<------ cy=0 !!!

@@:
    
It is certainly a way to find the "true" solution ...
but below, the ouadji_solution works fine.
Code:
proc     CommandLine hwnd_dlg,msg,wparam,lparam

          push    ebx esi edi

             mov     eax,[msg]
           cmp     eax,WM_INITDIALOG
           je      .initdialog
         cmp     eax,WM_COMMAND
              je      .command
            cmp     eax,WM_CLOSE
                je      .close

          btr     [hl_off],0
          jc      .hl_off ;<--------------

.notprocessed:   xor     eax,eax
             jmp     .finish

.initdialog: invoke  SetDlgItemText,\
           [hwnd_dlg],ID_CMDLINE,only_cmd_line

             bts     [hl_off],0 ;<--------------

          jmp     .finish


.hl_off: invoke  SendDlgItemMessage,\
               [hwnd_dlg],ID_CMDLINE,EM_SETSEL ,-1,0

           invoke  GetDlgItem,[hwnd_dlg],ID_CMDLINE
            invoke  SetFocus,eax
                jmp     .finish

         .....
               .....
    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 05 Jun 2011, 13:52
View user's profile Send private message Send e-mail Reply with quote
Gunner



Joined: 28 Jul 2003
Posts: 17
Location: In my head
Gunner 05 Jun 2011, 14:46
So, when you set the text of the control, the text is highlighted? then try SetFocus on that control BEFORE sending EM_SETSEL..

OR

You don't want the text highlighted when you tab to the control? If that is the case, then you have to subclass that one control and in WM_SETFOCUS, send EM_SETSEL... or if you don't want any of your controls to get highlighted, then superclass your edit controls and handle WM_SETFOCUS
Post 05 Jun 2011, 14:46
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 05 Jun 2011, 15:00
ctl3d32 wrote:
@ouadji,

ImageShack images doesn't show in this forum for many members, including me.

Use Gyazo. It takes a screenshot then uploads to a server automatically.

It really helps
Here is the link. : http://gyazo.com/en

Good luck Very Happy
Post 05 Jun 2011, 15:00
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 05 Jun 2011, 17:36

Quote:
@typedef
Use Gyazo. It takes a screenshot then uploads to a server automatically.
thank you for the tip (and the link)

Quote:
@Gunner
try SetFocus on that control BEFORE sending EM_SETSEL
I checked but it does not work.

Quote:
You don't want the text highlighted when you tab to the control? If that is the case, then you have to subclass that one control and in WM_SETFOCUS, send EM_SETSEL... or if you don't want any of your controls to get highlighted, then superclass your edit controls and handle WM_SETFOCUS
subclass and superclass Question Embarassed
my knowledge of the Windows API is not so deep!

That said, "my" solution works fine. (right below)
what do you think about it ?

it seems that this problem is not so easy to solve.
if someone has another solution that works,
of course it interests me
Code:
proc  CommandLine hwnd_dlg,msg,wparam,lparam

          mov     eax,[msg]
           cmp     eax,WM_INITDIALOG
           je      .initdialog
         cmp     eax,WM_COMMAND
              je      .command

                btr     [hl_off],0
          jc      .hl_off         ;<=====

.notprocessed:    xor     eax,eax
             jmp     .finish

.initdialog: invoke  SetDlgItemText,[hwnd_dlg],ID_CMDLINE,only_cmd_line

              bts     [hl_off],0      ;<=====
          .....

.hl_off:       invoke  SendDlgItemMessage,\
               [hwnd_dlg],ID_CMDLINE,EM_SETSEL ,-1,0
               .....
endp    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 05 Jun 2011, 17:36
View user's profile Send private message Send e-mail Reply with quote
Gunner



Joined: 28 Jul 2003
Posts: 17
Location: In my head
Gunner 05 Jun 2011, 17:48
Subclassing means you step between windows and the control (you "intercept" the messages sent to the control), so you can grab, say WM_KEYDOWN and not allow any numbers to be entered in the edit control

For instance, I subclass an edit control and intercept WM_KILLFOCUS, when I get that message, I get the text of the control and trim all leading and trailing spaces, then put the fixed text back into the control, and then call the default window proc to let windows continue the message loop...

You would use SetWindowLong with GWL_WNDPROC as the index and address of the new window proc as the dwNewLong, you save the returned value which is the address of the original window proc... in your callback you pass unwanted messages to the original window proc with CallWindowProc
You would have to subclass every control you want to intercept messages for... tedious

Superclassing is very cool... you get the values of the original control and modify say the cursor or color, then set the WNDPROC to your callback and all the controls will use that proc... so all your controls will be similar...


Question... have you tried SendMessage with WM_SETTEXT INSTEAD of SetDlgItemText?

_________________
~Rob (Gunner)
Forum Spam List Checker
Window Error Lookup Tool
and MORE!
Post 05 Jun 2011, 17:48
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 05 Jun 2011, 18:15

Quote:
have you tried SendMessage with WM_SETTEXT INSTEAD of SetDlgItemText?
yes, same result, the text is highlighted
and EM_SETSEL,-1,0 has no effect.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 05 Jun 2011, 18:15
View user's profile Send private message Send e-mail Reply with quote
Gunner



Joined: 28 Jul 2003
Posts: 17
Location: In my head
Gunner 05 Jun 2011, 19:04
I am at a lose then... Using SetDlgItemText or WM_SETTEXT does not/Should not highlight text... Unless some Window style got changed in an include file... but the problem is elsewhere

_________________
~Rob (Gunner)
Forum Spam List Checker
Window Error Lookup Tool
and MORE!
Post 05 Jun 2011, 19:04
View user's profile Send private message Visit poster's website Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho 05 Jun 2011, 19:14
Iczelion's Win32 Assembly Tutorials

Tutorial 20: Window Subclassing:
http://win32assembly.online.fr/tut20.html

Tutorial 22: Superclassing:
http://win32assembly.online.fr/tut22.html

ps
it is for masm,search this forum for fasm version ( but dont know if all tutorials are translated ) ...
Post 05 Jun 2011, 19:14
View user's profile Send private message Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 295
Alphonso 06 Jun 2011, 03:30
ouadji, see if this modified dlg example posted earlier works for you.
Code:

; DialogBox example

format PE GUI 4.0
entry start

include 'win32a.inc'

ID_CAPTION         = 101
ID_MESSAGE         = 102
ID_ICONERROR       = 201
ID_ICONINFORMATION = 202
ID_ICONQUESTION    = 203
ID_ICONWARNING     = 204
ID_TOPMOST         = 301

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
        or      eax,eax
        jz      exit
        invoke  MessageBox,HWND_DESKTOP,message,caption,[flags]
  exit:
        invoke  ExitProcess,0

proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      .wminitdialog
        cmp     [msg],WM_COMMAND
        je      .wmcommand
        cmp     [msg],WM_CLOSE
        je      .wmclose
        xor     eax,eax
        jmp     .finish
  .wminitdialog:
        invoke  CheckRadioButton,[hwnddlg],ID_ICONERROR,ID_ICONWARNING,ID_ICONINFORMATION
        invoke  SetDlgItemText,[hwnddlg],ID_TOPMOST,szString
        invoke  SetDlgItemText,[hwnddlg],ID_MESSAGE,szString     ; add some text
        invoke  SetDlgItemText,[hwnddlg],ID_CAPTION,szString     ; ...
        jmp     .processed
  .wmcommand:
        mov     eax,[wparam]                                     ; look for notification
        shr     eax,16                                           ;
        cmp     eax,EN_SETFOCUS                                  ;
        je      .setfocus                                        ;
        cmp     [wparam],BN_CLICKED shl 16 + IDCANCEL
        je      .wmclose
        cmp     [wparam],BN_CLICKED shl 16 + IDOK
        jne     .processed
        invoke  GetDlgItemText,[hwnddlg],ID_CAPTION,caption,40h
        invoke  GetDlgItemText,[hwnddlg],ID_MESSAGE,message,100h
        mov     [flags],MB_OK
        invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONERROR
        cmp     eax,BST_CHECKED
        jne     .iconerror_ok
        or      [flags],MB_ICONERROR
      .iconerror_ok:
        invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONINFORMATION
        cmp     eax,BST_CHECKED
        jne     .iconinformation_ok
        or      [flags],MB_ICONINFORMATION
      .iconinformation_ok:
        invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONQUESTION
        cmp     eax,BST_CHECKED
        jne     .iconquestion_ok
        or      [flags],MB_ICONQUESTION
      .iconquestion_ok:
        invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONWARNING
        cmp     eax,BST_CHECKED
        jne     .iconwarning_ok
        or      [flags],MB_ICONWARNING
      .iconwarning_ok:
        invoke  IsDlgButtonChecked,[hwnddlg],ID_TOPMOST
        cmp     eax,BST_CHECKED
        jne     .topmost_ok
        or      [flags],MB_TOPMOST
      .topmost_ok:
        invoke  EndDialog,[hwnddlg],1
        jmp     .processed
  .setfocus:
        invoke  SendMessage,[lparam],EM_SETSEL,0,0               ; set selection
        jmp .processed                                           ; not sure about this. Maybe eax=0?
  .wmclose:
        invoke  EndDialog,[hwnddlg],0
  .processed:
        mov     eax,1
  .finish:
        pop     edi esi ebx
        ret
endp

section '.bss' readable writeable
  szString db "TopMost", 0

  flags dd ?
  caption rb 40h
  message rb 100h

section '.idata' import data readable writeable

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

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

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         SendMessage,'SendMessageA',\
         CheckRadioButton,'CheckRadioButton',\
         GetDlgItemText,'GetDlgItemTextA',\
         SendDlgItemMessage,'SendDlgItemMessageA',\
         IsDlgButtonChecked,'IsDlgButtonChecked',\
         MessageBox,'MessageBoxA',\
         EndDialog,'EndDialog',\
         SetDlgItemText, 'SetDlgItemTextA'

section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration

  dialog demonstration,'Create message box',70,70,190,175,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
    dialogitem 'STATIC','&Caption:',-1,10,10,70,8,WS_VISIBLE
    dialogitem 'EDIT','',ID_CAPTION,10,20,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP
    dialogitem 'STATIC','&Message:',-1,10,40,70,8,WS_VISIBLE
    dialogitem 'EDIT','',ID_MESSAGE,10,50,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL
    dialogitem 'BUTTON','&Icon',-1,10,70,80,70,WS_VISIBLE+BS_GROUPBOX
    dialogitem 'BUTTON','&Error',ID_ICONERROR,20,82,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON+WS_TABSTOP+WS_GROUP
    dialogitem 'BUTTON','I&nformation',ID_ICONINFORMATION,20,95,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON
    dialogitem 'BUTTON','&Question',ID_ICONQUESTION,20,108,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON
    dialogitem 'BUTTON','&Warning',ID_ICONWARNING,20,121,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON
    dialogitem 'BUTTON','&Style',-1,100,70,80,70,WS_VISIBLE+BS_GROUPBOX
    dialogitem 'BUTTON','&Top most',ID_TOPMOST,110,82,60,13,WS_VISIBLE+WS_TABSTOP+BS_AUTOCHECKBOX
    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
  enddialog
    


BTW "EM_SETSEL,-1,0" selects no text with cursor at end.
Post 06 Jun 2011, 03:30
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 06 Jun 2011, 07:52


Yeaaaah, it works ! Razz Razz ... a round of beer for all!

the highlighting is removed, and the cursor at end ... perfect ! Very Happy

your example showed me where was my error!
the way to intercept the focus notification, here is my error.

I think JohnFound had already given the solution,
but I didn't know the right way to intercept the focus notification.

(I learned many things with this problem!)

thank you Alphonso
and again, thank you all for your help.
Code:
.command:     mov     eax,[wparam]
                shr     eax,16
              cmp     eax,EN_SETFOCUS 
            ;my 1st error : "EN_SETFOCUS" ... I did not know that!

            je      .setfocus
           .....

.setfocus:     invoke SendMessage,[lparam],EM_SETSEL,-1,0 
         ;my 2nd error : "[lparam]" ... obviously!!

                jmp .processed
    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 06 Jun 2011, 07:52
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1693
Location: Toronto, Canada
AsmGuru62 06 Jun 2011, 15:32
In cases like this (to override default Windows behavior) the custom message must be POSTED (not SENT) to your own dialog (or other HWND) procedure. This message will come when all focuses are set, dialog window is painted, etc. and dialog just waits for user input. Message (say WM_USER+4000h) should be posted as a last statement in WM_INITDIALOG case. In response to this message - use EM_SETSEL - it should then work.
Post 06 Jun 2011, 15:32
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.