Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Da li je ovo moguce uraditi u VB6!

[es] :: Visual Basic 6 :: Da li je ovo moguce uraditi u VB6!

[ Pregleda: 4444 | Odgovora: 11 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

notebookFun
System Administrator
Novi Sad

Član broj: 226286
Poruke: 835



+20 Profil

icon Da li je ovo moguce uraditi u VB6!02.05.2010. u 15:41 - pre 169 meseci
Kad se ucita forma da se pokrene jedna pjesma, ali da ta pjesma bude unutar EXE aplikacije a ne kao odvojen file.

Znaci da u folderu ne bude posebno pjesma.mp3 i program.exe, vec samo program.exe i u njemu ta pjesma!
Ukoliko se treseš od ljutnje na svaku nepravdu onda si moj suborac. ~Che Guevara
 
Odgovor na temu

rgdrajko
Beograd

Član broj: 117734
Poruke: 710
...216.wifi.dynamic.gronet.rs.



+3 Profil

icon Re: Da li je ovo moguce uraditi u VB6!02.05.2010. u 19:35 - pre 169 meseci
Preko RES fajla se to radi.
Pogledati na:

http://visualbasic.about.com/od/usevb6/a/ResVB6.htm



Creating a Resource File in VB 6

You can see the resources in a project in both VB 6 and VB.NET in the Project Explorer window (Solution Explorer in VB.NET - they had to make it just a little bit different). A new project won't have any since resources aren't a default tool in VB 6. So let's add a simple resource to a project and see how that is done.

Step one is to start VB 6 by selecting a Standard EXE project on the New tab in the startup dialog. Now select the Add-Ins option on the menu bar, and then the Add-In Manager.... This will open the Add-In Manager dialog window.

Scroll down the list and find VB 6 Resource Editor. You can just double-click it or you can put a check mark in the Loaded/Unloaded box to add this tool to your VB 6 environment. If you think you're going to use the Resource Editor a lot, then you can also place a check mark in the box Load on Startup and you won't have to go through this step again in the future. Click "OK" and the Resources Editor pops open. You're ready to start adding resources to your project!

Go to the menu bar and select Project then Add New Resource File or just right-click in the Resource Editor and select "Open" from the context menu that pops up. A window will open, prompting you for the name and location of a resource file. The default location will probably not be what you want, so navigate to your project folder and enter the name of your new resource file into the File name box. In this article, I'll use the name "AboutVB.RES" for this file. You'll have to confirm the creation of the file in a verification window, and the a "AboutVB.RES" file will be created and filled into the Resource Editor.

("Add Icon...")
Custom bitmaps - "BMP" files
("Add Bitmap...")
Programmer defined resources
("Add Custom Resource...")

VB 6 provides a simple editor for strings but you have to have a file created in another tool for all of the other choices. For example, you could create a BMP file using the simple Windows Paint program.

Each resource in the resource file is identified to VB 6 by an Id and a name in the Resource Editor. To make a resource available to your program, you add them in the Resource Editor and then use the Id and the resource "Type" to point to them in your program. Let's add four icons to the resource file and use them in the program.

When you add a resource, the actual file itself is copied into your project. Visual Studio 6 provides a whole collection of icons in the folder ...

C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons

To go with tradition, we'll select the Greek philosopher Aristotle's four "elements" - Earth, Water, Air, and Fire - from the Elements subdirectory. When you add them, the Id is assigned by Visual Studio (101, 102, 103, and 104) automatically.

To use the icons in a program, we use a VB 6 "Load Resource" function. There are several of these functions to choose from:
LoadResPicture(index, format) for bitmaps, icons, and cursors

Use the VB predefined constants vbResBitmap for bitmaps, vbResIcon for icons, and vbResCursor for cursors for the "format" parameter. This function returns a picture that you can use directly. LoadResData (explained below) returns a string containing the actual bits in the file. We'll see how to use that after we demonstrate icons.
LoadResString(index) for strings
LoadResData(index, format) for anything up to 64K

As noted earlier, this function returns a string with the actual bits in the resource. These are the values that can be used for format parameter here:
1 Cursor resource
2 Bitmap resource
3 Icon resource
4 Menu resource
5 Dialog box
6 String resource
7 Font directory resource
8 Font resource
9 Accelerator table
10 User-defined resource
12 Group cursor
14 Group icon

Since we have four icons in our AboutVB.RES resource file, let's use LoadResPicture(index, format) to assign these to the Picture property of a CommandButton in VB 6.

I created an application with four OptionButton components labeled Earth, Water, Air and Fire and four Click events - one for each option. Then I added a CommandButton and changed the Style property to "1 – Graphical". This is necessary to be able to add a custom icon to the CommandButton. The code for each OptionButton (and the Form Load event -- to initialize it) looks like this (with the Id and Caption changed accordingly for the other OptionButton Click events):

Private Sub Option1_Click()

Command1.Picture = _

LoadResPicture(101, vbResIcon)

Command1.Caption = _

"Earth"

End Sub
To download this complete project Click Here

The "Big Deal" with custom resources is that you normally have to provide a way to process them in your program code. As Microsoft states it, "This usually requires the use of Windows API calls." That's what we'll do.

The example we'll use is a fast way to load an array with a series of constant values. Remember that the resource file is included into your project, so if the values that you need to load change, you'll have to use a more traditional approach such as a sequential file that you open and read. The Windows API we'll use is the CopyMemory API. CopyMemory copies block of memory to a different block of memory without regard to the data type that is stored there. This technique is well known to VB 6'ers as an ultra fast way to copy data inside a program.

This program is a bit more involved because first we have to create the a resource file containing a series of long values. I simply assigned values to an array:

Dim longs(10) As Long
longs(1) = 123456
longs(2) = 654321

... and so forth.

Then the values can be written to a file called MyLongs.longs using the VB 6 "Put" statement.

Dim hFile As Long

hFile = FreeFile()

Open _

"C:\your file path\MyLongs.longs" _

For Binary As #hFile

Put #hFile, , longs

Close #hFile

It's a good idea to remember that the resource file doesn't change unless you delete the old one and add a new one. So, using this technique, you would have to update the program to change the values. To include the file MyLongs.longs into your program as a resource, add it to a resource file using the same steps described above, but click the Add Custom Resource ... instead of Add Icon ... Then select the MyLongs.longs file as the file to add. You also have to change the "Type" of the resource by right clicking that resource, selecting "Properties", and changing the Type to "longs". Note that this is the file type of your MyLongs.longs file.

To use the resource file you have created to create a new array, first declare the Win32 CopyMemory API call:

Private Declare Sub CopyMemory _

Lib "kernel32" Alias _

"RtlMoveMemory" (Destination As Any, _

Source As Any, ByVal Length As Long)

Then read the resource file:

Dim bytes() As Byte

bytes = LoadResData(101, "longs")

Next, move the data from the bytes array to an array of long values. Allocate an array for the longs values using the integer value of the length of the string of bytes divided by 4 (that is, 4 bytes per long):

ReDim longs(1 To (UBound(bytes)) \ 4) As Long

CopyMemory longs(1), bytes(0), UBound(bytes) - 1

Now ... this may seem like a whole lot of trouble when you could just initialize the array in the Form Load event, but it does demonstrate how to use a custom resource. If you had a large set of constants that you needed to initialize the array with, it would run faster than any other method I can think of and you wouldn't have to have a separate file included with your application to do it.

To download this complete project Click Here


rgdrajko
Prikačeni fajlovi
 
Odgovor na temu

notebookFun
System Administrator
Novi Sad

Član broj: 226286
Poruke: 835



+20 Profil

icon Re: Da li je ovo moguce uraditi u VB6!03.05.2010. u 14:05 - pre 169 meseci
Nasao sam u MSDN-u kako se kreira .RES file i naparvio taj fajl sa jednom pjesmom.

E sad ovaj tutorial sto si postovao je namjenjen najvise za SLIKE, i nema nista konkretno kako da automatski krene pjesma kad se ucita forma. Koja komponenta je najjednostavnija za pustanje .mp3 ili Wav ili .mid. Ako moze neko da mi uradi primjer, bio bih mu zahvalan!
Ukoliko se treseš od ljutnje na svaku nepravdu onda si moj suborac. ~Che Guevara
 
Odgovor na temu

vuchko.vuchko

Član broj: 217112
Poruke: 301
*.teol.net.



+2 Profil

icon Re: Da li je ovo moguce uraditi u VB6!03.05.2010. u 15:16 - pre 169 meseci
http://www.vb-helper.com/howto_play_mp3.html
 
Odgovor na temu

notebookFun
System Administrator
Novi Sad

Član broj: 226286
Poruke: 835



+20 Profil

icon Re: Da li je ovo moguce uraditi u VB6!03.05.2010. u 15:44 - pre 169 meseci
Joj ljudi sta je sa ovog foruma, hoce li se neko javiti sa konkretnim odgovorom. Ne treba mi da se pokrene zvuk uz pomoc putanje, jer bi u tom slucaju mp3 faj bio odvojen od EXE.

Meni treba da pokrenem .RES file u kojem se nalazi mp3 ili midi ili Wav. Procitajte prvi post u ovoj temi!
Ukoliko se treseš od ljutnje na svaku nepravdu onda si moj suborac. ~Che Guevara
 
Odgovor na temu

rgdrajko
Beograd

Član broj: 117734
Poruke: 710
...216.wifi.dynamic.gronet.rs.



+3 Profil

icon Re: Da li je ovo moguce uraditi u VB6!04.05.2010. u 00:42 - pre 169 meseci
Evo primera na http://www.bigresource.com/VB-...-Resource-File-34WXypEuhi.html



Resource File

The following code will display an AVI in a resource file.

Code:


Option Explicit
Private Sub Command1_Click()
Dim hRsrc As Long
Dim hGlobal As Long
Dim lpString As String
Dim strCmd As String, strReturnVal As String
Dim nbuf As Long

lpString = "#101" 

hInst = LoadLibrary("<Path resource dll file name>") 
hRsrc = FindResource(hInst, lpString, "AVI")
hGlobal = LoadResource(hInst, hRsrc)
lpData = LockResource(hGlobal)
fileSize = SizeofResource(hInst, hRsrc)

Call mmioInstallIOProc(MEY, AddressOf IOProc, _
MMIO_INSTALLPROC + MMIO_GLOBALPROC)
nbuf = 256

strCmd = "open test.MEY+ type avivideo alias test"
strReturnVal = mciSendString(strCmd, 0&, 0&, 0&)
strCmd = "play test wait"
strReturnVal = mciSendString(strCmd, 0&, 0&, 0&)
strCmd = "close test"
strReturnVal = mciSendString(strCmd, 0&, 0&, 0&)

Call mmioInstallIOProc(MEY, vbNull, MMIO_REMOVEPROC)
FreeLibrary hInst
End Sub

Option Explicit
Public lpData As Long
Public fileSize As Long
Public hInst As Long

Public Const MMIO_INSTALLPROC = &H10000 

Public Const MMIO_GLOBALPROC = &H10000000 


Public Const MMIO_READ = &H0
Public Const MMIOM_CLOSE = 4
Public Const MMIOM_OPEN = 3
Public Const MMIOM_READ = MMIO_READ
Public Const MMIO_REMOVEPROC = &H20000
Public Const MMIOM_SEEK = 2
Public Const SEEK_CUR = 1
Public Const SEEK_END = 2
Public Const SEEK_SET = 0
Public Const MEY = &H2059454D 


Public Type MMIOINFO
dwFlags As Long
fccIOProc As Long
pIOProc As Long
wErrorRet As Long
htask As Long
cchBuffer As Long
pchBuffer As String
pchNext As String
pchEndRead As String
pchEndWrite As String
lBufOffset As Long
lDiskOffset As Long
adwInfo(4) As Long
dwReserved1 As Long
dwReserved2 As Long
hmmio As Long
End Type


Public Declare Function FindResource Lib "kernel32" _
Alias "FindResourceA" _
(ByVal hInstance As Long, _
ByVal lpName As String, _
ByVal lpType As String) _
As Long


Public Declare Function LoadResource Lib "kernel32" _
(ByVal hInstance As Long, _
ByVal hResInfo As Long) _
As Long


Public Declare Function LockResource Lib "kernel32" _
(ByVal hResData As Long) As Long


Public Declare Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long


Public Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long


Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)


Public Declare Function mmioInstallIOProc Lib "winmm" _
Alias "mmioInstallIOProcA" _
(ByVal fccIOProc As Long, _
ByVal pIOProc As Long, _
ByVal dwFlags As Long) _
As Long

Public Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" _
(ByVal lpstrCommand As String, _
ByVal lpstrReturnString As Long, _
ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) _
As Long

Public Declare Function SizeofResource Lib "kernel32" _
(ByVal hInstance As Long, _
ByVal hResInfo As Long) As Long


Public Function IOProc _
(ByRef lpMMIOInfo As MMIOINFO, _
ByVal uMessage As Long, _
ByVal lParam1 As Long, _
ByVal lParam2 As Long) _
As Long

Static alreadyOpened As Boolean

Select Case uMessage
Case MMIOM_OPEN
If Not alreadyOpened Then
alreadyOpened = True
lpMMIOInfo.lDiskOffset = 0
End If
IOProc = 0

Case MMIOM_CLOSE
IOProc = 0

Case MMIOM_READ:
Call CopyMemory(ByVal lParam1, ByVal _
lpData + lpMMIOInfo.lDiskOffset, lParam2)
lpMMIOInfo.lDiskOffset = lpMMIOInfo.lDiskOffset + lParam2
IOProc = lParam2

Case MMIOM_SEEK

Select Case lParam2
Case SEEK_SET
lpMMIOInfo.lDiskOffset = lParam1

Case SEEK_CUR
lpMMIOInfo.lDiskOffset = lpMMIOInfo.lDiskOffset + lParam1
lpMMIOInfo.lDiskOffset = fileSize - 1 - lParam1

Case SEEK_END
lpMMIOInfo.lDiskOffset = fileSize - 1 - lParam1
End Select

IOProc = lpMMIOInfo.lDiskOffset

Case Else
IOProc = -1 

End Select

End Function

rgdrajko
 
Odgovor na temu

rgdrajko
Beograd

Član broj: 117734
Poruke: 710
...216.wifi.dynamic.gronet.rs.



+3 Profil

icon Re: Da li je ovo moguce uraditi u VB6!04.05.2010. u 01:43 - pre 169 meseci
Evo na brzinu sam napisao jednostavan primer za tebe, za to sto si trazio.

Code:
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long


Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2

Private Sub Command1_Click()
    Call Zvuk
End Sub

Public Sub Zvuk()
    Dim imeWavFajl As String
    Dim B() As Byte
    Dim s As String
    Dim i As Long
    
    Dim Temp As String
    Dim StartPosition As Long
    Dim mHandle As Integer

    Text1.Visible = True
    Text1.Refresh

    s = ""
    
    B = LoadResData(101, "CUSTOM")
    
    For i = 0 To UBound(B())
        s = s & Chr(B(i))
    Next i
    
    Erase B

    mHandle = FreeFile
    
    imeWavFajl = "zvuk.wav"
    
    Open imeWavFajl For Binary As #mHandle
        StartPosition = LOF(mHandle)
        Temp = s
        Put #mHandle, , Temp
        Put #mHandle, , StartPosition
    Close #mHandle
      
  Text1.Visible = False
  
    sndPlaySound imeWavFajl, SND_NODEFAULT Or SND_ASYNC
    
    Kill imeWavFajl

End Sub


rgdrajko
Prikačeni fajlovi
 
Odgovor na temu

notebookFun
System Administrator
Novi Sad

Član broj: 226286
Poruke: 835



+20 Profil

icon Re: Da li je ovo moguce uraditi u VB6!05.05.2010. u 14:00 - pre 169 meseci
@rgdrajko

Radi, ali sporo ucitava. Mora da postoji bolji naci za ovo, nalazio sam neke KEYGEN-e gdje se odmah ucitava, kako se forma ucita, a pisani su u VB6.
Ukoliko se treseš od ljutnje na svaku nepravdu onda si moj suborac. ~Che Guevara
 
Odgovor na temu

rgdrajko
Beograd

Član broj: 117734
Poruke: 710
...215.wifi.dynamic.gronet.rs.



+3 Profil

icon Re: Da li je ovo moguce uraditi u VB6!05.05.2010. u 22:21 - pre 169 meseci
Pa posto bas insistiras na brzini, ono je bio skolski primer.

Evo:

Code:
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long

Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2

Private Sub Command1_Click()
    Call Zvuk
End Sub

Public Sub Zvuk()
    Dim imeWavFajl As String
    Dim B() As Byte
    Dim s As String
    Dim i As Long
    
    Dim StartPosition As Long

    Text1.Visible = True
    Text1.Refresh

    s = ""
    
    B = LoadResData(101, "CUSTOM")
        
    imeWavFajl = "zvuk.wav"
    
    Open imeWavFajl For Binary As #1
       Put #1, 1, B()
    Close #1
    
    Erase B

      
    Text1.Visible = False
  
    sndPlaySound imeWavFajl, SND_NODEFAULT Or SND_ASYNC
    
    Kill imeWavFajl

End Sub

rgdrajko
Prikačeni fajlovi
 
Odgovor na temu

timmy
Jovan Timotijevic

Član broj: 37087
Poruke: 634

Sajt: www.e-tim.net


+89 Profil

icon Re: Da li je ovo moguce uraditi u VB6!05.05.2010. u 22:51 - pre 169 meseci
Evo jednog lepog primera za "pustanje" wav fajla iz kompajliranog .exe u koji je ugradjen kao resource...

http://answers.yahoo.com/question/index?qid=20080105064637AAPqcPE

Pozdrav
 
Odgovor na temu

notebookFun
System Administrator
Novi Sad

Član broj: 226286
Poruke: 835



+20 Profil

icon Re: Da li je ovo moguce uraditi u VB6!09.05.2010. u 13:06 - pre 169 meseci
@timmy odlicno, bas ti hvala!

E sad sam dobio novu ideju:)
Kako da ubacim neki exe file u Resource, pa da ga nekako raspakujem u neki TEMP file i da ga poslije koriscenja obrise iz TEMP-a.


Da li se na ovaj nacin prave PORTABLE programi. Oni sadrze obicno samo jedan file ?


Ukoliko se treseš od ljutnje na svaku nepravdu onda si moj suborac. ~Che Guevara
 
Odgovor na temu

rgdrajko
Beograd

Član broj: 117734
Poruke: 710
...212.wifi.dynamic.gronet.rs.



+3 Profil

icon Re: Da li je ovo moguce uraditi u VB6!11.05.2010. u 23:23 - pre 168 meseci
Pa dao sam ti primer na http://www.bigresource.com/VB-...-Resource-File-34WXypEuhi.html, trebao si bolje da pogledas.


EXE In A Resource File
I'm making a simple installer program for a little program a group of us made, I placed the EXE in a resource file, put it in the installer project, but when extracting it to an EXE file there are 12 extra bytes added to the front of the program, causing it to not work.

this is the code I'm using to try and write it from the res file to an EXE.

kioskexe = LoadResData("KIOSK.EXE", "CUSTOM")
KioskICO = LoadResData("KIOSK.ICO", "CUSTOM")


'Extracts Kiosk.exe from Kiosk Install.exe

Open frm_install4.InstallDir & "kiosk.exe" For Binary As #1
Put #1, , kioskexe
Close #1

Anyone got an idea why it isn't working
rgdrajko
 
Odgovor na temu

[es] :: Visual Basic 6 :: Da li je ovo moguce uraditi u VB6!

[ Pregleda: 4444 | Odgovora: 11 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.