Contents: Main
|
If you are stuck on something, this is the place to come. First check the previous questions because the likelihood is that someone's already had your problem. If your question/problem is not covered simply submit a question and I'll do my best to answer it or find someone who can. ALL THE ANSWERS USING API CALLS ARE FOR THE WIN32 ENVIRONMENTS, UNLESS OTHERWISE STATED. Also, all Answers are by me, unless oterwise stated. If you would like to answer questions, drop me a line, as I always appreciate some help. Submit a Question by Email. Contents of Questions:
Answers: 1. How to play a wave file
from with in a program Firstly, to do this it is necessary to make a call from the windows API, so we must declare the function and related constants. Place this code in the declarations section of a module. Global Const SND_SYNC =
&H0 Public Declare Function sndPlaySound% Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) This should all be on one line. Now, to make the programming neater add a Sub to the module which will play the sound: Public
Sub PlaySound(SoundName As String) You will notice that the sound name is changed to the full path, by adding the application's path to the beginning. This means that when you call the wave file you need only include the actual file name. Now to play a wave file simply put this code somewhere in your program Call PlaySound ("mywav.wav") Where mywav.wav is in the application's directory. 2. How to
make a form, always on top. Again, to do this we must call an API function. This is the declaration and should be placed in a module. Global
Const SWP_NOMOVE = 2 And again, this declaration should be on one line. This Sub should be placed in the module, and is what is called by your program. Sub FloatWindow(X As Integer, action As Integer) Then to call the procedure there are to options; the first to "float" the form, this makes it Always on Top, the second "sink", this makes it not Always on top. To Float a form : Dim f As Integer To Sink a form : Dim f As Integer 3. What's
the best way to center a form? I'm not saying this is the best way, but it's definitely one of the easiest. Simply add this Sub in a module or the declaration's section of the form. Public Sub
CenterForm(MeForm As Form) Then to center the current form use this code: Centerform Me or to center an MDIs active form use Centerform MDIForm1.ActiveForm 'Where MDIForm1 is the form's name 4. How to
use an INI file with your program This is another example that uses the Windows API. Put these functions in the Declarations section of a form or Module. Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnSring As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Long Again, make sure it's all on one line. Now to "GET" information from an INI use the following code: Dim FileName As String, lpAppName As String, lpKeyName As String * 20 So, this will get data from a file called MY_INI.INI, the section START_UP and Key Name FILE. If there is no entry under this name it will return a value of "unknown". The value is storred as LastFileName. The INI file might look like this: [START-UP] [OPTIONS] etc. etc. As, you can probably guess it is possible to "get" values from the WIN.INI and the SYSTEM.INI. Heres, how to "SAVE" a value to an INI. Dim FileName As String, lpAppName As String, lpKeyName As String * 20 Easy, eh? Oh, I should say. Unless a specific path is specified the INI file will be located in the windows directory. 5. How to
access the Windows Registry (only works with Win32s) This is actually an easier way to save data than using an INI file. To Get a setting: Dim X As String To Set a setting: SaveSetting "appname", "section", "key", value Like the INI file with the GetSetting, if no value is there then it returns the default. |