Welcome to Dream.In.Code
Become a VB Expert!

Join 137,356 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,723 people online right now. Registration is fast and FREE... Join Now!




Using hDc to draw using windows API's

 
Reply to this topicStart new topic

Using hDc to draw using windows API's

Maritime
8 Oct, 2008 - 01:51 AM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 6


My Contributions
Hello,

I need Help to complete code for drawing moon illuminated disk.
The moon is displayed properly in form, but coordinates are not correct according the scale.

Thank you.


User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Using HDc To Draw Using Windows API's
8 Oct, 2008 - 01:53 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,539



Thanked: 67 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is online!Profile CardPM
+Quote Post

Maritime
RE: Using HDc To Draw Using Windows API's
8 Oct, 2008 - 04:04 PM
Post #3

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 6


My Contributions
QUOTE(Maritime @ 8 Oct, 2008 - 02:51 AM) *

Hello,

I need Help to complete code for drawing moon illuminated disk.
The moon is displayed properly in form, but coordinates are not correct according the scale.

Thank you.


User is offlineProfile CardPM
+Quote Post

Maritime
RE: Using HDc To Draw Using Windows API's
8 Oct, 2008 - 04:21 PM
Post #4

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 6


My Contributions
[quote name='Maritime' date='8 Oct, 2008 - 02:51 AM' post='432046']
Hello,

I need Help to complete code for drawing moon illuminated disk.
The moon is displayed properly in form, but coordinates are not correct according the scale.

Thank you.

Hello,
It's better to send you project to see better what is wrong.

User is offlineProfile CardPM
+Quote Post

thava
RE: Using HDc To Draw Using Windows API's
8 Oct, 2008 - 05:19 PM
Post #5

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 456



Thanked: 18 times
Dream Kudos: 50
My Contributions
its better to post your problem code instead of the whole project
User is offlineProfile CardPM
+Quote Post

Maritime
RE: Using HDc To Draw Using Windows API's
9 Oct, 2008 - 02:14 AM
Post #6

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 6


My Contributions

Sorry if some comments are in French!

vb

Option Explicit
Private Sub Form_Click()
Dim x As Long, y As Long

AutoRedraw = True
ScaleMode = vbPixels

Scale (0, -120)-(360, 120)
BackColor = vbBlue

'moon aspect
Lune.Elongation = "Ouest"
Lune.Fraction = 0.7


'Moon Radius
Dim diam As Integer
diam = 50

'centre of moon
'with x=180 and y=0 the moon must be in the center of form, but it is not!
'coordinates start from the upper left corner in this case.
x = 150
y = 100


Dim ShowDarkMoon As Boolean
Dim lRgn1 As Long, lRgn2 As Long, lRgn3 As Long

'_____________
'lune entiere
lRgn1 = CreateEllipticRgn(0, 0, diam, diam)

'__________________________
'tracé de la partie sombre

'déplacement à l'endroit voulu
OffsetRgn lRgn1, x - diam / 2, y - diam / 2

'brosse pour le tracé
Dim lBrshDrk As Long
If ShowDarkMoon Then
lBrshDrk = CreateSolidBrush(&H404040)
Else
lBrshDrk = CreateSolidBrush(&H400000) 'pinf.BackGroundColor)
End If

'tracé
FillRgn hdc, lRgn1, lBrshDrk
DeleteObject lBrshDrk

'retour en (0,0) pour la suite
OffsetRgn lRgn1, -x + diam / 2, -y + diam / 2

'___________________________________
'cache rectangulaire pour la moitié
lRgn3 = CreateRectRgn(0, 0, diam / 2, diam)
If Lune.Elongation = "Ouest" Then _
OffsetRgn lRgn3, diam / 2, 0 'repositionnement du cache
CombineRgn lRgn1, lRgn1, lRgn3, RGN_DIFF 'on soustrait le cache à la lune

'________________
'région centrale
lRgn2 = CreateEllipticRgn(diam * Lune.Fraction, 0, diam * (1 - Lune.Fraction), diam)
If Lune.Fraction < 0.5 Then
CombineRgn lRgn1, lRgn1, lRgn2, RGN_DIFF 'région centrale sombre
Else
CombineRgn lRgn1, lRgn1, lRgn2, RGN_OR 'région centrale éclairée
End If

'______________________________
'déplacement à l'endroit voulu
OffsetRgn lRgn1, x - diam / 2, y - diam / 2

'______
'tracé
Dim lBrsh As Long
lBrsh = CreateSolidBrush(vbWhite) 'brosse pour le tracé
FillRgn hdc, lRgn1, lBrsh

'____________________________
'Suppression des objets créé
DeleteObject lBrsh
DeleteObject lRgn1
DeleteObject lRgn2
DeleteObject lRgn3


End Sub



'Module declarations API

Public Type Lune
x As Double
y As Double
Ad As Double
Dec As Double
Lat As Double
Lon As Double
Elongation As String
Fraction As Double
Nom As String
End Type

Public Lune As Lune

'Déclaration des APIs Windows pour l'utilisation des régions

Public Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Public Declare Function OffsetRgn Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function PaintRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long

'CombineRgn nCombineMode flag constants
Public Const RGN_AND = 1
Public Const RGN_OR = 2
Public Const RGN_XOR = 3
Public Const RGN_DIFF = 4
Public Const RGN_COPY = 5

Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long


User is offlineProfile CardPM
+Quote Post

thava
RE: Using HDc To Draw Using Windows API's
9 Oct, 2008 - 03:24 AM
Post #7

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 456



Thanked: 18 times
Dream Kudos: 50
My Contributions
sure i am try to solve your problem but wait for some time

This post has been edited by thava: 9 Oct, 2008 - 03:25 AM
User is offlineProfile CardPM
+Quote Post

Maritime
RE: Using HDc To Draw Using Windows API's
9 Oct, 2008 - 09:16 AM
Post #8

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 6


My Contributions
QUOTE(thava @ 9 Oct, 2008 - 04:24 AM) *

sure i am try to solve your problem but wait for some time

Thank you thava, I am trying to find solution too.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 12:55AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month