OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 14-04-2004, 13:53
please_reboot
Guest
 
Posts: n/a
Default replacing duotone bitmap

is there a way to convert (or more precisely change colors) all my bitmaps in a monotone or duotone using vba ? I tried many things like convert to bitmap but I found no way to assign one or more color.

I have many duotone bitmaps in a page that I need to convert to one or to process color like cyan or magnenta to beter separate colors for ptinting without losing existing curves.

Hope i'm clear enougn :cry:
Reply With Quote
  #2  
Old 15-04-2004, 13:12
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: replacing duotone bitmap

Yes, I understand what you want. You need to change the duotone paramaters (colors, or color curves) of a duotone bitmap.

However I don't think there is a way right now to do it through VBA. Sorry
Reply With Quote
  #3  
Old 15-04-2004, 14:40
please_reboot
Guest
 
Posts: n/a
Default

thanks for your fast reply

is there a way to do it by editing a bitmap in Paint while in Draw ?
Reply With Quote
  #4  
Old 15-04-2004, 20:27
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

I think what you can do is to simulate working with the dialog by sending keyboard messages using SendKeys in VBA. The only problem is that if you use VBA and send a key stroke to show a dialog, then the macro execution is suspended until the dialog is dismissed.

You can, however, overcome this by using either a stand-alone Visual Basic (rather than CorelDRAW's VBA) or if you don't have VB, you can use VBA of Photo-Paint to control CorelDRAW.

Here is how you can do it:

1. Start CorelDRAW and open (or create) a document with a few duotone bitmaps in it.
2. Start Corel PHOTO-PAINT and go it its VBA editor (Alt-F11)
3. Go to GlobalMacros project and insert a new code module.
4. Go to Tools>References and add a reference to "Corel - CorelDRAW 12.0 Type Library"
5. Copy the code sample below into the code module.
6. Run the ProcessDuotones macro and it will go through each duotone bitmap and invoke the Duotone dialog for each of them, convert the mode to "Duotone" (in case it is Monotone, Tritone, or Quadtone) and change the two color to PANTONE 219 M (from Pantone Solid Matte palette) and PANTONE Yellow M (from Pantone Solid Uncoated palette).

I tried to comment each step so you should be able to figure out exactly what is done. I had to use some of Windows API functions to emulate double-clicking the color entry from the color list (there seems to be no way to edit the color by using the keyboard only).

You might want to read more about SendKeys in VBA online help for more info on how it works.

I hope this helps.

Code:
Option Explicit

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal szClass As String, ByVal szWindow As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_LBUTTONDBLCLK = &H203

Private Sub SendDblClick()
    Dim hWnd As Long
    ' Get the dialog window handle
    hWnd = GetForegroundWindow()
    If hWnd = 0 Then Exit Sub
    ' Find the listbox control handle
    hWnd = FindWindowEx(hWnd, 0, "#32770", vbNullString)
    If hWnd = 0 Then Exit Sub
    hWnd = FindWindowEx(hWnd, 0, "#32770", "Curves")
    If hWnd = 0 Then Exit Sub
    hWnd = FindWindowEx(hWnd, 0, "ListBox", vbNullString)
    If hWnd = 0 Then Exit Sub
    ' Send double click at coordinate (0, 80) - just below any list item
    PostMessage hWnd, WM_LBUTTONDBLCLK, 0, 80 * 65536 + 0
    DoEvents
End Sub

Private Sub SelectColorByName(ByVal PaletteIndex As Long, ByVal sName As String)
    ' Go to the palette type list box (Alt-E)
    SendKeys "%e", True
    ' Drop the palette list box down and go to the top list element
    SendKeys "{DOWN}{HOME}", True
    ' Now select palette from the list, given its index in the list
    ' This will be converted into "{DOWN 9}" to select 9th entry, for example
    SendKeys "{DOWN " & PaletteIndex & "}{ENTER}", True
    ' Now go to the color listbox (Alt-N)
    SendKeys "%n", True
    ' Enter the color name
    SendKeys sName, True
    ' Close the color dialog by hitting Enter
    SendKeys "{ENTER}", True
End Sub

Public Sub ProcessDuotones()
    Dim draw As CorelDRAW.Application
    Dim s As CorelDRAW.Shape
    
    Set draw = New CorelDRAW.Application
    
    ' Make sure CorelDRAW is the active window
    AppActivate draw.AppWindow.Caption, True
    
    For Each s In draw.ActivePage.FindShapes(Type:=cdrBitmapShape)
        ' There is a bug in CorelDRAW that reports duotone bitmaps as just paletted
        If s.Bitmap.Mode = cdrDuotoneImage Or s.Bitmap.Mode = cdrPalettedImage Then
            ' Select the bitmap first
            s.CreateSelection
            ' Invoke the duotone dialog by sending Alt-B,D,D key strokes
           '  (through menu Bitmaps>Mode>Duotone)
            SendKeys "%(bdd)", True
            ' Now ensure that the Duotone is selected
            ' Send Alt-T to go to the Type list and select the second entry (Duotone)
            ' by sending Home (to go to the first element) and then Arrow down
            SendKeys "%t{HOME}{DOWN}", True
            ' Now go to the color list and select the first color entry
            SendKeys "{TAB}{HOME}", True
            ' Now send the double-click event to open the color dialog
            SendDblClick
            ' At this point the color dialog should be on the screen
            ' Now select 'PANTONE 219 M' color from
            ' "Pantone Solid Matte" palette which is 9th in the list
            SelectColorByName 9, "219 M"
            ' Go to the next color in the duotone list
            SendKeys "{DOWN}", True
            SendDblClick
            ' Select "PANTONE Yellow U" from "PANTONE Solid Coated" (entry #8)
            SelectColorByName 8, "Yellow U"
            ' Close dialog by hitting Enter
            SendKeys "{ENTER}", True
        End If
    Next s
    
    Set draw = Nothing
End Sub
P.S. I tested this on CorelDRAW 12, however this also should work for earlier versions. Some shortcuts or palettes may differ, but I hope you can adjust the program for your needs.

Last edited by Alex; 19-08-2005 at 09:45.
Reply With Quote
  #5  
Old 18-04-2004, 22:30
please_reboot
Guest
 
Posts: n/a
Default

damn, you're realy a God !!!

many thanks Alex, cannot ask for better !

it's easy to customize from there and I'll now save alot of time from now on
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
Bitmap names in Corel 12... meandirtyjoe CorelDRAW/Corel DESIGNER VBA 1 17-05-2005 09:14
Work with BITMAP in Corel drg CorelDRAW/Corel DESIGNER VBA 3 16-01-2005 09:29
How can I extract a piece of a bitmap object using VBA code oswaldon Corel Photo-Paint VBA 2 25-04-2004 19:37
Replacing Enveloped text Steve CorelDRAW/Corel DESIGNER VBA 2 26-09-2003 13:50
Determining whether a bitmap has a color mask applied to it pmeier CorelDRAW/Corel DESIGNER VBA 3 13-07-2003 23:46


All times are GMT -5. The time now is 18:54.


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