News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

WS_MAXIMIZE AND WS_MINIMIZE

Started by Ratch, November 16, 2005, 06:40:39 PM

Previous topic - Next topic

Ratch

arafel,
     WM_MAXIMIZE is equated to 3.  Putting a 3 into the vertical position and the window height parameters of the CreateWindow call seems like a strange way to get the window to maximize initially.  I will have to try it.  Ratch

tenkey,
     You might be onto something.  Ratch

arafel

Ratch,

It works, trust me  :toothy

Here something i just found in the sdk documentation:

QuoteWindows can set the initial size and position for overlapped windows. To have Windows set the window's initial position, an application uses CW_USEDEFAULT for the X parameter to CreateWindow or CreateWindowEx. When an application uses CW_USEDEFAULT to set an overlapped window's position and uses the WS_VISIBLE style to have the window visible when it is created, Windows passes the Y parameter of CreateWindow or CreateWindowEx to ShowWindow. Thus, when an application uses CW_USEDEFAULT for the X parameter to CreateWindow or CreateWindowEx, the Y parameter must be one of the following:

SW_HIDE
SW_SHOWNORMAL
SW_NORMAL
SW_SHOWMINIMIZED
SW_SHOWMAXIMIZED
SW_MAXIMIZE
SW_SHOWNOACTIVATE
SW_SHOW
SW_MINIMIZE
SW_SHOWMINNOACTIVE
SW_SHOWNA
SW_RESTORE
Usually an application should use SW_SHOW for the Y parameter because SW_SHOW allows the proper functioning for WS_MAXIMIZE and WS_MINIMIZE styles.

To have Windows set the window's initial size, an application uses CW_USEDEFAULT for the nWidth parameter to CreateWindow or CreateWindowEx. When an application uses CW_USEDEFAULT to have Windows set the window's initial size, the nHeight parameter to CreateWindow or CreateWindowEx is ignored.

MichaelW

For the CreateWindowEx API WS_MINIMIZE and WS_MAXIMIZE seem to work just as they should. Neither was affected by any of the class styles and extended window styles that I tested, or by SW_SHOWDEFAULT or SW_SHOWNORMAL, or by any but the most oddball window styles that I tested.

For the "CreateWindow" API, I don't know because the functions are not present in the user32.dll on my Windows 2000 system.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        hInst     dd          0
        hWnd      dd          0
        wc        WNDCLASSEX  <>
        msg       MSG         <>
        className db          "minimal_test"
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov   hInst, rv(GetModuleHandle, NULL)
    mov   wc.cbSize,        sizeof WNDCLASSEX
    ;CS_HREDRAW
    ;CS_VREDRAW
    ;CS_NOCLOSE
    ;CS_BYTEALIGNWINDOW
    mov   wc.style,         CS_HREDRAW or CS_VREDRAW \
                              or CS_BYTEALIGNWINDOW
    mov   wc.lpfnWndProc,   OFFSET WndProc
    mov   wc.cbClsExtra,    NULL
    mov   wc.cbWndExtra,    NULL
    m2m   wc.hInstance,     hInst
    mov   wc.hbrBackground, COLOR_BTNFACE+1
    mov   wc.lpszMenuName,  NULL
    mov   wc.lpszClassName, OFFSET className
    mov   wc.hIcon,         NULL
    mov   wc.hCursor,       NULL
    mov   wc.hIconSm,       0
    invoke RegisterClassEx, ADDR wc
    ;WS_EX_OVERLAPPEDWINDOW
    ;WS_EX_DLGMODALFRAME
    ;WS_EX_TOOLWINDOW
    ;WS_EX_PALETTEWINDOW
    ;WS_OVERLAPPEDWINDOW
    ;WS_MINIMIZE
    ;WS_MAXIMIZE
    ;WS_DISABLED
    ;WS_POPUP
    ;WS_VISIBLE
    invoke CreateWindowEx,  WS_EX_OVERLAPPEDWINDOW,
                            ADDR className,
                            chr$("Test"),
                            WS_OVERLAPPEDWINDOW or WS_MAXIMIZE,
                            0,0,400,300,
                            NULL, NULL,
                            hInst, NULL
    mov   hWnd, eax
    ;SW_SHOWDEFAULT
    ;SW_SHOWNORMAL
    invoke ShowWindow, hWnd, SW_SHOWNORMAL
    invoke UpdateWindow, hWnd
  msgLoop:
    invoke GetMessage, ADDR msg, NULL, 0, 0
    .IF (eax != 0)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
        jmp   msgLoop
    .ENDIF
    exit msg.wParam
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
    .IF (uMsg == WM_DESTROY)
        invoke PostQuitMessage, NULL
        return 0
    .ENDIF
    invoke DefWindowProc, hWin, uMsg, wParam, lParam
    ret
WndProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

Ratch

MichaelW,
     Copied your code into my test bed, then assembled and linked it.  I get a window that initially shows a 400x300 pixel size on my WinXP box.  Ratch

Ratch

arafel,
Quote
Here something i just found in the sdk documentation: .....

     Whew! No wonder MS has trouble keeping consistancy across OSes.  Ratch

PBrennick

Ratch,
Michael's version did not maximize on my machine, either.  It does if I do this...


;
include \masm32\include\masm32rt.inc
;
.data
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hInst       dd  0
hWnd        dd  0
wc   WNDCLASSEX <>
msg         MSG <>
className   db  "minimal_test"
;
.code
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
start:
    mov     hInst, rv(GetModuleHandle, NULL)
    mov     wc.cbSize, sizeof WNDCLASSEX
    mov     wc.style, CS_HREDRAW or CS_VREDRAW \
                      or CS_BYTEALIGNWINDOW
    mov     wc.lpfnWndProc, OFFSET WndProc
    mov     wc.cbClsExtra, NULL
    mov     wc.cbWndExtra, NULL
    m2m     wc.hInstance, hInst
    mov     wc.hbrBackground, COLOR_BTNFACE+1
    mov     wc.lpszMenuName, NULL
    mov     wc.lpszClassName, OFFSET className
    mov     wc.hIcon, NULL
    mov     wc.hCursor, NULL
    mov     wc.hIconSm, 0
    invoke  RegisterClassEx, ADDR wc
    invoke  CreateWindowEx, WS_EX_OVERLAPPEDWINDOW,
                            ADDR className, chr$("Test"),
                            WS_OVERLAPPEDWINDOW,
                            0, 0, 400, 300, NULL, NULL, hInst, NULL
    mov     hWnd, eax
    invoke  ShowWindow, hWnd, SW_SHOWMAXIMIZED  ; SW_SHOWNORMAL
    invoke  UpdateWindow, hWnd
msgLoop:
    invoke  GetMessage, ADDR msg, NULL, 0, 0
    .if (eax != 0)
      invoke  TranslateMessage, ADDR msg
      invoke  DispatchMessage, ADDR msg
      jmp     msgLoop
    .endif
    exit    msg.wParam
;
;
WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    .if (uMsg == WM_DESTROY)
      invoke  PostQuitMessage, NULL
      return  0
    .endif
    invoke  DefWindowProc, hWin, uMsg, wParam, lParam
    ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WndProc endp
;
;
    end     start


This will display as maximized and also shows that WS_OVERLAPPEDWINDOW is all that is needed by CreateWindowEx to create a window.

Quote
Whew! No wonder MS has trouble keeping consistancy across OSes

You hit the nail on the head with that comment.  Sometimes I just want to pull the hair out of my head!

I am using a plain jane copy of XP Home Edition. BTW.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

I don't have an XP system to test on, but on my Windows 2000 system I did note that this combination of styles will cause the window to open up maximized and then shrink back to 400x300:

invoke CreateWindowEx,  WS_EX_OVERLAPPEDWINDOW,
                            ADDR className,
                            chr$("Test"),
                            WS_OVERLAPPEDWINDOW or WS_MAXIMIZE or WS_VISIBLE,
                            0,0,400,300,
                            NULL, NULL,
                            hInst, NULL


I find it surprising that XP behaves this way. I thought maintaining code compatibility was a major design point for Microsoft.

eschew obfuscation

QvasiModo

This works like a charm. Tested on Win2k. I think some style flags must have been wrong, or maybe neither ShowWindow or UpdateWindow didn't need to be called...


.386
.model flat,stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib

.data
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hInst       dd  0
hWnd        dd  0
wc   WNDCLASSEX <>
msg         MSG <>
className   db  "minimal_test"
windName db  "Test"

.code
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
start:
invoke GetModuleHandle, NULL
    mov     hInst, eax
    mov     wc.cbSize, sizeof WNDCLASSEX
    mov     wc.style, CS_HREDRAW or CS_VREDRAW \
                      or CS_BYTEALIGNWINDOW
    mov     wc.lpfnWndProc, OFFSET WndProc
    mov     wc.cbClsExtra, NULL
    mov     wc.cbWndExtra, NULL
    mov     wc.hInstance, eax
    mov     wc.hbrBackground, COLOR_BTNFACE+1
    mov     wc.lpszMenuName, NULL
    mov     wc.lpszClassName, OFFSET className
    mov     wc.hIcon, NULL
    mov     wc.hCursor, NULL
    mov     wc.hIconSm, 0
    invoke  RegisterClassEx, ADDR wc
    invoke  CreateWindowEx, 0,
                            ADDR className, offset windName,
                            WS_OVERLAPPEDWINDOW or WS_MAXIMIZE or WS_MAXIMIZEBOX or WS_VISIBLE,
                            0, 0, 400, 300, NULL, NULL, hInst, NULL
    mov     hWnd, eax
;    invoke  ShowWindow, hWnd, SW_SHOWMAXIMIZED  ; SW_SHOWNORMAL
;    invoke  UpdateWindow, hWnd
msgLoop:
    invoke  GetMessage, ADDR msg, NULL, 0, 0
    .if (eax != 0)
      invoke  TranslateMessage, ADDR msg
      invoke  DispatchMessage, ADDR msg
      jmp     msgLoop
    .endif
    invoke ExitProcess,msg.wParam

WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    .if (uMsg == WM_DESTROY)
      invoke  PostQuitMessage, NULL
      xor eax,eax
      ret
    .endif
    invoke  DefWindowProc, hWin, uMsg, wParam, lParam
    ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WndProc endp

    end     start

arafel

QvasiModo,
The code you posted fails to create maximized window on XP.

This one works on my xp sp2. Could someone verify that it works on 2k too?

.386
.model flat,stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib


.data
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hInst       dd  0
hWnd        dd  0
wc   WNDCLASSEX <>
msg         MSG <>
className   db  "minimal_test"
windName db  "Test"

.code
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
start:
invoke GetModuleHandle, NULL
    mov     hInst, eax
    mov     wc.cbSize, sizeof WNDCLASSEX
    mov     wc.style, CS_HREDRAW or CS_VREDRAW \
                      or CS_BYTEALIGNWINDOW
    mov     wc.lpfnWndProc, OFFSET WndProc
    mov     wc.cbClsExtra, NULL
    mov     wc.cbWndExtra, NULL
    mov     wc.hInstance, eax
    mov     wc.hbrBackground, COLOR_BTNFACE+1
    mov     wc.lpszMenuName, NULL
    mov     wc.lpszClassName, OFFSET className
    mov     wc.hIcon, NULL
    mov     wc.hCursor, NULL
    mov     wc.hIconSm, 0
    invoke  RegisterClassEx, ADDR wc

    invoke  CreateWindowEx, 0,
                            ADDR className, offset windName,
                            WS_VISIBLE or WS_MAXIMIZE,
                            CW_USEDEFAULT, SW_MAXIMIZE, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL
    mov     hWnd, eax

                                  ; works even without WS_MINIMIZE

   ; invoke  CreateWindowEx, 0,
   ;                         ADDR className, offset windName,
   ;                         WS_VISIBLE,
   ;                         CW_USEDEFAULT, SW_MAXIMIZE, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL
   ; mov     hWnd, eax


msgLoop:
    invoke  GetMessage, ADDR msg, NULL, 0, 0
    .if (eax != 0)
      invoke  TranslateMessage, ADDR msg
      invoke  DispatchMessage, ADDR msg
      jmp     msgLoop
    .endif
    invoke ExitProcess,msg.wParam

WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    .if (uMsg == WM_DESTROY)
      invoke  PostQuitMessage, NULL
      xor eax,eax
      ret
    .endif
    invoke  DefWindowProc, hWin, uMsg, wParam, lParam
    ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WndProc endp

    end     start

PBrennick

The GeneSys Project is available from:
The Repository or My crappy website

QvasiModo

Quote from: arafel on November 18, 2005, 07:47:40 PM
QvasiModo,
The code you posted fails to create maximized window on XP.

That's very strange, it works on 2K and it should too. But I just tried it on an XP SP2 it doesn't. Maybe they broke something at MS? :eek

BTW, SW_MAXIMIZE should not be passed as a parameter to CreateWindowEx.

Just curious, what's your service pack number?

QvasiModo


arafel

Quote from: QvasiModo
Just curious, what's your service pack number?

sp2

arafel

Quote from: QvasiModo
BTW, SW_MAXIMIZE should not be passed as a parameter to CreateWindowEx.

do you mean the SW_MAXIMIZE i pass in y parameter?
i think CreateWindow expects it to be SW_MAXIMIZE if WS_MAXIMIZE specified as style and x parameter is CW_USEDEFAULT.

MichaelW

arafel,

On my Windows 2000 SP4 system your code opens a maximized window with nothing in the title bar except "Test".
eschew obfuscation