Archive for July, 2005

Popup Menus – Per Request

Believe it or not someone wants to know how to create popup menus. Wow! I can’t believe I am going to explain this. But here it goes. The easiest way is to:

Create a new Form in your Project. Name it frmMenuServer or something like that. Now use the ‘Edit Menus’ feature to create your menus.

Now for instance this guy wants to right click on his PictureBox control and view a menu. And heres how.

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y AsSingle)

If Button=1 Then PopUpMenu frmMenuServer.mnuMenuName,flags,X,Y
End Sub

And there you have it. You can create as many menus as you would like for popup use. Its’ about the simpliest thing you can do in VB. But hey, glad to help!

Popularity: 1% [?]

ICC is ICM – Per Request

Because Windows had already assigned the ICC suffix to another system component, Windows refers to ICC profiles as ICM. The suffixes ICC and ICM are interchangeable in the language of CMS.

In addition to performing regular calibration and profiling of the monitor, a user should try to maintain consistent lighting conditions. The monitor needs to be calibrated and profiled at least once a month. Of all the devices that require ICC profiles, the monitor loses its calibration the quickest. If your monitor has been calibrated correctly you should not have to full around with ICM profiles. However if you are wanting to create and use 3rd party ICM or custom ICM profiles you should only use one at a time. Please make sure you have a ICM for everyday use along with the ICM that you want to use with Video or Image editing.

I have done some research on implementing ICM with VB. Though it doesnt seem like an easy task, it is possible. Check back later for the VB code to interact with your ICM profiles. This is not something that I can write out in 5 minutes.

Popularity: 39% [?]

Per Request – bananahz Fom the LiveJournal community.

Here is a snippet that will optimize ram for you. You can call this code from within a timer and it will improve your pc performance greatly.

Private Declare Function GlobalAlloc Lib “kernel32″ (ByVal wFlags As Long, _
ByVal dwBytes As Long) As Long

Private Declare Function GlobalFree Lib “kernel32″ (ByVal hMem As Long) As _
Long

Public Sub Optimize_Ram()
On Error GoTo finish

Dim i As Integer
Dim Ptr_M() As Long
Dim PTR_F() As Long

Dim NF As Integer
Dim NM As Integer
Dim Rtn As Long
Dim Intact As Boolean
Dim MAX As Long

Dim Times, some As Long

Do While some <> 120
ReDim Preserve Ptr_M(NM)
ReDim Preserve PTR_F(NF)

Ptr_M(NM) = GlobalAlloc(&H2, 50000)
PTR_F(NF) = GlobalAlloc(&H2, 50000)


NM = NM + 1
NF = NF + 1
some = some + 1

Loop
GoTo finish:
Do While Intact = False
ReDim Preserve Ptr_M(NM)
ReDim Preserve PTR_F(NF)
Ptr_M(NM) = GlobalAlloc(&H2, 50000)
PTR_F(NF) = GlobalAlloc(&H0, 50000)

If Ptr_M(NM) = 0 Then Intact = True
If PTR_F(NF) = 0 Then Intact = True
NM = NM + 1
NF = NF + 1
Loop

finish:

For i = NM – 1 To 0 Step -1

Rtn = GlobalFree(Ptr_M(i))
ReDim Preserve Ptr_M(i)
Rtn = GlobalFree(PTR_F(i))
DoEvents
Next i

End Sub

This code could be used to free up ram as you process long complicated procedures or graphics rendering.

Popularity: 1% [?]

Very Easy INI handling

Alot of people wanted to know how they could use INI files with there applications. So here it is. This is the best way I can show a beginner. First you will need to declare two functions.

Declare Functions:

Declare Function GetPrivateProfileString Lib “KERNEL32″ Alias _
“GetPrivateProfileStringA” (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, ByVal _
lpReturnedString As String, ByVal nSize As Long, ByVal _
lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib “KERNEL32″ _
Alias “WritePrivateProfileStringA” (ByVal lpApplicationName _
As String, ByVal lpKeyName As String, ByVal lpString As Any, _
ByVal lpFileName As String) As Long

Now you need to create two custom functions to accompany the Decalres.

Function ReadINI(Section, KeyName, filename As String) As String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal _
KeyName, “”, sRet, Len(sRet), filename))
End Function

Function WriteINI(sSection As String, sKeyName As String, _
sNewString As String, sFileName) As Integer
Dim r
r = WritePrivateProfileString(sSection, sKeyName, _
sNewString, sFileName)
End Function

Now that you have that set up, here is an example of some data in an INI and how to retrieve and write to it.

INI Data Format

[Main]
Capation=myCaption
Width=5000
Password=true

The text within the [] defines the section of the INI to read from. Data below the Section are called keys. ‘Caption’ is a key in this case. That should sum up an INI file structure. You can have as many sections and keys as you need.

Reading from the INI

Dim myString as String
myString=ReadINI(“Main”,”Caption”, FILENAME)

Normally INI files carry the .ini extension. However you can create the file with any extension you want. Maybe you are not good with encryption and dont want people playing with the INI file. Make the extension .DLL or something that does not have a laymans editor. Its a cheap trick, but it works.

Writting to the INI

WriteINI “Main”,”Caption”,”YouCaption”,FILENAME

Thats not too hard. Just remember that you have to call the right section and key to retrieve your data. You can have section MAIN and section OTHER with both having keys named Caption. But if you call the wrong section, you will get the wrong key.

That should sum things up pretty well. Remember to email me any question or post one here, Im glad to help.

Popularity: 38% [?]

Too many questions.

I have recieved tons of emails and IM’s wanting to know what some of the following are. They are pretty simple, and if you dont know what they are, maybe you should not try to write code.

UDT = User Defined Type
Example

Public Type Car
myModel as string
myMake as string
myYear as single
End Type

Const = Constant
A constant carries the same value all throughout the code. For instance:

const myCaption as string = “Application Title”

Now anytime in your code you call set a windows caption using this constant. Constants are used to store set values that never change. Some examples of this might be: Dates, Times, Captions, Control names, File names and so on.

ReDim
Example

Say maybe you want to set up an array, but off hand you dont know how many elements you want to add. The you would define your array like this.

Dim myArray() as single

Now later on in your application you may have figured out how many elements your array should carry. Then you would ReDim the array like this.

ReDim myArray(userCount)

And there you have it, UTD’s, Constants and the ReDim statement.

Popularity: 75% [?]

Simple Window Animations

Use the following constants and function in a module


Public Const AW_HOR_POSITIVE = &O1 ‘ Animate the window from
‘left to right. This flag can be used with roll or slide
‘animation It is ignored when used with the AW_CENTER flag.

Public Const AW_HOR_NEGATIVE = &H2 ‘ Animate the window from
‘right to left. This flag can be used with roll or slide
‘animation. It is ignored when used with the AW_CENTER flag.

Public Const AW_VER_POSITIVE = &H4 ‘ Animate the window from
‘top to bottom. This flag can be used with roll or slide
‘animation. It is ignored when used with the AW_CENTER flag.

Public Const AW_VER_NEGATIVE = &H8 ‘ Animate the window from
‘bottom to top. This flag can be used with roll or slide
‘animation. It is ignored when used with the AW_CENTER flag.

Public Const AW_CENTER = &H10 ‘ Makes the window appear to
‘collapse inward if the AW_HIDE flag is used or expand outward
‘if the AW_HIDE flag is not used.

Public Const AW_HIDE = &H10000 ‘ Hides the window. By default,
‘the window is shown.

Public Const AW_ACTIVATE = &H20000 ‘ Activates the window. Do
‘not use this flag with AW_HIDE.

Public Const AW_SLIDE = &H40000 ‘ Uses slide animation. By
‘default, roll animation is used. This flag is ignored when used
‘with the AW_CENTER flag.

Public Const AW_BLEND = &H80000 ‘ Uses a fade effect. This flag
‘can be used only if hwnd is a top-level window.

Public Declare Function AnimateWindow Lib “user32″ ( _
ByVal hWnd As Long, ByVal dwTime As Long, _
ByVal dwFlags As Long) As Boolean

Now in your forms unload event try this.

Call AnimateWindow(Me.hWnd, 600, AW_CENTER Or AW_HIDE)

You can also use these methods in the forms load event.

And there you go. Quick, simple and effective. This gives your forms a great unload effect.

Popularity: 1% [?]

First Post

First off, we’re both thinking. “Why the hell Visual Basic?”. Well, it’s simple, fast, reliable, and very popular. You can write a VB application that can compete with any C code out there. I will show you step-by-step how to use custom window animations, database, ini file handling, graphics, skinning and whatever else you request.

Popularity: 1% [?]