The MASM Forum

General => The Campus => Topic started by: nidud on September 08, 2013, 10:09:49 PM

Title: Console window size
Post by: nidud on September 08, 2013, 10:09:49 PM
deleted
Title: Re: Console window size
Post by: dedndave on September 08, 2013, 10:50:08 PM
you might try GetConsoleScreenBufferInfoEx to fill a CONSOLE_SCREEN_BUFFER_INFOEX structure
then modify it and use SetConsoleScreenBufferInfoEx

srWindow.Right and srWindow.Bottom returned by the Get function are inclusive
so, increment them before you use the Set function

not sure how well that will work - it may only affect the buffer size

if all else fails, you can use GetConsoleWindow to get the window handle,
then MoveWindow to set the size
this involves calculating the size of the titlebar, borders, and scrollbars before you know what you want
Title: Re: Console window size
Post by: nidud on September 08, 2013, 11:57:43 PM
deleted
Title: Re: Console window size
Post by: dedndave on September 09, 2013, 01:04:16 AM
try this out...

it uses 2 functions that require XP or newer to get the font cell height
if you need win2000 support, there are other ways to get the character cell height

one way would be to use the (current client height pixels) / (current client height chars)
Title: Re: Console window size
Post by: dedndave on September 09, 2013, 01:45:31 AM
this one should work under win 2000....
Title: Re: Console window size
Post by: nidud on September 09, 2013, 03:06:08 AM
deleted
Title: Re: Console window size
Post by: dedndave on September 09, 2013, 04:39:12 AM
well - the console is buggish, no matter what you do - lol
if you can, try to write your app as a gui app   :t

as for sull-screen, you may not have any control over the layout in full-screen
either way, the display buffer has to be large enough to accomodate the screen layout
Title: Re: Console window size
Post by: nidud on September 09, 2013, 05:25:30 AM
deleted
Title: Re: Console window size
Post by: dedndave on September 09, 2013, 08:00:47 AM
 :P
Title: Re: Console window size
Post by: nidud on September 09, 2013, 11:04:16 PM
deleted
Title: Re: Console window size
Post by: dedndave on September 10, 2013, 03:23:28 AM
have to ask Japheth about that one   :shock:
Title: Re: Console window size
Post by: nidud on September 10, 2013, 04:24:15 AM
deleted
Title: Re: Console window size
Post by: dedndave on September 10, 2013, 04:31:41 AM
i believe windows looks for the first suitable icon in the resource
not sure what the issue is with JwLink, but it would seem that windows isn't finding it
see if you can export the resources with ResHack
Title: Re: Console window size
Post by: nidud on September 10, 2013, 05:26:06 AM
deleted
Title: Re: Console window size
Post by: dedndave on September 10, 2013, 07:01:18 AM
you can combine sections with ms link, as well
it takes a couple extra command-line switches

/OPT:NOREF /MERGE:.data=.text

at any rate, Andreas (Japheth) will probably want to address the issue and update JwLink, when he has time
that's assuming that it is an issue   :P
Title: Re: Console window size
Post by: nidud on September 21, 2013, 07:35:53 PM
deleted
Title: Re: Console window size
Post by: dedndave on September 21, 2013, 11:01:56 PM
doesn't do much good without the source   :P
Title: Re: Console window size
Post by: nidud on September 22, 2013, 12:04:46 AM
deleted
Title: Re: Console window size
Post by: GoneFishing on September 22, 2013, 12:51:21 AM
Quote from: nidud on September 22, 2013, 12:04:46 AM

the program: the flag is set in a window,
but if you do Ctrl-Enter to full screen nothing happens

the rest of the functions works...

maybe Alt-Enter ?
Title: Re: Console window size
Post by: dedndave on September 22, 2013, 02:39:39 AM
sorry - i guess i don't understand what you are trying to do
Title: Re: Console window size
Post by: nidud on September 22, 2013, 03:37:20 AM
deleted
Title: Re: Console window size
Post by: dedndave on September 22, 2013, 03:47:28 AM
i never tried using the mouse wheel in a console, before
in a GUI app, you handle WM_MOUSEWHEEL and possibly WM_MOUSEHWHEEL messages
it would seem that the console event trap doesn't do that - no surprise, there
i guess you could subclass the window and handle the messages, passing all other messages to the original window proc
Title: Re: Console window size
Post by: nidud on September 22, 2013, 04:58:59 AM
deleted
Title: Re: Console window size
Post by: dedndave on September 22, 2013, 06:20:35 AM
it is indeed a GUI app
and - the "standard" behaviour of the console mouse is very buggish
one might do well to subclass and disable the console mouse code, anyways - lol

if you want to see one of the bugs i'm talking about....
use the right-click context menu of the console to copy/paste text
the console window will lose track of the current X and Y position of the cursor
Title: Re: Console window size
Post by: nidud on October 04, 2013, 04:56:06 PM
deleted
Title: Re: Console window size
Post by: jj2007 on October 04, 2013, 06:01:02 PM
Quote from: nidud on October 04, 2013, 04:56:06 PMis there a simple way to test if the window is active or lurking in the background?

GetForegroundWindow
Title: Re: Console window size
Post by: nidud on October 04, 2013, 06:43:33 PM
deleted
Title: Re: Console window size
Post by: jj2007 on October 04, 2013, 06:50:25 PM
Quote from: nidud on October 04, 2013, 06:43:33 PMIn the case of not being active I need to call the GetForegroundWindow() function repeatedly, so how should this be handled?

Should I "sleep" for a while and then call it again?

WM_TIMER is a option. Another one is to check for WM_MOUSEMOVE messages, they are being sent even if the window is not active. But no such messages if you hover over an edit control.

The standard option, though, is monitoring WM_ACTIVATE.

Title: Re: Console window size
Post by: dedndave on October 04, 2013, 08:23:20 PM
even GetForegroundWindow doesn't always work the way you think it should
it's a problem i have fought with in the past
so far, i haven't found a perfect solution
Title: Re: Console window size
Post by: nidud on October 04, 2013, 08:59:58 PM
deleted
Title: Re: Console window size
Post by: dedndave on October 04, 2013, 09:36:30 PM
i do it a little differently
i store the HWND of my window
and compare the GetForegroundWindow result against that
    INVOKE  GetForegroundWindow
    .if eax==hwndMain
Title: Re: Console window size
Post by: nidud on October 04, 2013, 10:43:13 PM
deleted
Title: Re: Console window size
Post by: jj2007 on October 04, 2013, 10:55:29 PM
Just curious: How did you implement .if GetForegroundWindow() - a macro??
Title: Re: Console window size
Post by: nidud on October 04, 2013, 11:47:19 PM
deleted
Title: Re: Console window size
Post by: jj2007 on October 04, 2013, 11:54:27 PM
So it's your own JWasm build. Interesting ;)
Title: Re: Console window size
Post by: dedndave on October 05, 2013, 01:32:05 AM
rv(GetForegroundWindow)
will do the same

i don't use it much, but qWord seems to like it   :P
Title: Re: Console window size
Post by: jj2007 on October 05, 2013, 03:35:02 AM
Quote from: dedndave on October 05, 2013, 01:32:05 AM
i don't use it much, but qWord seems to like it   :P

Me too, it condenses the code a little bit:
      mov hMenu, rv(CreateMenu)            ; create the main menu
      mov hM1, rv(CreateMenu)              ; plus three
      mov hM2, rv(CreateMenu)              ; sub menus
      mov ghM3, rv(CreateMenu)

Title: Re: Console window size
Post by: dedndave on October 05, 2013, 03:49:07 AM
i find it a little easier to follow the code by not using it
especially if you are following along in a debugger
but - i have become more accustomed to it through reading qWord's code - lol
Title: Re: Console window size
Post by: nidud on October 10, 2013, 12:36:59 AM
deleted
Title: Re: Console window size
Post by: dedndave on October 10, 2013, 02:51:07 AM
the ones that have the IBM graphics characters in the upper range use the OEM_CHARSET
for the console it's normally a "Terminal" font

here are some links....
http://masm32.com/board/index.php?topic=1108 (http://masm32.com/board/index.php?topic=1108)
this one was posted by Vortex...
http://blogs.microsoft.co.il/blogs/pavely/archive/2009/07/23/changing-console-fonts.aspx (http://blogs.microsoft.co.il/blogs/pavely/archive/2009/07/23/changing-console-fonts.aspx)

and, attached is a little program to enumerate fonts
you can modify it to filter out different requirements

for example, if you just want monospaced fonts, you can look for those that use FIXED_PITCH
unfortunately, it's a little difficult to filter out all the monospace fonts
because a true-type font may be monospaced, without using the FIXED_PITCH flag
Title: Re: Console window size
Post by: dedndave on October 10, 2013, 03:00:06 AM
here is an image of using terminal fonts in a GUI app
kind of "reverse" of what you want to do, i think - lol

(http://imageshack.us/a/img811/8154/kinput.png)

i use the following routine to create the fonts
oddly enough - it doesn't always get the font i want, unless i enumerate terminal fonts, first   :redface:
MakeTerminalFont PROC wParam:WPARAM

;valid WxH: 4x6, 5x12, 6x8, 7x12, 8x8, 8x12, 10x18, 12x16, 16x8, 16x12

;--------------------------------

    LOCAL   _lf     :LOGFONT

;_lf              LOGFONT <height,width,,,,,,,OEM_CHARSET,,,,FF_MODERN or FIXED_PITCH,"Terminal">
;  lfHeight         DWORD height
;  lfWidth          DWORD width
;  lfEscapement     DWORD ?
;  lfOrientation    DWORD ?
;  lfWeight         DWORD ?
;  lfItalic         BYTE  ?
;  lfUnderline      BYTE  ?
;  lfStrikeOut      BYTE  ?
;  lfCharSet        BYTE  OEM_CHARSET
;  lfOutPrecision   BYTE  ?
;  lfClipPrecision  BYTE  ?
;  lfQuality        BYTE  ?
;  lfPitchAndFamily BYTE  FF_MODERN or FIXED_PITCH
;  lfFaceName       BYTE  LF_FACESIZE dup(?)        ;"Terminal",0

;--------------------------------

    INVOKE  GetStockObject,OEM_FIXED_FONT
    lea     edx,_lf
    INVOKE  GetObject,eax,sizeof LOGFONT,edx
    movzx   edx,byte ptr wParam[2]                  ;EDX = wParam high word = height
    movzx   ecx,byte ptr wParam                     ;ECX = wParam low word  = width
    mov     _lf.lfCharSet,OEM_CHARSET
    mov     _lf.lfPitchAndFamily,FF_MODERN or FIXED_PITCH
    mov     _lf.lfHeight,edx
    mov     _lf.lfWidth,ecx
    INVOKE  CreateFontIndirect,addr _lf
    ret

MakeTerminalFont ENDP


Title: Re: Console window size
Post by: nidud on October 10, 2013, 04:58:57 AM
deleted
Title: Re: Console window size
Post by: dedndave on October 10, 2013, 05:03:32 AM
as far as i know - a font used in the console must be monospaced
so - if you want to "carry" a font in resource or something, it may be do-able
that particular Lucida font is a monospaced font

Jochen has a lot more experience, here, as he has played with many foreign UNICODE fonts in the console

another possibility is to draw your own line graphics in the console client area
at that point, you may as well write a GUI app - lol
Title: Re: Console window size
Post by: dedndave on October 10, 2013, 05:14:10 AM
i forgot to mention....

you might have some luck with special "programming" fonts, which are typically monospaced
i use inconsolata-dz in NotePad and NotePad++, for example
another one is Proggy Square Slash Zero
there are numerous 3rd party programming fonts out there
some may do what you want
i haven't tried to find one that supported IBM graphics chars, though
Title: Re: Console window size
Post by: nidud on October 12, 2013, 10:41:13 PM
deleted
Title: Re: Console window size
Post by: dedndave on October 13, 2013, 06:02:16 AM
nice info, nidud
maybe someday i will experiment with creating a TrueType console font   :P
Title: Re: Console window size
Post by: nidud on October 16, 2013, 08:47:51 PM
deleted
Title: Re: Console window size
Post by: dedndave on October 17, 2013, 04:24:47 AM
looks like fun - nice letters   :t

in my viewer, i didn't see the IBM line-graphic chars
is that my viewer, or is that the font ?

by the way...
i wouldn't use a REG file to install a font
let the windows font manager do it for you (control panel)

EDIT: another question...
did you generate the font with an asm-written program ?
Title: Re: Console window size
Post by: nidud on October 17, 2013, 06:04:45 AM
deleted
Title: Re: Console window size
Post by: Gunther on October 17, 2013, 06:09:30 AM
Hi nidud,

Quote from: nidud on October 17, 2013, 06:04:45 AM
http://fontforge.sf.net

Excellent link. Thank you.  :t

Gunther
Title: Re: Console window size
Post by: nidud on October 17, 2013, 06:44:28 AM
deleted
Title: Re: Console window size
Post by: nidud on November 01, 2013, 04:10:32 AM
deleted
Title: Re: Console window size
Post by: nidud on April 03, 2016, 12:26:47 AM
deleted
Title: Re: Console window size
Post by: pcMike on April 21, 2016, 12:35:22 PM
nidud, your SetConsoleSize procedure works very well for the Window Size, but how is it possible to also set the Screen Buffer Size of the Console?  Do I have to shell to the MODE command, or can this be done programmatically?
Title: Re: Console window size
Post by: pcMike on April 21, 2016, 02:13:30 PM
nidud, I downloaded your two small windows console applications, and I see they do set both the Console Window Size, and the Console Buffer Size correctly... so it is possible after all. Oddly it did not change the Buffer Size of my Console when I used your SetConsoleSize proc.

Where can I find the following includes?
include conio.inc
include keyb.inc
include clip.inc
include stdio.inc

I see your Ascii.asm program calls SetConsoleSize, calls dlmodal, then calls SetConsoleSize a second time. I assume dlmodal must be in one of the missing includes.
Title: Re: Console window size
Post by: pcMike on April 21, 2016, 02:54:49 PM
It occurred to me the include files would be part of DOSZip itself.
Now I'm stuck here:

C:\console\src\Ascii>\asmc\asmc ascii.asm
Doszip Macro Assembler Version 2.19
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.

Assembling: ascii.asm

C:\console\src\Ascii>\masm32\bin\polink /SUBSYSTEM:CONSOLE /ALIGN:4096 /MERGE:.data=.text /MERGE:.rdata=.text ascii.obj
POLINK: fatal error: Invalid machine type in object 'ascii.obj'.
Title: Re: Console window size
Post by: hutch-- on April 21, 2016, 04:49:57 PM
Mike,

Its probably the wrong OBJ format, 32 bit PE code normally uses a 32 bit PE version, there used to be a 32 bit OMF object module but the assembler you are using may be producing a 16 bit OMF module that a 32 bit linker will not allow.
Title: Re: Console window size
Post by: nidud on April 21, 2016, 08:46:35 PM
deleted
Title: Re: Console window size
Post by: pcMike on April 22, 2016, 12:41:32 AM
Thanks Hutch and nidud,

After pulling some hair, I got it working.