7 Replies - 1648 Views - Last Post: 09 October 2008 - 10:16 AM Rate Topic: -----

#1 Maritime  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 08-October 08

Using hDc to draw using windows API's

Posted 08 October 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.
Is This A Good Question/Topic? 0
  • +

Replies To: Using hDc to draw using windows API's

#2 no2pencil  Icon User is online

  • Original Digital Gansta
  • member icon

Reputation: 4501
  • View blog
  • Posts: 24,967
  • Joined: 10-May 07

Re: Using hDc to draw using windows API's

Posted 08 October 2008 - 02:53 AM

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.
Was This Post Helpful? 0
  • +
  • -

#3 Maritime  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 08-October 08

Re: Using hDc to draw using windows API's

Posted 08 October 2008 - 05:04 PM

View PostMaritime, on 8 Oct, 2008 - 02:51 AM, said:

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.

Was This Post Helpful? 0
  • +
  • -

#4 Maritime  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 08-October 08

Re: Using hDc to draw using windows API's

Posted 08 October 2008 - 05:21 PM

[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.
Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,560
  • Joined: 17-April 07

Re: Using hDc to draw using windows API's

Posted 08 October 2008 - 06:19 PM

its better to post your problem code instead of the whole project
Was This Post Helpful? 0
  • +
  • -

#6 Maritime  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 08-October 08

Re: Using hDc to draw using windows API's

Posted 09 October 2008 - 03:14 AM

Sorry if some comments are in French!

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
 


Was This Post Helpful? 0
  • +
  • -

#7 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,560
  • Joined: 17-April 07

Re: Using hDc to draw using windows API's

Posted 09 October 2008 - 04:24 AM

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

This post has been edited by thava: 09 October 2008 - 04:25 AM

Was This Post Helpful? 0
  • +
  • -

#8 Maritime  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 08-October 08

Re: Using hDc to draw using windows API's

Posted 09 October 2008 - 10:16 AM

View Postthava, on 9 Oct, 2008 - 04:24 AM, said:

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

Thank you thava, I am trying to find solution too.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1