flat assembler
Message board for the users of flat assembler.

Index > Windows > How chess works?

Author
Thread Post new topic Reply to topic
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
ImageImage

I need some minimal example how to load and replace two bitmaps on window using ComboBox...
Confused

Image

How to load one bmp from resource with different coordinats?

_________________
Memory=8388608
Post 02 Jan 2011, 18:48
View user's profile Send private message ICQ Number Reply with quote
asmhack



Joined: 01 Feb 2008
Posts: 431
asmhack
With visual basic actually, pretty easy.
Post 02 Jan 2011, 19:47
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
You have to read several topics from WinAPI help. I will give you only references.
Create combo box (CreateWindowEx) with CBS_HASSTRINGS style.
Then you have to fill the combo with the names of the bitmaps (CB_ADDSTRING). For every added item, you have to assign item data, related to the bitmap location - resource identifier, file name or other.
(CB_SETITEMDATA).
Then, in the parent window procedure, you have to track WM_COMMAND message for CBN_EDITCHANGE (or maybe CBN_SELENDOK) notification in order to determine when the used changed the combo box selection.
Then for the selected item use CB_GETITEMDATA and with retrieved data load the bitmap (from file, resources or whatever). See LoadImage, LoadBitmap functions.
Then you can draw the bitmap to some device context - See BitBlt and other bitmap functions.
About bitmap, there is another approach, if all bitmaps you need have the same size - you can create one ImageList, that contains all bitmaps and then use ImageList_Draw or ImageList_DrawEx to draw needed bitmap by index.
Post 03 Jan 2011, 07:13
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
1. I found a code for paint the gui. But this code is wrong. Under WinXP the window is down to transparently ghost. Where is troubles?

Code:
include '%fasm%/win32ax.inc'
section '.code' executable
start:
        xchg eax,ebx
        invoke CreateWindowEx,ebx,StaticClass,ebx,WS_VISIBLE+WS_OVERLAPPEDWINDOW+WS_CLIPCHILDREN,ebx,ebx,200,200,ebx,ebx,ebx,ebx
        mov edi,eax
        invoke CreateWindowEx,ebx,ComboBoxClass,ebx,WS_VISIBLE+WS_CHILD+CBS_DROPDOWNLIST+WS_CLIPSIBLINGS,10,10,150,20,eax,ebx,ebx,ebx
        mov [combo],eax
        invoke GetDC,edi
        mov [DC],eax
        invoke CreatePen,PS_SOLID,4,0xff00
        invoke SelectObject,[DC],eax
        invoke SetWindowLong,edi,GWL_WNDPROC,wndproc
        stdcall wndproc,edi,WM_SIZE,ebx,ebx
@@:
        invoke GetMessage,msg,ebx,ebx,ebx
        invoke DispatchMessage,msg
        jmp @r
 
proc wndproc,wnd,msg,wparam,lparam
        mov eax,[msg]
        cmp eax,WM_PAINT
        jne @f
        mov edi,[DC]
        invoke FillRect,edi,Rect,ebx
        invoke FillRect,edi,Rect2,2
        invoke MoveToEx,edi,40,45,ebx
        invoke LineTo,edi,40,95
        invoke Ellipse,edi,20,50,60,90
        invoke ValidateRect,[wnd],ebx
        invoke InvalidateRect,[combo],ebx,eax
        ret
@@:
        cmp eax,WM_SIZE
        jne @f
        invoke GetClientRect,[wnd],Rect
        ret
@@:
        cmp eax,WM_CLOSE
        jne @f
        jmp exit; invoke ExitProcess,ebx
@@:
        leave
        jmp [DefWindowProc]
endp

exit:
        invoke ExitProcess,NULL

.end start

section '.data' readable

        ComboBoxClass db 'COMBOBOX',NULL
        StaticClass db 'STATIC',NULL

section '.data' readable writable

        Rect RECT
        Rect2 RECT 15,45,65,95
        DC rd 1
        msg MSG
        combo rd 1    

2. How to assing bitmap1, bitmap2 in resources? And how to load?..
Post 13 Jan 2011, 16:21
View user's profile Send private message ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
1. You have to read carefully WM_PAINT help topic in win32.hlp file of other help resource. Also read BeginPaint and EndPaint functions topics.

2. Read LoadImage, LoadResource;
Post 14 Jan 2011, 06:43
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
Image
Why window is black? Black/white from refresh.
Confused (I do not need to colorize window and/or load any skins. I need classic view)

Code:
format PE GUI 3.1
include '%fasm%/win32ax.inc'
section '.code' executable
start:
        invoke DialogBoxParam,400000h,37,HWND_DESKTOP,DialogProc,NULL
exit:
        invoke ExitProcess,NULL
        ID_LIST = 104

proc DialogProc wnd,msg,wparam,lparam
        cmp [msg],WM_PAINT
        je paint
        cmp [msg],WM_COMMAND
        je exec
        cmp [msg],WM_INITDIALOG
        je dlg
        cmp [msg],WM_CLOSE
        je exit
        xor eax,eax
        ret
paint:
        pushad
        invoke SendMessage,[CtrlID],WM_PAINT,NULL,NULL
        mov ebx,[ComboSel]
        mov ebx,[chords+ebx*4]
        mov [EmfRect.top],40
        mov [EmfRect.bottom],80
        mov esi,5
row:
        mov [EmfRect.left],10
        mov [EmfRect.right],50
        mov edi,6
col:
        xor eax,eax
        shl ebx,1
        adc eax,eax
        invoke PlayEnhMetaFile,[DC],[hemf+eax*4],EmfRect
        add [EmfRect.left],40
        add [EmfRect.right],40
        dec edi
        jne col
        add [EmfRect.top],40
        add [EmfRect.bottom],40
        dec esi
        jne row
        invoke ValidateRect,[wnd],NULL
        popad
        ret
exec:
        cmp [wparam],CBN_SELENDOK shl 16 + ID_LIST
        jne @f
        invoke SendMessage,[CtrlID],CB_GETCURSEL,NULL,NULL
        mov [ComboSel],eax
        jmp paint
@@:
        ret
dlg:
        push edi
        invoke GetDC,[wnd]
        mov [DC],eax
        invoke SetEnhMetaFileBits,emf1size,emf1
        mov [hemf],eax
        invoke SetEnhMetaFileBits,emf2size,emf2
        mov [hemf+4],eax
        invoke GetDlgItem,[wnd],ID_LIST
        mov [CtrlID],eax
        mov edi,items
@@:
        invoke SendMessage,[CtrlID],CB_ADDSTRING,NULL,edi
        xor eax,eax
        mov ecx,-1
        repne scasb
        cmp [edi],al
        jnz @r
        invoke SendMessage,[CtrlID],CB_SETCURSEL,[ComboSel],NULL
        pop edi
        ret
endp

.end start

section '.data' readable

        emf1 file '1.emf'
        emf2 file '2.emf'
        emf1size=$-emf1
        emf2size=$-emf2

section '.data' readable writeable

        EmfRect RECT
        items db 'Am',NULL
        db 'Em',NULL
        db 'C',NULL
        db NULL
        chords dd 00001000110000000000000000000000b,\
                  00000001100000000000000000000000b,\
                  00001000100011000000000000000000b
        ComboSel dd 2
        hemf rd 3
        DC dd NULL
        CtrlID dd NULL

section '.rsrc' resource readable

        directory RT_DIALOG,dialogs,RT_ICON,icons,RT_GROUP_ICON,group_icons,RT_VERSION,versions,RT_MANIFEST,_manifest

        resource dialogs,37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration

        resource icons,\
        1,LANG_NEUTRAL,icon_data1,\
        2,LANG_NEUTRAL,icon_data2,\
        3,LANG_NEUTRAL,icon_data3,\
        4,LANG_NEUTRAL,icon_data4

        resource group_icons,17,LANG_NEUTRAL,main_icon
        resource versions,1,LANG_NEUTRAL,version
        resource _manifest,1,LANG_NEUTRAL,manifest

        dialog demonstration,'Chords',0,25,150,180,WS_CAPTION+WS_SYSMENU+DS_CENTER+DS_SYSMODAL+WS_CLIPCHILDREN
        dialogitem 'Combobox','',ID_LIST, 8,8,121,100,WS_VISIBLE+CBS_DROPDOWNLIST+CBS_HASSTRINGS+WS_VSCROLL
        enddialog

        icon main_icon,\
        icon_data1,'%fasm%\exec1.ico',\
        icon_data2,'%fasm%\exec2.ico',\
        icon_data3,'%fasm%\exec3.ico',\
        icon_data4,'%fasm%\exec4.ico'

        versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,NULL,\
                    'FileDescription','~.exe',\
                    'LegalCopyright','2001-2005 GmbH',\
                    'FileVersion','1.0.0.0',\
                    'ProductVersion','1.0.0.0',\
                    'OriginalFilename','~.exe',\
                    'Company','Semiono'

        resdata manifest
        file '%fasm%\manifest32.xml'
        endres
    


What this is lame? Embarassed

---
If directive "format PE GUI" absent in this code the window is jump to center of screen... Rolling Eyes
Usaly i dont use "format"
?
Post 03 Feb 2011, 20:50
View user's profile Send private message ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
http://www.masm32.com/board/index.php?topic=10191.0
Quote:
1. Add the function gdiplusLoadBitmapFromResource to your program, or include gdiplusLoadBitmapFromResource.inc.
2. Add the proto (so you can use INVOKE to call gdiplusLoadBitmapFromResource):

How do it in fasm?

Code:
gdiplusLoadBitmapFromResource proto :HMODULE, :LPSTR, :LPSTR, :DWORD    

Confused
Post 04 Feb 2011, 01:27
View user's profile Send private message ICQ Number 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.