|
|
 Prize winner in Competition
"MFC/C++ Sep 2003"
Comments and Discussions
|
|
 |

|
Hello,
Pretty strange to use pack(1) for entire application, at least in common situations. You can always use 'push' for saving old state, applying your 1 byte alignment and restore it only for this library. Then, returning to your 1 byte alignment of course.
Regards
|
|
|
|

|
:(Did you try to use it with CMainFrame? I've tried to use it and it did not look good. What should I do in order to have support of you great class in CFrameWnd-derived classes like CMainFrame?
|
|
|
|

|
Hello peter,
Firstly, congratulation for your award !
About the "points of interest" in your article, I fall down the same problem in one of my software. I had write a CDialog derived class that "center" or "adjust" all the control in the runtime size of the dialog. The idea is to compute the size of the dialog box in proportion of the screen size, and to center all the control from their orignal position, or to adjust them (change their size in proportion of the original dialog size and the runtime screen size).
I found the same problem for combo, and the same solution (perhaps I will take more time to read and write the MFC forums...) !
The center function work well, but the adjust not, because of the size of the combo doesn't change. As you have work on a similar problem, have you encountered something like that, and found a solution ?
Regards
D. TRECHE
|
|
|
|

|
TRECHE wrote:
Firstly, congratulation for your award !
Thanks. Believe me, it was a surprise. I didn't think that this control would be as popular as it has become...
TRECHE wrote:
The center function work well, but the adjust not, because of the size of the combo doesn't change. As you have work on a similar problem, have you encountered something like that, and found a solution ?
What exactly were you doing in the Adjust() function that was different from the Center() functionality? If you have a look here, PJ Arends explained what actually happened with the Combobox control and why I had been experiencing the problem. Maybe this will help
Take care,
Peter
www.kinkycode.com
[Glossary Manager] [AfterThought Backup Lite]
99 little bugs in the code, 99 little bugs,
Fix 1 bug, recompile....
101 little bugs in the code...
|
|
|
|

|
Thank's for your help. I will read it very soon.
For both function I use MoveWindow(x,y,width,height)
For center, width and height are the same as original.
For adjust they are...adjusted in proportion. For all the control it works except for combo for which the size doesn't change.
D. TRECHE
|
|
|
|
|

|
I'm modied the "DrawTextFields" member like this .
....
pDC->SetTextColor(m_colTxtCaption);
nFont.CreateFontIndirect(&m_lfCaption);
pOldFont = pDC->SelectObject(&nFont);
// int arrWidths[256];
// pDC->GetCharWidth(0, 255, arrWidths);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
LONG lWidth = tm.tmAveCharWidth;
int nCount = m_strCaption.GetLength(), i, nHeight = 0;
CPoint ptDraw = pt2;
TCHAR ch;
TCHAR temp[3];
int add =1;
for ( i = 0; i < nCount; i+=add )
{
ch = m_strCaption.GetAt(i);
if ( ch == '\r' )
continue;
if ( ch == '\n' )
{
if ( m_uPosFlag & TDBE_ATTACH_LEFT )
{
ptDraw = pt2;
ptDraw.x -= m_lfCaption.lfHeight * (++nHeight);
}
else if ( (m_uPosFlag & TDBE_ATTACH_TOP) || (m_uPosFlag & TDBE_ATTACH_BOTTOM) )
{
ptDraw = pt2;
ptDraw.y -= m_lfCaption.lfHeight * (++nHeight);
}
else if ( (m_uPosFlag & TDBE_ATTACH_RIGHT) )
{
ptDraw = pt2;
ptDraw.x += m_lfCaption.lfHeight * (++nHeight);
}
continue;
}
if (ch & 0x80)
{
temp[0] = ch;
temp[1] = m_strCaption.GetAt(i+1);
temp[2] ='\0';
::TextOut(pDC->GetSafeHdc(),ptDraw.x,ptDraw.y,temp,2);
add =2;
}
else
{
temp[0] = ch;
temp[1] ='\0';
::TextOut(pDC->GetSafeHdc(),ptDraw.x,ptDraw.y,temp,1);
add =1;
}
//pDC->TextOut( ptDraw.x, ptDraw.y, m_strCaption );
if ( m_uPosFlag & TDBE_ATTACH_LEFT )
{
ptDraw.y -= lWidth*add;// arrWidths[ch];
if ( (i < nCount-1) &&
// ptDraw.y - arrWidths[m_strCaption.GetAt(i+1)] < rect.top )
ptDraw.y - lWidth*add < rect.top )
{
ptDraw = pt2;
ptDraw.x -= m_lfCaption.lfHeight * (++nHeight);
}
}
else if ( (m_uPosFlag & TDBE_ATTACH_TOP) || (m_uPosFlag & TDBE_ATTACH_BOTTOM) )
{
ptDraw.x +=lWidth*add;// arrWidths[ch];
if ( (i < nCount-1) &&
//ptDraw.x + arrWidths[m_strCaption.GetAt(i+1)] > rect.right )
ptDraw.x + lWidth*add > rect.right )
{
ptDraw = pt2;
ptDraw.y -= m_lfCaption.lfHeight * (++nHeight);
}
}
else if ( (m_uPosFlag & TDBE_ATTACH_RIGHT) )
{
ptDraw.y += lWidth*add;// arrWidths[ch];
if ( (i < nCount-1) &&
//ptDraw.y + arrWidths[m_strCaption.GetAt(i+1)] > rect.bottom )
ptDraw.y + lWidth*add > rect.bottom )
{
ptDraw = pt2;
ptDraw.x += m_lfCaption.lfHeight * (++nHeight);
}
}
}
pDC->SelectObject(pOldFont);
nFont.DeleteObject();
pDC->SetBkMode(nOldBkMode);
pDC->SetTextColor(oldTxtCol);
|
|
|
|

|
Your code does indeed enable the display of Chinese GB2312 characters but have you seen what it does to English!!!
|
|
|
|

|
if you change m_strCaption to "LiXiaoQing"(Chinese Spell), You can see Bug
I change to following:
////////////////////////////////////////////////////////////////////////////
// 2006.04.16 17:02 Modify by LiXiaoQing to Display GB2312 char
pDC->SetTextColor(m_colTxtCaption);
nFont.CreateFontIndirect(&m_lfCaption);
pOldFont = pDC->SelectObject(&nFont);
CPoint ptDraw = pt2;
pDC->TextOut(ptDraw.x,ptDraw.y,m_strCaption);
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|

|
Hey nnnnnnnnnnnnnnnn (is that too few or too little 'n's?)
Yes, I am aware of the problem when attaching the banner to a CFrameWnd derived object that contains CControlBar type controls. The problem comes in when the control requests the available area for itself to attach into. The CFrameWnd class does not calculate the area to take the CControlBar controls into account...
I will have a look at how to get around this, however one possible solution would be to create your own CControlBar derivative that merely contains the CKCSideBannerWnd control, and attach that to the CMainFrame.
Any other ideas (from whoever might be reading this thread?)
Cheers,
Peter
www.kinkycode.com
[Glossary Manager] [AfterThought Backup Lite]
99 little bugs in the code, 99 little bugs,
Fix 1 bug, recompile....
101 little bugs in the code...
|
|
|
|

|
Using the control in dialogs requires a lot of initialisation e.g. setting texts and icon. To reduce the code needed for each dialog I wrote the following function to set up the control - perhaps it helps you using this great control:
void SetupSidebannerWnd(CWnd* pWnd, CKCSideBannerWnd* pWndBanner, UINT uiDlgID)
{
ASSERT(pWnd);
ASSERT(pWndBanner);
if (!pWnd) return;
if (!pWndBanner) return;
pWndBanner->Attach(pWnd, KCSB_ATTACH_TOP);
HICON hIcon = AfxGetApp()->LoadIcon(uiDlgID);
if (hIcon)
pWndBanner->SetIcon(hIcon);
pWndBanner->SetIconPos(KCSB_ICON_LEFT|KCSB_ICON_VCENTER);
CString strTitle(MAKEINTRESOURCE(uiDlgID));
CString strTop;
CString strSub;
AfxExtractSubString(strTop, strTitle, 0, '|');
AfxExtractSubString(strSub, strTitle, 1, '|');
pWndBanner->SetTitle(strTop);
pWndBanner->SetCaption(strSub);
}
To use it in your dialog simply add the following call to your OnInitDialog():
SetupSidebannerWnd(this, &m_wndBanner, IDD);
(assuming that m_wndBanner is the banner window).
Now add a string "Title|Caption" to your resource with the same ID as the dialog and an icon also using this ID. That's it!
Ciao,
Alex
|
|
|
|
|

|
Thanks for this nice control!
I just wanted to put it to my project (which has also a German UI) and figured out some problems with the German characters ÄÖÜäöüß and even € (EUR). It seems that CDC::GetCharWidth() return bad values for these characters. My only solution is to replace the arrWidths[] entries for äö... with the corresponding values of ao...
Do you have any better solution?
Ciao,
Alex
|
|
|
|

|
do you need a hwnd at all? if i was to make such a banner i would make a class that attaches to a certain hwnd (a dialog or whatever) and then subclasses it. next i would intercept WM_NCCALCSIZE, remember currently calculated rect (after caption and borders) and modify it to make some room for the banner. another interesting message would be WM_NCPAINT where i can use the rect from WM_NCCALCSIZE and the attached hwnd to get a window dc and paint directly. benefits: no hacks with moving controls around -- suppose the developer actually does move some controls at fixed locations. in your case he/she will need to fix the positioning code. in the proposed case only the hwnd client size will be affect and control positions on the hwnd basicly remain the same (although space is still somewhat reduced). just my $.02 worth before downloading the code ) cheers, </wqw>
|
|
|
|

|
You're absolutely right! It would be possible to implement this without an HWND the way you described. It would be interesting if you (or someone else) actually went and did this.
Take care and thanks for the input
www.kinkycode.com
[Glossary Manager] [AfterThought Backup Lite]
99 little bugs in the code, 99 little bugs,
Fix 1 bug, recompile....
101 little bugs in the code...
|
|
|
|

|
Hi everyone,
I've added the UNICODE fix that was mentioned in the thread below this one. Sorry about that! Atleast its done now. This will probably be the last update unless someone (or I) have a great idea of how to improve this control some more...
www.kinkycode.com
[Glossary Manager] [AfterThought Backup Lite]
99 little bugs in the code, 99 little bugs,
Fix 1 bug, recompile....
101 little bugs in the code...
|
|
|
|

|
I really hate to tell you this, especially since you just updated the article.... but.....
The call in the CKCSideBannerWnd constructor, to load the msimg32.dll needs to be wrapped in the _T("") macro.
// try and load the MSIMG32.LIB
if ( (m_hGradMod = LoadLibrary(_T("MSIMG32.DLL"))) )
m_pGradFill = (PFNGRADFILL) GetProcAddress(m_hGradMod, "GradientFill" );
At least *I* had to, to get my unicode build to quit whining.....
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
|
|

|
hi,
I tried to compile the demo projet and I have execution error "can't find MSGIM32.dll".
I scanned my disk, I found MSGIM32.lib.
I use VC++ 6.0 and NT 4.0.
I'd like to link statically the MSGIM32.
Can you help me ?
|
|
|
|

|
Hey,
Ok, the first problem is that you are running NT 4.0. According to MSDN, they say the dll/lib is available on:
Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Included in Windows 98 and later.
secondly, I know you've probably made a typo, but you made it twice (twece), so its actually MSIMG32. What you can do is get hold of a 98, or 2K machine, find the MSIMG32.DLL file and copy that over to your NT4 machines system(32) directory.
That should resolve the issue
Regarding the static linking question, I'm not sure of the lib is available as a static link, or if merely acts as a stub. I have a feeling the lib is merely a stub (can't be statically linked)
www.kinkycode.com
[Glossary Manager] [AfterThought Backup Lite]
99 little bugs in the code, 99 little bugs,
Fix 1 bug, recompile....
101 little bugs in the code...
|
|
|
|

|
thank you for your advice, I'm going to try.
If I found an issue on how using CKCSideBannerWnd with NT 4.0, I will post the solution.
|
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A CWnd-derived control that can attach itself to any window, without the programmer making provisions for it
| Type | Article |
| Licence | CPOL |
| First Posted | 21 Oct 2003 |
| Views | 192,242 |
| Downloads | 1,878 |
| Bookmarked | 130 times |
|
|