News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to change the icon of my program

Started by Dasar, June 28, 2006, 11:10:48 AM

Previous topic - Next topic

Dasar

hi

i made a little program in masm32 v9, just display a message, but i don't know how to change its icon  ??

note: i tried to change it with "Resource Hacker" but i found no resources to edit   o_0

could you please tell me how to change the icon with "coding in masm32" ?

and what i have to do, to be able to change it in "Resouce Hacker" ??

and how to change any other applications icon using ( functions like: BeginUpdateResource, EndUpdateReource, etc ) ?




sorry for my newbie questions, but i want to learn ^_^

thank you alot in advance ...

zooba

You'll need to create a resource file (*.rc) and compile it with RC.EXE and link it.

Here's a sample which will set the icon for your program:
1 ICON MOVEABLE PURE DISCARDABLE "mouse.ico"

Then call these as part of your build process:
\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res


And add rsrc.obj to your link parameters.

As for resource hacker, it probably needs a resource file to be linked in there before it can hack it - your project doesn't have a resource file yet.

Cheers,

Zooba :U

P1

Dasar,

Post the code, we can not read your computer screen from here.   :wink

Regards,  P1  :8)

Dasar

#3
hi zooba, thank you very for the answer ...

@P1:

i said
Quotejust display a message
, if you want the code, see iczelion's  second tutorial ;)


i want to remind:

Quoteand how to change any other applications icon using ( functions like: BeginUpdateResource, EndUpdateReource, etc ) ?

thank you in advance ...

Mark Jones

Hello Dasar.

If by "Iczelions Second Tutorial" you mean \masm32\icztutes\tute02 , then you have to understand what the MessageBox limitations are. A MessageBox is a pre-defined, simple window. It can have a custom title and body message, and some preset buttons, and one system icon. That's it. (The messagebox system icon is provided by windows, so that is why there is no icon included inside the executable itself.)

Open up your Win32.hlp file (or go to MSDN) and find the entry for MessageBox. It will say something like:

Quoteint MessageBox(
    HWND hWnd,   // handle of owner window
    LPCTSTR lpText,   // address of text in message box
    LPCTSTR lpCaption,   // address of title of message box 
    UINT uType    // style of message box
   );

The uType is an identifier for the type of MessageBox icons and features used. See that in the code,

Quotestart:
   invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK
   invoke ExitProcess,NULL
end start

"MB_OK" is the uType identifier here. According to Win32.hlp, this specifies that "The message box contains one push button: OK. This is the default." If you wanted to give the MessageBox a stop-sign icon in addition to this, you could write:

Quotestart:
   invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK or MB_ICONSTOP
   invoke ExitProcess,NULL
end start

and that should give you an "ok" button and a red stop-sign icon. Try it and see.

A better version of the MessageBox can be created with MessageBoxIndirect, but this is much more complicated. That can do custom icons in the messagebox. Look that up and see what that can do.

Other types of windows can have many more features. Look up CreateDialogParam, CreateWindow, etc.

I don't have resource-hacker (and "hacking resources" doesn't sound very cool...)

Quote from: Dasar on June 28, 2006, 03:01:37 PM
i want to reminder:
Quoteand how to change any other applications icon using ( functions like: BeginUpdateResource, EndUpdateReource, etc ) ?

Open up your Win32.hlp or MSDN and search for those. It looks like you have to do BeginUpdateResource, then UpdateResource, then EndUpdateResource. Try to do this and post your code if it doesn't work. Good luck.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Dasar

hello Mark Jones...

Thank you alot for your answer..

but i know all what you said about "MessageBox" already........      (yes, i'm a newbie, but not at this level  ^_^)

when i said:
Quotei made a little program in masm32 v9, just display a message, but i don't know how to change its icon  ??

i was talking about the icon of the program itself, not about The icon of the "Window"     ;)

and thank you for mention of "MessageBoxIndirect",  i never tested it before  ^_^


----------------------------------------------------------------------------------------------------------------------------------------------------------


About the function of BeginUpdateResource, etc...

i tested them before but in "Delphi" and they didn't work for me,  i'll try to translet them to masm32 and i'll post my code here...

see you later, after my translation ^_^

Mark Jones

Quote from: Dasar on June 28, 2006, 09:16:21 PM
when i said:
Quotei made a little program in masm32 v9, just display a message, but i don't know how to change its icon  ??

i was talking about the icon of the program itself, not about The icon of the "Window"     ;)

Oh okay. Icons sure can be confusing, no?

Try:

Quote from: rsrc.rc
5   ICON    DISCARDABLE PURE LOADONCALL "MyIcon.ico"

plus


include masm32rt.inc

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

IDD_DIALOG                      equ 1000
IDI_ICON                          equ 6
IDM_MENU                       equ 10000
IDM_FILE_EXIT                    equ 10001
IDM_HELP_ABOUT                equ 10101

.const
ClassName db 'DLGCLASS',0

.data?
hInstance dd ?
CommandLine dd ?
hWnd dd ?
hIcon                           dd ?

.code
start:
    invoke GetModuleHandle,NULL
    mov hInstance,eax
    invoke GetCommandLine
    invoke InitCommonControls
    mov CommandLine,eax
    invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
    invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG

    mov wc.cbSize,sizeof WNDCLASSEX
    mov wc.style,CS_HREDRAW or CS_VREDRAW
    mov wc.lpfnWndProc,offset WndProc
    mov wc.cbClsExtra,NULL
    mov wc.cbWndExtra,DLGWINDOWEXTRA
    m2m wc.hInstance,hInst
    mov wc.hbrBackground,COLOR_BTNFACE+1
    mov wc.lpszMenuName,IDM_MENU
    mov wc.lpszClassName,offset ClassName
    invoke LoadIcon,hInst,5
    mov hIcon,eax
    mov wc.hIcon,eax
    mov wc.hIconSm,eax
    invoke LoadCursor,NULL,IDC_ARROW
    mov wc.hCursor,eax
    invoke RegisterClassEx,addr wc
    invoke CreateDialogParam,hInstance,IDD_DIALOG,NULL,addr WndProc,NULL
    invoke ShowWindow,hWnd,SW_SHOWNORMAL
    invoke UpdateWindow,hWnd
    .while TRUE
        invoke GetMessage,addr msg,NULL,0,0
    .BREAK .if !eax
        invoke TranslateMessage,addr msg
        invoke DispatchMessage,addr msg
    .endw
    mov eax,msg.wParam
    ret
WinMain endp

; then make sure to delete the icon in the WndProc when exiting,

WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    mov eax,uMsg
    .if eax==WM_INITDIALOG
        m2m hWnd,hWin
    .elseif eax==WM_COMMAND
; parse button clicks, etc...
   .elseif eax==WM_CLOSE
       invoke DestroyIcon,hIDI_ICON
       invoke DestroyWindow,hWin
   .elseif uMsg==WM_DESTROY
       invoke PostQuitMessage,NULL
   .else
       invoke DefWindowProc,hWin,uMsg,wParam,lParam
       ret
   .endif
   xor eax,eax
   ret
WndProc endp

end start


then, compile this with something like:

Quote from: BuildMe.bat
rc rsrc.rc
ml /c /coff MyFile.asm
link /subsystem:windows MyFile.obj MyFile.res

All of this came from a RadASM "DialogAsMain" Win32 template. If you have RadASM, try doing that.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Dasar

thank you alot for your fast reply :-D

your help is very appreciated ^_^

P1

Quote from: P1 on June 28, 2006, 01:52:04 PMPost the code, we can not read your computer screen from here.   :wink
You were given the same answer twice.  Had to work through getting what you meant, guessing three times.  Plus, giving a Moderator a hard time for trying to get clear what you were asking for.

I recommend you go through the tutorials and Helps better.

Now, what is it that your doing? 

Regards,  P1  :8)