flat assembler
Message board for the users of flat assembler.

Index > Windows > Can't get spin control working\visible

Author
Thread Post new topic Reply to topic
moriman



Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman
Hi,

The follow test app has three edit windows, two for entering numbers and one for displaying the result. The first two should have an attached UPDOWN_CLASS 'spin' control. I have linked to comctrl.dll and used InitCommonControls but can't get them to display Confused
Both calls to CreateWindowEx to set up these two controls fail (eax=0).

Any help would be greatly appreciated Very Happy

btw, the two controls in question are at lines 75 and 80 Wink
Code:
format PE GUI 4.0
include '%fasminc%\win32a.inc'

entry start

section '.data' data readable writeable
        FirstEditId     =   256
        SecondEditId    =   257
        ResultEditId    =   258
        ButtonId        =   259
        FirstUpDownId   =   260
        AddRadioId      =   261
        SubRadioId      =   262
        GroupBoxId      =   263
        FirstUpDownId   =   264
        SecondUpDownId  =   265
        First           dd 0
        Second          dd 0
        Result          dd 0
        wndMsg          MSG
        StaticCls       db 'STATIC', 0
        ButtonCls       db 'BUTTON', 0
        UpDownCls       db 'UPDOWN_CLASS', 0
        EditCls         db 'EDIT', 0
        Static1Text     db '0', 0
        Button1Text     db 'Push Me', 0
        UpDown1Text     db 'Spin1', 0
        UpDown2Text     db 'Spin2', 0
        AddText         db 'Add', 0
        SubText         db 'Sub', 0
        CalculateText   db 'Calculate', 0
        wndClsName      db 'TestCls', 0
        WindowHandle    dd ?
        InstanceHandle  dd ?
        MainWinText     db 'UPDOWN_CLASS Test', 0
        wc              WNDCLASS CS_HREDRAW+CS_VREDRAW+CS_DBLCLKS,DialogProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,wndClsName

section '.code' code readable executable
start:
        invoke  GetModuleHandle,NULL
                mov     [InstanceHandle],eax
                invoke  InitCommonControls
        invoke  RegisterClass,wc
        invoke  CreateWindowEx, 0,wndClsName,MainWinText,WS_MINIMIZEBOX+WS_VISIBLE+WS_MAXIMIZEBOX+WS_CAPTION+WS_BORDER+WS_SYSMENU,100, 100, 140, 200,NULL,NULL,[InstanceHandle],0
        mov     [WindowHandle], eax

wndMsgStart:
        invoke  GetMessage,wndMsg,NULL,0,0
                or   eax,eax
                je   wndMsgEnd
        invoke  TranslateMessage,wndMsg
        invoke  DispatchMessage,wndMsg
                jmp  wndMsgStart
wndMsgEnd:
        invoke  ExitProcess,0

proc DialogProc, hwndDlg, msg, wParam, lParam
                push ebx esi edi
                cmp     [msg], WM_CREATE
                je      .wmCREATE
                cmp     [msg], WM_COMMAND
                je      .wmCOMMAND
                cmp     [msg], WM_CLOSE
                je      .wmCLOSE
                cmp     [msg],WM_DESTROY
                je      .wmDESTROY

        .wmDEFAULT:
                invoke  DefWindowProc,[hwndDlg],[msg],[wParam],[lParam]
                jmp  .wmBYE

        .wmCREATE:
                invoke  CreateWindowEx, WS_EX_CLIENTEDGE,EditCls,NULL,WS_CHILD+WS_VISIBLE+ES_NUMBER+WS_TABSTOP+WS_GROUP,5, 5, 120, 20,[hwndDlg],FirstEditId,[InstanceHandle],0
                ;UPDOWN control below should be automatically 'buddied' to above edit control with UDS_AUTOBUDDY
                invoke  CreateWindowEx, 0,UpDownCls,UpDown1Text,UDS_AUTOBUDDY+UDS_ALIGNRIGHT+UDS_SETBUDDYINT+WS_CHILD+WS_VISIBLE+UDS_ARROWKEYS,105, 5, 20, 20,[hwndDlg],FirstUpDownId,[InstanceHandle],0
                invoke  SendDlgItemMessage, [hwndDlg], FirstUpDownId, UDM_SETRANGE, 0, 0064FF9Ch ;set range from -100 to 100

                invoke  CreateWindowEx, WS_EX_CLIENTEDGE,EditCls,NULL,WS_CHILD+WS_VISIBLE+ES_NUMBER+WS_TABSTOP,5, 35, 120, 20,[hwndDlg],SecondEditId,[InstanceHandle],0
                ;UPDOWN control below should be automatically 'buddied' to above edit control with UDS_AUTOBUDDY
                invoke  CreateWindowEx, 0,UpDownCls,UpDown2Text,UDS_AUTOBUDDY+UDS_ALIGNRIGHT+UDS_SETBUDDYINT+WS_CHILD+WS_VISIBLE+UDS_ARROWKEYS,105, 35, 20, 20,[hwndDlg],SecondUpDownId,[InstanceHandle],0
                invoke  SendDlgItemMessage, [hwndDlg], SecondUpDownId, UDM_SETRANGE, 0, 0064FF9Ch ;set range from -100 to 100

                invoke  CreateWindowEx, WS_EX_CLIENTEDGE,EditCls,NULL,WS_CHILD+WS_VISIBLE+ES_NUMBER+ES_READONLY,5, 65, 120, 20,[hwndDlg],ResultEditId,[InstanceHandle],0
                invoke  CreateWindowEx, 0,ButtonCls,AddText,WS_CHILD+WS_VISIBLE+WS_TABSTOP+BS_AUTORADIOBUTTON,10, 105, 50, 14,[hwndDlg],AddRadioId,[InstanceHandle],0
                invoke  CreateWindowEx, 0,ButtonCls,SubText,WS_CHILD+WS_VISIBLE+WS_TABSTOP+BS_AUTORADIOBUTTON,65, 105, 50, 14,[hwndDlg],SubRadioId,[InstanceHandle],0
                invoke  CreateWindowEx, 0,ButtonCls,CalculateText,WS_CHILD+WS_VISIBLE+WS_TABSTOP,5, 130, 120, 30,[hwndDlg],ButtonId,[InstanceHandle],0
                invoke  CreateWindowEx, 0,ButtonCls,NULL,WS_CHILD+WS_VISIBLE+BS_GROUPBOX,5, 85, 120, 40,[hwndDlg],GroupBoxId,[InstanceHandle],0
                invoke  CheckDlgButton, [hwndDlg], AddRadioId, BST_CHECKED
                jmp     .wmBYE

        .wmCOMMAND:
                cmp     [wParam], BN_CLICKED shl 16 + ButtonId
                je      .wmCOMMAND_ButtonID
                jmp     .wmBYE

            .wmCOMMAND_ButtonID:
                invoke  GetDlgItemInt, [hwndDlg], FirstEditId, 0, FALSE
                mov     [First], eax
                invoke  GetDlgItemInt, [hwndDlg], SecondEditId, 0, FALSE
                mov     [Second], eax
                invoke  IsDlgButtonChecked, [hwndDlg], AddRadioId
                cmp     eax, BST_CHECKED
                jne     .DoSubtract
            .DoAdd:
                mov     eax, [First]
                add     eax, [Second]
                jmp     @f
            .DoSubtract:
                mov     eax, [First]
                sub     eax, [Second]
            @@:
                mov     [Result], eax
                invoke  SetDlgItemInt, [hwndDlg], ResultEditId, [Result], TRUE
                jmp     .wmBYE

            .wmCLOSE:
                invoke  DestroyWindow,[hwndDlg]
                jmp     .wmBYE

            .wmDESTROY:
                invoke  PostQuitMessage,0

            .wmBYE:
                pop  edi esi ebx
                ret
endp

section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
        user32,  'USER32.DLL',\
        gdi32,   'GDI32.DLL',\
        comdlg32,'COMDLG32.DLL',\
        advapi32,'ADVAPI32.DLL',\
        comctl32,'COMCTL32.DLL'

include '%fasminc%\apia\Kernel32.inc'
include '%fasminc%\apia\User32.inc'
include '%fasminc%\apia\Gdi32.inc'
include '%fasminc%\apia\Comdlg32.inc'
include '%fasminc%\apia\Advapi32.inc'
include '%fasminc%\apia\Comctl32.inc'    
Post 08 May 2006, 17:18
View user's profile Send private message Reply with quote
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey
You are not using the correct classname for the spin-control. It is actually
"msctls_updown32". The info in the api docs is wrong. Iczelion's tutorial on common controls has a correct list.

http://win32asm.cjb.net/

A tip for finding errors.

If you run GetLastError after CreateWindowEx in this case it returns 57f which in decimal is 1407. Looking up the system error codes we find:

ERROR_CANNOT_FIND_WND_CLASS
1407

_________________
silkodyssey
Post 08 May 2006, 17:45
View user's profile Send private message MSN Messenger Reply with quote
moriman



Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman
silkodyssey wrote:
You are not using the correct classname for the spin-control. It is actually
"msctls_updown32". The info in the api docs is wrong. Iczelion's tutorial on common controls has a correct list.


Many thanks silkodyssey, that fixed it Very Happy
It was actually code from a website tutorial of a supposedly work app Sad
Here's their code...
Code:
CreateWindow(UPDOWN_CLASS,
                   "Spin1",
                   UDS_AUTOBUDDY | UDS_ALIGNRIGHT |
                   UDS_SETBUDDYINT | WS_CHILD | WS_VISIBLE |
                   UDS_ARROWKEYS,
                   105, 5, 20, 20,
                   hwndDlg,
                   (HMENU )FirstUpDownId,
                   InstanceHandle,
                   0);
No surprise here. UPDOWN_CLASS is the name for an predefined wnd-class for updown controls.    


So I assumed it was something I was doing wrong.

Quote:

A tip for finding errors.

If you run GetLastError after CreateWindowEx in this case it returns 57f which in decimal is 1407. Looking up the system error codes we find:

ERROR_CANNOT_FIND_WND_CLASS
1407


Strange, I actually tried this and was getting an error code of 0 (Everything OK). Oh! well lol

Thx again Wink
Post 08 May 2006, 19:06
View user's profile Send private message Reply with quote
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey
Ah I see what's going on now.

Code:
 

CommCtrl.h: 

//====== UPDOWN CONTROL =======================================================

#ifndef NOUPDOWN

#ifdef _WIN32

#define UPDOWN_CLASSA           "msctls_updown32"
#define UPDOWN_CLASSW           L"msctls_updown32"

#ifdef UNICODE
#define  UPDOWN_CLASS           UPDOWN_CLASSW
#else
#define  UPDOWN_CLASS           UPDOWN_CLASSA
#endif

#else
#define UPDOWN_CLASS            "msctls_updown"
#endif
    


UPDOWN_CLASS is a constant or C macro thing Very Happy

_________________
silkodyssey
Post 08 May 2006, 19:45
View user's profile Send private message MSN Messenger Reply with quote
moriman



Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman
Right, thx again, I'll know where to check in future Very Happy
Post 08 May 2006, 20:09
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.

Powered by rwasa.