Announcement

Collapse
No announcement yet.

Help - generate a maximized window ??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help - generate a maximized window ??

    First, just to set the level of this question, I am new to PB and new to windows programming in general but am very familiar with console programming in other languages.

    I am trying to figure out the correct syntax to create a window that is initially maximized. I have gone through several references and found things such as WS_MAXIMIZE etc etc along with various options for windows style and initial position etc....all seem to be related ... the problem is that when I attempt to use them as listed in various tutorials, I get no effect....

    So, starting with the template below, how would I modify the syntax so the window is maximized at program start?

    g_hWndMain = CreateWindow(szClassName, _ ' window class name
    "Simple Program Skeleton", _ ' window caption
    %WS_OVERLAPPEDWINDOW, _ ' window style
    %CW_USEDEFAULT, _ ' initial x position
    %CW_USEDEFAULT, _ ' initial y position
    %CW_USEDEFAULT, _ ' initial x size
    %CW_USEDEFAULT, _ ' initial y size
    %HWND_DESKTOP, _ ' parent window handle
    hMenu, _ ' window menu handle
    hInstance, _ ' program instance handle
    BYVAL %NULL) ' creation parameters

  • #2
    Use:

    Code:
    %WS_OVERLAPPEDWINDOW [b]OR %WS_MAXIMIZE[/b], _ ' window style
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      I tried that ... does not work

      I tried that first. I am just trying to modify the skeleton program that came with PB Windows - file found in PB v8.04 subdirectory: ..\samples\sdk\skeleton

      I made the mod as you described with no effect

      g_hWndMain = CreateWindow(szClassName, _ ' window class name
      "Simple Program Skeleton", _ ' window caption
      %WS_OVERLAPPEDWINDOW OR %WS_MAXIMIZE,_ ' window style
      %CW_USEDEFAULT, _ ' initial x position
      %CW_USEDEFAULT, _ ' initial y position
      %CW_USEDEFAULT, _ ' initial x size
      %CW_USEDEFAULT, _ ' initial y size
      %HWND_DESKTOP, _ ' parent window handle
      hMenu, _ ' window menu handle
      hInstance, _ ' program instance handle
      BYVAL %NULL) ' creation parameters

      Comment


      • #4
        You can override the maximized style when you call ShowWindow... are you doing that? The skeleton provided with PB/Win 8.03 uses 'icmdShow' ... but I cannot find a default for that.

        SDK for ShowWindow() tells us..
        SW_SHOWNORMAL
        Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
        Or, you can change the size and location in WM_CREATE... are you doing that? (the skeleton provided with PB/Win 8.03 does not do this)

        At least its some stuff to try....

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Lost ???

          sorry ... new to Windows programming ... Lots of reading to do yet.

          I'm really not sure how to use your suggestions....

          I was hoping this was a common thing !!!! Figured creating a maximized window was an every day trick! Was hoping to use this as a learning tool...

          I suppose just need to start reading Petzold cover to cover...

          Comment


          • #6
            Originally posted by Mark Farrar View Post
            sorry ... new to Windows programming ... Lots of reading to do yet.
            As an alternative to Petzold and SDK style programming you might try DDT style, which is less demanding of Windows knowhow. Nothing to stop you doing both, either, and to a large extent they can be mixed. See the examples in the \PBWIN\Samples\DDT subtree.

            I found Petzold rather unrewarding as only a subset of what I needed was there. Maybe I got the wrong Petzold.

            MCM, isn't PB Win at v8.04?

            Comment


            • #7
              If you added %WS_MAXIMIZE and you use ShowWindow with iCmdShow param, it won't work.... either use %WS_MAXIMIZE OR %WS_VISIBLE ,..or don't use %WS_MAXIMIZE and use ShowWindow with %SW_SHOWMAXIMIZED,.. or use %WS_MAXIMIZE and ShowWindow with %SW_SHOW param.

              Simply,(if using %WS_MAXIMIZE) ...just replace your iCmdshow param with %SW_SHOW.

              Code:
              #COMPILE EXE
              #INCLUDE "Win32API.inc"
              
              '------------------------------------------------------------------------------
              '
              '------------------------------------------------------------------------------
              FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, _
                                BYVAL lpCmdLine AS ASCIIZ PTR,BYVAL iCmdShow  AS LONG) AS LONG
                                
                  LOCAL Msg       AS tagMsg
                  LOCAL wce       AS WndClassEx
                  LOCAL szAppName AS ASCIIZ * 80
                  LOCAL hWnd      AS DWORD
              
                  szAppName         = "MaxWin"
                  wce.cbSize        = SIZEOF(wce)
                  wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
                  wce.lpfnWndProc   = CODEPTR(MaxWndProc)
                  wce.cbClsExtra    = 0
                  wce.cbWndExtra    = 0
                  wce.hInstance     = hInstance
                  wce.hIcon         = 0
                  wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
                  wce.hbrBackground = GetStockObject(%WHITE_BRUSH)
                  wce.lpszMenuName  = %NULL
                  wce.lpszClassName = VARPTR(szAppName)
                  wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)
              
                  RegisterClassEx wce
              
                  ' Create a window using the registered class
                  hWnd = CreateWindow( szAppName, "Max Window on Start...", _
                                       %WS_OVERLAPPEDWINDOW OR %WS_MAXIMIZE , _ ' %WS_MAXIMIZE OR %WS_VISIBLE
                                       %CW_USEDEFAULT,%CW_USEDEFAULT, _
                                       %CW_USEDEFAULT,%CW_USEDEFAULT, _
                                       %NULL,%NULL,hInstance,BYVAL %NULL)
              
                  ' Display the window on the screen
                  ShowWindow hWnd, %SW_SHOW 'iCmdShow
                  'ShowWindow hWnd, %SW_SHOWMAXIMIZED
                  UpdateWindow hWnd
              
                  DO WHILE GetMessage(Msg, %NULL, 0, 0)
                      TranslateMessage Msg
                      DispatchMessage Msg
                  LOOP
              
                  FUNCTION = msg.wParam
              END FUNCTION
              
              '------------------------------------------------------------------------------
              '
              '------------------------------------------------------------------------------
              FUNCTION MaxWndProc( BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                                   BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
              
                  SELECT CASE wMsg
                      CASE %WM_CREATE
                      CASE %WM_DESTROY
                          PostQuitMessage 0
                          EXIT FUNCTION
                  END SELECT
              
                  FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
                  
              END FUNCTION
              HTH
              Regards,
              Jules
              Last edited by Jules Marchildon; 24 May 2008, 06:38 PM.
              Best regards
              Jules
              www.rpmarchildon.com

              Comment


              • #8
                thanks

                Actually I have been screwing around with this all night and I actually came to the same conclusion, but there is one thing I don't get.

                I understand now that the following is the key to making this work...

                ShowWindow hWnd, %SW_SHOWMAXIMIZED

                What I don't understand is the following: ShowWindow hWnd, iCmdShow

                I get it that the value come from the WinMain call, but....

                Where,How, What does WinMain (x,x,x, iCmdShow) default too? How does it get it's value? I read some traffic on the net about behaving differently when clicked from exlorer than it does when launched from the command line ????

                Comment


                • #9
                  OMG - I got it!!!!

                  ok ... figured this out ... thanks to all for your help.

                  here is the part that was driving me nuts...

                  How does the parameter "iCmdShow" get loaded on startup...

                  well...from the properties check box if you if create a shortcut to the .exe file!!!

                  sure enough ... leave "iCmdShow" in ShowWindow and whatever you check in the shortcut's startup property is what happend. If you hard code the the ShowWindow to use %SW_SHOWMAXIMIZED, then it doesn't matter what the shortcut says, you always get a maximized window....

                  ok...why is this important and what does it tell us ??? well...

                  if you do not have a shortcut to the program the "default" value for "iCmdShow" passed to WinMain is the one for "normal window" ... so ... if you want to force a maximizes startup, do it either a shortcut property or if you really don't want the user to mess with it, just hard code ShowWindow to maximize for you every time....

                  ugh!!! I'm going to go watch TV ... been working on this all eveining...my brain is melting!

                  thanks to all...

                  MF

                  Comment


                  • #10
                    Yes, the shortcut setting will override the style (I think) if CW_USEDEFAULT is used for the position constants. For resizable windows, I always use SetWindowPlacement to save/restore the position, this guarantees the window is resized to how it was last session.
                    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                    Comment

                    Working...
                    X