flat assembler
Message board for the users of flat assembler.

Index > Windows > How to change the font of a dialog box during runtime?

Author
Thread Post new topic Reply to topic
extra_12345



Joined: 21 Apr 2020
Posts: 9
extra_12345
Hey everyone!
I'm wondering how can I change the font of a dialog box created with DialogBoxParam API to for example Terminal font during the runtime?
I tried defining the font in the .rc file but still windows ignores my selection and chooses the default font during runtime,so I'mma have to change it programmatically.
Any help will be highly appreciated.
Post 07 Jun 2020, 15:21
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 365
Ali.Z
it is most likely you did not properly defined that.

here is the resource format for dialog boxes in fasm:

Code:
; dialog label,title,x,y,cx,cy,style,exstyle,menu,fontname,fontsize

dialog main_dialog,'window name',0,0,100,100,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME,0,0,'terminal',8
   ; dialogitem class,title,id,x,y,cx,cy,style,exstyle
   dialogitem 'static','some text',-1,10,10,90,90,WS_VISIBLE
enddialog    

_________________
Asm For Wise Humans
Post 07 Jun 2020, 17:59
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
WS_CAPTION or WS_POPUP or WS_SYSMENU or DS_MODALFRAME it is all good.
But where DS_SETFONT?
without this flag
0,0,'terminal',8
is ignored.
Post 07 Jun 2020, 18:18
View user's profile Send private message Send e-mail Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 365
Ali.Z
ProMiNick wrote:
WS_CAPTION or WS_POPUP or WS_SYSMENU or DS_MODALFRAME it is all good.
But where DS_SETFONT?
without this flag
0,0,'terminal',8
is ignored.


well, that is not true.
before posting my previous post, i did actually made a quick dialog and kept changing the fonts and it did work without issues.

DS_SETFONT, is used when you want to have a custom font made by you or any other personl and font data must be in resource section i.e. RT_FONT.

not specifying DS_SETFONT means the application is going to use system fonts; where system font means any font is loaded by the OS or built-in or in font directory of the operating system; which in this case terminal is a system font.

_________________
Asm For Wise Humans
Post 07 Jun 2020, 18:46
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 810
Location: Belarus
DimonSoft
MSDN wrote:
typeface
Specifies a null-terminated Unicode string that contains the name of the typeface for the font.
This member is present only if the style member specifies DS_SETFONT or DS_SHELLFONT.
Post 07 Jun 2020, 18:49
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
Ali.Z, if thou so sured that DS_SETFONT is for using only RT_FONT

before this
Code:
dialog main_dialog,'window name',0,0,100,100,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME,0,0,'terminal',8
   ; dialogitem class,title,id,x,y,cx,cy,style,exstyle
   dialogitem 'static','some text',-1,10,10,90,90,WS_VISIBLE
enddialog        
try to write
Code:
DS_SETFONT=0    

or replace this
Code:
dialog main_dialog,'window name',0,0,100,100,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME,0,0,'terminal',8
   ; dialogitem class,title,id,x,y,cx,cy,style,exstyle
   dialogitem 'static','some text',-1,10,10,90,90,WS_VISIBLE
enddialog        

with this
Code:
dialog main_dialog,'window name',0,0,100,100,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME+0*0,0,0,'terminal',8
   ; dialogitem class,title,id,x,y,cx,cy,style,exstyle
   dialogitem 'static','some text',-1,10,10,90,90,WS_VISIBLE
enddialog        
Code:
from adding +0*0 nothing changed (if nothing covered from pure newbie)    


Oh, how thou will be suprised.

That is because of cheating: no matter willing programmer using DS_SETFONT or not, - it hardcoded in fasm macros. Thou could see that other assemblers & compilers have dialog resourse both without & with this flag.

SO FOR CLEARNESS ALWAYS list DS_SETFONT in dialog resource flags. BE HONIEST WITH PEOPLE THAT THEY WOULD READ THOUR CODE. they shouldn`t make assumpions about this flag absense.
Post 07 Jun 2020, 20:33
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17639
Location: In your JS exploiting you and your system
revolution
I don't know if it is important, but the title says "at runtime" but the comments are discussing "at compile time".
Post 08 Jun 2020, 06:27
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
revolution, in 1st post requester says that he have to change programmatically "at runtime", but he wants via resource "at compile time".
Post 08 Jun 2020, 09:44
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlonga

ressources are not necessary, you can also compose your windows by calling win32 functions related to window programming.
Post 08 Jun 2020, 16:27
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 707
Location: Adelaide
sinsi
During runtime you would use WM_SETFONT.

edit: WM_SETFONT for each control, not just the dialog.
Post 08 Jun 2020, 22:48
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 365
Ali.Z
ProMiNick wrote:
Oh, how thou will be suprised.

That is because of cheating: no matter willing programmer using DS_SETFONT or not, - it hardcoded in fasm macros. Thou could see that other assemblers & compilers have dialog resourse both without & with this flag.


oh yeah, i just checked fasm's resource macro and yes as you said it was hardcoded.

that means if we want to make a dialong from memory i.e. at runtime using CreateDialogIndirectParam or DialogBoxIndirectParam not from resource section, then we will need to specify the DS_SETFONT.

_________________
Asm For Wise Humans
Post 09 Jun 2020, 18:33
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
no DS_SETFONT needed only for initialization of dialog resource with current structure of items, without this flags members for font are excluded from structure - this behavior absent in standart fasm dialog init structure.
Post 09 Jun 2020, 18:49
View user's profile Send private message Send e-mail Reply with quote
extra_12345



Joined: 21 Apr 2020
Posts: 9
extra_12345
Well I'm creating my dialog using resources but I do prefer to change the font of the main dialog later programmatically during the runtime, let's just say I'm interested to know how also learn something new.
Post 11 Jun 2020, 11:01
View user's profile Send private message Reply with quote
extra_12345



Joined: 21 Apr 2020
Posts: 9
extra_12345
well here's the contents of .rc file:
Code:
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

150  RCDATA "devil.bmp"
151  RCDATA "bloody_font.bmp"
152  RCDATA "enochian_font.bmp"
160  RCDATA "devil.txt"

100 DIALOG DISCARDABLE  0, 0, 0, 0
STYLE DS_CENTER | WS_POPUP
FONT 12, "Terminal"
BEGIN
END

#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED    


i've tried everything mentioned in this thread but still terminal font is ignored....
also WM_SETFONT for some reason is not working for me,so this brings us back to the zero ground,how can i change the font during the runtime using win32 api?
Post 11 Jun 2020, 21:07
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 707
Location: Adelaide
sinsi
Code:
        invoke  CreateFont,16,0,0,0,0,0,0,0,0,0,0,0,0,facename
        mov     ebx,eax
        invoke  GetDlgItem,[hwnddlg],control1_id
        invoke  SendMessage,eax,WM_SETFONT,ebx,TRUE
        invoke  GetDlgItem,[hwnddlg],control2_id
        invoke  SendMessage,eax,WM_SETFONT,ebx,TRUE
    
Post 11 Jun 2020, 22:07
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 GitHub, YouTube, Twitter.

Website powered by rwasa.