OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > Corel Photo-Paint VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 17-05-2005, 09:08
tonywong
Guest
 
Posts: n/a
Default default the crop property

i wish to know whether i can set the property of crop tool by the VB script. What i want to do is to click one button, then the crop tool will be ready at 240 x 300 and box centrally in the window. i find the similar things at "how to create a COM add-in?"

my story is :
i have lots of head photos to crop regularly. it can save me lots of steps
if i can record the steps in one key.

1. select crop tool
2. set crop frame at 240 x 360
3. centralise the crop frame in the centre of the photo

sometimes, the person head in the photo is not central in the photo, so i
need to move the crop frame to adjust the position manually.

secondly, the person head may be too large or small, i have to change the
size of the crop frame (move smaller or bigger) as long as the cropped photo
in 240 x 320 ratio, not necessary in 240 x 320 size cos the final print
software can fit it even the size or ratio is not fit. the proper ratio can
keep a normal look from the print out.

Thanks a lot in advance for your assistance.
Reply With Quote
  #2  
Old 17-05-2005, 09:16
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Unfortunately no, you can't control the actual tool and its properties. You can crop the image in VBA, but you can't create a crop rectangle and then let user reposition/apply the crop...

You might be able to do this by sending some keyboard input though, using VBA's SendKeys command. Let me try to come up with some example code.

Last edited by Alex; 17-05-2005 at 09:18.
Reply With Quote
  #3  
Old 17-05-2005, 10:44
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Ok, here is what I have come up with. Before you can run the macro, do the following:

1. Create a new document in PhotoPaint.
2. Select the crop tool
3. Make sure that the property bar is expanded (you can see the position and size of the crop box). If not, press the ">>" button at the end of property bar to expand this. Once this is done, it will always be in this state and the macro can work now.
4. You can close the document if you wish.

So, here is the macro:

Code:
Option Explicit

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
                    (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, _
                    ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Const GW_CHILD = 5

Sub CreateCrop()
    Dim hPaintWindow As Long
    Dim hWndDocArea As Long
    Dim hWndPropBar As Long
    
    AppWindow.Activate
    
    ' Select the crop tool by pressing "d"
    SendKeys "d", True
    
    ' Find the property bar window
    hWndDocArea = 0
    hWndPropBar = 0
    Do
        hWndDocArea = FindWindowEx(AppWindow.Handle, hWndDocArea, "AfxControlBar70u", vbNullString)
        If hWndDocArea = 0 Then Exit Do
        hWndPropBar = FindWindowEx(hWndDocArea, 0, vbNullString, "Property Bar")
        If hWndPropBar <> 0 Then Exit Do
    Loop
    
    If hWndPropBar <> 0 Then
        hWndPropBar = GetWindow(hWndPropBar, GW_CHILD)
    End If
    
    If hWndPropBar = 0 Then
        MsgBox "Cannot find the property bar", vbCritical
        Exit Sub
    End If
    
    ' Set keyboard focus to the property bar
    SetFocus hWndPropBar
    
    ' Now enter go to the width controls and enter values
    ' You need to hit TAB key 7 times once the property bar is activated to get
    ' to the width controls.
    SendKeys "{TAB 7}100px{TAB}200px{ENTER}", True
End Sub
I hope this helps
Reply With Quote
  #4  
Old 17-05-2005, 11:32
tonywong
Guest
 
Posts: n/a
Default

Thanks a lot.

i cannot imagine you can write the script for me.

thanks with smile
Reply With Quote
  #5  
Old 22-11-2008, 20:38
Jeff Harrison
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by Alex View Post

I hope this helps
Hi Alex,

Error appears in PPX4. Can't find property bar...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Style being weird in cd10 xombie General 3 24-05-2005 12:29
Crop photo tonywong General 1 18-05-2005 02:53
PAINT 10 - Crop to a circular object colinstone General 1 07-05-2005 01:02
Palette (or Colors array) property in VBA class in CDR12 zlatev CorelDRAW/Corel DESIGNER VBA 7 22-02-2005 11:28
VB6, GMS questions bbolte CorelDRAW/Corel DESIGNER VBA 12 06-12-2002 15:32


All times are GMT -5. The time now is 03:24.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com