flat assembler
Message board for the users of flat assembler.

Index > Windows > InitCommonControls

Author
Thread Post new topic Reply to topic
kasake36



Joined: 28 Mar 2006
Posts: 68
kasake36
Hello! I want to create a Tab-Control. For that, the WIN32API.HLP-docu says that before a tab-control can be created with CREATE_WINDOW_EX, the programmer should check if the common-control-dll is loaded. This is done by calling the InitCommonControls function.

So when i call InitCommonControls, the executable crashes, when i do not call InitCommonControls, no tab-control is created. InitCommonControls crashes everytime and everywhere i call it...

I attached my code; as you will notice i have copied some snippets out of the "Tabbed"-example http://board.flatassembler.net/topic.php?t=2380.
Is it possible to create a tab-control in the resource-section? If yes, how is the tab-control defined then?

Thank you very much!

Code:

format PE GUI 4.0
entry start

include '%fasmwinc%win32a.inc'

;===============================================================================
section '.data' data readable writeable
;===============================================================================

IDD_MAIN        = 100

struct TC_ITEM
        imask          dd  0
        lpReserved1    dd  0
        lpReserved2    dd  0
        pszText        dd  0
        cchTextMax     dd  0
        iImage         dd  0
        lParam         dd  0
ends

tci     TC_ITEM
wc      WNDCLASS
flags   dd      ?
tab     dd      ?
caption rb      40h
message rb      100h
hInst   dd      ?
cl_tab  db      'SysTabControl32',0
cl_main db      'TISCHPRO',0
fini    db      'TabControl konnte nicht erstellt werden',0


;===============================================================================
section '.code' code readable executable
;===============================================================================

start:  invoke  GetModuleHandle,0
        mov     [hInst],eax
        mov     [wc.hInstance],eax
        mov     [wc.hIcon],NULL
        mov     [wc.hCursor],NULL
        mov     [wc.style],0
        mov     [wc.hbrBackground],COLOR_WINDOW
        mov     [wc.lpfnWndProc],MainDialogProc
        mov     [wc.cbClsExtra],0
        mov     [wc.cbWndExtra],0
        mov     [wc.lpszMenuName],0
        mov     [wc.lpszClassName],cl_main
        invoke  RegisterClass,wc
        invoke  DialogBoxParam,[hInst],IDD_MAIN,HWND_DESKTOP,\
                MainDialogProc,0
        or      eax,eax
        jz      exit
exit:   invoke  ExitProcess,0

proc MainDialogProc 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:
        ;call    InitCommonControls
        invoke  CreateWindowEx,0,cl_tab,NULL,\
                WS_CHILD+WS_VISIBLE,0,0,100,200,[hwnddlg],NULL,[hInst],NULL
        cmp     eax,NULL
        je      failed
        mov     [tab],eax
        mov     [tci.imask],TCIF_TEXT+TCIF_IMAGE
        mov     [tci.pszText],cl_main
        mov     [tci.iImage],-1
        lea     ebx,[tci]
        invoke  SendMessage,eax,TCM_INSERTITEM,0,ebx
        mov     [tci.pszText],cl_main
        invoke  SendMessage,[tab],TCM_INSERTITEM,1,ebx
        jmp     finish
    failed:
        invoke  MessageBox,[hwnddlg],fini,cl_main,MB_ICONERROR+MB_OK
    wmcommand:
        jmp     processed
    wmclose:
        invoke  EndDialog,[hwnddlg],0
    processed:
        mov     eax,1
    finish:
        pop     edi esi ebx
        ret
endp


;===============================================================================
section '.idata' import data readable writeable
;===============================================================================

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

import      kernel,\
            GetModuleHandle,'GetModuleHandleA',\
            ExitProcess,'ExitProcess'
import      user,\
            CreateWindowEx,'CreateWindowExA',\
            DialogBoxParam,'DialogBoxParamA',\
            GetDlgItemText,'GetDlgItemTextA',\
            IsDlgButtonChecked,'IsDlgButtonChecked',\
            MessageBox,'MessageBoxA',\
            RegisterClass,'RegisterClassA',\
            SendMessage,'SendMessageA',\
            EndDialog,'EndDialog'
import      comctl32,\
            InitCommonControls,'InitCommonControls'


;===============================================================================
section '.rsrc' resource data readable
;===============================================================================

directory   RT_DIALOG,dialogs

resource    dialogs,\
            IDD_MAIN,LANG_GERMAN+SUBLANG_DEFAULT,aka
resource    versions,\
            1,LANG_GERMAN+SUBLANG_DEFAULT,vinfo

dialog      aka,'TISCHPRO',0,0,390,275,\
            WS_CAPTION+WS_TABSTOP+WS_SYSMENU or\
            WS_MAXIMIZEBOX+DS_CENTER
;            WS_CAPTION+WS_POPUP+WS_SYSMENU+WS_TABSTOP+DS_MODALFRAME+DS_CENTER
;dialogitem  'STATIC','&Caption',-1,10,10,70,8,WS_VISIBLE
;dialogitem  'SysTabControl32',NULL,1000,\
;            3,3,361,216,WS_VISIBLE+WS_TABSTOP
enddialog

versioninfo vinfo,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,\
            LANG_GERMAN+SUBLANG_DEFAULT,0,\
            'FileDescription','Arbeitskarten-Verwaltung',\
            'LegalCopyright','2006 by Kasake36',\
            'FileVersion','0.01',\
            'ProductVersion','0.1'
    
Post 19 Apr 2006, 11:33
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
do it:
Code:
; not call and not in wm_init
start:
invoke InitCommonControls
    


ps. also you can create tabbed control in reseditor (class is "SysTabControl32")
Post 19 Apr 2006, 12:14
View user's profile Send private message Reply with quote
kasake36



Joined: 28 Mar 2006
Posts: 68
kasake36
ARGH! ARGH! ARGH! I could have sworn i've tested it that way! But probably used "call" instead of invoke. Thank you a lot!

Does it make a difference if i invoke InitCommonControls at the very beginning of the program instead of just before CreateWindowEx?

Ah, now i know what the class-field in the reseditor is for. I just installed the Resource-Editor that "ships" with lcc-win32, which looks pretty good!
Post 19 Apr 2006, 12:35
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
Quote:
Does it make a difference if i invoke InitCommonControls at the very beginning of the program instead of just before CreateWindowEx?


i think you can call InitCommonControls everywhere (it used just for linking comclt32 import to executalbe, for more options see InitCommonControlsEx)
Post 20 Apr 2006, 16:41
View user's profile Send private message Reply with quote
kasake36



Joined: 28 Mar 2006
Posts: 68
kasake36
Ok. I read the Win32API-Help about TabControls and it says that InitCommonControls has to be called before a TabControl is created so i expect it can be called at every position. But i was not sure when you wrote i had to call it as first command after the start label, because it worked and my "call" before the TabControl creation didn't work.
Thank you for the help.
Post 20 Apr 2006, 17:41
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Well, you were using a dialog with common controls, and expecting InitCommonControls to work in the initdialog? Eek. On a lot of windows versions, InitCommonControls is just a "dummy" that does nothing but make sure the DLL file is linked in. but still.

Best practise is to initialize the "subsystems" (common controls, winsock, COM) you need early on. That way, you can check for errors and not have to bomb out in the middle of everything...
Post 23 Apr 2006, 10:04
View user's profile Send private message Visit poster's website Reply with quote
kasake36



Joined: 28 Mar 2006
Posts: 68
kasake36
? Why shouldn't it work to initalise a subsystem in the wminitdialog? To what problems this could lead in older than WinXP Systems for example?
Post 24 Apr 2006, 08:08
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
I'm not saying it will necessarily lead to problems, just that it's cleaner initializing subsystems at program start...

But WM_INITIDIALOG / WM_CREATE are somewhat bad places to put initialization. Consider you need to call InitMyWidget before you can use MyWidget controls. You make a dialog with some MyWidgets, and put the InitMyWidget call in WM_INITDIALOG. Obviously this will fail, windows cannot create the dialog because the MyWidget class hasn't been registered, and thus your dialog proc won't be called.

I've seen people run amok with "we're gonna localize the use of subsystems". The end result was Winsock init/shutdown code for basically every time a socket call was necessary - very ugly. Better centralize subsystem init/shutdown.
Post 24 Apr 2006, 09:11
View user's profile Send private message Visit poster's website Reply with quote
kasake36



Joined: 28 Mar 2006
Posts: 68
kasake36
Although i stood up with the left leg first i believe i see the point. Thx!
Post 24 Apr 2006, 09:23
View user's profile Send private message 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.