Author Topic: WS_TABSTOP for Dialogs created with CreateDialogParam  (Read 3210 times)

2B||!2B

  • Member
  • **
  • Posts: 85
WS_TABSTOP for Dialogs created with CreateDialogParam
« on: November 20, 2018, 04:24:27 PM »
Hi,

I need to create a modaless dialog box using CreateDialogParam api but i can not get the WS_TABSTOP to work on this newly created dialog.
This modaless dialog box does not have WS_CHILD style set. If i create it with DialogBoxParam, the WS_TABSTOP will work but i do not want to block the execution of my application.

My main dialog is created with DialogBoxParam using windows default message loop.

Any ideas?



aw27

  • Guest
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #1 on: November 20, 2018, 06:17:26 PM »
Call IsDialogMessage for modaless modeless dialogs.

2B||!2B

  • Member
  • **
  • Posts: 85
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #2 on: November 20, 2018, 07:29:22 PM »
Hi AW,

Nice way. I think it must be used this way for Modeless dialog boxes that are created with CreateDialogParam
are there any benefits from creating the Main dialog using CreateDialogParam and then add our own message loop with IsDialogMessage?
What is the difference between using this method and using DialogBoxParam (For the parent)?

BTW, for anyone who might have the same issue, here is a nice trick from Microsoft on how to call the IsDialogMessage for multiple modeless dialogs
The link was removed but thanks to archive.org  :icon_mrgreen:

https://web.archive.org/web/20100826033540/http://support.microsoft.com/kb/71450

The trick is to make a global variable that will hold he currently active window handle. And then, the IsDialogMessage will use this handle. Because only one active window can be set at time, the IsDialogMessage will switch for the current active window automatically once you change the global variable for the current active window handle in response to WM_ACTIVATE in each modaless dialog.

aw27

  • Guest
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #3 on: November 20, 2018, 10:57:57 PM »
What is the difference between using this method and using DialogBoxParam (For the parent)?
DialogBoxParam is for modal dialog boxes - this is clearly mentioned in the online reference from Microsoft. So, if you changed your mind, use it.

2B||!2B

  • Member
  • **
  • Posts: 85
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #4 on: November 21, 2018, 01:10:49 PM »
AW,

Thanks for your help.

I have one more question:

If i want to get WM_KEYDOWN/WM_KEYUP messages in my modaless dialog box how would i do so?

Because the IsDialogMessage/TranslateMessage convert them to WM_COMMAND and this message does not catch all keystrokes

I managed to add a filter before passing the message to translation with the above API's and then examine the message and if the message is WM_KEYDOWN/WM_KEYUP, i will pass it to the corresponding window directly using SendMessage and skip the message translation part.

Example for message loop:

Code: [Select]
    .WHILE TRUE
Skip:
        invoke GetMessage, addr msg, NULL, 0, 0
       
        .BREAK .if !eax
        .if msg.message == WM_KEYDOWN || msg.message == WM_KEYUP
       
        invoke SendMessage,CurrentActiveDialog,msg.message,msg.wParam,msg.lParam
        JMP Skip
        .endif
        invoke IsDialogMessage, CurrentActiveDialog, addr msg
       
        .if EAX == 0

        Invoke TranslateMessage, addr msg
            Invoke DispatchMessage, addr msg
        .endif
       
    .ENDW

Is there something wrong by doing this?

Because i want to catch all pressed keystrokes, if i don't look for WM_KEYDOWN/WM_KEYUP, the keystroke will come as a WM_COMMAND but the problem here is that this message does not provide all keystrokes (for example, the CTRL or SHIFT are never delivered)


aw27

  • Guest
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #5 on: November 21, 2018, 07:05:40 PM »
I would suggest you to start a new thread for each new question because I rather prefer to answer only the questions I freely choose to.

Only for this one, you can't forget that a modeless dialog has its own message loop and certain types of messages, including WM_KEYDOWN and WM_KEYUP are directed to that message loop whenever the dialog has the focus.

2B||!2B

  • Member
  • **
  • Posts: 85
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #6 on: November 23, 2018, 06:52:28 AM »
I would suggest you to start a new thread for each new question because I rather prefer to answer only the questions I freely choose to.

Fair enough.

For the last code i posted about fetching WM_KEYDOWN, it is not recommended to do so because that will break any chars from being entered into an edit control. You have to add a check and not skip translating WM_KEYDOWN if an edit control has the focus.

jj2007

  • Member
  • *****
  • Posts: 11587
  • Assembler is fun ;-)
    • MasmBasic
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #7 on: November 23, 2018, 07:55:50 AM »
fetching WM_KEYDOWN, it is not recommended to do so because that will break any chars from being entered into an edit control.

Who says that?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8549
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #8 on: November 23, 2018, 10:22:33 AM »
Its usually the case that an edit or richedit control uses its own subclass procedure to process messages which you either allow to be default processed OR modified OR thrown away if it is used as a trigger for an event.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

2B||!2B

  • Member
  • **
  • Posts: 85
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #9 on: November 23, 2018, 01:36:51 PM »
fetching WM_KEYDOWN, it is not recommended to do so because that will break any chars from being entered into an edit control.

Who says that?

Try it jj, you will see that the text won't be entered in an edit control.

Code: [Select]
.WHILE TRUE
Skip:
        invoke GetMessage, addr msg, NULL, 0, 0
       
        .BREAK .if !eax
        .if msg.message == WM_KEYDOWN || msg.message == WM_KEYUP
       
        invoke SendMessage,CurrentActiveDialog,msg.message,msg.wParam,msg.lParam
        JMP Skip
        .endif
        invoke IsDialogMessage, CurrentActiveDialog, addr msg
       
        .if EAX == 0

        Invoke TranslateMessage, addr msg
            Invoke DispatchMessage, addr msg
        .endif
       
    .ENDW

The weird thing is that this only happens if you use the default class dialog. If you create a custom class dialog (use RegisterClass etc) it will work and you will receive WM_KEYDOWN/WM_KEYUP without the need to trap the message after GetMessage. Maybe that's because we are providing the WndProc callback ourselves?


Its usually the case that an edit or richedit control uses its own subclass procedure to process messages which you either allow to be default processed OR modified OR thrown away if it is used as a trigger for an event.

That is true. If we subclass the control then we can get WM_KEYDOWN without problem.

jj2007

  • Member
  • *****
  • Posts: 11587
  • Assembler is fun ;-)
    • MasmBasic
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #10 on: November 23, 2018, 06:52:51 PM »
Code: [Select]
        .if msg.message == WM_KEYDOWN || msg.message == WM_KEYUP
        invoke SendMessage,CurrentActiveDialog,msg.message,msg.wParam,msg.lParam
        JMP Skip
        .endif

Since you didn't post a complete example, and since I am far too lazy to write one around your few lines, I can only guess what will happen if you check also for the wParam, and allow the SendMessage, CurrentActiveDialog only for wParams that you want to see processed.

2B||!2B

  • Member
  • **
  • Posts: 85
Re: WS_TABSTOP for Dialogs created with CreateDialogParam
« Reply #11 on: November 28, 2018, 03:17:30 PM »
Code: [Select]
        .if msg.message == WM_KEYDOWN || msg.message == WM_KEYUP
        invoke SendMessage,CurrentActiveDialog,msg.message,msg.wParam,msg.lParam
        JMP Skip
        .endif

Since you didn't post a complete example, and since I am far too lazy to write one around your few lines, I can only guess what will happen if you check also for the wParam, and allow the SendMessage, CurrentActiveDialog only for wParams that you want to see processed.

Hi jj,

Sorry for late reply.
The project is just a template using RadASM DialogAsMain.
I have found the issue. We must never use SendMessage to skip translate of message. Instead, we only need to skip IsDialogMessage on the desired message if we want to get the WM_KEYDOWN/WM_KEYUP instead of the traditional WM_COMMAND.

But if the message was generated for a control, it must have its own window callback.That is, subclassed. Otherwise, the system will just send you a WM_COMMAND contains the control's info whether you called IsDialogMessage on the message or not.
It works this way i have tested it.