Hi, I've had a look through the resource compiler help files but couldn't find the answer so ... Is it possible for a dialog box to have an associated icon which is specified in the dialog box template in the resource file? I know they can have menus because there is a MENU keyword associated with dialogs But there isn't an ICON keyword.
Posted on 2001-04-04 09:18:00 by MArtial_Code
There is an ICON keyword for Resource files use it like this :-

ICON  , IDC_STATIC,11,11,20,20
the last four parameters are it's position in the dialog. umbongo
Posted on 2001-04-04 09:45:00 by umbongo
umbongo, I know there's an ICON keyword...I've used it for "normal" windows. When I declare an icon for a dialog box I keep getting errors. If I move the icon declaration out of the block which defines the dialog box then everything compiles ok. If you look up the DIALOGEX keyword in RC.hlp you see it has other key words defined under it eg MENU. These can be used in the dialog box definition: for instance you could define a menu for that particaular dialog box... The keyword ICON is not associated with DIALOGEX Perhaps something can be done during processing of the WM_INITDIALOG message, hmmm...
Posted on 2001-04-04 09:55:00 by MArtial_Code
here is the code you need to add in your uMsg==WM_INITDIALOG add the below lines invoke LoadIcon,hInstance,200 mov hIcon,eax invoke SendMessage,hWnd,WM_SETICON,NULL,hIcon next you must initialize the variable hIcon so in your .data section add hIcon dd 0 lastly to your resource file add the following line 200 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "skull.ico" ;change skull.ico to your icons name
Posted on 2001-04-04 10:17:00 by smurf
Put three different icons in your proj. directiory Name them svin.ico,svin2.ico,svin3.ico. Here are text for two files rsrc.rc and new.asm. Put them as two separate files in yout proj. dorectory. Compile rsrc.rc, compile new.asm. You'll have an example of not just how to load icon in start but also how to change them at any time: RSRC.RC file

;########################################
#include "C:\masm32\include\resource.h"
1 ICON "svin.ico"
2 ICON "svin2.ico"
3 ICON "svin3.ico"
6 DIALOG 6, 15, 207, 111
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | DS_CENTER
CAPTION "Icons"
FONT 8, "MS Sans Serif"
{
 DEFPUSHBUTTON "OK", 1, 148, 6, 50, 14
 PUSHBUTTON "Cancel", 2, 148, 24, 50, 14
 PUSHBUTTON "Help", 3, 148, 42, 50, 14
 LTEXT "OK icon",4, 5, 4, 97, 15
}
;########################################

NEW.ASM file
;#########################################
.586
.model flat,stdcall
option casemap:none
include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
DlgID equ 6
.code

start:
	invoke DialogBoxParam,400000h,DlgID,0,addr DlgProc,0
	invoke ExitProcess,0
DlgProc proc uses ebx edi esi hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL texthandle:DWORD
.data
ltext1 	db 'OK icon',0
ltext2	db 'CANCEL icon',0
ltext3	db 'HELP icon',0
ALIGN 4
offsettext dd offset ltext1
	dd offset ltext2
	dd offset ltext3
.code
	mov eax,uMsg
.IF eax==WM_CLOSE
	invoke EndDialog,hWnd,0
.ELSEIF eax==WM_INITDIALOG
	invoke LoadIcon,400000h,1
	invoke SetClassLong,hWnd,GCL_HICON,eax
	invoke GetDlgItem,hWnd,4
	mov texthandle,eax

.ELSEIF eax== WM_COMMAND
	mov eax,wParam
	.IF al < 4
	AND eax,0Fh
	push eax
	invoke LoadIcon,400000h,eax
	invoke SetClassLong,hWnd,GCL_HICON,eax
	pop eax
	dec eax
	mov eax,
	invoke SetDlgItemText,hWnd,4,eax
	.ENDIF
.ELSE
	xor eax,eax
	ret
.ENDIF
	mov eax,1
	ret

DlgProc endp

end	start
;###############################################
The Svin. This message was edited by The Svin, on 4/4/2001 11:25:04 AM
Posted on 2001-04-04 11:07:00 by The Svin
There seems to be a theme in my messages today.. getting it wrong or upsetting people... I think you mis understood me, the command I gave you was for putting a ICON in a dialog, like this:-

#include "resource.h"

500 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "ICON.ICO"

TESTWIN DIALOGEX MOVEABLE IMPURE LOADONCALL DISCARDABLE	10, 10, 205, 122, 0
STYLE DS_MODALFRAME | 0x0004 | DS_CENTER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_POPUP
CAPTION "Dialog"
FONT 8, "MS Sans Serif", 700, 0 /*FALSE*/
BEGIN
    ICON 500,0,11,11,20,20 /* this puts an icon in a dialog */
END
Your dialog will automatically load the icon and display it. Hope that clears that up :) Umbongo
Posted on 2001-04-04 11:31:00 by umbongo
Cheers All, I've settled for smurf's way. I'm sure your's work Svin, I'm sure I'll need it sometime soon. Umbongo your method works too...just not the way I wanted!! I wanted the icon to be in the title bar. At least now I know how to put an icon on the client area Thanks again
Posted on 2001-04-04 15:09:00 by MArtial_Code