****************************************************************************** * Program : BTNBMP.PRG * Launch BTNBMP.EXE * ..........: Show how to use NTK's RAD Button possibilities. * Make : MKRAD BTNBMP * Date : 09/08/05 * Author(s) : Jn DECHEREUX * Copyright : (c) 2005 - Jn DECHEREUX. Tous droits r‚serv‚s/All Rights Reserved. ******************************************************************************** // -- Manifest Windows XP #define ISOLATION_AWARE_ENABLED 1 // remove remarks if you want fancy XP Theme buttons. #include "windows.ch" #include "ntkcctrl.ch" #include "ntkgdi.ch" #include "ntkmsg.ch" #include "ntkacc.ch" #include "ntkcmd.ch" #include "wNtk.ch" #include "wNtkKeys.ch" #include "ntkbtn.ch" #include "ntkimg.ch" #define CR CHR(13) #define ID_BTN0 8000 #define ID_BTN1 8001 #define ID_BTN2 8002 #define ID_BTN3 8003 #define ID_BTN4 8004 #define ID_BTN5 8005 #define ID_BTN6 8006 Static aMyODHyperLinkFont Static hMyODHyperLinkFont Static hBmp, hBmpBtn2 , hWndBtn2 FUNCTION MAIN() LOCAL hWndDemo LOCAL cWinTitle := "BitMap buttons with NTK rad's system..." PRIVATE aBtnList := {} // Do not forget it! CREATE WINDOW hWndDemo ; TITLE cWinTitle ; // Minimum declaration AT 0,0 SIZE 400,300 ; ON PAINT DoRePaint() ; ON EXIT DoExit() // ----- Ensure that the common control dynamic-link library (DLL) is loaded. // ----- Don't forget to use this command if U plan to use controls such as DatePicker, tooltips... NTK_InitCommonControlsEx( ICC_DATE_CLASSES + ICC_BAR_CLASSES + ICC_STANDARD_CLASSES + ICC_WIN95_CLASSES ) // Creating font - Core Method... aMyODHyperLinkFont := { -12,6,0,0,700, .F., .T., .F., 1, 0, 0, 0, 0, "MS SAN SERIF" } // "TIMES NEW ROMAN" } // hMyODHyperLinkFont := NTK_CreateFont( aMyODHyperLinkFont ) // Creating font - RAD Method... Just make your choice... //CREATE FONT hMyODHyperLinkFont FACENAME "MS SAN SERIF" SIZE -12 WIDTH 6 WEIGHT 700 UNDERLINE IF hMyODHyperLinkFont == 0 NTK_MsgBox( , "Can not create MyODHyperLinkFont..." ) RETURN Nil ENDIF *$ /* CREATE A Multiline TOOLTIP WINDOW help For the whole parent window */ *$ // NTK_CreateToolTip( nStyle, cTTMsg, nLeft, nTop, nWidth, nHeight, hWndP, nuFlags, nuId, hInst ) *$ NTK_CreateMLToolTip( WS_POPUP + TTS_NOPREFIX ,; // + TTS_BALLOON,; *$ "Click a buton or press its shortcut "+CR+" key to perform the associated event...",; *$ 0, 0, 400, 190,; *$ hWndDemo,; *$ TTF_SUBCLASS) *$ // -------- A STANDARD WINDOWS BUTTON USING NEW XP THEME (if MANIFEST is activated in the .RC resource file) @ 200,050 BUTTON "&Quit (Esc)" SIZE 40,90 ; ID ID_BTN0 ; SUPER ACCEL KEY K_ESC ; ACTION NTK_SendCloseEvent(hWndDemo) ; // Tell NTK RAD system to call the ON EXIT proc. STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "This is a classic button using a manifest (new enhanced XP style)!" ; OF hWndDemo // STYLE BS_FLAT ; // -------- A OWNERN DRAWN BUTTON USING NTK INTERNAL MODERN (XP Like) SYTLE (works on all Win32 Plateform) @ 200,150 BUTTON "Event &1" SIZE 40,90 ; ID ID_BTN1 ; TYPE NTK_BT_OWNERDRAWN ; SUPER ACCEL KEY K_ALT_F1 ; ACTION HelloEvent1(hWndDemo) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; STYLE BS_TOP+BS_RIGHT ; TEXTCOLOR NTK_RGB(255,000,000) ; BACKCOLOR NTK_BT_CLR_DEFBACKGROUND ; // NTK default visual style. see NtkBtn.ch BITMAP UP "LOUPE_UP" ; BITMAP DN "LOUPE_DN" ; BITMAP GRAYED "LOUPE_OFF" ; BITMAP SHIFT TO 5,5 ; // , MESSAGE "This is an owner drawn button, whole painted with NTK_BT_* styles. See NTKBTN.CH ..."+CR+" No need of Manifest! " ; OF hWndDemo // BACKCOLOR NTK_BT_CLR_DEFBACKGROUND ; // NTK default visual style. see NtkBtn.ch // BACKCOLOR NTK_RGB(250,250,249) ; // XP style approach, gradient less! // BACKCOLOR NTK_RGB(000,250,000) ; // Green. Just to show... // -------- A STANDARD WINDOWS BITMAP BUTTON @ 200,250 BUTTON "Event &2" SIZE 40,90 ; ID ID_BTN2 ; ACCEL KEY K_ALT_F2 ; ACTION HelloEvent2(hWndDemo) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; STYLE BS_BITMAP ; MESSAGE "This is standard button in which we have inserted a bitmap..." ; OF hWndDemo // -------- A OWNERN DRAWN BUTTON USING NTK NATIVE HYPERLINK (common web) STYLE (works on all Win32 Plateform) @ 090,120 BUTTON "Go to &Google" SIZE 40,120 ; ID ID_BTN3 ; TYPE NTK_BT_OD_HYPERLINK ; SUPER ACCEL KEY K_F3 ; ACTION GoGoogle(hWndDemo) ; STATE NTK_BT_ENABLE ; FONT hMyODHyperLinkFont ; TEXTCOLOR NTK_RGB(000,000,255) ; BACKGROUND BRUSH NTK_GetStockObject(LTGRAY_BRUSH) ; // Take care to use the SAME BKG as the parent window, otherwise no hyperlink aspect! BITMAP UP "LOUPE_DN" ; BITMAP DN "LOUPE_DN" ; BITMAP OVER "LOUPE_OVR" ; BITMAP GRAYED "LOUPE_OFF" ; MESSAGE "This is an HyperLink owner drawn button,"+CR+CR+; "www.google.com"+CR+; "A powerful search engine.." ; OF hWndDemo // -------- AN OTHER KIND OF OWNER DRAWN BUTTON USING NTK NATIVE MODERN (XP Like) STYLE (works on all Win32 Plateform) @ 140,120 BUTTON "&Google" SIZE 40,120 ; ID ID_BTN4 ; TYPE NTK_BT_OWNERDRAWN ; SUPER ACCEL KEY K_F4 ; ACTION GoGoogle(hWndDemo) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(ANSI_VAR_FONT) ; STYLE BS_CENTER ; TEXTCOLOR NTK_RGB(000,000,255) ; BACKCOLOR NTK_BT_CLR_DEFBACKGROUND ; // NTK default visual style. see NtkBtn.ch BITMAP UP "LOUPE_UP" ; BITMAP DN "LOUPE_DN" ; BITMAP OVER "LOUPE_OVR" ; BITMAP GRAYED "LOUPE_OFF" ; BITMAP SHIFT TO 5,5 ; // , MESSAGE "This is an owner drawn button, entirely painted with NTK_BT_* styles. See NTKBTN.CH ..."+CR+" No need of Manifest! " ; OF hWndDemo // -------- AN OTHER KIND OF OWNER DRAWN BUTTON USING NTK's FREE SHAPE BITMAPS (works on all Win32 Plateform) @ 090,250 BUTTON CR+CR+"&Free"+CR+"Shape"+CR+"Button" SIZE 100,100 ; ID ID_BTN5 ; TYPE NTK_BT_OD_FREESHAPE ; SUPER ACCEL KEY K_F5 ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(ANSI_VAR_FONT) ; STYLE BS_CENTER ; TEXTCOLOR NTK_RGB(255,255,255) ; BITMAP UP "FSHAPE_UP" ; BITMAP DN "FSHAPE_DN" ; BITMAP OVER "FSHAPE_OVR" ; BITMAP GRAYED "FSHAPE_OFF" ; MESSAGE "This is a Free Shape owner drawn bitmap button ..."+CR+" Great isn't it?" ; OF hWndDemo // -------- A STANDARD WINDOWS TOGGLE BUTTON USING NEW XP THEME (if MANIFEST is activated in the .RC resource file) @ 080,050 BUTTON "&T"+CR+"o"+CR+"g"+CR+"g"+CR+"l"+CR+"e" SIZE 100,040 ; ID ID_BTN6 ; ACTION EventToggle(hWndDemo,ID_BTN6) ; STATE NTK_BT_ENABLE ; STYLE NTK_BXT_TOGGLE+BS_MULTILINE ; FONT NTK_GetStockObject(SYSTEM_FONT) ; MESSAGE "This is a toggle button using a manifest (new enhanced XP style)!" ; OF hWndDemo // ---------- Load the Magnify bitmap to use with ID_BTN2 and with the '@ Y,X SAY...' clause into the REPAINT procedure hBmp := NTK_LoadImage( Nil,; // handle of the instance that contains the image "Loupe_UP",; // name or identifier of image IMAGE_BITMAP,; // type of image 0,; // LR_DEFAULTSIZE : desired width 0,; // LR_DEFAULTSIZE : desired height LR_LOADTRANSPARENT+LR_LOADMAP3DCOLORS ) // loading flags //LR_LOADMAP3DCOLORS) // loading flags // LR_LOADTRANSPARENT) // loading flags hBmp := NTK_LoadBitmap( NTK_GetInstance(), "Loupe_UP" ) // ---------- Pass the Bitmap to our standard button ... This it will become a Windows Bitmap Button! hWndBtn2 := NTK_GetDlgItem( hWndDemo, ID_BTN2 ) IF hWndBtn2 != 0 NTK_SendMessage( hWndBtn2, BM_SETIMAGE, IMAGE_BITMAP, hBmp ) ENDIF ACTIVATE WINDOW hWndDemo NORMAL // Display window and its controls // here we go... AUTO HANDLE EVENTS OF WINDOW hWndDemo USING ; // Start background processing BUTTON LIST aBtnList // ----------- Do not forget to release unused objects before exiting the program ! NTK_DeleteObject( hBmp ) NTK_DeleteObject( hBmpBtn2 ) DELETE FONT hMyODHyperLinkFont CLOSE WINDOW hWndDemo RETURN // End running NTK RAD application. ****** ****** ****** FUNCTION DoExit(hWnd, message, nwParam, nlParam) // This proc. is automatically called each time our window receives a Destroy Msg or // when NTK_SendCloseEvent() is invoked... IF NTK_MsgBox( hWnd,; "Do you really want to quit ?",; "Bitmap Buttons",; MB_OKCANCEL+MB_ICONQUESTION ) == IDOK //NTK_PostQuitMessage(0) // tell OS to terminate the application. Do not forget! //RETURN(.T.) // Quit RETURN( NTK_SendQuitEvent() ) // Same as both to previous lines : Terminate current app. ENDIF RETURN(.F.) // Do not quit, keep on current task ****** ****** ****** FUNCTION DOREPAINT(hWnd, message, nwParam, nlParam, hDC) NTK_DrawBmpTransparent( hDC, hBmp , 20, 40, NTK_RGB(255,0,255) ) //------ 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+ @ 050,50 SAY "Bitmap Buttons and Owner Drawn Buttons !" ; INTO CONTEXT hDC RETURN(0) ****** ****** ****** FUNCTION HelloEvent1(hWnd) NTK_MsgBox(hWnd, "Btn #1 has been clicked...", "Bitmap Button") // // Some other code here... // RETURN Nil ****** ****** ****** FUNCTION HelloEvent2(hWnd) LOCAL hBtn1 := NTK_GetDlgCtrlID(ID_BTN1, hWnd ) // Retrieve child Btn handle in its parent window... NTK_MsgBox(hWnd, "Btn #2 has been clicked...", "Bitmap Button") // // Some other code here... // IF NTK_IsWindowEnabled( hBtn1 ) NTK_EnableBtn( hBtn1, .F. ) ELSE NTK_EnableBtn( hBtn1, .T. ) ENDIF RETURN Nil ****** ****** ****** FUNCTION GoGoogle(hwndP) NTK_ShellExecute(hWndP, "open", "http://www.google.com", 0, 0, 0) CLEAR TYPEAHEAD RETURN Nil ****** ****** ****** FUNCTION EventToggle(hWndP, nID) LOCAL hToggleBtn := NTK_GetDlgItem( hWndP, nID ) // Retrieve child ctrl handle in its parent window... //LOCAL cToggleState := IIF( NTK_SendMessage(hToggleBtn, BM_GETSTATE, 0, 0)==BST_CHECKED , "ON", "OFF" ) LOCAL cToggleState := IIF( NTK_SendMessage(hToggleBtn, BM_GETCHECK, 0, 0)==BST_CHECKED , "Pushed", "UnPushed" ) NTK_MsgBox(hWndP, "Current state is "+cToggleState, "Toggle button - ID#"+STR(nID) ) RETURN Nil ****** ****** ******