flat assembler
Message board for the users of flat assembler.

Index > Windows > LoadIcon and LoadImage

Author
Thread Post new topic Reply to topic
smoke



Joined: 16 Jan 2006
Posts: 42
smoke
heya all, im quite a newbie in programming in asm .. so i would really need some help with this : i dont know how to load an image and an icon .. this the code :
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

WM_COMMAND1        = 109
ID_EXIT            = 105
ID_NAME            = 103
ID_SERIAL          = 104
ID_GENERATE        = 201
ID_CAPTION         = 101
ID_CAPTION1        = 102

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
        invoke  ExitProcess,0


proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        cmp     [msg],WM_COMMAND1
        je      wmclose
        xor     eax,eax
        jmp     finish


 wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + ID_EXIT
        je      wmclose
wmcommand1:
        cmp     [wparam],BN_CLICKED shl 16 + ID_GENERATE
        jne     finish
        cmp     [chg],1
        je      finish
        mov     [chg],1
        invoke  GetDlgItemText,[hwnddlg],ID_CAPTION,namebuffer
        invoke  SetDlgItemText,[hwnddlg],ID_CAPTION1,inputserial
        mov     [chg],0
        jmp     finish


  wmclose:
        invoke  EndDialog,[hwnddlg],0

  finish:
        pop     edi esi ebx
        ret

endp



section '.idata' import data readable writeable

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

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         lstrlen,'lstrlen',\
         ExitProcess,'ExitProcess'


  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         CheckRadioButton,'CheckRadioButton',\
         GetDlgItemText,'GetDlgItemTextA',\
         SetDlgItemText,'SetDlgItemTextA',\
         IsDlgButtonChecked,'IsDlgButtonChecked',\
         MessageBox,'MessageBoxA',\
         EndDialog,'EndDialog'

;#################
namebuffer        rb 200h
inputserial       rb 200h
chg               dd 0
;#################


section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
           37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration

  dialog demonstration,'test app',70,70,200,110,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
    dialogitem 'EDIT','',ID_CAPTION,60,10,130,12,WS_VISIBLE+WS_BORDER+WS_TABSTOP
    dialogitem 'EDIT','',ID_CAPTION1,60,30,130,12,WS_VISIBLE+WS_BORDER+WS_TABSTOP
    dialogitem 'STATIC','Name:',ID_NAME,8,10,40,20,WS_VISIBLE+WS_TABSTOP+BS_TEXT
    dialogitem 'BUTTON','Generate',ID_GENERATE,20,65,70,20,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
    dialogitem 'BUTTON','Exit',ID_EXIT,110,65,70,20,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
    dialogitem 'STATIC','Serial:',ID_SERIAL,8,30,40,20,WS_VISIBLE+WS_TABSTOP+BS_TEXT
  enddialog
    

ps .. i was wondering if its possible to create a 'movable' window which has no Caption
Post 09 May 2006, 18:13
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
for moving without caption

Code:
        cmp     ax,WM_LBUTTONDOWN
        jz      .move

  .move:
        invoke  ReleaseCapture
        invoke  SendMessage,[hWnd],WM_NCLBUTTONDOWN,HTCAPTION,NULL
        jmp     .processed
    


for load simple bmp's you can use LoadBitmap and for icons you can use LoadIcon
Post 10 May 2006, 16:23
View user's profile Send private message Reply with quote
smoke



Joined: 16 Jan 2006
Posts: 42
smoke
thanks very much for this ! but i have some problems with adding this code . (im still a newb ..) so if you could tell me what im doing wrong .. i'll attach the code
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

HTCAPTION          = 56
WM_COMMAND1        = 109
ID_EXIT            = 105
ID_NAME            = 103
ID_SERIAL          = 104
ID_GENERATE        = 201
ID_CAPTION         = 101
ID_CAPTION1        = 102

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
        invoke  ExitProcess,0

proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        cmp     [msg],WM_COMMAND1
        je      wmclose
        xor     eax,eax
        jmp     finish
        cmp     ax,WM_LBUTTONDOWN
        jz      .move 
  .move:
        invoke  ReleaseCapture 
        invoke  SendMessage,[hwnddlg],WM_NCLBUTTONDOWN,HTCAPTION,NULL
        jmp     processed

 wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + ID_EXIT
        je      wmclose
wmcommand1:
        cmp     [wparam],BN_CLICKED shl 16 + ID_GENERATE
        jne     finish
        cmp     [chg],1
        je      finish
        mov     [chg],1
        invoke  GetDlgItemText,[hwnddlg],ID_CAPTION,namebuffer
        xor     ecx,ecx
        xor     ebx,ebx
     l00p1:
        mov     [inputserial+ecx],0
        inc     bl
        inc     ecx
        cmp     bl,10h
        jne     l00p1
        xor     ecx,ecx
        xor     edx,edx
        xor     ebx,ebx
      l00p:
        mov     dl,byte [namebuffer+ecx]
        xor     dl,byte [namebuffer+ecx+1]
        add     dl,29h
        mov     [inputserial+ecx],dl
        inc     ecx
        inc     bl
        cmp     bl,10h
        jne     l00p
        mov     [inputserial+ecx],0
        invoke  SetDlgItemText,[hwnddlg],ID_CAPTION1,inputserial
        mov     [chg],0
        jmp     finish


  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'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         lstrlen,'lstrlen',\
         ExitProcess,'ExitProcess'

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         CheckRadioButton,'CheckRadioButton',\
         GetDlgItemText,'GetDlgItemTextA',\
         SetDlgItemText,'SetDlgItemTextA',\
         IsDlgButtonChecked,'IsDlgButtonChecked',\
         MessageBox,'MessageBoxA',\
         SendMessage,'SendMessageA',\
         ReleaseCapture,'ReleaseCapture',\
         EndDialog,'EndDialog'

;#################
namebuffer        rb 200h
inputserial       rb 200h
chg               dd 0
;#################


section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs


  resource dialogs,\
           37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration

  dialog demonstration,'Keygen',70,70,200,110,WM_NCLBUTTONDOWN+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
    dialogitem 'EDIT','',ID_CAPTION,60,10,130,12,WS_VISIBLE+WS_BORDER+WS_TABSTOP
    dialogitem 'EDIT','',ID_CAPTION1,60,30,130,12,WS_VISIBLE+WS_BORDER+WS_TABSTOP
    dialogitem 'STATIC','Name:',ID_NAME,8,10,40,20,WS_VISIBLE+WS_TABSTOP+BS_TEXT
    dialogitem 'BUTTON','Generate',ID_GENERATE,20,65,70,20,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
    dialogitem 'BUTTON','Exit',ID_EXIT,110,65,70,20,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
    dialogitem 'STATIC','Serial:',ID_SERIAL,8,30,40,20,WS_VISIBLE+WS_TABSTOP+BS_TEXT
  enddialog
    
Post 11 May 2006, 05:39
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
Code:
        push    ebx esi edi
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        cmp     [msg],WM_COMMAND1
        je      wmclose
        xor     eax,eax
        jmp     finish
        cmp     ax,WM_LBUTTONDOWN
        jz      .move 
    


must be

Code:
        push    ebx esi edi
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        cmp     ax,WM_LBUTTONDOWN
        jz      .move 
        cmp     [msg],WM_COMMAND1
        je      wmclose
        xor     eax,eax
        jmp     finish
    
Post 11 May 2006, 15:16
View user's profile Send private message Reply with quote
smoke



Joined: 16 Jan 2006
Posts: 42
smoke
hmm weird , but the code doesnt work , Vasilev Vjacheslav can you check my code again ? maybe i defined something wrong ?
Post 14 May 2006, 20:36
View user's profile Send private message Reply with quote
Kenneth



Joined: 16 Nov 2005
Posts: 38
Location: United States of America
Kenneth
HTCAPTION is 2, not 56. http://board.flatassembler.net/topic.php?t=4015 has those missing constants for future reference.

and
Code:
cmp     ax,WM_LBUTTONDOWN    

should be
Code:
cmp     [msg],WM_LBUTTONDOWN    
Post 14 May 2006, 23:16
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I'll use this thread to ask some question about bitmaps too.

* I want a bitmap to act as a button. So, I add it to my dialog and make it answer to clicks. Now, how can I change it when mouse is over it and when user clicked it?

Example:
1) I have a button in gray, black and white colors.
2) When user place the mouse in it, it changes to another picture that is colored.
3) When the user click it, it changes the picture to another one that gives the effect of button pressed.
4) When mouse leaves the bitmap, it changes to the original gray, black and white one.
Any ideas?
Post 17 May 2006, 15:39
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
OzzY, take a look to masm examples for such button
Post 17 May 2006, 18:00
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 YouTube, Twitter.

Website powered by rwasa.