Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about "What does this statement do?" 1

Status
Not open for further replies.

dbrooks74

Programmer
Nov 13, 2001
105
US
I've been working to create a game using visual basic, and using some examples I found on the internet. My problem is that I'm constantly getting a return code of 0 because it doesn't return a handle. The following function is continously returning 0, because of the line in bold. However I'm not sure what it does because the program works fine without it. Can someone help? I want to keep it in if it has a purpose, but it keeps on crashing my program. AHAHAHAHAHA. Thanks. -db

Public Function GenerateDC(FileName As String) As Long
'*******************************************************
'* Function: GenerateDC() As Long
'* Parameters: A file Name
'* Purpose: Gives you back the handle to the file
'*******************************************************
Dim lFileHandle As Long 'The file handle for the file
Dim hBitmap As Long 'The bitmap for the file

'Create a Device Context, compatible with the screen
lFileHandle = CreateCompatibleDC(0)

If lFileHandle < 1 Then
GenerateDC = 0
Exit Function
End If

.
.
.

End Function

 
It checks to see if a handle was returned from CreateCompatibleDC. If a null value is returned it sets GenerateDC to 0 then exits the procedure. It is kind of acting as a form of error handling. The reason the game works is because the CreateCompatibleDC function is working properly, if it returns an error you will see the effect of the code. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]

[cheers]
 
That makes sense, but why would I send &quot;CreateCompatibleDC&quot; a parameter of 0? That doesn't make any sense to me, any ideas? What is parameter 0? -Thanks. -db
 
From MSDN:

CreateCompatibleDC
This function creates a memory device context (DC) compatible with the specified device.

HDC CreateCompatibleDC(
HDC hdc
);
Parameters
hdc
[in] Handle to an existing device context. If this handle is NULL, the function creates a memory device context compatible with the application's current screen./ If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]

[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top