Announcement

Collapse
No announcement yet.

Questions on Creating Modal Dialog Using SDK - CreateWindowEx

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

  • Questions on Creating Modal Dialog Using SDK - CreateWindowEx

    I have a couple of question about using CreateWindowEx to create a modal dialog. I’m trying to emulate what DialogBox does. According to MS after creating a dialog, DialogBox disables the owner window, and starts its own message loop. Does anyone know exactly how MS does that? How do they disable the main message loop? Also, how do you capture the return value from EndDialog? I’ve shown my main window message loop below (not that there is anything very unique about it).

    Code:
       ' Message loop
       DO WHILE GetMessage(tMsg, BYVAL %NULL, 0, 0)
           IF ISFALSE TranslateAccelerator(hWnd, hAccelerator, tMsg) THEN
               TranslateMessage (tMsg)
               DispatchMessage  (tMsg)
           END IF
       LOOP
    Larry Kruse

  • #2
    Use EnableWindow to disable mouse and keyboard input in the parent window, before you enter the local message pump, then restore mouse and keyboard input in the parent when you leave the child popup.
    Patrice Terrier
    www.zapsolution.com
    www.objreader.com
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

    Comment


    • #3
      Patrice - thank you. Can you tell me what the message pump for the dialog would look like and how would it capture the return value from EndDialog?
      Larry Kruse

      Comment


      • #4
        Here are just a few quick cut and paste examples, however there are many other ways to do it.

        Code:
        FUNCTION ZI_FontBox ALIAS "ZI_FontBox" (BYVAL hParent&, zCaption AS ASCIIZ, zUseText AS ASCIIZ, zUseFont AS ASCIIZ, UseSize&, UseARGB&, Use3D&) EXPORT AS LONG
        
            LOCAL Msg        AS tagMsg
            LOCAL wc         AS WndClassEx
            LOCAL zFontClass AS ASCIIZ * 10
        
            zFontClass = "zFontBox"
            UseText$ = zUseText
            UseFont$ = zUseFont
        
            IsInitialized& =  GetClassInfoEx(zInstance, zFontClass, wc)
            IF IsInitialized& = 0 THEN
               wcStyle& = %CS_HREDRAW OR %CS_VREDRAW
               wc.cbSize        = SIZEOF(wc)
               wc.style         = wcStyle&
               wc.lpfnWndProc   = CODEPTR(FontBoxProc)
               wc.cbClsExtra    = 0
               wc.cbWndExtra    = 0
               wc.hInstance     = zInstance
               wc.hIcon         = 0
               wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
               wc.hbrBackground = GetSysColorBrush(%COLOR_BTNFACE) ' %COLOR_WINDOW
               wc.lpszMenuName  = %NULL
               wc.lpszClassName = VARPTR(zFontClass)
               wc.hIconSm       = %NULL '//3.00 LoadIcon(zInstance, "SIZE16")
               IF RegisterClassEx(wc) THEN IsInitialized& = %TRUE
            END IF
        
            IF IsInitialized& THEN
        
               CALL zSetFontBoxData(Button$, UseText$, UseFont$, UseSize&, UseARGB&, Use3D&, hParent&, 1)
               Style& = %WS_OVERLAPPED OR %WS_SYSMENU OR %WS_CLIPCHILDREN
               StyleEx& = 0
               hFontBox& = CreateWindowEx(StyleEx&, zFontClass, _
                                       zCaption, _ '// zCaption
                                       Style&, _
                                       0, _
                                       0, _
                                       0, _
                                       0, _
                                       hParent&, 0, zInstance, BYVAL %NULL)
        
               IF hFontBox& THEN
        
                  CALL SetWindowPos(hParent&, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE)
                  CALL EnableWindow(hParent&, 0) ' Disable Mouse and keyboard input
        
                  CALL ShowWindow(hFontBox&, %SW_SHOW)
                  CALL UpdateWindow(hFontBox&)
        
        
                  DO WHILE GetMessage(Msg, %NULL, 0, 0)
                     IF IsDialogMessage(hFontBox&, Msg) = %FALSE THEN
                        TranslateMessage Msg
                        DispatchMessage Msg
                     END IF
                     IF Msg.Message = %WM_CLOSE THEN EXIT DO ' Bail out from the message pump
        
                   ' To force redraw of the entered text using the selected gdi+ font
                     IF Msg.Message = %WM_CHAR OR Msg.Message = %WM_KEYDOWN THEN
                        CALL ZI_UpdateWindow(hFontBox&, 0)
                     END IF
        
                  LOOP
        
                  CALL EnableWindow(hParent&, 1) ' Enable Mouse and keyboard input
                  CALL SetWindowPos(hParent&, %HWND_NOTOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE)
        
               END IF
        
               CALL zSetFontBoxData("", UseText$, UseFont$, UseSize&, UseARGB&, Use3D&, Choice&, 0)
        
               CALL zSplitColorARGB(UseARGB&, A?, R?, G?, B?)
               IF RGB(R?,G?,B?) = 0 THEN
                  UseARGB& = ZD_ColorARGB(A?, RGB(0, 0, 1))
               END IF
        
               zUseText = UseText$
               zUseFont = UseFont$
        
               FUNCTION = Choice&
        
            END IF
        
        END FUNCTION
        Code:
        FUNCTION zcAboutBox() AS LONG
        
            LOCAL Msg    AS tagMsg
            LOCAL zClass AS ASCIIZ * 32
            LOCAL wc     AS WndClassEx
        
            zClass = "ZCDIALBOX"
            wcStyle& = %CS_HREDRAW OR %CS_VREDRAW
            IF zcOsVersion > 500 THEN wcStyle& = wcStyle& OR %CS_DROPSHADOW
        
            IsInitialized& = GetClassInfoEx(zcInstance, zClass, wc)
            IF IsInitialized&   = 0 THEN
               wc.cbSize        = SIZEOF(wc)
               wc.style         = wcStyle&
               wc.lpfnWndProc   = CODEPTR(AboutProc)
               wc.cbClsExtra    = 0
               wc.cbWndExtra    = 0
               wc.hInstance     = zcInstance
               wc.hIcon         = %NULL
               wc.hCursor       = %NULL' LoadCursor(%NULL, BYVAL %IDC_ARROW)
               wc.hbrBackground = hBrush&
               wc.lpszMenuName  = %NULL
               wc.lpszClassName = VARPTR(zClass)
               wc.hIconSm       = %NULL
               IF RegisterClassEx(wc) THEN IsInitialized& = %TRUE
            END IF
            IF IsInitialized& THEN
        
               W& = 300: H& = 200
               CALL zcCenterWind(hMain, W&, H&, x&, y&)
        
               Style& = %WS_POPUP OR %WS_VISIBLE OR %WS_BORDER ' %WS_DLGFRAME
        
               'StyleEx& = %WS_EX_CLIENTEDGE or %WS_EX_WINDOWEDGE
               Af$ = PARSE$(cfgStr$(2), $zcLim, 3)
               hWin& = CreateWindowEx(StyleEx&, _
                                      zClass, _                ' window class name
                                      (Af$), _                 ' window title
                                      Style&, _                ' window style
                                      x&, _                    ' initial x position
                                      y&, _                    ' initial y position
                                      W&, _                    ' initial x size
                                      H&, _                    ' initial y size
                                      hMain, _                 ' parent window handle
                                      0, _                     ' window menu handle
                                      zcInstance, _            ' program instance handle
                                      BYVAL %NULL)             ' creation parameters
               IF hWin& THEN
                  ButW& = 50: ButH& = 18
                  x& = (W& - ButW&) \ 2: y& = H& - ButH& - 8
        
                  hCtl& = CreateWindowEx(%WS_EX_STATICEDGE OR %WS_EX_NOPARENTNOTIFY, "Static", BYVAL %NULL, _
                                        %WS_CHILD OR %WS_VISIBLE OR %SS_ETCHEDHORZ, _
                                        0, 52, W&, 2, hWin&, 0, zcInstance, BYVAL %NULL)
                  hCtl& = CreateWindowEx(0, "BUTTON", (cfgStr$(49)), %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
                                         x&, 168, ButW&, 20, hWin&, 1, zcInstance, BYVAL %NULL)
                  CALL zcSetCTLFont(hCtl&, zcDefaultFont)
        
                  CALL SetWindowPos(hMain, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE)
                  CALL EnableWindow(hMain, 0) ' Disable Mouse and keyboard input
        
                  CALL ShowWindow(hWin&, %SW_SHOW)
                  CALL UpdateWindow(hWin&)
        
                  DO WHILE GetMessage(Msg, %NULL, 0, 0)
                     IF IsDialogMessage(hWin&, Msg) = %FALSE THEN
                        TranslateMessage Msg
                        DispatchMessage Msg
                     END IF
                     IF Msg.Message = %WM_CLOSE THEN EXIT DO ' Bail out from the message pump
                  LOOP
        
                  CALL EnableWindow(hMain, 1) ' Enable Mouse and keyboard input
                  CALL SetWindowPos(hMain, %HWND_NOTOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE)
        
                  FUNCTION = LOWRD(Msg.wparam)
        
               END IF
            END IF
        
        END FUNCTION

        There is also a very easy way using these two GDImage API:
        ZI_CreateDW and ZI_DestroyDW
        Code:
        '// Create a Disabled Window that works with any control created directly with the API
        '// This creates a layered transparent window hover the window you want to disable.
          DECLARE FUNCTION ZI_CreateDW LIB "GDIMAGE.DLL" ALIAS "ZI_CreateDW" ( _
          BYVAL hParent AS LONG _
          ) AS LONG
        
          DECLARE SUB ZI_DestroyDW LIB "GDIMAGE.DLL" ALIAS "ZI_DestroyDW" ( _
          BYREF hDW AS LONG _          ' The Disabled Window handle to destroy
          )
        And you use them like this:

        Code:
        hDW AS DWORD = ZI_CreateDW(The_DWORD/LONG_MainParentWindowHandle)
        nRet AS LONG = MyModalChildPopupWindo() 
        CALL ZI_DestroyDW(hDW)
        When using these two API:
        - The underlaying parent window looks grayed/blured as long as the child popup is active.
        - The cursor is turned into an hour glass when the mouse hover the disabled parent window.

        And it looks like this:
        Patrice Terrier
        www.zapsolution.com
        www.objreader.com
        Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

        Comment


        • #5
          >Can you tell me what the message pump for the dialog would look like

          DialogBox[Indirect][Param] creates its own modal message loop; you don't write one.

          For windows created with CreateWindowEx() OR CreateDialog[Indirect][Param], you use a standard message loop as shown, except you probably want to include IsDialogMessage() in there.

          > and how would it capture the return value from EndDialog?
          You don't use EndDialog with a window created with CreateWindowEx() or CreateDialog[Indirect][Param].

          To ask the question, why do you want to use CreateWindowEx "to create a modal dialog?" Why not just use DialogBox[Indirect][Param] ????

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

          Comment


          • #6
            Patrice – thank you again. I’ll try out your message pump. That was definitely the area I was having problems with. I’ll post how it turns out. BTW, you do come up with some visually stunning windows – nice job!

            Michael – Most of my programs use an SDK main window and DDT dialogs. The recent SDK vs DDT post prompted me to experiment with doing the dialogs SDK style. I started by using DialogBox and CreateDialog however they require the dialogs to be laid out in a resource script. Because of using DDT, I’ve become use to doing the layout in the dialog show routine. Besides, PB has figured out a way to do it (presumably using DialogEnd), I was trying to emulate what they have done. You even mentioned that you use CreateWindowEx for your dialogs.
            Larry Kruse

            Comment


            • #7
              I'm still having problems . Hopefully someone can spot the problem. I've stripped down the program to the bare minimum. If you click on menu item Test, a small dialog will appear. The main dialog still has the focus (which is not desired) and when you close the dialog, the main window does not resume working. Please note that in its current form, you will have to use the Task Manager to shut down this program.
              Code:
              #COMPILE EXE
              #DIM ALL
              #COMPILER PBWIN
              #DEBUG ERROR ON
              #TOOLS ON
              #DEBUG DISPLAY ON
              #OPTIMIZE SPEED
              #REGISTER NONE
              #OPTION VERSION5
              
              #INCLUDE "Win32API.inc"
              #INCLUDE "CommCtrl.inc"
              #INCLUDE "InitCtrl.inc"
              
              $project_name           = "Test"
              $project_description    = "Test Program"
              '$MainIcon               = ""
              '$MainAccel              = ""
              
              GLOBAL ghInstance AS DWORD
              GLOBAL ghWnd AS DWORD
              
              
              '=====================================================================
              'Main
              '=====================================================================
              FUNCTION WINMAIN  (  _
                 BYVAL  hInstance                    AS DWORD       ,  _
                 BYVAL  hPrevInst                    AS DWORD       ,  _
                 BYVAL  lpszCmdLine                  AS ASCIIZ PTR  ,  _
                 BYVAL  nCmdShow                     AS LONG           _
                 ) AS LONG
              
                 FUNCTION = MainProgram (hInstance, lpszCmdLine, nCmdShow)
              
              END FUNCTION
              
              FUNCTION MainProgram  (  _
                 BYVAL  hInstance     AS DWORD       ,  _
                 BYVAL  lpszCmdLine   AS ASCIIZ PTR  ,  _
                 BYVAL  nCmdShow      AS LONG           _
                 ) AS LONG
              
                 DIM   hAccelerator                  AS LOCAL    DWORD
                 DIM   tMsg                          AS LOCAL    TagMsg
                 DIM   tWce                          AS LOCAL    WndClassEx
                 DIM   hWnd                          AS LOCAL    DWORD
                 DIM   szClassName                   AS LOCAL    ASCIIZ * 128
                 DIM   szCaption                     AS LOCAL    ASCIIZ * 128
                 DIM   szIcon                        AS LOCAL    ASCIIZ * 128
                 DIM   szAccel                       AS LOCAL    ASCIIZ * 128
              
                 'Capture startup directory, instantance handle and set other basic information
                 ghInstance  = hInstance
                 szClassName = $project_name
                 szCaption   = $project_description
               '  szIcon      = $MainIcon
               '  szAccel     = $MainAccel
              
              
                 'Window Class Styles to consider:
                 '  %CS_VREDRAW   Redraws the entire window if a movement or size adjustment changes the height of the client area.
                 '  %CS_HREDRAW   Redraws the entire window if a movement or size adjustment changes the width of the client area.
              
                 'Register window class
                 tWce.cbSize          = SIZEOF(tWce)
                 tWce.style           = 0   '%CS_HREDRAW OR %CS_VREDRAW
                 tWce.lpfnWndProc     = CODEPTR( MainWindowProcedure )
                 tWce.cbClsExtra      = 0
                 tWce.cbWndExtra      = 0
                 tWce.hInstance       = hInstance
                 tWce.hIcon           = 0 'LoadIcon( hInstance, szIcon )
                 tWce.hCursor         = LoadCursor( %NULL, BYVAL %IDC_ARROW )
                 tWce.hbrBackground   = GetStockObject( %WHITE_BRUSH )
                 tWce.lpszMenuName    = %NULL
                 tWce.lpszClassName   = VARPTR( szClassName )
                 tWce.hIconSm         = 0 'LoadIcon( hInstance, BYVAL %IDI_APPLICATION )
              
                 'Error message if failed to register window
                 IF ISFALSE RegisterClassEx (tWce) THEN
                    MessageBox (hWnd, "Failed to register class.", $project_description, %MB_ICONERROR)
                    EXIT FUNCTION
                 END IF
              
                 ' Create window using the registered class
                 hWnd = CreateWindow( _
                    szClassName, _                   ' window class name
                    szCaption, _                     ' 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
                    BYVAL %NULL, _                   ' window menu handle
                    hInstance, _                     ' program instance handle
                    BYVAL %NULL)                     ' creation parameters
              
                 'Error message if failed to create window
                 IF ISFALSE hWnd THEN
                    MessageBox (hWnd, "Failed to create window.", $project_description, %MB_ICONERROR)
                    EXIT FUNCTION
                 END IF
              
                 'Load accelerator if present
                 'hAccelerator = LoadAccelerators(hInstance, szAccel)
              
                 'Paint window for first time
                 ShowWindow (hWnd, nCmdShow)
                 IF ISFALSE UpdateWindow (hWnd) THEN
                    MessageBox (hWnd, "Failed to update window.", $project_description, %MB_ICONERROR)
                    EXIT FUNCTION
                 END IF
              
                 ' Message loop
                 DO WHILE GetMessage(tMsg, BYVAL %NULL, 0, 0)
              '       IF ISFALSE TranslateAccelerator(hWnd, hAccelerator, tMsg) THEN
                         TranslateMessage (tMsg)
                         DispatchMessage  (tMsg)
              '       END IF
                 LOOP
              
                 FUNCTION = tMsg.wParam
              END FUNCTION
              
              FUNCTION MainWindowProcedure ( BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG ) PRIVATE AS LONG
                 DIM   hMenu                         AS LOCAL    DWORD
                 DIM   tInfo                         AS LOCAL    MenuItemInfo
                 DIM   szTxt                         AS LOCAL    ASCIIZ * 256
              
                 SELECT CASE AS LONG wMsg
                    CASE  %WM_CREATE
                       InitCommonControls
                       ghWnd = hWnd
              
                       '========================================================================
                       'Menu
                       '========================================================================
                       hMenu = CreateMenu
              
                       szTxt                = "Test"
                       tInfo.cbSize         = SIZEOF (tInfo)
                       tInfo.fMask          = %MIIM_ID OR %MIIM_STATE OR %MIIM_TYPE OR %MIIM_DATA
                       tInfo.fType          = %MFT_STRING
                       tInfo.dwTypeData     = VARPTR (szTxt)
                       tInfo.cch            = LEN (szTxt)
                       tInfo.fState         = %MFS_ENABLED
                       tInfo.wID            = 1001
                       tInfo.dwItemData     = 1001
                       InsertMenuItem (hMenu, 1001, %FALSE, tInfo)
              
                       szTxt                = "Exit"
                       tInfo.cbSize         = SIZEOF (tInfo)
                       tInfo.fMask          = %MIIM_ID OR %MIIM_STATE OR %MIIM_TYPE OR %MIIM_DATA
                       tInfo.fType          = %MFT_STRING
                       tInfo.dwTypeData     = VARPTR (szTxt)
                       tInfo.cch            = LEN (szTxt)
                       tInfo.fState         = %MFS_ENABLED
                       tInfo.wID            = 1002
                       tInfo.dwItemData     = 1002
                       InsertMenuItem (hMenu, 1002, %FALSE, tInfo)
              
                       SetMenu (hWnd, hMenu)
                       DrawMenuBar (hWnd)
              
                    CASE  %WM_COMMAND
                       SELECT CASE AS LONG LO (WORD, wParam)
                          CASE  1001  :  MyDialog (hWnd)
                          CASE  1002  :  DestroyWindow (hWnd)
                       END SELECT
              
                    CASE  %WM_DESTROY
                       PostQuitMessage 0
                 END SELECT
                 FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
              END FUNCTION
              
              FUNCTION MyDialog ( BYVAL hWnd AS DWORD ) PRIVATE AS DWORD
              
                 DIM   tWce                          AS LOCAL    WndClassEx
                 DIM   szClassName                   AS LOCAL    ASCIIZ * 128
                 DIM   szCaption                     AS LOCAL    ASCIIZ * 128
                 DIM   dwStyle                       AS LOCAL    DWORD
                 DIM   dwExStyle                     AS LOCAL    DWORD
                 DIM   hDlg                          AS LOCAL    DWORD
              
                 szClassName = "MyDialog"
                 szCaption   = "My Dialog"
              
                 'Register window class
                 tWce.cbSize          = SIZEOF(tWce)
                 tWce.style           = %CS_HREDRAW OR %CS_VREDRAW
                 tWce.lpfnWndProc     = CODEPTR( cbMy )
                 tWce.cbClsExtra      = 0
                 tWce.cbWndExtra      = 0
                 tWce.hInstance       = ghInstance 'Instance handle held in a global variable
                 tWce.hIcon           = 0   'LoadIcon( ghInstance, szIcon )
                 tWce.hCursor         = LoadCursor( %NULL, BYVAL %IDC_ARROW )
                 tWce.hbrBackground   = GetStockObject( %WHITE_BRUSH )
                 tWce.lpszMenuName    = %NULL
                 tWce.lpszClassName   = VARPTR( szClassName )
                 tWce.hIconSm         = 0   'LoadIcon( ghInstance, BYVAL %IDI_APPLICATION )
              
                 IF ISFALSE RegisterClassEx (tWce) THEN
                    MessageBox (hWnd, "Failed to register class.", szCaption, %mb_iconerror)
                    EXIT FUNCTION
                 END IF
              
                 dwStyle     =  %WS_POPUP  OR %WS_CAPTION OR %WS_SYSMENU OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR _
                                %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT
              
                 dwExStyle   =  %WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE
              
              
                 ' Create window using the registered class
                 ' szClassName = "#32770"
              
                 hDlg = CreateWindowEx( _
                    dwExStyle, _                     ' Ex style
                    szClassName, _                   ' window class name
                    szCaption, _                     ' window caption
                    dwStyle, _                       ' window style
                    100, _                           ' initial x position
                    100, _                           ' initial y position
                    150, _                           ' initial x size
                    200, _                           ' initial y size
                    hWnd, _                          ' parent window handle
                    BYVAL %NULL, _                   ' window menu handle
                    ghInstance, _                    ' program instance handle
                    BYVAL %NULL)                     ' creation parameters
              
                 'Error message if failed to create window
                 IF ISFALSE hDlg THEN
                    MessageBox (hWnd, "Failed to create window.", szCaption, %mb_iconerror)
                    EXIT FUNCTION
                 END IF
              
                 SetWindowPos(hWnd, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE)
                 EnableWindow(hWnd, 0) ' Disable Mouse and keyboard input
              
                 ShowWindow  (hDlg, %SW_SHOW)
                 UpdateWindow(hDlg)
              
                 DIM   tMsg                          AS LOCAL    TagMsg
                 DO WHILE GetMessage(tMsg, %NULL, 0, 0)
                    IF IsDialogMessage(hDlg, tMsg) = %FALSE THEN
                       TranslateMessage tMsg
                       DispatchMessage tMsg
                    END IF
                    IF tMsg.Message = %WM_CLOSE THEN EXIT DO ' Bail out from the message pump
                 LOOP
              
                 EnableWindow(hWnd, 1) ' Enable Mouse and keyboard input
                 SetWindowPos(hWnd, %HWND_NOTOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE)
              
                 FUNCTION = LO(WORD, tMsg.wParam)
              END FUNCTION
              
              FUNCTION cbMy (   BYVAL hWnd   AS DWORD, _
                                BYVAL wMsg   AS DWORD, _
                                BYVAL wParam AS DWORD, _
                                BYVAL lParam AS LONG ) PRIVATE AS LONG
              
                 SELECT CASE AS LONG wMsg
                    CASE   %WM_COMMAND
                       SELECT CASE AS LONG LO (WORD, wParam)
                          CASE   %idok
                       END SELECT
                    CASE  %WM_SYSCOMMAND
                       IF LO(WORD, wParam) = %SC_CLOSE THEN
                       END IF
                 END SELECT
              
                 FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
              END FUNCTION
              Larry Kruse

              Comment


              • #8
                An small example:

                Code:
                #COMPILE EXE
                #DIM ALL
                #INCLUDE "win32api.inc"
                
                ' ========================================================================================
                ' Main
                ' ========================================================================================
                FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                
                   LOCAL hWndMain    AS DWORD
                   LOCAL hCtl        AS DWORD
                   LOCAL hFont       AS DWORD
                   LOCAL wcex        AS WNDCLASSEX
                   LOCAL szClassName AS ASCIIZ * 80
                   LOCAL rc          AS RECT
                   LOCAL szCaption   AS ASCIIZ * 255
                   LOCAL nLeft       AS LONG
                   LOCAL nTop        AS LONG
                   LOCAL nWidth      AS LONG
                   LOCAL nHeight     AS LONG
                
                   hFont = GetStockObject(%ANSI_VAR_FONT)
                
                   ' Register the window class
                   szClassName        = "MyClassName"
                   wcex.cbSize        = SIZEOF(wcex)
                   wcex.style         = %CS_HREDRAW OR %CS_VREDRAW
                   wcex.lpfnWndProc   = CODEPTR(WndProc)
                   wcex.cbClsExtra    = 0
                   wcex.cbWndExtra    = 0
                   wcex.hInstance     = hInstance
                   wcex.hCursor       = LoadCursor (%NULL, BYVAL %IDC_ARROW)
                   wcex.hbrBackground = %COLOR_3DFACE + 1
                   wcex.lpszMenuName  = %NULL
                   wcex.lpszClassName = VARPTR(szClassName)
                   wcex.hIcon         = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Sample, if resource icon: LoadIcon(hInst, "APPICON")
                   wcex.hIconSm       = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Remember to set small icon too..
                   RegisterClassEx wcex
                
                   ' Window caption
                   szCaption = "SDK Main Window"
                
                   ' Retrieve the size of the working area
                   SystemParametersInfo %SPI_GETWORKAREA, 0, BYVAL VARPTR(rc), 0
                
                   ' Calculate the position and size of the window
                   nWidth  = (((rc.nRight - rc.nLeft)) + 2) * 0.75   ' 75% of the client screen width
                   nHeight = (((rc.nBottom - rc.nTop)) + 2) * 0.70   ' 70% of the client screen height
                   nLeft   = ((rc.nRight - rc.nLeft) \ 2) - nWidth \ 2
                   nTop    = ((rc.nBottom - rc.nTop) \ 2) - (nHeight \ 2)
                
                   ' Create a window using the registered class
                   hWndMain = CreateWindowEx(%WS_EX_CONTROLPARENT, _           ' extended style
                                             szClassName, _                    ' window class name
                                             szCaption, _                      ' window caption
                                             %WS_OVERLAPPEDWINDOW OR _
                                             %WS_CLIPCHILDREN, _               ' window styles
                                             nLeft, _                          ' initial x position
                                             nTop, _                           ' initial y position
                                             nWidth, _                         ' initial x size
                                             nHeight, _                        ' initial y size
                                             %NULL, _                          ' parent window handle
                                             0, _                              ' window menu handle
                                             hInstance, _                      ' program instance handle
                                             BYVAL %NULL)                      ' creation parameters
                
                   hCtl = CreateWindowEx(0, "BUTTON", "&Ok", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
                          0, 0, 0, 0, hWndMain, %IDOK, hInstance, BYVAL %NULL)
                   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
                
                   hCtl = CreateWindowEx(0, "BUTTON", "&Close", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
                          0, 0, 0, 0, hWndMain, %IDCANCEL, hInstance, BYVAL %NULL)
                   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
                
                   ' Show the window
                   ShowWindow hWndMain, nCmdShow
                   UpdateWindow hWndMain
                
                   ' Message handler loop
                   LOCAL uMsg AS tagMsg
                   WHILE GetMessage(uMsg, %NULL, 0, 0)
                      IF ISFALSE IsDialogMessage(hWndMain, uMsg) THEN
                         TranslateMessage uMsg
                         DispatchMessage uMsg
                      END IF
                   WEND
                
                   FUNCTION = uMsg.wParam
                
                END FUNCTION
                ' ========================================================================================
                
                ' ========================================================================================
                ' Main Window procedure
                ' ========================================================================================
                FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                
                   LOCAL rc AS RECT
                
                   SELECT CASE wMsg
                
                      CASE %WM_SIZE
                         ' Resize the two sample buttons of the dialog
                         IF wParam <> %SIZE_MINIMIZED THEN
                            GetClientRect hWnd, rc
                            MoveWindow GetDlgItem(hWnd, %IDOK), (rc.nRight - rc.nLeft) - 185, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
                            MoveWindow GetDlgItem(hWnd, %IDCANCEL), (rc.nRight - rc.nLeft) - 95, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
                         END IF
                
                      CASE %WM_COMMAND
                
                         SELECT CASE LO(WORD, wParam)
                
                            CASE %IDOK
                               IF HI(WORD, wParam) = %BN_CLICKED THEN
                                  ShowPopupDialog hwnd
                               END IF
                
                            CASE %IDCANCEL
                               IF HI(WORD, wParam) = %BN_CLICKED THEN
                                  SendMessage hWnd, %WM_CLOSE, 0, 0
                                  EXIT FUNCTION
                               END IF
                
                         END SELECT
                
                      CASE %WM_SYSCOMMAND
                         ' Capture this message and send a WM_CLOSE message
                         IF (wParam AND &HFFF0) = %SC_CLOSE THEN
                            SendMessage hWnd, %WM_CLOSE, 0, 0
                            EXIT FUNCTION
                         END IF
                
                      CASE %WM_DESTROY
                         PostQuitMessage 0
                         EXIT FUNCTION
                
                   END SELECT
                
                   FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
                
                END FUNCTION
                ' ========================================================================================
                
                ' ========================================================================================
                ' Popup dialog - Calling example: ShowPopupDialog hWnd
                ' ========================================================================================
                FUNCTION ShowPopupDialog (BYVAL hParent AS LONG) AS LONG
                
                   LOCAL hWndPopup   AS LONG
                   LOCAL hCtl        AS LONG
                   LOCAL hFont       AS LONG
                   LOCAL rc          AS RECT
                   LOCAL wcex        AS WNDCLASSEX
                   LOCAL szClassName AS ASCIIZ * 80
                   LOCAL szCaption   AS ASCIIZ * 255
                
                   hFont = GetStockObject(%ANSI_VAR_FONT)
                
                   szClassName        = "MyPopupClassName"
                   wcex.cbSize        = SIZEOF(wcex)
                   wcex.style         = %CS_HREDRAW OR %CS_VREDRAW
                   wcex.lpfnWndProc   = CODEPTR(PopupDlgProc)
                   wcex.cbClsExtra    = 0
                   wcex.cbWndExtra    = 0
                   wcex.hInstance     = GetModuleHandle("")
                   wcex.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
                   wcex.hbrBackground = %COLOR_3DFACE + 1
                   wcex.lpszMenuName  = %NULL
                   wcex.lpszClassName = VARPTR(szClassName)
                   wcex.hIcon         = 0
                   wcex.hIconSm       = 0
                   RegisterClassEx wcex
                
                   GetWindowRect hParent, rc          ' For centering child in parent
                   rc.nRight = rc.nRight - rc.nLeft   ' Parent's width
                   rc.nBottom = rc.nBottom - rc.nTop  ' Parent's height
                
                   szCaption = "Popup dialog"
                   hWndPopup = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT, _
                               szClassName, szCaption, %WS_CAPTION OR %WS_POPUPWINDOW OR %WS_VISIBLE, _
                               rc.nLeft + (rc.nRight - 290) / 2, _
                               rc.nTop + (rc.nBottom - 180) / 2, _
                               290, 180, hParent, 0, GetModuleHandle(""), BYVAL %NULL)
                
                   hCtl = CreateWindowEx(0, "BUTTON", "&Close", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
                               200, 118, 75, 23, hWndPopup, %IDCANCEL, GetModuleHandle(""), BYVAL %NULL)
                   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
                
                   ShowWindow hWndPopup, %SW_SHOW
                   UpdateWindow hWndPopup
                   ' Message handler loop
                   LOCAL uMsg AS tagMsg
                   WHILE GetMessage(uMsg, %NULL, 0, 0)
                      IF ISFALSE IsDialogMessage(hWndPopup, uMsg) THEN
                         TranslateMessage uMsg
                         DispatchMessage uMsg
                      END IF
                   WEND
                
                   FUNCTION = uMsg.wParam
                
                END FUNCTION
                ' ========================================================================================
                
                ' ========================================================================================
                ' Popup dialog procedure
                ' ========================================================================================
                FUNCTION PopupDlgProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                
                   SELECT CASE wMsg
                      CASE %WM_CREATE
                         EnableWindow GetWindow(hWnd, %GW_OWNER), %FALSE   ' To make the popup dialog modal
                
                      CASE %WM_COMMAND
                         SELECT CASE LO(WORD, wParam)
                            CASE %IDCANCEL
                               IF HI(WORD, wParam) = %BN_CLICKED THEN
                                  SendMessage hWnd, %WM_CLOSE, 0, 0
                                  EXIT FUNCTION
                               END IF
                         END SELECT
                
                      CASE %WM_CLOSE
                         EnableWindow GetWindow(hWnd, %GW_OWNER), %TRUE  ' Maintains parent's zorder
                
                      CASE %WM_DESTROY
                         PostQuitMessage 0
                         EXIT FUNCTION
                
                   END SELECT
                
                   FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
                
                END FUNCTION
                ' ========================================================================================
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  Jose,
                  Excellent, that's it! Thank you.
                  Larry Kruse

                  Comment

                  Working...
                  X