|
hey can u solve my 1 more issue?
i want to show popup menu on edit box after right clicking on edit box. how can i do this?
thanks in advance
|
|
|
|
|
Yes.
here is a logic commonly used to load context menus:
You have to create a menu with id IDR_POPUP,
put this in onNMRclick handler in your Dialog class.
CPoint ptScreen;
if (GetCursorPos(&ptScreen))
{
CMenu menu;
VERIFY(menu.LoadMenu(IDR_POPUP));
CMenu *popup = menu.GetSubMenu(0);
ASSERT(popup);
VERIFY(popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
ptScreen.x, ptScreen.y, this, NULL));
}
|
|
|
|
|
thanks a lot,
it is working.
i have 1 more issue
can u plz tell me how to display help information on 1st pane of status bar about the menu items when there are selected or positioned, that is windows standard practice. how to do this.
thanks in advance
|
|
|
|
|
I think that's simple . I dont have a code snippet for this. Dont need code.
You have to just provide a prompt for each menu command(find in properties window - "Prompt" property).
Check if it works..
|
|
|
|
|
since 2 days m trying this only but this is not working at all
|
|
|
|
|
Did you add prompts for each of your Menu items?
|
|
|
|
|
|
Is your application dialog based? This feature is not available for dialog based apps..
|
|
|
|
|
yaa,it is dialog based application.
if i want to do this then how will i be able to show?
|
|
|
|
|
I have no idea. but Im sure its untidy and tough stuff to do in a dialog based app.
You have one option but equally tedious. Convert your app to SDI. your View class should inherit from CFormView class. copy all your dialog resources to this app. you will have to modify code here and there. I wont recommend this to you.
All the Best Anjali from Gemalto..
|
|
|
|
|
What is a singleton class? Plz explain me with a suitable example.
Thanks in advance
Rajendra
|
|
|
|
|
Do you hate google?
You could have searched with "Singleton C++" and would get lots of resources where you could have read from
A class whose number of instances is only one is called a singleton class. only one instance of a class can exist at any given time.
A raw class definition would be similar to what is mentioned below
class CXSingleton
{
public:
static CXSingleton& Instance()
{
static CXSingleton ston;
return ston;
}
};
And yes there are n number of ways of implementing this
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Singleton!
Intent
Ensure a class only has one instance, and provide a global point of access to it.
Motivation
It's important for some classes to have exactly one instance. Although there can be many printers in a system, there should be only one printer spooler. There should be only one file system and one window manager. A digital filter will have one A/D converter. An accounting system will be dedicated to serving one company.
How do we ensure that a class has only one instance and that the instance is easily accessible? A global variable makes an object accessible, but it doesn't keep you from instantiating multiple objects.
A better solution is to make the class itself responsible for keeping track of its sole instance. The class can ensure that no other instance can be created (by intercepting requests to create new objects), and it can provide a way to access the instance. This is the Singleton pattern.
class CSingleton
{
public:
static CSingleton * getInstance() {
if (!_singleton) _singleton = new CSingleton;
return _singleton;
}
protected:
CSingleton() { }
~CSingleton() { }
private:
static CSingleton * _singleton;
};
CSingleton* CSingleton ::_singleton = NULL;
Try to look at singleton destroyers too especially when you singleton holds a database connection or similar resources.
You can also create a SINGLETON TEMPLATE like the one below. In this way your singleton holds a pointer and it ensures that only one instance exists of the object the pointer is pointing at.
template < typename T >
class CSingleton
{
public:
static CSingleton * getInstance() {
if (!_singleton) _singleton = new CSingleton;
return _singleton;
}
const T* operator->() { return m_ptr; };
protected:
CSingleton() { m_ptr = new T; }
~CSingleton() { if (m_ptr) delete m_ptr; }
private:
static CSingleton * _singleton;
T * m_ptr;
};
Hth
--
Jess Nielsen, b.sc.
Security Analyst
http://jessn.blogspot.com/
|
|
|
|
|
Hi All
i have two dialog A and B.I set hot key on Main Dialog A.It's working fine.But i am getting one error when Dialog A and B both open then i use short cut key then main Dialog A is close and B is still open.What i want to do if i use short cut key when both dialog open.Case one short key will not work on that condition or case two both dialog effect.Code is here
[code]
m_UniqueIdentifier = ::GlobalAddAtom( "SINGLE_INSTANCE_APP");
::RegisterHotKey( m_hWnd, /*Your window handle*/
m_UniqueIdentifier, /*Unique identifier to uniquely identify this hotkey*/
MOD_ALT|MOD_CONTROL, /*Modifier keys*/
VK_F2); /*Virtual
LRESULT CADlg::HotKeyHandler(WPARAM wParam, LPARAM lParam)
{
if( IsWindowVisible() )
{
ShowWindow( SW_HIDE );
}
else
{
ShowWindow( SW_NORMAL );
}
return 0;
}// End HotKeyHandler
plz help me
|
|
|
|
|
|
Just keep a pointer in your A dialog to your B dialog and call its ShowWindow apropriately.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
I have a simple dialog box. On its OnInitDialog() function I prompt for a existing image file name(jpg, bmp, png). I need to convert this image to bmp and draw the bitmap image in the client area.
Thanks!!!!
|
|
|
|
|
Here's one of the simplest ways I can think of:
LPCTSTR imgpathname = ...;
CImage img;
img.Load(imgpathname);
CClientDC dc(this);
img.Draw(dc, 0, 0);
The drawing code should really be done in a WM_PAINT handler (OnPaint) or
a WM_ERASEBKGND handler (OnEraseBkgnd).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your reply Mark. I need to save the bitmap image to a xml file along some other data (bitmap image data will be in tag.) . how do i get bitmap data that is writable to xml. I need bitmap data because the xml should be readable on a mac. How do i do this?
Thanks!!
|
|
|
|
|
Here is my class implementation:
CImageDlg::CImageDlg(CWnd* pParent )
: CDialog(CImageDlg::IDD, pParent)
{
m_StrTitle = _T("Image for ");
m_hBmp = NULL;
}
CImageDlg::~CImageDlg()
{
}
void CImageDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CImageDlg, CDialog)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CImageDlg::OnPaint()
{
CPaintDC dc(this);
RECT rect = {0};
GetClientRect(&rect);
if (m_hBmp != NULL)
{
....
BitBlt(dc.GetSafeHdc(), 0, 0, 100, 100, memDC, 0,0, SRCCOPY);
}
}
void CImageDlg::SetTitle(CString str)
{
m_StrTitle += str;
}
void CImageDlg::SetBitmap(HBITMAP hBmp)
{
m_hBmp = hBmp;
}
BOOL CImageDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowText(m_StrTitle);
if (m_hBmp == NULL)
{
TCHAR szFile[260] = {0};
OPENFILENAME openfilename = {0};
wchar_t wcsMyPicturesPath[1024] = {0};
SHGetFolderPath( NULL, CSIDL_MYPICTURES, NULL, 0, wcsMyPicturesPath );
ZeroMemory(&openfilename, sizeof(openfilename));
openfilename.lStructSize = sizeof(OPENFILENAME);
openfilename.hwndOwner = this->m_hWnd;
openfilename.lpstrFile = szFile;
openfilename.lpstrFile[0] = _T('\0');
openfilename.nMaxFile = sizeof(szFile);
TCHAR szFltr[200] = {0};
lstrcat(szFltr, _T("*.JPG;*.JPEG;*.BMP;*.PNG;\0"));
openfilename.lpstrFilter = szFltr;
openfilename.nFilterIndex = 0;
openfilename.lpstrFileTitle = NULL;
openfilename.nMaxFileTitle = 0;
openfilename.lpstrInitialDir = wcsMyPicturesPath;
openfilename.lpstrTitle = NULL;
openfilename.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
if(GetOpenFileName(&openfilename) == TRUE)
{
using namespace Gdiplus;
Gdiplus::Image *img = Image::FromFile(openfilename.lpstrFile);
Gdiplus::Image *thumbImg = img->GetThumbnailImage(100, 100);
m_hBmp = (HBITMAP)thumbImg;
}
else
{
return -1;
}
}
return TRUE;
}
How should i write the drawing code now?
|
|
|
|
|
void CImageDlg::OnPaint()
{
CPaintDC dc(this);
RECT rect = {0};
GetClientRect(&rect);
if (m_hBmp != NULL)
{
CDC memDC;
MemDC.CreateCompatibleDC(&dc);
HBITMAP OrigBmp = ::SelectObject(memDC, m_hBmp);
BITMAP BInfo;
::GetObject(m_hBmp, sizeof(BInfo), &BInfo);
::BitBlt(dc.GetSafeHdc(), 0, 0, BInfo.bmWidth, BInfo.bmHeight, memDC, 0,0, SRCCOPY);
::SelectObject(memDC, OrigBmp);
}
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Thanks for replying.
After I do stretchblt() the image quality is lost. how do I avoid this.
Thanks in advance.
|
|
|
|
|
CDC::SetStretchBltMode()[^], try settting it to ... COLORONCOLOR i believe.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Dude it did not work. I think I have to use GDI+. That renders images beautifully. What say? But the problem there is that Im unable to convert a HBITMAP to Gdiplus::Image. Any Ideas?
|
|
|
|
|
Did you use That StretchBlitMode on memDC or dc? Anyhows, there's something like Gdiplus::Image::fromHBITMAP or something similar...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|