|
Hi, All
Purpose of my dialog:
When user chose color from CColorDialog, i make color value to Hex value.
three edit include on this dialog.
I wrote my class public from CColorDialog
class CColorDialogExt : public CColorDialog
and i add three edit control to my class:
BOOL CColorDialogExt::OnInitDialog()
{
CColorDialog::OnInitDialog();
m_pRed->Create(WS_EX_STATICEDGE | WS_EX_CLIENTEDGE | ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ,CRect(445, 203, 475, 220), this, 1000);
m_pGreen->Create(WS_EX_CLIENTEDGE | ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ,CRect(445, 225, 475, 242), this, 2000);
m_pBlue->Create(WS_EX_CLIENTEDGE | ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP , CRect(445, 247, 475, 264), this, 3000);
return TRUE;
}
So, three edit view ok, when i change color, i want to get color value (COLORREF)
but i can not get it.
( action : OnLbuttonDown)
Can you help me now?
Thank for advance.
Huynhnb
.: Your success is also mine :.
|
|
|
|
|
forst get the color value (COLORREF actually it is a DWORD)
use the following macros
GetRValue - for Red value
GetGValue - for Green value
GetBValue - for Blue value
this will return a byte value.
format to hex value using sprintf or CString.Format functiion
put these values to your edit boxes.
HTH
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
i use
COLORREF color = GetColor();
but value of color = 0;
i don't know why?
my function:
void CColorDialogExt::OnLButtonDown(UINT flag, CPoint mousePos)
{
COLORREF clColor = GetColor();// clColor value alway = 0
DWORD dwTemp;
CString strTemp;
dwTemp = GetRValue(clColor);
strTemp.Format("%d", dwTemp);
m_pRed->SetWindowText(strTemp);
dwTemp = GetGValue(clColor);
strTemp.Format("%d", dwTemp);
m_pGreen->SetWindowText(strTemp);
dwTemp = GetBValue(clColor);
strTemp.Format("%d", dwTemp);
m_pBlue->SetWindowText(strTemp);
CColorDialog::OnLButtonDown(flag, mousePos);
}
Huynhnb
.: Your success is also me :.
|
|
|
|
|
I think the value will upate to its color ref member on DoModal function.
it has a colorchooser memmber. ( CColorDialog::m_cc.rgbResult )
huynhnb wrote: COLORREF clColor = GetColor();// clColor value alway = 0
change this to
COLORREF clColor = m_cc.rgbResult;
seems this will work
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
COLORREF clColor = m_cc.rgbResult;
but m_cc.rgbResult still zero, when i OnOK to Close dialog, rgbResult will have value.
to SaRath: i have just visited your blog, very cool.
Huynhnb
.: Your success is also me :.
|
|
|
|
|
Can you show how you to use for get values and get color
when you use
<br />
CColorDialog m_dlg;<br />
m_dlg.DoModal();<br />
COLORREF color=m_dlg.GetColor();<br />
you can get color anyway you derived ColorDialog but i think its not problem
whitesky
|
|
|
|
|
he is trying to get the color from an a class derived from CColorDialog
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
yes i see but i think it not problem you use CColorDialog now you use CMyColorDialog
whitesky
|
|
|
|
|
huynhnb wrote: i have just visited your blog, very cool.
thanks alot for your comment
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
|
Michael Dunn wrote: 0 is a valid COLORREF - it's black
but, all times i click ( click on other color) m_cc.rgbResult always is 0->Not good.
-------
I debug and see: all time, m_cc.rgbResult is 0.
When EndDialog();
API function:
INT_PTR CColorDialog::DoModal()
{
ASSERT_VALID(this);
ASSERT(m_cc.Flags & CC_ENABLEHOOK);
ASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
m_cc.hwndOwner = PreModal();
INT_PTR nResult = ::ChooseColor(&m_cc); // this function to getcolor
PostModal();
return nResult ? nResult : IDCANCEL;
}
but i dont know action: when i drag or choose color : value of color set into: Hue, Sat, Lum, Reg, Green, Blue? but i can get this color value.
I want to handle this and change it to Hex value in my edit :
Huynhnb
.: Your success is also me :.
|
|
|
|
|
I had some time, and it didn't look difficult so...
Tested on Windows XP. Modify to taste.
CColorDialogEx.h
#pragma once
#include "afxwin.h"
class CColorDialogEx : public CColorDialog
{
DECLARE_DYNAMIC(CColorDialogEx)
public:
CColorDialogEx(COLORREF clrInit = 0, DWORD dwFlags = 0, CWnd* pParentWnd = NULL);
virtual ~CColorDialogEx();
protected:
DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnInitDialog();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
CEdit m_editRed;
CEdit m_editGreen;
CEdit m_editBlue;
private:
void UpdateHexValues();
};
CColorDialogEx.cpp
#include "stdafx.h"
#include "ColorDialogEx.h"
#include ".\colordialogex.h"
IMPLEMENT_DYNAMIC(CColorDialogEx, CColorDialog)
CColorDialogEx::CColorDialogEx(COLORREF clrInit, DWORD dwFlags, CWnd* pParentWnd) :
CColorDialog(clrInit, dwFlags, pParentWnd)
{
}
CColorDialogEx::~CColorDialogEx()
{
}
BEGIN_MESSAGE_MAP(CColorDialogEx, CColorDialog)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
BOOL CColorDialogEx::OnInitDialog()
{
CColorDialog::OnInitDialog();
CWnd *pRed = GetDlgItem(706);
CWnd *pGreen = GetDlgItem(707);
CWnd *pBlue = GetDlgItem(708);
CRect rcRed;
CRect rcGreen;
CRect rcBlue;
pRed->GetWindowRect(&rcRed);
ScreenToClient(&rcRed);
pGreen->GetWindowRect(&rcGreen);
ScreenToClient(&rcGreen);
pBlue->GetWindowRect(&rcBlue);
ScreenToClient(&rcBlue);
pRed->ShowWindow(SW_HIDE);
pGreen->ShowWindow(SW_HIDE);
pBlue->ShowWindow(SW_HIDE);
m_editRed.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL, ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP , rcRed, this, 1000);
m_editGreen.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL, ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ,rcGreen, this, 2000);
m_editBlue.CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL, ES_LEFT | WS_CHILD | WS_VISIBLE | WS_TABSTOP , rcBlue, this, 3000);
m_editRed.SetFont(GetFont());
m_editGreen.SetFont(GetFont());
m_editBlue.SetFont(GetFont());
UpdateHexValues();
return TRUE;
}
void CColorDialogEx::UpdateHexValues()
{
CWnd *pRed = GetDlgItem(706);
CWnd *pGreen = GetDlgItem(707);
CWnd *pBlue = GetDlgItem(708);
CString strTemp;
int nTemp;
pRed->GetWindowText(strTemp);
nTemp = _ttoi(strTemp);
strTemp.Format(_T("%02X"), nTemp);
m_editRed.SetWindowText(strTemp);
pGreen->GetWindowText(strTemp);
nTemp = _ttoi(strTemp);
strTemp.Format(_T("%02X"), nTemp);
m_editGreen.SetWindowText(strTemp);
pBlue->GetWindowText(strTemp);
nTemp = _ttoi(strTemp);
strTemp.Format(_T("%02X"), nTemp);
m_editBlue.SetWindowText(strTemp);
}
void CColorDialogEx::OnLButtonDown(UINT nFlags, CPoint point)
{
CColorDialog::OnLButtonDown(nFlags, point);
UpdateHexValues();
}
void CColorDialogEx::OnMouseMove(UINT nFlags, CPoint point)
{
CColorDialog::OnMouseMove(nFlags, point);
if(GetCapture() == this)
{
UpdateHexValues();
}
}
|
|
|
|
|
Very thanks hfry
Greate code.
Huynhnb
.: Your success is also me :.
|
|
|
|
|
how we can compare the dialog length to screen length.my project is when we click the button in the main dialog one child dialog must attach to the right of main dialog if we move the dialog to end of the screen then the child must move to left this is my project.
thank u in advance.
vasu.
|
|
|
|
|
Hope I understood your question
GetSystemMetrics
GetSystemMetrics(SM_CXSCREEN and SM_CYSCREEN) for get Width and Height from screen
whitesky
|
|
|
|
|
thank u,
please give me anye example or any code that's y i can easily understood,
vasu
|
|
|
|
|
I think you need to calculate (width and height) from windows and then you want to set location from window
but i see in first your message "if we move the dialog to end of the screen then the child must move to left this is my project" you can use GetWindoRect(rect);ScreenToClient(rect); and then use from rect for location child window
whitesky
|
|
|
|
|
i done it partially.
because once i compare this co-ordinates then it is moving towards left.after that if we move with mouse cursor then it will not moving to left.no action is there.
so please help me.
vasu.
|
|
|
|
|
your window is child so it depend to main dialog so when you want to change location to out main dialog you cant(my guess)
whitesky
|
|
|
|
|
For the logic, you have to work it out yourself. Basically you may wish to check out these functions.
GetSystemMetrics[^] - To get the width and height of your desktop.
GetWindowRect[^] - To get the location and size of your dialog.
SetWindowPos[^] - Set the location for your dialog.
CWnd::OnMoving[^] - The framework calls this member function while a user is moving a CWnd object.
|
|
|
|
|
Hello, I receive a string from registry which looks like this "(1;2;3;4;5;6;7)" it saves the order of the columns of my listview object
Now I want to put it into an LPINT but when I use SetColumnOrderArray it causes an exception:
LPINT lp_OrderArray = (LPINT) malloc(iColumns*sizeof(int));<br />
<br />
for( i;i < iColumns-1; i++)<br />
{<br />
strRegPos = strColOrder[p]; <br />
int nNumField = _stscanf(strRegPos, _T("%i"), &iPos);<br />
<br />
if (nNumField != EOF) <br />
{ <br />
lp_OrderArray[i] = iPos; <br />
p = p + 2;
}<br />
}
I am not the best developer, but maybe someone here could help me
regards
|
|
|
|
|
One thing. the exception is not occured by LPINT
Checker2003 wrote: strRegPos = strColOrder[p];
what is the value of p? I clearly doubt this. on each iteration you are incrementing p by 2 it will cause array bound exception. you are not checking it whether it is in array size or not
suppose you have 10 elements.
if the index reach 5th (or 6th) element, I think you program will crash unless there are more elements ni steColOrder.
One more thing, in your loop, make sure that the i is initialize properly.
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
Thank you for your fast reply sarath,
My Array has always the same size, because my Listview control hast always 7 Columns.
My tags are initialized in this way:
int iColumns = 8;
int i = 0;
int iPos = 0;
int p = 0;
thank you for your efforts
|
|
|
|
|
Shouldn't it be
iColumns = 7;
int p = 1;
for(i=0; i < iColumns; i++)
?
I don't see where the exception is coming from though. What is the exception and which line does it occur?
|
|
|
|
|
In an MSDN sample, I saw a code snippet
HWND hwnd;
hwnd = CreateWindowEx(
);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
Why should we call UpdateWindow,after showing window? Don't the ShowWindow function refreshes the window?
Here that code!!![^]
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|