|
Hello Friends
I am creating a win32 based application. Creating A Dialog with TabControl and Buttons using BS_OWNERDRAW as i want to set the color of button.
On WM_DRAWITEM, I implemented a function to set the color of button[ by getting all dc and rect of button and then fillrect).
So,when I open the Dialog, it is showing Initial Color Fine.
Now,I want to change the colors of button when I change the Tab. But,I am not able to find the Event or same WM_DRAWITEM will change button color on changing tab.
So,On Tab change,button colors remain same. How can I change the button color on Tab change.
Thanks & Regards
Yogesh
|
|
|
|
|
The right message (to handle) for changing button's color is WM_CTLCOLORBTN
|
|
|
|
|
But when this message(WM_CTLCOLORBTN) will be called ?
How can I handle this ?
Need little explanation.
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
It will be sent to the parent window (in your case the dialog) just before the button is painted. So handle it in your dialog's DlgProc function by creating a brush in the background color that you want, casting it to BOOL and returning it. See MSDN for details.
http://msdn.microsoft.com/en-us/library/aa930774.aspx[^]
|
|
|
|
|
I took HBRUSH as Global variable and then how it will be responsible for drawing all buttons and with different color.
Here is WM_DRAWITEM:
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpDrawItemStruct = (DRAWITEMSTRUCT*)lParam;
switch (lpDrawItemStruct->itemAction)
{
case ODA_DRAWENTIRE:
case ODA_SELECT:
{
int ndxColor = 0 ;
switch (lpDrawItemStruct->CtlID)
{
case IDC_btnPantone1 : ndxColor = 0 ; break ;
case IDC_btnPantone2 : ndxColor = 1 ; break ;
case IDC_btnPantone3 : ndxColor = 2 ; break ;
case IDC_btnPantone4 : ndxColor = 3 ; break ;
case IDC_btnPantone5 : ndxColor = 4 ; break ;
case IDC_btnPantone6 : ndxColor = 5 ; break ;
case IDC_btnPantone7 : ndxColor = 6 ; break ;
default : break ;
}
switch (lpDrawItemStruct->CtlID)
{
case IDC_btnPantone1 :
case IDC_btnPantone2 :
case IDC_btnPantone3 :
case IDC_btnPantone4 :
case IDC_btnPantone5 :
case IDC_btnPantone6 :
case IDC_btnPantone7 :
DrawButtonColor (ndxColor, lpDrawItemStruct) ;
break ;
default : break ;
}
}
default:
return DefWindowProc (hwndDlg, msg, wParam, lParam);
break;
break;
}
return TRUE;
}
case WM_CTLCOLORBTN :
{
SetBkColor((HDC)wParam, RGB(0,0,255));
return (BOOL)g_hBrush;
}
it is not changing .
Or m wrong somewhere ?
|
|
|
|
|
No need to use SetBkColor(). Windows uses the returned brush to paint the background.
Check the color used for g_hBrush.
|
|
|
|
|
void CPNGButton::OnLButtonDown(UINT nFlags, CPoint point)
{
SetCapture();
SetPNG2Button(m_strMouseDownImagePath);
CStatic::OnLButtonDown(nFlags, point);
}
void CPNGButton::OnLButtonUp(UINT nFlags, CPoint point)
{
SetPNG2Button(m_strMouseMoveImagePath);
CStatic::OnLButtonUp(nFlags, point);
}
void CPNGButton::OnMouseMove(UINT nFlags, CPoint point)
{
SetCapture();
CRect rc;
GetClientRect(rc);
if (rc.PtInRect(point))
{
if (!m_isPointInWnd)
{
OnMouseEnter();
m_isPointInWnd = TRUE;
}
}
else
{
SetPNG2Button(m_strMouseAwayImagePath);
ReleaseCapture();
m_isPointInWnd = FALSE;
}
CStatic::OnMouseMove(nFlags, point);
}
void CPNGButton::OnMouseEnter()
{
SetPNG2Button(m_strMouseMoveImagePath);
}
I create a CPNGButton class to display a button. Using three images to display three different status. No mouse, mouse move, L Button down. CPNGButton is a child class of CStatic. Now if this CPNGButton button is a Minize button, when click this button. After restore the MainFrame, how to restore the minimize button status. Just to how to capture the mouse away from this minimize button?
|
|
|
|
|
BOOL CMainFrame::Login()
{
this->ShowWindow(SW_MINIMIZE);
CLoginForm loginForm();
if (loginForm.DoModal() != IDOK)
{
this->PostMessage(WM_CLOSE);
return FALSE;
}
...
this->ShowWindow(SW_SHOWNORMAL);
return TRUE;
}
void CLoginForm::OnClickedMinimize()
{
ShowWindow(SW_MINIMIZE);
}
The MainFrame is showing and the user click the logout button to call login function. The the CLoginForm show, CLoginForm is a no border CDialog, when user click the minimize button of CLoginForm. The CLoginForm is hide, but there is a black block in the left-bottom of the screem. I donot know why this happen.
|
|
|
|
|
My guess is that login being a modal dialog will prevent the parent window from processing things (like paint messages) until the modal dialog is dismissed. Might you use a modeless dialog in this case?
|
|
|
|
|
Why, oh, Why do you want to minimize the main frame window when the Modal login dialog is displayed ?
Don't make it hard on you, just keep the main frame as is.
Nihil obstat
|
|
|
|
|
Hi all,
I'm abit of a newbie to C so what i am askign may be simple but i can't seem to find much on the internet.
i have:
char name[15];
Which could for example, contain the name "james". What can i use to check if the first character (in this case "j") is lowercase and if it is, change it to uppercase.
Many Thanks!
|
|
|
|
|
Sorry just found it myself, literally just after i posted this.
name[0] = toupper(name[0]);
|
|
|
|
|
In c language you can check wether the language is in lower case or upper case by using their ASCII value.
ie, for "A" ASCII value is 65. for "a" ASCII is 97. by directly checking this condition you can ensure character is small letter or capital letter.
to convert you can use
toupper or
tolower .
|
|
|
|
|
What happens if the letter is "b" or ... The standard way of checking is to use isupper() [^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi,
I am working on a project in which we can capture a video, save it in avi format. We are using Microsoft Directx for the same.
Now I want to increase the quality of the video similar to the HD mode. Is It possible using C++/VC++/MFC.?
Is it possible that we can capture a video with high quality or after capturing/saving the video, play the same in HD mode.?
Please let me know if the above discussion is ambiguous.
Anybody have any idea regarding the same.?
Any help would be appreciated.
Thanx in Advance.
Regards,
Mbatra
|
|
|
|
|
Hi All,
I am using below code to convert CString to char* and again back to CString. I am using 3rd party code which takes char* only.
const size_t newsizew = (str.GetLength()+1)*2;
char *nstringw = new char[newsizew];
size_t convertedCharsw = 0;
wcstombs_s(&convertedCharsw, nstringw, newsizew, str.GetBuffer(), newsizew /*_TRUNCATE*/ );
AfxMessageBox(CString(CA2T(nstringw)));
The conversion is working fine when content of str is in english. But this is not working properly when str is in other language.
Can anyone suggest me how to make it work even for other languages.
Thanks in advance.
|
|
|
|
|
To convert wide strings to char or multi-byte without loss of information, the wide string must only contain characters from a specific known character set / code page.
When using the wcstombs() conversion function, you must first set the locale to those used by the input string and restore it after conversion (see setlocale()[^]). The default locale is 'C' which is not language specific (English).
Another method is using WideCharToMultiByte()[^] where the code page can be specified:
int nCP = 1252; int nSize = ::WideCharToMultiByte(nCP, 0, str.GetString(), -1, NULL, 0, NULL, NULL);
char *nstringw = new char[nSize];
::WideCharToMultiByte(nCP, 0, str.GetString(), -1, nstringw, nSize, NULL, NULL);
If the code page of the input string is the same as for the current thread, you can use conversions provided by the CStringT class. This should do the job in most cases:
CStringA strA(str.GetString());
CStringW strW(strA.GetString());
|
|
|
|
|
Thanks for your reply. I am able to convert successfully using WideCharToMultiByte function. But I am facing the same problem when I use CStringA strA(str.GetStrng()) for conversion, even when I use SetLocale() function. Can you please help me out in this.
modified 21-Nov-12 5:49am.
|
|
|
|
|
Sorry for my late answer. I overlooked your reply.
The CStringT class constructors and assignment operators accepting the LPCSTR and LPCWSTR types will convert the string if it does not match (when assigning LPCWSTR to a CStringA object it is converted to ANSI and when assigning LPCSTR to a CStringW object it is converted to Unicode). The conversion is internally performed using WideCharToMultiByte() and MultiByteToWideChar() with code page CP_THREAD_ACP (when using Visual Studio 2003 and later; with older versions or manually set preprocessor definition _CONVERSION_DONT_USE_THREAD_LOCALE , CP_ACP is used). See the ATL/MFC source files cstringt.h and atlconv.h if you are interested in how the conversions are performed.
If you are not calling SetThreadLocale() within your app, the thread will use the system locale.
If the results from using WideCharToMultiByte() and CStringT constructors are different, you have passed a code page number that differs from the default code page of the used locale.
So you may post your settings here or check it yourself:
- The code page passed to
WideCharToMultiByte() - The code page used by the
CStringT class
To get the code page used by the CStringT class use this code snippet (assuming CP_THREAD_ACP is used):
int nCP = ::GetACP();
LCID nLCID = ::GetThreadLocale();
TCHAR szACP[7];
if (::GetLocaleInfo(nLCID, LOCALE_IDEFAULTANSICODEPAGE, szACP, 7) != 0)
nCP = _tstoi(szACP);
Now compare nCP with the value passed to WideCharToMultiByte() .
All these different locales and code pages may be confusing. So I will sum up the settings that may effect your conversions:
- The system locale including its default ANSI code page
- The user's locale including its default ANSI code page
- The thread's locale including its default ANSI code page
- The code page used by the
CStringT class - The code page passed to conversion functions in your code
|
|
|
|
|
I want to set the alignment of the items only and not for the header.
I tried with SetColumn with LVCFMT_RIGHT
but that aligns header also. I just want to align only the items(header should be skipped)
I also thought that SetItem should work for aligning only a single item but I don't know how it can be used for aligning a single item.
|
|
|
|
|
According to the documentation[^] alignment affects both header and content. The only way I can think to work round this would be to make it owner drawn and catch the WM_DRAWITEM message[^] to draw the items yourself.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
|
That first link looks like it is the answer to your question, give it a try and then modify to your specific requirements.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks a lot. That worked. It aligned the text as I expected but few items could not be drawn, I guess I have to skip where the item type is image instead of text. Or may be I have to set the image also. I am working on it. I had used lvs_ownerdrawfixed.
Thanks,
Rahul Kulshreshtha
|
|
|
|
|
In general the items in a list control consist of a text description and an image. If you use images then you would normally have one for every item. Take a look at Windows explorer and switch between the various views to see how the 'standard' displays are laid out.
One of these days I'm going to think of a really clever signature.
|
|
|
|