******************************************************************************* * Program : DEMOMULT.PRG * Launch DEMOMULT.EXE * Goal : Demonstrate how to define different kind of controls *...........: Win32's API functions) * Make : Just type MK demomult * Date : 15/05/03 * Author(s) : Jn DECHEREUX * Copyright : (c) 2003 - 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... ******************************************************************************** #define ISOLATION_AWARE_ENABLED 1 // #include "ntkacc.ch" #include "ntkgdi.ch" #include "ntkimg.ch" #include "ntkmsg.ch" #include "ntkmenus.ch" #include "windows.ch" #include "ntkcctrl.ch" #include "ntkcmdlg.ch" #include "ntkdlg.ch" #include "wNtk.ch" #define CR chr(13)+chr(10) #define ID_EDIT1 1 // unique id (used for the edit control) #define IDBTN1 7501 // unique id (used for the PushButton control) #define IDDTP1 8501 // unique id (used for the DatePicker control) 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(GRAY_BRUSH) // DKGRAY_BRUSH, LTGRAY_BRUSH, WHITE_BRUSH ... LOCAL cWinTitle := "DEMOMULT: Various kind of controls with NTKCore!" LOCAL hWndDemo LOCAL aMenu, aPopupMenu, aPopupSubMenu PRIVATE aDemoFont1 PRIVATE hDemoFont1 PRIVATE cMenuHlpMsg := "" PRIVATE cTheMovie := "SHUTTLE.AVI" PRIVATE cDibFile := "BFLY01.BMP" PRIVATE cDib //SET CENTURY ON SET EPOCH TO 1980 IF !NTK_RegisterClassEx( CS_HREDRAW + CS_VREDRAW,; // CS_OWNDC + CS_VREDRAW + CS_HREDRAW + CS_DBLCLKS,; hInst,; hIcon,; hCurs,; hBrush,; "MAINCLASS",; { |hWnd, message, nwParam, nlParam|; MAINWNDPROC(hWnd, message, nwParam, nlParam) } ) NTK_MsgBox( , "Can't register MAINCLASS class..." ) RETURN Nil ENDIF IF !NTK_RegisterClassEx( CS_HREDRAW + CS_VREDRAW,; // CS_OWNDC + CS_VREDRAW + CS_HREDRAW + CS_DBLCLKS,; hInst,; hIcon,; hCurs,; NTK_GetStockObject(WHITE_BRUSH) ,; "MYCLASS",; { |hWnd, message, nwParam, nlParam|; MYWNDPROC(hWnd, message, nwParam, nlParam) } ) NTK_MsgBox( , "Can't register MYCLASS class..." ) RETURN Nil ENDIF // ----- Ensure that the common control dynamic-link library (DLL) is loaded. // ----- Don't forget to use this command if plan to use controls such as DatePicker, tooltips... NTK_InitCommonControlsEx( ICC_DATE_CLASSES + ICC_BAR_CLASSES ); //hWndDemo = NTK_CreateWindowEx( WS_EX_WINDOWEDGE+WS_EX_CONTROLPARENT, "MAINCLASS", cWinTitle, ; hWndDemo = NTK_CreateWindowEx( WS_EX_WINDOWEDGE, "MAINCLASS", cWinTitle, ; F_MIN+F_MAX+WS_SIZEBOX+WS_SYSMENU, ; 0, 0, 640, 480 ) IF hWndDemo == 0 NTK_MsgBox( , "Can not create 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 aMenu := NtkCreateMenu() aPopupMenu := NtkCreatePopupMenu() NtkAppendMenu(aPopupMenu, "WIND", MF_ENABLED + MF_STRING, "&Windows", {|| DoWIND(hWndDemo) }, "Windows creation..." ) NtkAppendMenu(aPopupMenu, "", MF_SEPARATOR) aPopupSubMenu := NtkCreatePopupMenu() NtkAppendMenu(aPopupSubMenu, "DYNDLG", MF_ENABLED + MF_STRING, "&Dynamic Dialog", {|| DoDynDLG(hWndDemo) }, "Dynamic dialog creation..." ) NtkAppendMenu(aPopupSubMenu, "RESDLG", MF_ENABLED + MF_STRING, "&Resource Dialog", {|| DoResDLG(hWndDemo) }, "Calling a dialog from a resource..." ) NtkAppendMenu(aPopupSubMenu, "", MF_SEPARATOR) NtkAppendMenu(aPopupSubMenu, "OPENDLG", MF_ENABLED + MF_STRING, "&Open File Dialog", {|| DoOpenFileDLG(hWndDemo) }, "Calling common dialog function : NTK_GetOpenFileName() ..." ) NtkAppendMenu(aPopupSubMenu, "SAVEDLG", MF_ENABLED + MF_STRING, "&Save File Dialog", {|| DoSaveFileDLG(hWndDemo) }, "Calling common dialog function : NTK_GetSaveFileName() ..." ) NtkAppendMenu(aPopupSubMenu, "", MF_SEPARATOR) NtkAppendMenu(aPopupSubMenu, "CLRDLG", MF_ENABLED + MF_STRING, "&Color Dialog", {|| DoColorDLG(hWndDemo) }, "Calling common dialog function : NTK_ChooseColor() ..." ) NtkAppendMenu(aPopupMenu, "DLG" , MF_ENABLED + MF_POPUP, "Dialo&gs", aPopupSubMenu, "Sample dialogs possibilities..." ) NtkAppendMenu(aPopupMenu, "", MF_SEPARATOR) aPopupSubMenu := NtkCreatePopupMenu() NtkAppendMenu(aPopupSubMenu, "BEEP" , MF_ENABLED + MF_STRING, "USER32.DLL : &MessageBeep", {|| DoDLLCall() } , "External call of MessageBeep() from USER32.DLL. Just to learn how to do (the way it works)... " ) NtkAppendMenu(aPopupSubMenu, "WAVE" , MF_ENABLED + MF_STRING, "WINMM.DLL : &sndPlaySoundA", {|| MyPlayWav( "WINNER", 0, .T. ) } , "External call of sndPlaySoundA() from WINMM.DLL. How to create your own PlayWav() function!" ) NtkAppendMenu(aPopupSubMenu, "VIDEO", MF_ENABLED + MF_STRING, "WINMM.DLL : &mciExecute", {|| MyVideo( "CLOCK.AVI",hWndDemo, {10,10,280,280},.F., .F. ),MyVideo( cTheMovie, hWndDemo, {10,10,216,192},.F., .T.) } , "External call of mciExecute() from WINMM.DLL. How to create your own PlayVideo() function!" ) NtkAppendMenu(aPopupSubMenu, "FILM" , MF_ENABLED + MF_STRING, "WINMM.DLL : &mciExecute+sndPlaySoundA", {|| MyVideo( cTheMovie, hWndDemo, {10,10,216,192}, .T., .T.) } , "External call of mciExecute()+sndPlaySoundA() from WINMM.DLL. Combined video and sound functions..." ) NtkAppendMenu(aPopupMenu, "DLL" , MF_ENABLED + MF_POPUP, "&DLL Calls", aPopupSubMenu, "Call a function from an external DLL..." ) NtkAppendMenu(aPopupMenu, "", MF_SEPARATOR) NtkAppendMenu(aPopupMenu, "QUIT", MF_ENABLED + MF_STRING, "E&xit", {|| DoQUIT() } , "Quit this program." ) NtkAppendMenu( aMenu, "DMO", MF_ENABLED + MF_POPUP, "&Demos", aPopupMenu, "Various demonstrations..." ) aPopupMenu := NtkCreatePopupMenu() NtkAppendMenu(aPopupMenu, "WND", MF_ENABLED + MF_STRING, "&Windows", {|| JNDWNDINFO() } , "Internal informations about NTK Windows subsystem..." ) NtkAppendMenu(aPopupMenu, "MNU", MF_ENABLED + MF_STRING, "&Menus", {|| __jndMnuInfos(aMenu) } , "Internal informations about NTK Hi-Level Menus subsystem." ) NtkAppendMenu( aMenu, "INFO", MF_ENABLED + MF_POPUP, "&NTK Infos", aPopupMenu, "Internal informations about NTK subsystems (for Beta-Testers only)..." ) //aPopupMenu := NtkCreatePopupMenu() NtkAppendMenu( aMenu, "ABOUT", MF_ENABLED + MF_STRING, "&?", {|| DOABOUT() }, "About this program..." ) lRet := NtkSetMenu(hWndDemo, aMenu) 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( "MYCLASS", hInst ) NTK_UnregisterClass( "MAINCLASS", hInst ) RETURN ****** ****** ****** FUNCTION DOABOUT(hwnd, cDispMsg) NTK_MsgBox( hWnd,; "¸ 2002-2003 Jn Dechereux.",; "About...",; MB_OK+MB_ICONASTERISK ) RETURN(Nil) ****** ****** ****** FUNCTION DOQUIT(hwnd) IF NTK_MsgBox( hWnd,; "Do you really want to quit ?",; "That's all Folks !",; MB_OKCANCEL+MB_ICONQUESTION ) == IDOK NTK_PostQuitMessage(0) RETURN .T. ENDIF RETURN .F. ****** ****** ****** FUNCTION MAINWNDPROC( 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) LOCAL nDkGray := NTK_RGB(164,164,164) LOCAL hMyIcon := NTK_LoadIcon( , IDI_ASTERISK ) // EXCLAMATION LOCAL aCliRect := NTK_GetClientRect(hWnd) LOCAL aDibRect := NTK_GetDibRect(cDib) LOCAL nXpos, nYpos LOCAL nMenuItem, bMenu DO CASE CASE message == WM_CREATE cDib := NTK_ReadDib(cDibFile) // ----- Another possibility. Just think about it... ** hBmp := NTK_ReadPictureToBmp("Musique.jpg") ** aBmpStruct := NTK_StoreBmpToMem( hBmp ) ** NTK_DeleteObject(hBmp) ** cDib := LTRIM(STR(aBmpStruct[BM_Type] )) + "," + ; ** LTRIM(STR(aBmpStruct[BM_Width] )) + "," + ; ** LTRIM(STR(aBmpStruct[BM_Height] )) + "," + ; ** LTRIM(STR(aBmpStruct[BM_WidthBytes])) + "," + ; ** LTRIM(STR(aBmpStruct[BM_Planes] )) + "," + ; ** LTRIM(STR(aBmpStruct[BM_BitsPixel] )) + "-" + ; ** aBmpStruct[BM_Bits] IF !EMPTY( cDib ) NTK_MsgBox( , cDibFile+": Successfuly read and stored into cDib mem var..." ) aDibRect := NTK_GetDibRect(cDib) NTK_MsgBox( , cDibFile+" nLeft="+str(aDibRect[1])+chr(13)+; cDibFile+" nRigh="+str(aDibRect[2])+chr(13)+; cDibFile+" Width="+str(aDibRect[3])+chr(13)+; cDibFile+" Heigh="+str(aDibRect[4]),; "Bitmap Infos...",; MB_OK+MB_ICONASTERISK ) ****NTK_InvalidateRect( hWndDemo, 70, 50, 70+aDibRect[3], 50+aDibRect[4], .T. ) ELSE NTK_MsgBox( , "Can not read "+cDibFile, MB_OK+MB_ICONHAND ) ENDIF NTK_MsgBox( , "aCliRect[4]= "+str(aCliRect[4]), MB_OK+MB_ICONHAND ) CASE message == WM_CHAR IF nwParam==27 // K_ESC DoQuit(hWnd) ENDIF CASE message == WM_RBUTTONDOWN DoQuit(hWnd) CASE message == WM_SYSCOMMAND IF nwParam == SC_CLOSE // system menu double click, or Alt-F4 IF DoQuit(hWnd) tone(130,1) tone(130,1) ENDIF RETURN(0) // According to M$ Win32 SDK Doc. We tell Windows we've processed the message ENDIF **RETURN 0 CASE message == WM_MENUSELECT nMenuItem := NTK_LoWord(nwParam) cMenuHlpMsg := NtkGetMenuHlpMsg( NtkGetMenu(hWnd), nMenuItem, nlParam ) NTK_InvalidateRect( hWnd,; {0, aCliRect[4]-40, aCliRect[3], aCliRect[4]},; .T. ) CASE message == WM_COMMAND nMenuItem := NTK_LoWord(nwParam) bMenu := NtkGetMenuBlock( NtkGetMenu(hWnd), nMenuItem ) IF !EMPTY(bMenu) // IF bMenu != Nil EVAL(bMenu) // Evaluer le Code Block du Menu RETURN 0 ENDIF CASE message == WM_PAINT hDC := NTK_BEGINPAINT( hWnd, aPS ) IF !EMPTY(cDib) //NTK_ShowDib( hDC, cDib, 170, 50 ) NTK_ShowDib( hDC, cDib,; (aCliRect[3]-aDibRect[3])/2,; (aCliRect[4]-aDibRect[4])/2 -50 ) ENDIF //NTK_DrawIcon( hDC,160, 320, hMyIcon ) //NTK_TextOut( hDC, 190, 350, "Press Esc or hit right mouse button to quit..." ) nXpos := (aCliRect[3]-(35*08)) / 2 nYpos := aCliRect[4]-100 NTK_DrawIcon( hDC, nXpos-30, nYpos-30, hMyIcon ) NTK_TextOut( hDC, nXpos, nYpos, "Press Esc or hit right mouse button to quit..." ) NTK_SetTextColor( hDC, nDkGray ) NTK_SetBkMode( hDC, TRANSPARENT ) NTK_DrawText( hDC, cMenuHlpMsg,; { 0, aCliRect[4]-40, aCliRect[3], aCliRect[4] },; DT_CENTER+DT_VCENTER ) NTK_ENDPAINT( hWnd, aPS ) RETURN(0) CASE message == WM_CLOSE // WM_DESTROY NTK_PostQuitMessage(0) RETURN(0) ENDCASE RETURN( NTK_DEFWNDPROC(hWnd, message, nwParam, nlParam) ) //RETURN -1 // OR NTK_DEFWNDPROC( ... ) is the same ! ****** ****** ****** ****** ****************************************************************************************** ****** *********************** INTERNAL VARS & SUBROUTINES **************************** ****** ****************************************************************************************** FUNCTION JNDWNDINFO(void) // UNDOC'ed - TOP SECRET ;-) __jndWndList() RETURN( Nil ) ****** ****** ****** ****** ****************************************************************************************** ****** *********************** WINDOWS CREATION **************************** ****** ****************************************************************************************** FUNCTION DoWind( hWndParent ) LOCAL hInst := NTK_GetInstance() LOCAL NTK_aMSG := { 0,0,0,0,0,0,0 } // 7 elements, see NTKMSG.CH LOCAL cEdit1 := "This is a single line Edit test" LOCAL hEdit1, hBtn1, hDtp1 LOCAL hWndDemo2 PRIVATE hMyBkgBmp := NTK_ReadPictureToBmp( "Musique.jpg" ) PRIVATE hMyBmp := NTK_ReadBmp( "Wiz01.bmp" ) //hWndDemo2 = NTK_CreateWindowEx( WS_EX_CLIENTEDGE, "MYCLASS", "Miscellaneous controls...", ; hWndDemo2 = NTK_CreateWindowEx( WS_EX_WINDOWEDGE, "MYCLASS", "Miscellaneous controls...", ; F_MIN+F_MAX+WS_SYSMENU, ; 50, 50, 540, 380, hWndParent ) IF hWndDemo2 == 0 NTK_MsgBox( , "Can not create Window #2..." ) RETURN( Nil ) ENDIF hBtn1 := NTK_CreateWindowEx( WS_EX_WINDOWEDGE,"BUTTON", ; // window class "&Close Me !", ; // Button Title WS_CHILD ; // child window + WS_VISIBLE ; // - that can be seen + WS_TABSTOP ; // ... + BS_PUSHBUTTON,; // - a normal PushButton 50, 150, ; // x,y position 120, 50, ; // width, height hWndDemo2 , ; // parent window IDBTN1, ; // id for child control to use hInst) // our own app instance //hEdit1 := NTK_CreateWindow("EDIT", ; // window class hEdit1 := NTK_CreateWindowEx( WS_EX_WINDOWEDGE,"EDIT", ; // window class cEdit1, ; // initial buffer WS_CHILD ; // child window + WS_VISIBLE ; // ... that can be seen + WS_BORDER ; // ... with a border + ES_LEFT ; // ... left justified + ES_AUTOHSCROLL,; // ... auto horiz. scroll 50, 50, ; // x,y position 250, 30, ; // width, height hWndDemo2 , ; // parent window ID_EDIT1, ; // id for child control to use hInst) // our own app instance hDtp1 := NTK_CreateWindowEx( WS_EX_CLIENTEDGE, "SYSDATETIMEPICK32",; // window class 0, ; // Window Title WS_CHILD ; // child window + WS_VISIBLE ; // - that can be seen + WS_TABSTOP ; // ... + WS_BORDER, ; // - with a border 50, 100, ; // x,y position 90, 22 , ; // width, height hWndDemo2 , ; // parent window IDDTP1, ; // id for child control to use hInst ) // our own app instance IF hDtp1 == 0 NTK_MsgBox( , "Can not create Window DatePicker #1..." ) ENDIF //NTK_SetFocus(hEdit1) //NTK_SetFocus(hBtn1) //NTK_SetFocus(hDtp1) NTK_ShowWindow( hWndDemo2, SW_SHOW ) NTK_UpdateWindow( hWndDemo2 ) // ---------------------------------- NTK's Main Events (Windows Msg) Loop DO WHILE NTK_GetMessage( NTK_aMSG, hWndDemo2) // hWndDemo2, 0,0 ) NTK_TranslateMessage( NTK_aMSG ) NTK_DispatchMessage( NTK_aMSG ) ENDDO NTK_DeleteObject(hMyBmp) NTK_DeleteObject(hMyBkgBmp) NTK_SelectWindow( hWndDemo2 ) NTK_DestroyWindow( hWndDemo2 ) RETURN(Nil) ****** ****** ****** FUNCTION MYWNDPROC( hWnd, message, nwParam, nlParam) LOCAL aPS := { 0,.T.,0,0,0,0,.T.,.T.,nil } // 9 elements, see NTKGDI.CH LOCAL hDC := 0 DO CASE CASE message == WM_CREATE CASE message == WM_CHAR IF nwParam==27 // K_ESC NTK_PostQuitMessage(0) ENDIF CASE message == WM_RBUTTONDOWN NTK_PostQuitMessage(0) CASE message == WM_SYSCOMMAND IF nwParam == SC_CLOSE // system menu double click, or Alt-F4 NTK_PostQuitMessage(0) ENDIF **RETURN 0 CASE message == WM_COMMAND IF nwParam == IDBTN1 // user clicked on 'Close me !' button NTK_PostQuitMessage(0) ENDIF CASE message == WM_PAINT hDC := NTK_BEGINPAINT( hWnd, aPS ) IF !EMPTY(hMyBkgBmp) NTK_DrawBmp( hDC, hMyBkgBmp, 0, 0, SRCCOPY ) ENDIF IF !EMPTY(hMyBmp) NTK_DrawBmp( hDC, hMyBmp, 470, 10, SRCCOPY ) ENDIF NTK_TextOut( hDC, 70, 300, "Child Wnd : Press Esc or hit right mouse button to quit..." ) NTK_DrawFocusRect( hDC, {300,100,400,200} ) NTK_MoveTo( hDC, 300, 100 ) NTK_LineTo( hDC, 400, 200 ) // a horizontal line NTK_MoveTo( hDC, 300, 200 ) NTK_LineTo( hDC, 400, 100 ) // a horizontal line NTK_ENDPAINT( hWnd, aPS ) CASE message == WM_CLOSE // WM_DESTROY NTK_PostQuitMessage(0) RETURN(0) ENDCASE RETURN( NTK_DEFWNDPROC(hWnd, message, nwParam, nlParam) ) ****** ****** ****** ****** ****** ****** ****** ****************************************************************************************** ****** *********************** CALLING EXTERNAL DLL SAMPLES **************************** ****** ****************************************************************************************** FUNCTION DoDLLCall( void ) LOCAL hLib, aMBeep // -------------------------------------- Load the library into memory hLib = NTK_LoadLibrary( "USER32.DLL" ) // part of Windows IF hlib >=0 .AND. hLib <= 32 RETURN ENDIF //NTK_MsgBox( , STR(hLib,15,0), "hLib Infos" ) // ----------- Declare function parameters and Retrieve the function address (by name or ordinal) aMBeep = NTK_GetProcAddress( hLib, "MessageBeep",; // get by name "Pascal", "BOOL",; // Pascal, returns BOOL "uint" ) // 1 uint params IF aMBeep==Nil NTK_MsgBox( , "[MessageBeep] call error", "NTK_GetProcAddress" ) NTK_FreeLibrary( hLib ) RETURN(Nil) ENDIF // -------------------------------------- Call and execute the function with its parameters NTK_CallDll(aMBeep, MB_ICONASTERISK ) // -1) // -1 = Standard Beep from the speaker NTK_FreeLibrary( hLib ) RETURN(Nil) ****** ****** ****** FUNCTION MyPlayWav(cWaveFic, nModeFin, lSnd ) LOCAL hLib := NTK_LoadLibrary("WINMM.DLL") LOCAL acSound := NTK_GetProcAddress(hLib, "sndPlaySoundA", "Pascal", "INT", "str, int") LOCAL cFicWav := IF( ".WAV" $ Upper(cWaveFic), AllTrim(cWaveFic), AllTrim(cWaveFic)+".WAV" ) IF hlib >=0 .AND. hLib <= 32 NTK_MsgBox( , "hLib Value:"+STR(hLib,15,0), "NTK_LoadLibrary ERROR!" ) RETURN(-4) ENDIF IF Empty(acSound) // Empty or Nil NTK_MsgBox( , "THE FUNCTION DOES NOT EXIST OR IS MISSPELLED !"+chr(13)+; "(Remember, Win32 function names are case-sensitive...)" ,; "NTK_GetProcAddress ERROR!" ) NTK_FreeLibrary( hLib ) RETURN(-3) ENDIF IF PCOUNT() < 1 NTK_FreeLibrary( hLib ) RETURN(-2) ELSEIF PCOUNT() < 2 nModeFin := 1 lSnd := .T. // Sound Device Flag. Default is assume to be .T. (enable). ENDIF IF .NOT. lSnd // Automaticaly stop, in case Sound Device Flag is OFF or if the computer // hasn't got a sound card... NTK_FreeLibrary( hLib ) RETURN(-1) ENDIF // sndPlaySoundA(szwavefilename, iduration) --> int (0=function fails, 1=Sound has been played) //ÄÄÄÄÄ Second parameter to sndPlaySoundA() is: 1 == return instantly, //ÄÄÄÄÄ 0 == wait until finished playing before returning n := NTK_CallDLL(acSound, cFicWav, nModeFin) if Empty(n) // if n==0 OR n==Nil NTK_MsgBox(, "No audio hardware" + chr(13) + "Or other error", "Error !", ; MB_ICONHAND + MB_OK) endif NTK_FreeLibrary( hLib ) RETURN n ****** ****** ****** FUNCTION MyVideo(cFile, hWnd, aRect, lBkgMusic, lTryAgain ) LOCAL cCmd, nRet LOCAL hLib := NTK_LoadLibrary("WINMM.DLL") LOCAL acMci := NTK_GetProcAddress(hLib, "mciExecute", "Pascal", "INT", "str") LOCAL cnX := STR(aRect[1],4,0) LOCAL cnY := STR(aRect[2],4,0) LOCAL cnW := STR(aRect[3],4,0) LOCAL cnH := STR(aRect[4],4,0) IF hlib >=0 .AND. hLib <= 32 NTK_MsgBox( , "hLib Value:"+STR(hLib,15,0), "NTK_LoadLibrary ERROR!" ) RETURN(-4) ENDIF IF Empty(acMci) // Empty or Nil NTK_MsgBox( , "THE FUNCTION DOES NOT EXIST OR IS MISSPELLED !"+chr(13)+; "(Remember, Win32 function names are case-sensitive...)" ,; "NTK_GetProcAddress ERROR!" ) NTK_FreeLibrary( hLib ) RETURN(-3) ENDIF //------- The original C syntax is : mciExecute(LPCSTR cCmd ) cCmd := "open " + cFile + " type avivideo alias MyVideo style child" ; + " parent " + ltrim(str(hWnd)) nRet := NTK_Calldll( acMci, cCmd) //NTK_MsgBox( , "nRet="+STR(nRet,15,0), "mciExecute" ) //nRet := NTK_Calldll( acMci, "put MyVideo window at 10 10 280 280" ) nRet := NTK_Calldll( acMci, "put MyVideo window at "+cnX+cnY+cnW+cnH ) IF lTryAgain DO WHILE .T. IF lBkgMusic // Play a default bkg melodie... for movies without sound... MyPlayWav( "BEETH9TH", 1, .T. ) // It's always better with sound. Isn't it? // sadly, it seems to work only with W9X & Me OS's. To be confirmed... ENDIF // ---- seek Offset & play MyVideo nRet := NTK_Calldll( acMci, "seek MyVideo to start" ) nRet := NTK_Calldll( acMci, "play MyVideo" ) IF NTK_MsgBox( hWnd,; "Do you want to Play this video again ?",; "That's all Folks !",; MB_OKCANCEL+MB_ICONQUESTION ) == IDCANCEL EXIT ENDIF ENDDO ELSE // ---- seek Offset & play MyVideo nRet := NTK_Calldll( acMci, "seek MyVideo to start" ) nRet := NTK_Calldll( acMci, "play MyVideo wait" ) ENDIF NTK_Calldll( acMci, "close MyVideo" ) NTK_FreeLibrary( hLib ) RETURN ****** ****** ****** ****** ****************************************************************************************** ****** *********************** DYNAMIC DIALOG USING SAMPLE **************************** ****** ****************************************************************************************** FUNCTION DoDynDLG(hWndDemo) LOCAL hInst := NTK_GetInstance() LOCAL aDlg, nRet LOCAL aCbChoices := {"Potatoes", "Carrots", "Tomatoes"} LOCAL aLbChoices := {"Plum", "Banana", "Apple", "Peach", "Apricot" } LOCAL cSomeText := "This is a sample of how to use Windows multilines edit control..." aDlg = NTK_CreateDialog("Dynamic Modeless Dialog Sample", ; WS_CAPTION + WS_SYSMENU ; + WS_GROUP + WS_TABSTOP ; + WS_THICKFRAME + WS_VISIBLE + WS_POPUP, ; 24, 12, 490, 290, 08, "MS SANS SERIF" ) //24, 12, 390, 290, 10, "SYSTEM" ) // 24, 12, 390, 290, 08, "COMIC SANS MS" ) aDlg = NTK_AppendDialog(aDlg, IDOK, DLG_BUTTON, ; BS_DEFPUSHBUTTON + WS_GROUP + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ; 10, 85, 35, 15, ; "&Ok") aDlg = NTK_AppendDialog(aDlg, IDCANCEL, DLG_BUTTON, ; BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE,; 55, 85, 35, 15, ; "&Cancel") aDlg = NTK_AppendDialog(aDlg, "cbox1", DLG_COMBOBOX, ; CBS_DROPDOWNLIST + CBS_AUTOHSCROLL + WS_TABSTOP + WS_CHILD + WS_VISIBLE,; 10, 10, 80, 60, ; aCBChoices) aDlg = NTK_AppendDialog(aDlg, "lbox1", DLG_LISTBOX, ; LBS_STANDARD + WS_TABSTOP + WS_CHILD + ; WS_VISIBLE + LBS_MULTIPLESEL, ; 10, 30, 80, 50, ; aLBChoices) aDlg = NTK_AppendDialog(aDlg, "group", DLG_BUTTON, ; BS_GROUPBOX + WS_GROUP + WS_CHILD + WS_VISIBLE+ WS_TABSTOP, ; 120, 06, 60, 34, ; "Group") aDlg = NTK_AppendDialog(aDlg, "radioa", DLG_BUTTON, ; BS_AUTORADIOBUTTON ; + WS_CHILD + WS_VISIBLE + WS_TABSTOP, ; 125, 14, 39, 10, ; "&A Choice") aDlg = NTK_AppendDialog(aDlg, "radiob", DLG_BUTTON, ; BS_AUTORADIOBUTTON + WS_CHILD + WS_VISIBLE + WS_TABSTOP,; 125, 27, 39, 10, ; "&B Choice") aDlg = NTK_AppendDialog(aDlg, "chk1", DLG_BUTTON, ; BS_AUTOCHECKBOX + WS_CHILD + WS_VISIBLE + WS_TABSTOP,; 120, 42, 80, 10, ; "&Check to activate...") aDlg = NTK_AppendDialog(aDlg, "chk2", DLG_BUTTON, ; BS_AUTO3STATE + WS_CHILD + WS_VISIBLE + WS_TABSTOP,; 120, 52, 80, 10, ; "&3-State check box") *aDlg = NTK_AppendDialog(aDlg, "edit", DLG_EDIT, ; * ES_LEFT + ES_MULTILINE + ES_NOHIDESEL ; * + ES_AUTOVSCROLL + ES_AUTOHSCROLL ; * + WS_VSCROLL + WS_HSCROLL + WS_BORDER ; * + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ; * 122, 64, 40, 38, cSomeText) aDlg = NTK_AppendDialog(aDlg, "edit", DLG_EDIT, ; WS_CHILD ; // child window + WS_VISIBLE ; // ... that can be seen + WS_BORDER ; // ... with a border + WS_VSCROLL ; // ... force vert. scroll bar + WS_TABSTOP ; // + ES_MULTILINE ; // ... Multiline + ES_LEFT ; // ... left justified + ES_AUTOVSCROLL; // ... auto horiz. scroll + ES_WANTRETURN,; // ... cr lf possibility 120, 64, 60, 38, cSomeText) aDlg = NTK_AppendDialog(aDlg, "DTP1", DLG_DATEPICKER,; WS_CHILD + WS_VISIBLE + WS_TABSTOP ,; 120, 105, 60, 12, ; 0 ) // ---------- Press ESCAPE always returns 0... nRet = NTK_ModalDialog(aDlg, hInst, hWndDemo) //s = NTK_GetDialogResult(aDlg,"lbox1" ) //s = NTK_GetDialogResult(aDlg,"cbox1" ) //s = NTK_GetDialogResult(aDlg,"edit" ) //s = NTK_GetDialogResult(aDlg, IDOK ) //s = NTK_GetDialogResult(aDlg,"radioa" ) //s = NTK_GetDialogResult(aDlg,"chk1" ) //s = NTK_GetDialogResult(aDlg,"chk2" ) s = NTK_GetDialogResult(aDlg,"DTP1" ) NTK_MsgBox( , "NTK_ModalDialog() returned the following value ->"+STR(nRet,15,0) ) IF VALTYPE(s)=="C" NTK_MsgBox( , "NTK_GetDialogResult :"+s ) ELSEIF VALTYPE(s)=="D" NTK_MsgBox( , "NTK_GetDialogResult :"+DTOC(s) ) ELSEIF VALTYPE(s)=="N" NTK_MsgBox( , "NTK_GetDialogResult :"+Str(s) ) ELSEIF VALTYPE(s)=="A" FOR nJ := 1 TO LEN(s) NTK_MsgBox( , "ItemSel #"+LTRIM(STR(nJ))+":"+s[nJ], "NTK_GetDialogResult()" ) NEXT ELSEIF "U" $ VALTYPE(s) NTK_MsgBox( , "NTK_GetDialogResult : Nil" ) ENDIF RETURN( NIL ) ****** ****** ****** ****** ****************************************************************************************** ****** ******************* CALLING A DIALOG FROM A RESSOURCE - SAMPLE CODE ******************** ****** ****************************************************************************************** FUNCTION DoResDLG(hWndDemo) LOCAL hInst := NTK_GetInstance() LOCAL nResDlg PRIVATE hMyBmp := NTK_LoadBitmap( NTK_GetInstance(), "rBBUNNY" ) //PRIVATE hMyBmp := NTK_LoadBitmap( NULL, OBM_CHECK ) // To use OBM_* Win32 predefined bitmaps set hInst to NULL PRIVATE cName := "Bugs Bunny" PRIVATE cCity := "Acme Toons city" PRIVATE nAmount := "10000.00" PRIVATE cMemo := "This rabbit is very clever!"+ CR +; "So, be careful to what he does"+ CR +; "or what he says..." // ------- See DEMOMULT.RC resources file. //-------- Demomult.rc has been mostly created with Borland Resource Workshop //nResDlg := NTK_DialogBox( hInst, "SAMPLE_DLG", hWndDemo ) nResDlg := NTK_DialogBox( hInst, "CUSTOMER_DLG", hWndDemo,; {|hDlg, msg, wparam, lparam| ; ResDlgProc(hDlg, msg, wparam, lparam)} ) NTK_MsgBox( , STR(nResDlg), "DialogBox() result :" ) NTK_DeleteObject(hMyBmp) RETURN( NIL ) ****** ****** ****** ****** // Resource Dialog WndProc FUNCTION ResDlgProc(hWndDlg, nMsg, nwParam, nlParam) LOCAL aPS := { 0,.T.,0,0,0,0,.T.,.T.,nil } // 9 elements, see NTKGDI.CH LOCAL hDC := 0 // Message from Windows : // - hWndDlg Handle to the Dialog // - nMsg Message number // - nwParam ID of the control (child window ) // - nlParam handle to the child window + notification code DO CASE CASE nmsg == WM_INITDIALOG // DLG INITIALIZATION // Windows sends this message as soon as the Dlg is created. // Unlike a classic window procedure a Dialog doesn't send // WM_CREATE msg, but WM_INITDIALOG... NTK_SetDlgItem(hWndDlg, 5000, cName ) // Sending (initializing) a NTK_SetDlgItem(hWndDlg, 5001, cCity ) // value for each get... NTK_SetDlgItem(hWndDlg, 5002, nAmount ) NTK_SetDlgItem(hWndDlg, 5003, cMemo ) // Set focus on the first control... **NTK_SetFocus( NTK_GetDlgItem( hWndDlg, IDOK ) ) // 'Save' Button NTK_SetFocus( NTK_GetDlgItem( hWndDlg, 5000 ) ) // 'Name' Edit control) RETURN .F. CASE nmsg == WM_COMMAND // Windows sends this message as soon as you click on a control (EDIT,BUTTON,LISTBOX, ...) // nwparam is the control ID Do Case Case nwparam==IDCANCEL // 2 - 'Cancel' Button // Tell Windows to close the Dialog //NTK_DestroyWindow(hWndDlg, nwparam) NTK_EndDialog(hWndDlg, nwparam) RETURN .T. Case nwparam==IDOK // 1 - 'Save' Button // Pick-up the modified (or not) value of each get... cName := NTK_GetDlgItemText(hWndDlg, 5000) cCity := NTK_GetDlgItemText(hWndDlg, 5001) nAmount := VAL( NTK_GetDlgItemText(hWndDlg, 5002) ) cMemo := NTK_GetDlgItemText(hWndDlg, 5003) // Tell Windows to close the Dialog NTK_EndDialog(hWndDlg, nwparam) RETURN .T. EndCase CASE nmsg == WM_PAINT hDC := NTK_BeginPaint( hWndDlg, aPS ) IF !EMPTY(hMyBmp) //NTK_DrawBmp( hDC, hMyBmp, 224, 095, SRCCOPY ) // Win 9x NTK_DrawBmp( hDC, hMyBmp, 158, 76, SRCCOPY ) // Win XP ENDIF NTK_EndPaint( hWndDlg, aPS ) ENDCASE RETURN .F. ****** ****** ****** FUNCTION DoOpenFileDlg(hWndDemo) LOCAL cFile LOCAL aFilter := { { "programs", "*.exe;*.com;*.bat" },; { "source", "*.c;*.prg" },; { "xbase common datas", "*.dbf;*.dbt;*.ftp;*.ntx;*.cdx" } } cFile := NTK_GetOpenFileName( hWndDemo, "*.TXT", "Pick a file...", aFilter, , "\WNTK4HRB\NTKCORE\LIB\" ) IF cFile == Nil NTK_MsgBox( hWndDemo, "Nothing and cancel", "You chose to open:", MB_OK+MB_ICONASTERISK ) RETURN .F. ENDIF NTK_MsgBox( hWndDemo, cFile, "You chose to open:", MB_OK+MB_ICONASTERISK ) RETURN .T. ****** ****** ****** FUNCTION DoSaveFileDlg(hWndDemo) LOCAL cFile cFile = NTK_GetSaveFileName( hWndDemo, "*.txt" ) IF cFile == Nil NTK_MsgBox( hWndDemo, "Nothing and cancel", "You chose to save:", MB_OK+MB_ICONASTERISK ) RETURN .F. ENDIF NTK_MsgBox( hWndDemo, cFile, "You chose to save:", MB_OK+MB_ICONASTERISK ) RETURN .T. ****** ****** ****** FUNCTION DoColorDlg(hWndDemo) LOCAL nColor := NTK_ChooseColor() IF nColor == -1 NTK_MsgBox( hWndDemo, "Nothing and cancel", "The chosen colour is:", MB_OK+MB_ICONASTERISK ) RETURN .F. ENDIF NTK_MsgBox( hWndDemo, Str(nColor), "The chosen colour is:", MB_OK+MB_ICONASTERISK ) RETURN .T. ****** ****** ******