The MASM Forum

General => The Campus => Topic started by: ragdog on November 06, 2016, 12:41:36 AM

Title: TabControl
Post by: ragdog on November 06, 2016, 12:41:36 AM
Hello Community

I´m confused why have a Tabcontrol (Tab dialog) after clicking buttons both a focus?
And how i can set the focus on any tab page on a edit control on start my program?

I have try Setfocus but not working  :shock:

http://fs5.directupload.net/images/161105/n4zd685l.png

Regards,

ps: I use Radasm Tabcontrol template
Title: Re: TabControl
Post by: HSE on November 06, 2016, 11:15:44 AM
Have both buttons the same ID?
Title: Re: TabControl
Post by: ragdog on November 06, 2016, 07:22:39 PM
Hi

QuoteHave both buttons the same ID?

#ifndef IDOK
  #define IDOK 1
#endif
#ifndef IDCANCEL
  #define IDCANCEL 2
#endif

No have no same id´s with a normal dialog have i no problem only is this dialog in a tabcontrol
Title: Re: TabControl
Post by: ragdog on November 07, 2016, 06:32:27 AM
This problem is only if set Ws_child by a tabbed dialog  :icon_eek:
I have look on other examples but not any solution found.

Regards,
Title: Re: TabControl
Post by: ragdog on November 19, 2016, 12:33:35 AM
Hello

I have looking for a soulution.
Have not any an idea?



.386
.model flat,stdcall
option casemap:none

include dd.inc
.const

IDD_TABTEST equ 1000
IDC_TAB1 equ 1001
IDD_TAB1 equ 2000
IDD_TAB2 equ 3000
IDD_TAB3 equ 4000

.data

TabTitle1       db "Tab1",0
TabTitle2       db "Tab2",0
TabTitle3       db "Tab3",0

.data?

hInstance dd ?
hTab dd ?
hTabDlg dd 4 dup(?)
SelTab dd ?
.code

start:

invoke GetModuleHandle, NULL
mov hInstance, eax
invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_TABTEST,NULL,addr DlgProc,NULL
invoke ExitProcess,eax

Tab1Proc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

.if uMsg==WM_INITDIALOG

.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

Tab1Proc endp

Tab2Proc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

.if uMsg==WM_INITDIALOG
.else
mov eax,FALSE
ret
.endif
mov eax,0
ret

Tab2Proc endp

Tab3Proc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

.if uMsg==WM_INITDIALOG

.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

Tab3Proc endp

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ts:TC_ITEM

mov eax,uMsg
.if eax==WM_COMMAND
mov eax,wParam
mov edx,eax
and eax,0FFFFh
shr edx,16
.if edx==BN_CLICKED
.if eax==IDCANCEL
invoke SendMessage,hWin,WM_CLOSE,0,0
.elseif eax==IDOK
invoke SendMessage,hWin,WM_CLOSE,0,0
.endif
.endif


      .elseif uMsg == WM_NOTIFY
            mov     eax, lParam                         ; lParam is a pointer to a NMHDR Struct
            mov     eax, (NMHDR ptr [eax]).code         ; Check for TCN_SELCHANGE notify message
         .if eax == TCN_SELCHANGE
               mov     ebx, SelTab                   ; Previous selected Tab
               mov     eax, hTabDlg[ebx*4]             ; Extract previous Tabs handle
              push     eax
            INVOKE     SendMessage, hTab, TCM_GETCURSEL, 0, 0  ; New selected Tab
               mov     SelTab, eax                   ; Save the Tab ID
               mov     ebx, hTabDlg[eax*4]             ; Extract new Tabs handle
            INVOKE     ShowWindow, ebx, SW_SHOWDEFAULT  ; Show its window
               pop     eax
            INVOKE     ShowWindow, eax, SW_HIDE         ; Hide previous Tab window, prevents flicker if done after
            INVOKE     SetFocus, ebx
.endif


.elseif eax==WM_INITDIALOG
;Create the tabs
invoke GetDlgItem,hWin,IDC_TAB1
mov hTab,eax
mov ts.imask,TCIF_TEXT
mov ts.lpReserved1,0
mov ts.lpReserved2,0
mov ts.iImage,-1
mov ts.lParam,0
mov ts.pszText,offset TabTitle1
mov ts.cchTextMax,sizeof TabTitle1
invoke SendMessage,hTab,TCM_INSERTITEM,0,addr ts
mov ts.pszText,offset TabTitle2
mov ts.cchTextMax,sizeof TabTitle2
invoke SendMessage,hTab,TCM_INSERTITEM,1,addr ts
mov ts.pszText,offset TabTitle3
mov ts.cchTextMax,sizeof TabTitle3
invoke SendMessage,hTab,TCM_INSERTITEM,2,addr ts
;Create the tab dialogs
invoke CreateDialogParam,hInstance,IDD_TAB1,hTab,addr Tab1Proc,0
mov hTabDlg,eax
;
invoke CreateDialogParam,hInstance,IDD_TAB2,hTab,addr Tab2Proc,0
mov hTabDlg[4],eax
;
invoke CreateDialogParam,hInstance,IDD_TAB3,hTab,addr Tab3Proc,0
mov hTabDlg[8],eax
invoke ShowWindow, hTabDlg,SW_SHOWDEFAULT
invoke SetFocus, hTabDlg

.elseif eax==WM_CLOSE
invoke EndDialog,hWin,NULL
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

DlgProc endp




#define IDC_TAB 1001
#define IDC_TAB1EDT1 2001
#define IDC_STCTAB1 2002
#define IDD_TABTEST 1000
#define IDC_BTN3 1002
#define IDD_TAB1 2000
#define IDC_BTN1 2003
#define IDC_BTN2 2004
#define IDD_TAB2 3000
#define IDC_TAB2EDT1 3001
#define IDC_TAB2EDT2 3002
#define IDD_TAB3 4000
#define IDC_TAB3EDT1 4001
#define IDC_TAB3EDT2 4002
#define IDC_TAB3EDT3 4003
#define IDR_XPMANIFEST1 1

IDD_TABTEST DIALOGEX 6,6,408,243
CAPTION "Tab Demo"
FONT 8,"MS Sans Serif",0,0,0
STYLE 0x16C80000
EXSTYLE 0x00000080
BEGIN
  CONTROL "IDC_TAB",1001,"SysTabControl32",0x52000440,54,12,233,145
  CONTROL "IDC_BTN",IDC_BTN3,"Button",0x50010000,63,183,132,39
END

IDD_TAB1 DIALOGEX 1,13,190,87
FONT 8,"MS Sans Serif",0,0,0
STYLE 0x56000000
BEGIN
  CONTROL "a",IDC_BTN1,"Button",0x50010080,42,33,114,24
  CONTROL "b",IDC_BTN2,"Button",0x50010000,42,60,114,18
END

IDD_TAB2 DIALOGEX 1,13,190,87
FONT 8,"MS Sans Serif",0,0,0
STYLE NOT 0x10000000|0x46000000
BEGIN
  CONTROL "",IDC_TAB2EDT1,"Edit",0x50010000,3,15,186,13,0x00000200
  CONTROL "Tab 2",-1,"Static",0x50020100,3,3,102,9
  CONTROL "",IDC_TAB2EDT2,"Edit",0x50010000,3,42,186,13,0x00000200
END

IDD_TAB3 DIALOGEX 1,13,190,87
FONT 8,"MS Sans Serif",0,0,0
STYLE NOT 0x10000000|0x46000000
BEGIN
  CONTROL "Tab 3",-1,"Static",0x50020100,3,3,102,9
  CONTROL "",IDC_TAB3EDT1,"Edit",0x50010000,1,16,186,13,0x00000200
  CONTROL "",IDC_TAB3EDT2,"Edit",0x50010000,1,33,186,13,0x00000200
  CONTROL "",IDC_TAB3EDT3,"Edit",0x50010000,1,49,186,13,0x00000200
END


Greets,
Title: Re: TabControl
Post by: jj2007 on November 19, 2016, 01:03:38 AM
If you want help, post a complete project.
Tmp_File.asm(6) : Error A2106: Cannot open file: "dd.inc" [ENOENT]
Tmp_File.asm(31) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(33) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(34) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(35) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(37) : Error A2102: Symbol not defined : HWND
Tmp_File.asm(50) : Error A2102: Symbol not defined : HWND
Tmp_File.asm(62) : Error A2102: Symbol not defined : HWND
Tmp_File.asm(75) : Error A2102: Symbol not defined : HWND
Tmp_File.asm(76) : Error A2102: Symbol not defined : TC_ITEM
Tmp_File.asm(86) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(88) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(100) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(103) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(105) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(106) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(112) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(115) : Warning A4073: Size not specified, assuming: BYTE
Tmp_File.asm(116) : Warning A4073: Size not specified, assuming: BYTE
Tmp_File.asm(117) : Warning A4073: Size not specified, assuming: DWORD
Tmp_File.asm(118) : Warning A4073: Size not specified, assuming: BYTE
Tmp_File.asm(120) : Warning A4073: Size not specified, assuming: BYTE
Tmp_File.asm(121) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(123) : Warning A4073: Size not specified, assuming: BYTE
Tmp_File.asm(124) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(126) : Warning A4073: Size not specified, assuming: BYTE
Tmp_File.asm(127) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(129) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(132) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(135) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(137) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(138) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(141) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm: 151 lines, 1 passes, 0 ms, 7 warnings, 26 errors
Title: Re: TabControl
Post by: ragdog on November 19, 2016, 01:24:04 AM
Hello Jochen

Here is the complet project example but is radasm 3 project.

The buttons have the style 50010000 if i run or click both button is the buttons style 50010001  BS_DEFPUSHBUTTON
But why

I have look on other tools what uses Tabcontrols and Buttons but it have it not after push 2 buttons

Greets
Title: Re: TabControl
Post by: ragdog on November 19, 2016, 03:03:22 AM
Hello

I think i Have a soltion


Quote
japheth:

> STYLE 0xD0000000+WS_CHILD+WS_POPUP

WS_CHILD and WS_POPUP should not be declared both (I dont know for sure, but they may even be mutually exclusive). And IIRC you must also define DS_CONTROL:

> STYLE 0xD0000000+WS_CHILD+DS_CONTROL

Title: Re: TabControl
Post by: jj2007 on November 19, 2016, 04:01:11 AM
Quote from: ragdog on November 19, 2016, 03:03:22 AM
japheth:
> STYLE 0xD0000000+WS_CHILD+WS_POPUP

I don't see these style declarations in your code, but in any case, it's a HORRIBLE habit to use the "+" sign to combine styles. I cannot imagine that Japheth ever used such a declaration.

In case you don't understand:include \masm32\MasmBasic\MasmBasic.inc ; download
  Init
  xd0=0xD0000000
  xd1=0xD0000000+WS_CHILD
  xd2=0xD0000000+WS_POPUP
  xd3=0xD0000000+WS_CHILD+WS_POPUP
  xdOr=0xD0000000 or WS_CHILD or WS_POPUP
  deb 4, "test", x:WS_CHILD, x:WS_POPUP, x:DS_CONTROL, x:xd0, x:xd1, x:xd2, x:xd3, x:xdOr
EndOfCode


Output:test
x:WS_CHILD      40000000
x:WS_POPUP      80000000
x:DS_CONTROL    00000400
x:xd0           D0000000
x:xd1           10000000
x:xd2           50000000
x:xd3           90000000
x:xdOr          D0000000


xd3 is the one you are attributing to Japheth.
Title: Re: TabControl
Post by: ragdog on November 19, 2016, 04:27:45 AM
QuoteI don't see these style declarations in your code

I found this solution later, After I had post the attach.

The SysTabControl must have the StyleEx WS_EX_CONTROLPARENT and Child dialog STYLE 0xD0000000+WS_CHILD+DS_CONTROL.
I have look on Cpp projects on github and it same  :t

Here is the project
Title: Re: TabControl
Post by: jj2007 on November 19, 2016, 04:39:42 AM
STYLE 0xD0000000+WS_CHILD+DS_CONTROL is a no-no in programming :eusa_naughty:

If you have any doubt about that, have a look at WS_OVERLAPPEDWINDOW

And, please, post a link to the site where you saw Japheth using a plus sign for combining styles.
Title: Re: TabControl
Post by: ragdog on November 19, 2016, 05:56:53 AM
http://www.masmforum.com/board/index.php?PHPSESSID=8d46cd4ecb1688be429ab49694ec53e6&topic=5744.0
Title: Re: TabControl
Post by: jj2007 on November 19, 2016, 09:21:13 AM
Oh well...

Style constants in Windows have to be or-ed, not added. You may be lucky that adding works, too, simply because many constants have exactly one bit set. But, for example
0xD0000000  + WS_CHILD  + WS_POPUP = 90000000
0xD0000000 or WS_CHILD or WS_POPUP = D0000000


have completely different values, and only one is valid - the second one. Provided, of course, the 0xD0000000 is a valid constant documented somewhere at MSDN - they usually have names ::)
Title: Re: TabControl
Post by: ragdog on November 19, 2016, 11:03:04 AM
Quotethe 0xD0000000 is a valid constant documented somewhere at MSDN - they usually have names

Yes i have allready search for the name but i cannot find.
Title: Re: TabControl
Post by: jj2007 on November 19, 2016, 11:45:07 AM
The name of the "constant" 0D0000000h is WS_CHILD OR WS_POPUP or WS_VISIBLE

And btw, MSDN says WS_CHILD cannot be used with the WS_POPUP style (https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx) 8)
Title: Re: TabControl
Post by: HSE on November 19, 2016, 09:44:01 PM
How could be a window a child and a popup at same time? Not posible  :biggrin:
Sorry not to have an unzip in this phone. :(
Title: Re: TabControl
Post by: Ding on May 26, 2020, 01:06:14 PM
Is this the common way to use tab control ? through dialogs ?
is there any alternatives , if so is there any examples ?

Ding

Title: Re: TabControl
Post by: jj2007 on May 26, 2020, 01:52:28 PM
I suggest a forum search (http://masm32.com/board/index.php?action=search;advanced;search=) for SysTabControl32 createwindowex. Check also the old forum (http://www.masmforum.com/board/index.php?action=search;advanced)

Btw resuscitating over 3 years old threads is not a good habit :cool:
Title: Re: TabControl
Post by: Ding on May 26, 2020, 02:24:49 PM
I'll keep that in mind  :thumbsup:
Thanks for helping me .
Title: Re: TabControl
Post by: jj2007 on May 26, 2020, 02:37:59 PM
There is also \Masm32\examples\Bill_Cravener\tabs\tabs.asm
Title: Re: TabControl
Post by: Ding on May 26, 2020, 03:30:21 PM
Amazing ! thanks jj  :thumbsup: I really appreciate your help .
Title: Re: TabControl
Post by: Mikl__ on May 26, 2020, 04:38:50 PM
Hi, Ding
This text is in Russian, but via the help of a Google translator you can easily translate the text into English or Chinese