flat assembler
Message board for the users of flat assembler.

Index > Windows > DirectDraw in windowed mode

Author
Thread Post new topic Reply to topic
proveren



Joined: 24 Jul 2004
Posts: 68
Location: Bulgaria
proveren
I am making a small application in fullscreen/windowed mode with directdraw, the fullscreen is ok, the windowed is veeeery slow rendering and when i try to move,or resize the window. The message pump is one and the same, the initialization code is specific for the different modes and is correct as well as the flipping procedures. I would be glad if anyone can give me an advice, or his implementation if he has done ddraw in windowed mode.
Post 24 Jul 2004, 10:31
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
problem might be that you created window of bad size. Depending on drawing method, client window sizes must be same as sizes of backbuffer, otherwise directdraw performs stretching (slow).

Check client window sizes.
Post 24 Jul 2004, 14:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
proveren



Joined: 24 Jul 2004
Posts: 68
Location: Bulgaria
proveren
Actually I had a very stupid syntax error where I forgot to put the [] around a variable and instead of creating a backbuffer in windowed mode with dimensions 320/240 it creates a surface with size dword addresses like 40040444/40040448 for example.
Anyway, I am almost finished with my ddraw code and I want to upload it here as a template to end any ddraw difficulties for fasm coders. It is very flexible as it supports changing of modes, automatically restoring of surfaces, clean message pump etc.
However, I would like it if you could tell me how I can make the client rect the size of my backbuffer in windowed mode. This is important in some applications(and for some speed issues?) .There isn't a function SetClientRect after all.
Post 25 Jul 2004, 05:58
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
There is API sunc GetSystemMetrics, which reads some parameters (size of window border, height of caption etc.) You can use these to get these sizes (the vary with different windows styles, like "windows classic" or "window XP") If you have DirectX SDK (i quess you have) take a look at windowed mode example, and at "DDutil" common include it uses.
Post 25 Jul 2004, 12:50
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
The simplest way to set client rect size I've found is using of WM_WINDOWPOSCHANGING message.
This works well when user changes XP styles etc, while app is running.
Code:
;; [Height] & [Width] - client rect size
......
CreateWindow(Ex) with [Height] & [Width]
.......
;;  WM_WINDOWPOSCHANGING handler
    mov       edx, [lParam]           ;;  Pointer to a WINDOWPOS structure
    test byte[edx+WINDOWPOS.flags], SWP_SHOWWINDOW
    jz @f
     sub     esp, sizeof.RECT        ;;  local var
       invoke  GetClientRect,[hwnd], esp

       mov     edx, [lParam]           ;;  Pointer to a WINDOWPOS structure
        mov     eax, [Width]
        add     eax, eax
    sub     eax, [esp+RECT.right]
       mov     [edx+WINDOWPOS.cx], eax
     
    mov     eax, [Height]
       add     eax, eax
    sub     eax, [esp+RECT.bottom]
      mov     [edx+WINDOWPOS.cy], eax
     and     [edx+WINDOWPOS.flags],NOT SWP_NOSIZE
        add     esp, sizeof.RECT        ;;  release stack
@@:    
Post 25 Jul 2004, 19:14
View user's profile Send private message Reply with quote
proveren



Joined: 24 Jul 2004
Posts: 68
Location: Bulgaria
proveren
hmm, S.T.A.S. , I neither understand what exactly your code does and when it does it, and where I should include it in my source. I put it in a the message handler when the message WM_WINDOWPOSCHANGING was met but it didn't do anything. Could you explain it please!
Post 28 Jul 2004, 09:17
View user's profile Send private message Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
Ok, here's quick example of use.
Idea is very simple, when window is about to be displayed, we just override cx & cy members of WINDOWPOS structure.
MSDN wrote:
While this message is being processed, modifying any of the values in WINDOWPOS affects the window's new size, position, or place in the Z order.

So, when windows is being created and this message is processed first time, cx = width of window (250).
But we want client rect's whidth to be 250, so we need to modify cx. New value is calculated this way:
desired client whidth + dx
dx = 250 - currend client width ;; left + right border
or: 2*250-currend client width

Try to comment "je .WM_WINDOWPOSCHANGING" line and se the difference
Code:
include       '%fasminc%\WIN32AX.INC' 

IMAGE_BASE = 400000h

start:       xor     ebx, ebx
    mov     esi, IMAGE_BASE
     mov     edi, wc
     invoke  LoadCursor, ebx,IDC_ARROW
   mov     [edi+WNDCLASSEX.hCursor], eax
       invoke  LoadIcon, esi,IDI_APPLICATION
       mov     [edi+WNDCLASSEX.hIcon], eax     
    mov     [edi+WNDCLASSEX.hIconSm],eax
        invoke  RegisterClassEx, edi
        add     edi, sizeof.WNDCLASSEX  ;;  = wc.Name  
     invoke  CreateWindowEx,ebx,edi,caption,\
           WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE,\
               CW_USEDEFAULT,CW_USEDEFAULT,[Width],[Height],ebx,ebx,esi,ebx

msg_loop:
   invoke  GetMessage,msg,ebx,ebx,ebx
  or      eax,eax
     jz      end_loop
    invoke  DispatchMessage,msg
 jmp     msg_loop
end_loop:
   invoke  ExitProcess,[msg.wParam]

proc WndProc, hwnd,wmsg,wparam,lparam
               mov     dx,word[wmsg]

           cmp     dx,WM_PAINT
         je      .WM_PAINT

               cmp     dx,WM_WINDOWPOSCHANGING
             je      .WM_WINDOWPOSCHANGING

   cmp     dx,WM_DESTROY
       je      .WM_DESTROY

.def:    leave
       jmp     [DefWindowProc]

.WM_PAINT:
       invoke  BeginPaint, [hwnd],ps
       invoke  GetClientRect, [hwnd], rect
 invoke  wsprintf, txt,form,[rect.right],[rect.bottom]
       ;add    esp,4*4
     invoke  TextOut, [ps.hdc],0,0,txt,eax
       invoke  EndPaint, [hwnd],ps
 jmp     .def

.WM_WINDOWPOSCHANGING:
      mov     edx,[lparam]           ;;  Pointer to a WINDOWPOS structure
 test    byte[edx+WINDOWPOS.flags], SWP_SHOWWINDOW
   jz      .def
        push    edx
        invoke  GetClientRect,[hwnd], rect
        pop        edx

        mov     eax, [Width]
        add     eax, eax
        sub     eax, [rect.right]
        mov     [edx+WINDOWPOS.cx], eax
       
        mov     eax, [Height]
        add     eax, eax
        sub     eax, [rect.bottom]
        mov     [edx+WINDOWPOS.cy], eax
        and     [edx+WINDOWPOS.flags],NOT SWP_NOSIZE
        jmp     .def

.WM_DESTROY:
        invoke  PostQuitMessage, 0
  jmp     .def
endp

align       4       
msg MSG
ps       PAINTSTRUCT
rect     RECT
Width   dd 250
Height        dd 200
wc    dd  sizeof.WNDCLASSEX,0,WndProc,0,0,IMAGE_BASE,0,0,\
               COLOR_WINDOW+1,0,.Name,0
    .Name           db  'MyWndClass',0
caption db 'Just some window',0
form       db 'client rect size: x=%04ld, y=%04ld',0
txt  rb 20

.end start    
Post 29 Jul 2004, 02:01
View user's profile Send private message Reply with quote
proveren



Joined: 24 Jul 2004
Posts: 68
Location: Bulgaria
proveren
Hey, that's nice, now I got it, thanks. However, I am using another method because I want the user to be able to resize it and set the client are to the desired one from the menu.
Post 29 Jul 2004, 09:26
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 YouTube, Twitter.

Website powered by rwasa.