Solved

Getting a DC for an memory image in Axapta

Posted on 2009-03-31
6
872 Views
Last Modified: 2013-11-20
 I am trying to use the BitBlt function within Dynamics AX (Axapta) 3.0 and cannot make it work.  I can load the bitmap I am trying to work with in an image (memory) or container, but these don't have device contexts available.  How can I get a device context for a memory image in Axapta?

Tom T.
0
Comment
Question by:tturney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:quale-kaizen
ID: 24034221
Try the hdc() method of the 'Window' control on your form.
Don't forget to set the 'Auto declaration' property of the control.

Regards,
QK
0
 

Author Comment

by:tturney
ID: 24035088
quale-kaizen,

  Thanks for your reply.  I am trying to do this in a class and it doesn't have a FormWindowControl on it.  Is there a way of creating an hdc for an image, bindata or container?

Tom T.
0
 
LVL 7

Expert Comment

by:quale-kaizen
ID: 24037615
Tom,

You can use the win32 api to create in-memory device context,
not associated with an area on a screen or a printing device.
Normally you would use the CreateCompatibleDC() function for this purpose.

Here is an example (not tested) of how you would do this in X++.
 

   DLL gdi32 = new DLL(@"Gdi32.dll");
    DLLFunction createCompatibleDC = new DLLFunction(gdi32, "CreateCompatibleDC");
    ;
    createCompatibleDC.arg(ExtTypes::DWord);
    createCompatibleDC.returns(ExtTypes::DWord);
    hdc = createCompatibleDC.call(0); //NULL

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tturney
ID: 24040001
quale-kaizen,

  Thanks again for your reply. I took what you gave me and tried to make it work on a test form.  The form has a formwindowcontrol named CopyCanvas I'm using to hopefuily display a merged image.  I read a record from our table bscProfileItem that has a container field holding a bitmap.  I then try to merge the bitmap onto the CopyCanvas using BitBlt,  Unfortunately, it doens't seem to be working.  I'm attaching the code piece.  How do I assign the Hdc to the bitmap in the record field?

Tom T.

void clicked()
{
    bscProfileItem   TmpProfile;
    BinData TmpBin = new BinData();
    Int              TmpInt, Hdc;
    WinGDI           TmpGDI;
    DLL Gdi32      = new DLL(@"gdi32.dll");
    DLLFunction      CreateCompatibleDC = new DLLFunction(Gdi32, "CreateCompatibleDC");
    DLLFunction      SelectObject       = new DLLFunction(Gdi32, "SelectObject");
    ;
    CreateCompatibleDC.arg(ExtTypes::DWord);
    CreateCompatibleDC.returns(ExtTypes::DWord);
    SelectObject.arg(ExtTypes::DWORD,ExtTypes::DWORD);
    SelectObject.returns(ExtTypes::DWORD);
    super();
    TmpProfile = bscProfileItem::find("PF000001");
    TmpBin.setData(TmpProfile.Image);
    TmpInt     = TmpBin.size();
    CopyCanvas.lockDC();
    Hdc        = CreateCompatibleDC.Call(0);
    TmpInt     = SelectObject.call(Hdc, TmpBin);
    TmpGDI     = new WinGDI(CopyCanvas.hDC());
    TmpGDI.bitBlt(0,0,CopyCanvas.widthValue(), CopyCanvas.heightValue(), Hdc, 0, 0, 0x00CC0020);
    TmpGDI     = Null;
    CopyCanvas.unlockDC();
}

Open in new window

0
 
LVL 7

Accepted Solution

by:
quale-kaizen earned 500 total points
ID: 24045499
Tom,

The code below is placed on the clicked() method of a button.
It grabs an image from the DB and puts it in the 'in-memory' DC and than applies the bitBlt() function
in order to copy the image from memory to the window control.

Regards,
QK
void clicked()
{
    #WinGDI
 
    WinGdi winGDI;
    int memDC, BMP;
    qk_ImageTable imageTable;       // table containing the images
    Image imageDB = new Image();
    DLL gdi32 = new DLL("GDI32");
    DLLFunction CreateCompatibleDC = new DLLFunction(gdi32, 'CreateCompatibleDC');
    DLLFunction CreateBitmap = new DLLFunction(gdi32, 'CreateBitmap');
    DLLFunction SelectObject = new DLLFunction(gdi32, 'SelectObject');
    DLLFunction DeleteObject  = new DLLFunction(gdi32, 'DeleteObject');
 
    ;
 
    CreateCompatibleDC.arg(ExtTypes::DWord);
    CreateCompatibleDC.returns(ExtTypes::DWord);
 
    CreateBitmap.arg(ExtTypes::DWord);
    CreateBitmap.arg(ExtTypes::DWord);
    CreateBitmap.arg(ExtTypes::DWord);
    CreateBitmap.arg(ExtTypes::DWord);
    CreateBitmap.arg(ExtTypes::DWord);
    CreateBitmap.returns(ExtTypes::DWord);
 
    SelectObject.arg(ExtTypes::DWord);
    SelectObject.arg(ExtTypes::DWord);
    SelectObject.returns(ExtTypes::DWord);
 
    DeleteObject.arg(ExtTypes::DWord);
    DeleteObject.returns(ExtTypes::DWord);
 
    super();
 
    Select FirstOnly imageTable;
    imageDB.setData(imageTable.image);
 
    //paneFst.image(imageDB);
    paneFst.lockDC();   // lock the DC of the window control on the form
 
    memDC = CreateCompatibleDC.call(paneFst.hdc());
 
    BMP = CreateBitmap.call(    paneFst.widthValue(),
                                paneFst.heightValue(),
                                WinApi::getDeviceCaps(paneFst.hDC(), 14),
                                WinApi::getDeviceCaps(paneFst.hDC(), 12),
                                0);
 
    SelectObject.call(memDC, BMP);
 
    imageDB.displayImage(memDC);    // move the image to the in-memory DC
 
    winGDI = new WinGdi(paneFst.hdc());
    winGdi.bitBlt(0, 0, paneFst.widthValue(),paneFst.heightValue(), memDC, 0, 0, #SRCCOPY);
 
    paneFst.unlockDC();
    DeleteObject.call(BMP);
    WinApi::deleteDC(memDC);
}

Open in new window

0
 

Author Closing Comment

by:tturney
ID: 31564809
quale-kaizen,

  Thank you very much for all your help and the code to make it work.

Tom T.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 151
Path of Workbook 3 88
Bartender label printing - switch on and off graphics 3 94
Data Migration: SSIS vs. Microsoft Dynamic CRM 7 59
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question