The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: hfheatherfox07 on August 11, 2011, 08:38:52 PM

Title: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 11, 2011, 08:38:52 PM
Hi,
I am trying to create 2 things;

1. creating a window with F1 toggle for full screen
2. creating a window with F1 toggle for full screen  and a message box at the beginning asking the user  "Would you like to run in fullscreen mode ?" Yes or No

here are the 2 windows that I am trying to make into this:

Blank Window.zip and Blank Executer Window.zip

Project.zip is my bad attempt ....

I used lesson01.zip from NeHe Productions  Creating an OpenGL Window (Win32)_files and

Direct draw that was posted here by Siekmanski -> http://www.masm32.com/board/index.php?PHPSESSID=43d48ba8df22eda20b351e7f68364200&action=dlattach;topic=16710.0;id=9354

I am not trying to do a OpenGL or a direct draw....

any help?  :(

Title: Re: creating a window with F1 toggle for full screen
Post by: baltoro on August 11, 2011, 09:21:49 PM
Here's an article written for C++ MFC programmers from MSDN: Full Screen Display and Implementing (http://msdn.microsoft.com/en-us/magazine/cc188910.aspx). You won't use the code, obviously, but the concept is fairly simple.
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 11, 2011, 11:53:11 PM
Quote from: baltoro on August 11, 2011, 09:21:49 PM
Here's an article written for C++ MFC programmers from MSDN: Full Screen Display and Implementing (http://msdn.microsoft.com/en-us/magazine/cc188910.aspx). You won't use the code, obviously, but the concept is fairly simple.

Sorry no help to me ...I have 2 MASM examples DD and openGL and I have problems
Title: Re: creating a window with F1 toggle for full screen
Post by: baltoro on August 12, 2011, 12:43:19 AM
Yeah,...I read those four examples in your first post.
You're overthinking it,...it's actually quite simple,...
You don't need DirectX or OpenGL to display a graphic in full screen  mode.
That first blank window example just needs a few changes,...
Here is a MASM forum thread about: Processing Keyboard Input (http://www.masm32.com/board/index.php?topic=16649.0)
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 12, 2011, 01:00:57 AM
Quote from: baltoro on August 12, 2011, 12:43:19 AM
Yeah,...I read those four examples in your first post.
You're overthinking it,...it's actually quite simple,...
You don't need DirectX or OpenGL to display a graphic in full screen  mode.
That first blank window example just needs a few changes,...
Here is a MASM forum thread about: Processing Keyboard Input (http://www.masm32.com/board/index.php?topic=16649.0)

any idea were I am going wrong? i tried about a dozen times

that is what I am trying to do... no  DirectX or OpenGL
Title: Re: creating a window with F1 toggle for full screen
Post by: baltoro on August 12, 2011, 01:20:41 AM
The only difficult part is handling the keyboard input. Here is the MSDN reference: Keyboard Input (http://msdn.microsoft.com/en-us/library/ms645530(v=vs.85).aspx).
Essentially, you want to add a message handler to your Window Procedure. You've got it all already in place (with a few inconsequentials errors).
This is the way you've got it declared:
WndProc  PROC   uses edx ecx ebx esi edi  hWnd :HWND,uMsg :DWORD,wParam :DWORD,lParam :DWORD

Somewhere in that procedure you want to add a block of code that handles the: WM_KEYDOWN Message (http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx).   
There are other ways to do it,...but, that's the simplest.
The alternative is to call either, GetAsyncKeyState Function (http://msdn.microsoft.com/en-us/library/ms646293(v=VS.85).aspx), or, GetKeyboardState Function (http://msdn.microsoft.com/en-us/library/ms646299(v=VS.85).aspx), but, that requires a little more work.

You should probably read this for an overview: About Keyboard Input (http://msdn.microsoft.com/en-us/library/ms646267(v=VS.85).aspx)
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 12, 2011, 01:25:40 AM
Quote from: baltoro on August 12, 2011, 01:20:41 AM
The only difficult part is handling the keyboard input. Here is the MSDN reference: Keyboard Input (http://msdn.microsoft.com/en-us/library/ms645530(v=vs.85).aspx).
Essentially, you want to add a message handler to your Window Procedure. You've got it all already in place (with a few inconsequentials errors).
This is the way you've got it declared:
WndProc  PROC   uses edx ecx ebx esi edi  hWnd :HWND,uMsg :DWORD,wParam :DWORD,lParam :DWORD

Somewhere in that procedure you want to add a block of code that handles the: WM_KEYDOWN Message (http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx).   
There are other ways to do it,...but, that's the simplest.


that was just one of my trials that I uploaded like i said I tried a bout a dozen time... I have one with the WM_KEYDOWN ...I have no problems with that...I can not get the screen to become full ... I can get it to switch back and forth ... but I can not get it to show.....

All I want is to add a simple text saying  something like  "Press F1 to toggle to full screen and back".... and I want it to work ....

you keep focusing on key input -no problems there... problems showing the screen
Title: Re: creating a window with F1 toggle for full screen
Post by: baltoro on August 12, 2011, 01:32:22 AM
This is from that first article that i recommended:   
"There's nothing in MFC that does full-screen display explicitly; however, it's not hard to implement. The basic idea is to adjust the size and position of your main window so it's bigger than the screen by the exact amount to make the active view exactly fill the display. This will always require an origin (top-left corner) with negative x,y coordinates."

He shows a simple handler for switching from Maximized to Full Screen mode (I assume you don't understand C++ code). this he does by calling this sequence of Windows API functions:
GetWindowRect
GetSystemMetrics (http://msdn.microsoft.com/en-us/library/ms724385(v=vs.85).aspx)
SetWindowPos (http://msdn.microsoft.com/en-us/library/ms633545(v=vs.85).aspx)

I'm sitting at a public terminal, so I don't have access to MASM, here,...and, I can't provide you with a code example that I've tested to make sure it works. But, the general idea is to call (ijn MASM, invoke) GetWindowRect for the maximized rectangle (or, whatever size you want to toggle back to), and save these coordinates in a global RECT structure. Then you would call GetSystemMetrics to determine the width of the window frame, horizontally, and the height of the title bar and menu bar, vertically (if you have one). These values are then used to initialize another RECT structure that will hold the size of the larger window coordinates. Your origin coordinates will be negative values. Then invoke SetWindowPos for the fuul screen mode.

To show text to instruct the user how to toggle the screen, use: TextOut Function (http://msdn.microsoft.com/en-us/library/dd145133(v=vs.85).aspx)
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 12, 2011, 04:53:10 AM
this seems to work fine under XP
i would be interested to see if it works as well under win7   :P
if so, it would give the forum members a way to go into a "pseudo-full-screen" mode where it is supposedly not available
you could also reply to WM_SETCURSOR or use SetWindowLong to hide it

NOTE:
the F1 key toggles full-screen mode
the window must have focus to get to full screen, of course
Title: Re: creating a window with F1 toggle for full screen
Post by: ToutEnMasm on August 12, 2011, 05:24:45 AM

What you have to do to go full screen is to hide the tray (task bar).Search this word in the forum and you will find the group of functions with the one who hide it.
When it is done,give the correct size to your window.

Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 12, 2011, 05:34:19 AM
this one covers the taskbar under XP
i used SetWindowPos to make it "topmost"
that may not fly under win 7, though

did you try it Yves ?
do you have XP ?
Title: Re: creating a window with F1 toggle for full screen
Post by: ToutEnMasm on August 12, 2011, 05:40:53 AM

I try your sample but he don't go full screen.
I think i hve found the soluce here.
http://msdn.microsoft.com/en-us/library/bb774640(v=vs.85).aspx
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 12, 2011, 05:45:05 AM
thanks Yves   :U

what version of windows do you use ?
Title: Re: creating a window with F1 toggle for full screen
Post by: ToutEnMasm on August 12, 2011, 05:51:38 AM
I have XP SP3
I try to build  sample  with ITaskbarList3.
Title: Re: creating a window with F1 toggle for full screen
Post by: zekyr on August 12, 2011, 07:54:38 AM
I'm on windows 7 and it works fine! :) I'm so glad that this forum exists!

If it weren't for this forum I wouldn't know that you could do this:

WinMain   PROC hInst :DWORD,hPrevInst :DWORD,CmdLine :DWORD,CmdShow :DWORD


does that really give you the commandline? i saw the xor edi, edi but im really curious now :)

    xor     edi,edi           
    invoke  GetModuleHandle,edi
    mov     hInstance, eax
    invoke  WinMain,hInstance,edi,edi,SW_SHOWDEFAULT   

Title: Re: creating a window with F1 toggle for full screen
Post by: ToutEnMasm on August 12, 2011, 09:06:10 AM

This  one work
Quote
invoke  GetSystemMetrics,SM_CXSCREEN
mov MaxX,eax
invoke  GetSystemMetrics,SM_CYSCREEN
mov MaxY,eax
;---------------------------------------
mov Fenetre.extstyles,WS_EX_TOPMOST   
mov Fenetre.styles,WS_EX_TOPMOST or WS_POPUP or WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN
INVOKE     CreateWindowEx,Fenetre.extstyles,ADDR Fenetre.class,ADDR Fenetre.titre,\
   Fenetre.styles,0,0,MaxX,MaxY, NULL, NULL,ModHandle, NULL
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 12, 2011, 11:24:44 AM
zekyr,
no - you have to pass the command line to the function when you call it
however, in C, the commandline is parsed by the compiler start-up code
the whole "WinMain with 4 parameters" is a compiler thing - totally unnecessary in ASM
but, if you want your program to look, act, and smell like a C program......
Start:  xor     edi,edi
        INVOKE  InitCommonControls
        INVOKE  GetCommandLine
        mov     ecx,edi
        mov     dx,2220h                       ;double quote and space
        mov     lpCmndLineFull,eax             ;i like to store a pointer to the full cmd line

Start0: cmp     cl,dh                          ;double quote
        jnz     Start2

Start1: mov     cl,[eax]
        jecxz   Start4

        inc     eax
        cmp     cl,dh                          ;double quote
        jnz     Start1

Start2: mov     cl,[eax]
        jecxz   Start4

        inc     eax
        cmp     cl,dl                          ;space
        jnz     Start0

Start3: mov     cl,[eax]
        inc     eax
        cmp     cl,dl                          ;space
        jz      Start3

        dec     eax

Start4: mov     lpCmndLine,eax                 ;i like to store a pointer to the parsed cmd line
        push    eax
        INVOKE  GetModuleHandle,edi
        pop     edx
        mov     hInstance,eax
        INVOKE  WinMain,eax,edi,edx,SW_SHOWNORMAL
        INVOKE  ExitProcess,eax
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 12, 2011, 11:29:11 AM
Yves - with my program, did you press the F1 key ?
if you are running XP SP3, it should work
Title: Re: creating a window with F1 toggle for full screen
Post by: ToutEnMasm on August 12, 2011, 11:50:24 AM

Quote
Yves - with my program, did you press the F1 key ?
if you are running XP SP3, it should work

Sorry,I haven't do this.It works also for me now.I am not sure you intercept the event with the best method,but your code hasn't  a very good look to read it.
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 12, 2011, 11:53:22 AM
thanks Yves

yah - many do not like my coding style - lol
the WM_GETMINMAXINFO code could probably be simplified
i'd have to have a vista and a win7 machine to test
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 12, 2011, 10:57:23 PM
Quote from: dedndave on August 12, 2011, 04:53:10 AM
this seems to work fine under XP
i would be interested to see if it works as well under win7   :P
if so, it would give the forum members a way to go into a "pseudo-full-screen" mode where it is supposedly not available
you could also reply to WM_SETCURSOR or use SetWindowLong to hide it

NOTE:
the F1 key toggles full-screen mode
the window must have focus to get to full screen, of course

very nice and simple ...thank you very much!  :U

I will try adding a WM_SETCURSOR to it.....and and a message box at the beginning asking the user  "Would you like to run in fullscreen mode ?" Yes or No

Later on tonight when I get home  :U

Thank you again!  :bg
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 18, 2011, 11:57:55 PM
Well I don't know I can't seem to add hide cursor to it ... I don't get  the VK_F1 here which draw the full screen ? ...which draws the window?

So I can add the hide cursor and that message box at start up....your code is nice but I don't seem to get it ......
I want to show cursor when it is a window , and hide it full screen...also that  message box at the beginning asking the user  "Would you like to run in fullscreen mode ?" Yes or No
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 19, 2011, 12:28:59 AM
for the message box, i used a little thread proc   :P
that way, the main window message loop can go ahead and run
and - we can show them the regular window while they are answering the question
rather than re-writing a bunch of code to set full-screen, i just use SendMessage...
        INVOKE  SendMessage,hWin,WM_KEYDOWN,VK_F1,NULL

if you wanted to, you could put the message box in before you create the window
and set the value of FsState with the answer
then, add a little code in WM_CREATE to start the window in the selected mode
it would only do something different if the answer is yes

turning the cursor off and on - i just used the FsState with a little calculation to make TRUE or FALSE
then use the ShowCursor function
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 19, 2011, 12:39:24 AM
I think I will look into other ways of doing this... I like to use show cursor, TRUE and  show cursor,FALSE.....
Also the window can not start before the message box......
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 19, 2011, 12:48:43 AM
TRUE = 1
FALSE = 0

we calculate the desired values all the time   :U

;EAX = HWND_TOPMOST (-1) or HWND_NOTOPMOST (-2)
        neg     eax
        dec     eax
        INVOKE  ShowCursor,eax


that's much more efficient than comparing eax with -1 and branching
        cmp     eax,HWND_TOPMOST
        jz      TurnCursorOff

        INVOKE  ShowCursor,TRUE
        jmp short CursorDone

TurnCursorOff:
        INVOKE  ShowCursor,FALSE

CursorDone:




try this...
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 19, 2011, 12:56:23 AM
I t works great but I don't understand the code at all .....

I don't get this part the most:

;########################################################
        cmp     wParam,VK_F1
        jnz     SkipWindPos

        mov     eax,FsState
        xor     eax,HWND_TOPMOST xor HWND_NOTOPMOST
        mov     edx,offset wps
        cmp     eax,HWND_NOTOPMOST
        mov     FsState,eax
        jz      SetWindPos

        push    eax
        push    edx
        INVOKE  GetWindowRect,hWnd,edx
        pop     edx
        mov     eax,[edx].RECT.right
        mov     ecx,[edx].RECT.bottom
        sub     eax,[edx].RECT.left
        sub     ecx,[edx].RECT.top
        mov     [edx].WindPos.xc,eax
        mov     [edx].WindPos.yc,ecx
        pop     eax
        add     edx,WindPosStruct.fsp-WindPosStruct.nwp

SetWindPos:
        push    eax
        INVOKE  SetWindowPos,hWnd,eax,[edx].WindPos.x,[edx].WindPos.y,[edx].WindPos.xc,[edx].WindPos.yc,SWP_SHOWWINDOW
        pop     eax
        neg     eax
        dec     eax
        INVOKE  ShowCursor,eax                                        ;####### ShowCursor TRUE or FALSE

SkipWindPos:
;########################################################


Also what calculates eax value of the cursor?
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 19, 2011, 01:04:22 AM
ok
we want a variable to hold the current "full-screen" state
i made it a dword named FsState
as it turns out, if we are in full-screen mode, the window is set to HWND_TOPMOST
if it is not full-screen, we set it to HWND_NOTOPMOST
the values for HWND_TOPMOST and HWND_NOTOPMOST are -1 and -2
so - we just use those values to set FsState

now - when the user presses the F1 key, we can examine the FsState dword to
see whether we are toggling to full-screen or normal window
we simply XOR a 1 onto the current value to come up with the new value
-1 XOR 1 = -2
-2 XOR 1 = -1

this is what gives us the toggling action

the part that is probably a little strange is the fact that we want to
store the current window size and position if we are toggling INTO full-screen mode
that way, when they go back to normal window, we can set it to the same place and size

if we are going from full-screen to normal window, we do not have to save the window size and position
we just have to recall the saved position and set it

after the screen position and size are set, we can use the FsState value to determine whether to hide or show the cursor
        push    eax
        INVOKE  SetWindowPos,hWnd................
        pop     eax
        neg     eax
        dec     eax
        INVOKE  ShowCursor,eax


it is this code that makes the conversion
        neg     eax
        dec     eax

if FsState is -1, we get 0 (FALSE)
if FsState is -2, we get 1 (TRUE)
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 19, 2011, 01:12:08 AM
Thanks ....

I am going to have to go through it and comment as much as I can.... that way I can understand it and quickly use this template to ad stuff to it ...

you are a very skilled programmer to come up with that....

Thank you again.... :bg
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 19, 2011, 01:20:46 AM
well - you will want to start out by looking at the structures i made for window position
WindPos       STRUCT
  x        dd ?
  y        dd ?
  xc       dd ?
  yc       dd ?
WindPos       ENDS

WindPosStruct STRUCT
  nwp WindPos <>  ;normal window position
  fsp WindPos <>  ;full-screen window position
WindPosStruct ENDS


the first one stores a single set of window position and size values
the second structure has 2 versions of the first one

the nwp structure is used to save the normal window size and position before switching to full-screen
we use this set when we exit full-screen mode

the other version, fsp, is used to store the full-screen position and size values
these are calculated in the SetFsp procedure, which is called during WM_CREATE
i put that in a proc, so it could be used again if they switch resolution
if uMsg == WM_DISPLAYCHANGE
        call    SetFsp

you would have to add a little more code to set the window size and position if they are in full-screen
however, i don't know how they'd switch screen mode if the window is full-screen   :P
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 19, 2011, 02:28:34 AM
this one is a little cleaner
i put the screen-mode-toggle code in a proc that can be called
that way, we don't have to use PostMessage
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 19, 2011, 02:33:45 AM
thanks... so what does the SetFsp  PROC  does exactly....

I meant to ask this earlier .... how come the message box "X" close is deactivated ....it is like that with some of my other examples too....is this something in MASM specific?
I have some examples with no source and the "x" is activated so you have the option to cancel....
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 19, 2011, 02:37:45 AM
i suspect you need an InitCommonControls before calling MessageBox
let me try it...
Title: Re: creating a window with F1 toggle for full screen
Post by: hfheatherfox07 on August 19, 2011, 02:39:48 AM
Quote from: dedndave on August 19, 2011, 02:37:45 AM
i suspect you need an InitCommonControls before calling MessageBox
let me try it...

would coinitialize CommonControls be better? just remembered seeing that yesterday when I was doing something
Title: Re: creating a window with F1 toggle for full screen
Post by: dedndave on August 19, 2011, 02:50:13 AM
ok - if the message box does not have a cancel button, it won't have a close box, either   :P
so - if we use MB_YESNO, you won't get the close box

so, back to SetFsp
that procedure probably looks a little intimidating
i should have written it for clarity instead of small size
sorry about that

the job of that proc is to figure out what window position and size values to use to get full screen
the window has borders and a title bar
so, that proc determines how large they are
then figures out the coordinates for the fsp structure
for example, if the border on the left side of the window is 4 pixels wide, we need to set the x position to -4
i think the title bar is 30 pixels high, so we set the y position to -30
it does this by getting the window rectangle and the client rectangle,
converting 2 points using ClientToScreen, and doing some math to set the fsp structure values