NTK and The NTK Project
are properties of Jn Dechereux
Home | Documentation | FAQ.

Vanilla 1.1.8 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    •  
      CommentAuthorjnd
    • CommentTimeOct 10th 2009 edited
     
    The following template works pretty well and should be called by both NTKRad or NTKCore applications.

    So, your main window is supposed to invoke SplashScreen passing:
    - The main window handle
    - The fullname of the picture file to display (e.g "c:\myapp\mysplash.bmp|.jpg")
    - The maximum display time

    Enjoy!
    Jnd

    FUNCTION SplashScreen(hmainwnd, cImgFile, nseconds)
    Local hbmp     := NTK_ReadPictureToBmp(cImgFile)
    Local aBmpRect := NTK_GetBmpRect(hbmp)
    Local aScreen  := NTK_GetClientRect( NTK_GetDesktopWindow() )
    Local hsplash, nProc
    
    
    // Remember a splash screen window is always on top....
    hsplash := NTK_CreateWindowEx( WS_EX_STATICEDGE+WS_EX_TOPMOST,  "static", ;
                                   'Splash Screen', ;
                                   WS_VISIBLE+WS_BORDER+WS_POPUP, ;
                                   (aScreen[RECT_Width]  - aBmpRect[RECT_Width])  /2 , ;
                                   (aScreen[RECT_Height] - aBmpRect[RECT_Height]) /2 , ;
                                   aBmpRect[RECT_Width]+2                            , ;
                                   aBmpRect[RECT_Height]+2                           , ;
                                   hmainwnd                                          , ;
                                   nil                                               , ;  // ID is not needed
                                   _GetInstance() )
    
    nproc := NTK_SubClassWindow( hsplash, ;
                                 {|hWnd,nMsg,nwParam,nlParam| ;
                                 splashproc(nproc,hWnd,nMsg,nwParam,nlParam,hbmp,hmainwnd)}  , ;
                                 {WM_PAINT,WM_DESTROY,WM_TIMER,WM_LBUTTONDOWN} )
    
    
    
    
      NTK_HideCaret(hsplash)
    
      NTK_UpdateWindow(hsplash)
      NTK_SetTimer(hsplash,1,nseconds*1000)
    
    
    Return(NIL)
    ******
    ******
    ******
    Static Function SplashProc(nproc, hWnd, nMsg, nwParam, nlParam, hbmp, hmainwnd)
    local hDc
    Local aPaint[PS_LENGTH] // 9 elements, see NTKGDI.CH
    LOCAL nRed   := NTK_RGB(255,0,0)
    Local aRect  := NTK_GetClientRect( hWnd )
    
    
    
    Do Case
      Case nMsg==WM_PAINT
           hDc := NTK_BeginPaint(hWnd, aPaint)
               NTK_DrawBmp( hDC, hBmp, 0, 0, SRCCOPY )
    
               NTK_SelectObject( hDC, NTK_GetStockObject(SYSTEM_FONT)  )
               NTK_SetTextColor( hDC, nRed )
               NTK_SetBkMode( hDC, TRANSPARENT )
               NTK_DrawText( hDC,;
                          CHR(13)+"Wait a few seconds or Click left to bypass splash screen intro...",;
                          aRect, DT_CENTER )
    
           NTK_EndPaint(hWnd,aPaint)
    
    
      Case nMsg==WM_TIMER .or. nMsg==WM_LBUTTONDOWN
           // Time duration is over or user has cliked the left mouse button.
           // So, we have to stop the splash screen...
           NTK_KillTimer(hWnd,1)
           NTK_ShowCaret(hWnd)
           NTK_DestroyWindow(hWnd)
    
    
      Case nMsg==WM_DESTROY
           NTK_DeleteObject(hbmp)
           NTK_SelectWindow(hmainwnd)
           NTK_ShowWindow(hmainwnd,SW_SHOW)
           NTK_UpdateWindow(hmainwnd)
    EndCase
    
    Return NTK_CallWindowProc(nProc, hWnd, nMsg, nwParam, nlParam)
    
    •  
      CommentAuthorjnd
    • CommentTimeOct 10th 2009 edited
     
    Here is now how to call our SplashScreen() function from a NTKRad main window:


    ******************************************************************************
    * Program   : SPLASHRAD.PRG
    * Launch      SPLASHRAD.EXE
    * ..........: SPLASH SCREEN demonstration based on the Minimalist Hello World
    * Make      : MKRAD SPLASHRAD
    * Date      : 09/08/05
    * Author(s) : Jn DECHEREUX
    ********************************************************************************
    
    
    #include "windows.ch"
    #include "ntkgdi.ch"
    #include "ntkmsg.ch"
    #include "ntkacc.ch"
    #include "ntkcmd.ch"
    #include "wNtk.ch"
    #include "wNtkKeys.ch"
    
    #define CR CHR(13)
    
    STATIC cImgFile  := "musique.jpg"
    STATIC nDuration := 7 // In seconds
    
    FUNCTION MAIN()
    LOCAL hWndDemo
    LOCAL cWinTitle := "Splash Screen demo using  NTK rad's system..."
    
    
    CREATE WINDOW hWndDemo       ;
           TITLE cWinTitle       ; // Minimum declaration
           AT 0,0 SIZE 320,200   ;
           ON INIT  DoInit()     ;
           ON PAINT DoRePaint()  ;
           ON EXIT  NTK_SendQuitEvent()   // We do want to quit app.
    
    
    // You don't need to Activate the main window, the SplashScreen() function called ON INIT will to it for you!
    // ACTIVATE WINDOW hWndDemo NORMAL             // Display the current window and its child controls
    
    AUTO HANDLE EVENTS OF WINDOW hWndDemo       // Start processing background events (animate the current window)
    
    CLOSE WINDOW hWndDemo
    RETURN
    ******
    ******
    ******
    FUNCTION DoInit(hWnd, message, nwParam, nlParam)
     SplashScreen(hWnd, cImgFile, nDuration)
    RETURN Nil
    ******
    ******
    ******
    FUNCTION DOREPAINT(hWnd, message, nwParam, nlParam, hDC)
    
    
    //------ Old Style/fashion way to code ... more xBase-console like
    //       Note that we can also use/mix Windows enhanced capabilities if
    //       more power is needed...
    SET COLOR TO R+/W+
    @ 080,015 SAY "You've seen the splash screen..."+CR+;
                  "Now, here is Hello World!"   ;
                  SIZE 040, 280 ;
                  INTO CONTEXT hDC
    
    
    
    RETURN(0)
    


    That's all folks!
    Jnd
    •  
      CommentAuthorjnd
    • CommentTimeOct 10th 2009 edited
     
    If you're a NTKcore developer, your main window should look like this:


    ********************************************************************************
    * Program   : SPLASHCORE.PRG
    * Launch      SPLASHCORE.EXE
    * Aim       : Shows how to invoke the SplashScreen() function using Windows traditional manner.
    * Make......: MK SPLASHCORE
    ********************************************************************************
    
    
    
    #include "windows.ch"
    #include "ntkgdi.ch"
    #include "ntkimg.ch"
    #include "ntkmsg.ch"
    #include "ntkacc.ch"
    #include "wNtk.ch"
    
    
    STATIC aDemoFont1
    STATIC hDemoFont1
    
    STATIC cSplashImg := "Musique.jpg"
    STATIC nDuration  := 10  // in seconds
    
    
    FUNCTION MAIN()
    LOCAL cMsg
    LOCAL NTK_aMSG   := { 0,0,0,0,0,0,0 }     // 7 elements, see NTKMSG.CH
    LOCAL hInst      := NTK_GetInstance()
    LOCAL hIcon      := NTK_LoadIcon( Nil , IDI_HAND ) // IDI_APPLICATION)
    LOCAL hCurs      := NTK_LoadCursor( Nil , IDC_ARROW)
    LOCAL hBrush     := NTK_GetStockObject(WHITE_BRUSH) //LTGRAY_BRUSH)
    LOCAL cWinTitle  := "Splash demonstration and hello world!"
    LOCAL hWndDemo
    
    
    
    
    IF !NTK_RegisterClassEx( CS_HREDRAW + CS_VREDRAW,; 
                   hInst,;
                   hIcon,;
                   hCurs,;
                   hBrush,;
                   "NTKFEN",;
                   { |hWnd, message, nwParam, nlParam|;
                   HELLOWNDPROC(hWnd, message, nwParam, nlParam) } )
       NTK_MsgBox( , "Can't register NTKFEN class..." )
       RETURN Nil
    ENDIF
    
    
    hWndDemo := NTK_CreateWindowEx( WS_EX_WINDOWEDGE, "NTKFEN", cWinTitle, ;
                                  F_MIN+F_MAX+WS_SYSMENU, ;
                                 0, 0, 640, 480 ) 
    IF hWndDemo == 0
       NTK_MsgBox( , "Can not create Hello Window..." )
       RETURN Nil
    ENDIF
    
    
    aDemoFont1 := { -48,12,0,0,700, .F., .F., .F., 1, 0, 0, 0, 0, "ARIAL" }
    hDemoFont1 := NTK_CreateFont( aDemoFont1 )
    IF hDemoFont1 == 0
       NTK_MsgBox( , "Can not create DemoFont1..." )
       RETURN Nil
    ENDIF
    
    
    
    // No need to show main window, splashscreen will do it when ended-up
    // NTK_ShowWindow( hWndDemo, SW_SHOW )
    // NTK_UpdateWindow( hWndDemo )
    
    
    // ---------------------------------- NTK's Main Events (Windows Msg) Loop
    DO WHILE NTK_GetMessage( NTK_aMSG, 0 ) //,hWndDemo,0,0 )
       NTK_TranslateMessage( NTK_aMSG )
       NTK_DispatchMessage( NTK_aMSG )
    ENDDO
    
    
    
    NTK_DeleteObject( hDemoFont1 )
    
    NTK_SelectWindow( hWndDemo )
    NTK_DestroyWindow( hWndDemo )
    
    NTK_UnregisterClass( "NTKFEN", hInst )
    RETURN
    ******
    ******
    ******
    FUNCTION HELLOWNDPROC( hWnd, message, nwParam, nlParam)
    LOCAL aPS    := { 0,.T.,0,0,0,0,.T.,.T.,nil } // 9 elements, see NTKGDI.CH
    LOCAL hDC    := 0
    LOCAL nRed   := NTK_RGB(255,0,0)
    
    DO CASE
    
       CASE message == WM_CREATE
            SplashScreen( hWnd, cSplashImg, nDuration )
            RETURN(0)
    
       CASE message == WM_CHAR
            IF nwParam==27  // K_ESC
               IF NTK_MsgBox( hWnd,;
                              "Do you really want to quit ?",;
                              "Your Attention Please !",;
                              MB_OKCANCEL+MB_ICONQUESTION  ) == IDOK
                  NTK_PostQuitMessage(0)
               ENDIF
            ENDIF
    
       CASE message == WM_RBUTTONDOWN
            IF NTK_MsgBox( hWnd,;
                           "Do you really want to quit ?",;
                           "Your Attention Please !",;
                           MB_OKCANCEL+MB_ICONQUESTION  ) == IDOK
               NTK_PostQuitMessage(0)
            ENDIF
    
       CASE message == WM_SYSCOMMAND
            IF nwParam == SC_CLOSE      // system menu double click, or Alt-F4
               IF NTK_MsgBox( hWnd,;
                              "Do you really want to quit ?",;
                              "Your Attention Please !",;
                              MB_OKCANCEL+MB_ICONQUESTION  ) == IDOK
                  NTK_PostQuitMessage(0)
               ENDIF
               RETURN(0) 
            ENDIF
    
       CASE message == WM_PAINT
            hDC := NTK_BEGINPAINT( hWnd, aPS )
    
            NTK_TextOut( hDC, 100, 400, "Press Esc or hit right mouse button to quit..." )
    
            NTK_DrawText( hDC,;
                          "This sample has shown you a splash screen before this main window takes place.",;
                          {0,50,200,350}, DT_CENTER )
    
    
    
            NTK_SelectObject( hDC, hDemoFont1  )
            NTK_SetTextColor( hDC, nRed )
            NTK_SetBkMode( hDC, TRANSPARENT )
            NTK_DrawText( hDC,;
                          "Yet another Helloworld with splash screen!",;
                          {250,100,450,300}, DT_CENTER )
    
    
            NTK_ENDPAINT( hWnd, aPS )
    
    
       CASE message == WM_DESTROY
            NTK_PostQuitMessage(0)
            RETURN(0)
    
    ENDCASE
    RETURN( NTK_DEFWNDPROC(hWnd, message, nwParam, nlParam) )
    


    A little bit longer! Isn't it? :wink:
    Jnd