******************************************************************************** * Program : BRWRAD.PRG * Launch BRWRAD.EXE * Goal : R.A.D browse sample * Make : Just type MKrad BRWRAD * Date : 09/08/05 * Author(s) : Jn DECHEREUX * Copyright : (c) 2005 - Jn DECHEREUX. Tous droits r‚serv‚s/All Rights Reserved. ******************************************************************************** * Remark: * I have to confess that English is not my mother tongue. So, in case of * typo or misspelling, don't be too angry - just bear with me. * You have to know that i'll do consider any comment, correction, suggestion * with great pleasure and high kindliness. Just be polite ! ;-) * This remark is also available for bug notifications or any other kind of * contributions that can improve my product... ******************************************************************************** #include "windows.ch" #include "ntkbtn.ch" #include "ntkgdi.ch" #include "ntkmsg.ch" #include "ntkacc.ch" #include "ntkcmd.ch" #include "ntkcctrl.ch" #include "wNtk.ch" #include "wNtkKeys.ch" #define CR CHR(13) #define ID_BTN0 8000 #define ID_BTN1 8001 #define ID_BTN2 8002 STATIC hDemoFont1, oB1, oB2 FUNCTION MAIN() //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 := "BRWRAD, This is an ultra simplified browse with NTKRad for X/HRB !" LOCAL hWndDemo //PRIVATE hDemoFont1, oB1, oB2 CREATE WINDOW hWndDemo ; TITLE cWinTitle ; // Minimum declaration AT 0,0 SIZE 640,480 ; CURSOR hCurs ; ICON hIcon ; BRUSH hBrush ; ON PAINT DoRePaint() ; ON EXIT DoExit() *ON INIT DoInit() ; // The 4 following clauses can be used with *ON PAINT DoRePaint() ; // code block or function using or not *ON EXIT DoExit() ; // facultative parameters like : *ON MSG DoHandleMsg() // hWnd, nMsg, nwParam, nlParam,... IF hWndDemo == 0 NTK_MsgBox( , "Can not create Hello Window..." ) RETURN Nil ENDIF SET PIXEL MODE ON // default is always ON **SET DEFAULT SAY FONT TO NTK_GetStockObject(ANSI_FIXED_FONT) // Courier New 10 Fixe Font SET DEFAULT SAY FONT TO NTK_GetStockObject(SYSTEM_FONT) // Windows proportionnal Syst. Font Courier New 10 Fixe Font CREATE FONT hDemoFont1 FACENAME "ARIAL" SIZE -48 WIDTH 10 WEIGHT 700 IF hDemoFont1 == 0 NTK_MsgBox( , "Can not create DemoFont1..." ) CLOSE WINDOW hWndDemo RETURN Nil ENDIF // ------ Databases opening SELECT 1 USE ("PRODUCT.DBF") SHARE ALIAS products SELECT 2 USE ("ARTICLE.DBF") SHARE ALIAS articles @ 001,001 BUTTON "&About (F1)" SIZE 35,100 ; ID ID_BTN2 ; TYPE NTK_BT_OWNERDRAWN ; SUPER ACCEL KEY K_F1 ; ACTION DoAbout(hwndDemo) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(ANSI_VAR_FONT) ; STYLE BS_CENTER ; TEXTCOLOR NTK_RGB(000,000,128) ; BACKCOLOR NTK_BT_CLR_DEFBACKGROUND ; // NTK default visual style. see NtkBtn.ch MESSAGE "Give informations about Brwrad datagrid sample..." ; OF hwndDemo @ 001,102 BUTTON "&Make 3D"+CR+"On/off (F3)" SIZE 35,100 ; ID ID_BTN1 ; TYPE NTK_BT_OWNERDRAWN ; SUPER ACCEL KEY K_F3 ; ACTION DoMake3D(hwndDemo) ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(ANSI_VAR_FONT) ; STYLE BS_CENTER ; TEXTCOLOR NTK_RGB(000,000,128) ; BACKCOLOR NTK_BT_CLR_DEFBACKGROUND ; // NTK default visual style. see NtkBtn.ch MESSAGE "Switch current datagrid to 3D/normal look..." ; OF hwndDemo @ 001,203 BUTTON "&Quit" SIZE 35,100 ; ID ID_BTN0 ; TYPE NTK_BT_OWNERDRAWN ; SUPER ACCEL KEY K_F3 ; ACTION NTK_SendCloseEvent() ; STATE NTK_BT_ENABLE ; FONT NTK_GetStockObject(ANSI_VAR_FONT) ; STYLE BS_CENTER ; TEXTCOLOR NTK_RGB(000,000,128) ; BACKCOLOR NTK_BT_CLR_DEFBACKGROUND ; // NTK default visual style. see NtkBtn.ch MESSAGE "Stop this demo application and return to Windows..." ; OF hwndDemo SELECT 1 // -------- Mininum required syntax //@ 200,150 TO 500,750 BROWSE // oB1 INTO hWndDemo @ 200,150 TO 375,750 CREATE BROWSE oB1 ; WITH DBAREA products; // This can also be used: WITH DBAREA 1; FIELDS Codeart, Codebarre, Designart, PuaHT, PuvHT ; // Optional: Needed Field list... INTO hWndDemo // STYLE WS_CHILD+WS_VISIBLE+WS_DLGFRAME; // Use this if you don't want user to be able to resize browse control... // STYLE WS CHILD+WS VISIBLE+WS OVERLAPPED+WS_THICKFRAME; // Use this if you allow user the ability to resize browse control... SELECT 2 @ 400,150 TO 650,750 CREATE BROWSE oB2 ; WITH DBAREA articles; // This can also be used: WITH DBAREA 2; TITLES "Sku", "Description", "BarCod"; FIELDS CodArticle, NomArticle, CodeBarre, PuHTachat, PuHTvente ; // Optional: Needed Field list... SIZES 130,350,150,90,90 ; ON INIT DoInitBrw2(oB2); INTO hWndDemo ACTIVATE WINDOW hWndDemo MAXIMIZE // Show main container window and all its children AUTO MANAGE EVENTS OF WINDOW hWndDemo USING BUTTON LIST aBtnList // Event Manager for main container window // AUTO MANAGE clause replace all this stuff!! *// ------------------- Event Management Loop "a la" xBase-console ! *DO WHILE .T. * nKey := NtkInkey(0) // Mini Msg Pump implementation + Keyb & Btn event Receiver * * IF nKey == K_ESC .OR. nKey==K_ALT_F4 ; // if user exit by Esc, ALT_F4 or Windows Close menu * .OR. NTK_LastBtn()==-1 // if user clicked on close Btn [x] * * IF DoExit( hWndDemo ) * EXIT * EndIf * ENDIF *ENDDO NTK_MsgBox( hWndDemo, "Bye, bye...", "That's all folks!" ) DELETE FONT hDemoFont1 CLOSE WINDOW hWndDemo CLOSE DATABASES RETURN ****** ****** ****** FUNCTION DoExit(hWnd,Msg,wParam,lParam) // 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 ?",; "Your Attention Please !",; MB_OKCANCEL+MB_ICONQUESTION ) == IDOK NTK_PostQuitMessage(0) RETURN(.T.) // Quit RETURN( NTK_SendQuitEvent() ) // Same as both previous lines : Terminate current app. ENDIF RETURN(.F.) // Do not quit, keep on current task ****** ****** ****** 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 need // more power... SET COLOR TO R+/W+ @ 100,150 SAY "This is a minimalist datagrid sample made with NTKRad !" ; INTO CONTEXT hDC ; FONT hDemoFont1 **SET COLOR TO N/T // T=TRANSPARENT COLOR (background only) **@ 400,200 SAY "Press Esc or hit right mouse button to quit..." ; ** INTO CONTEXT hDC // Don't forget this clause. // Without it no (correct) repaint ... RETURN Nil ****** ****** ****** FUNCTION DoMake3D(hwnd) LOCAL hWndCurTB // Returns the handle to the current active browse (if any). // Very Useful in a multiple browse environment. hWndCurTB := NtkTBGetCurrent() IF oB1:hWnd == hWndCurTB oB1:make3D := IIF( oB1:make3D, .F., .T. ) oB1:Configure() // Reconfigure oB1 again! NTK_SetFocus(oB1:hWnd) ELSEIF oB2:hWnd == hWndCurTB oB2:make3D := IIF( oB2:make3D, .F., .T. ) oB2:Lineheight := IIF( oB2:make3D, 24, 18 ) // Change Line Height according to 3D flag or not oB2:autoLite := IIF( oB2:autoLite, .F., .T. ) // We want Complete Highlight Bar or Current cell only oB2:headHeight := IIF( oB2:make3D, 40, 35 ) // We want to change nubHeadings height (in pixels) oB2:headColor := IIF( oB2:make3D,NTK_RGB(0,128,0), NTK_RGB(0,0,255) ) // Super nubHeadings Foreground Color // A little useless sample, just to show how to make things... DoChangeCol2( oB2) // Shows how to modify column #2 oB2:Configure() // Now we just have to configure oB2 again! oB2:RefreshAll() NTK_SetFocus(oB2:hWnd) ENDIF RETURN(Nil) ****** ****** ****** FUNCTION DoInitBrw2(MyoB2) *** NTK_MessageBox(, "Browse #2 Intialization procedure..." ) MyoB2:ShowFocus := .T. // If set to .T. NtkTBrowse() will draw a focus rectangle around the currently selected cell. Defaults to .F. MyoB2:nubWidth := 32 // pixels MyoB2:headHeight := 35 // pixels MyoB2:headColor := NTK_RGB(0,0,255) // Super nubHeadings Foreground Color //MyoB2:autoSize := .F. // Don't let NtkTBrowse calculate automatically the width of each Col, regarding to its type and the OEM_FIXED FONT size. // The following is not very fancy, but it shows how to do things... //MyoB2:HeadFont := NTK_GetStockObject( ANSI_FIXED_FONT ) // nubHeading font //MyOB2:tbFont := NTK_GetStockObject( OEM_FIXED_FONT) // SYSTEM_FONT ) //ANSI_VAR_FONT ) //MyoB2:KeyBlock := { || NTK_MsgBox( , "LastKey pressed is "+STR(NTK_LastKey()), "info!") } MyoB2:KeyBlock := { || DoApplyKey(MyoB2) } RETURN(Nil) ****** ****** ****** FUNCTION DoChangeCol2( MyOb2 ) LOCAL oOldCol, oNewCol LOCAL nCol := 2 SELECT (MyOb2:Alias) // More safe, we never know... // Remove column object, but keep its properties. oOldCol := MyOb2:DelColumn( nCol ) IF MyOb2:Make3D // here we're preparing the new #2 column for "tweaking"... oOldCol:font := NTK_GetStockObject( SYSTEM_FONT ) // OEM_FIXED_FONT ) // hDemoFont1 oOldCol:width := 200 //oOldCol:align := DT_CENTER //Example: (codeblock is just for C4W compatibility. NTK accepts direct RGBs!) //oOldCol:fgcolor := {|| NTK_RGB( 0, 128, 0 ) } // Make data green //oOldCol:bgcolor := {|| NTK_RGB( 255, 255, 255 ) } // on white... //oOldCol:fgColor := NTK_RGB(000,000,255) // Make data blue //oOldCol:bgColor := NTK_RGB(151,255,151) // on apple green... oOldCol:fgColor := NTK_RGB(255,255,128) // Make data Yellow oOldCol:bgColor := NTK_RGB(208,208,208) // on Light Gray... ELSE // Back to orignal/default values. oOldCol:font := MyOb2:tbFont // General TBrowse's font oOldCol:width := LEN( (MyOb2:Alias)->NomArticle ) * 8.8 //I know, I'm a lazy boy! I'd rather get the FontHeight using NTK_GetTextMetrics()... oOldCol:fgColor := NTK_RGB(000,000,000) // Make data black oOldCol:bgColor := NTK_RGB(255,255,255) // on white... ENDIF oNewCol := NtkColumn():Init( oOldCol:Heading ,; // title heading oOldCol:Block ,; // data retrieval block oOldCol:Picture ,; // picture: Must be conform to Transform() Clause oOldCol:fgcolor ,; // data color oOldCol:bgcolor ,; // data background color oOldCol:align ,; // data align oOldCol:width ,; // data width oOldCol:bitmap ,; // data bitmap oOldCol:bitalign ,; // data bmp align oOldCol:headblock ,; // header click block oOldCol:cargo ,; // data cargo oOldCol:font ,; // data font handle (for the whole column) oOldCol:headColor ) // header text color // header font handle // header align // header bitmap // header bmp horz. align // header bmp vert. align MyOb2:InsColumn( nCol, oNewCol ) RETURN( Nil ) ****** ****** ****** FUNCTION DoApplyKey( MyoB ) SET COLOR TO G/W+ @ 470, 05 SAY "LastKey pressed is: " INTO WINDOW MyOb:hWndParent @ 490, 20 SAY STR(NTK_LastKey(),6)+SPACE(2) INTO WINDOW MyOb:hWndParent RETURN( Nil ) ****** ****** ****** ****** ****** ****** FUNCTION DOABOUT(hwnd) // "Developped with NTK Project for X/HARBOUR."+STR(ORDRELKEYPOS())+chr(13)+; NTK_MsgBox( hWnd,; "Developped with NTK Project for X/HARBOUR."+chr(13)+; "¸ 2006 Jn Dechereux.",; "About...",; MB_OK+MB_ICONASTERISK ) RETURN(Nil) ****** ****** ******