creating a window with F1 toggle for full screen

Started by hfheatherfox07, August 11, 2011, 08:38:52 PM

Previous topic - Next topic

ToutEnMasm


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

dedndave

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

dedndave

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

ToutEnMasm


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.

dedndave

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

hfheatherfox07

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

hfheatherfox07

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

dedndave

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

hfheatherfox07

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......

dedndave

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...

hfheatherfox07

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?

dedndave

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)

hfheatherfox07

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

dedndave

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

dedndave

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