Solved

Image based MFC application with image mapping to catch clicks on different part of image

Posted on 2004-09-16
16
310 Views
Last Modified: 2010-04-17
I have to create an MFC based application where my User Interface will be a wizard and we want this wizard to be a bitmap (image) with  Prev/Next button + some dynamic text to display the current status.  Is there any sample code for how to do it?

I was planning to use some dialog based application use SetBitmap functions in a dialog based application but then how to do image mapping so that I can catch Prev/Next button clicks and changed the text of prev/next button and status text?

Is there way to do it?
 
0
Comment
Question by:amitguliani
  • 7
  • 7
16 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12078655
You can use CPropertyPage/CPropertySheet with 'Wizard' attribute, but you must design a different dialog layout for every page. To insert a bitmap in every page, just include inside your resource, and create a static control with 'Image' attribute in every page.

There are many examples at:
http://www.codeproject.com/property/
0
 

Author Comment

by:amitguliani
ID: 12078873
Sorry I didn.t mention it earlier but I  already have my wizard ready but that does not have images and I have to introduce images and handle it.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
ID: 12078962
Ok, then just use static controls to show the images, then create event handler for WM_LBUTTONDOWN message using ClassWizard. To know where in the image has been clicked you have to substract coordinates. Something like:

void CYourWizardWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rectImage;
GetDlgItem(YOUR_STATIC_IMAGE_ID)->GetClientRect(&rectImage);

CPoint ptInImage(point.x - rectImage.left, point.y-rectImage.top);
// Process ptInImage here

}
0
 

Author Comment

by:amitguliani
ID: 12383205
How will I know where the mouse has been clicked? I know the cooridinates but how will it help?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12383283
You can know where have been clicked by using ScreenToClient and ClientToScreen functions.

inside your dialog function:
ClientToScreen(&point);
yourStaticImageCtrl.ScreenToClient(&point);

now 'point' contains coordinates relative to the static image.
0
 

Author Comment

by:amitguliani
ID: 12383473
So lets say my bitmap has 4 buttons like prev/next/cancel/help next to each other then what you are suggesting is that I have to use ScrrenToCLient function to get the relative location of the click. But after that how ill I know whether User has clicked Prev/Next/Help/Cancel etc?
 Do I need to know the positions of these buttons in adv and compare them with what I get by calling ScreenToClient ?
Thanks in adv
Aguliani

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12383634
Are you talking about buttons or image?
For buttons don't need to know anything about cursor position. Every button generates a message you can manage with a message handler function.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:amitguliani
ID: 12383651
I am talking about image. My image has text like prev/next/cancel/help.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12383758
In this case you can do this (after obtaining correct coordinates):

CRect rectPrev(10,200,40,215);
CRect rectNext(50,200,90,215);
CRect rectCancel(110,200,140,215);

if (rectPrev.PtInRect(point)) {
    // some action
} else if (rectNext.PtInRect(point)) {
    // some action
} else if (rectCancel.PtInRect(point)) {
    // some action
}
0
 

Author Comment

by:amitguliani
ID: 12383876
Ok then let me give it a shot. But quick question How will I find out the rectangular coordinates for prev/next buttons?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12384138
Open your bitmap inside the Visual C++ IDE, when moving on, coordinates appear at bottom.
0
 

Author Comment

by:amitguliani
ID: 12384574
My bitmap has more than 256 colors and hence can't be seen in IDE. How can I see it?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12384827
No, then you can't see it inside your IDE. You will have to use another image editor to access it externally.
0
 

Author Comment

by:amitguliani
ID: 12402957
Thanks a lot. It all worked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now