|
I tried printing out each character individually at one stage, both data_buffer[0].ToString() and Char::ToString(data_buffer[0]), then removing the first element until there were none left (data_buffer is the vector I was referring to in the previous post). The results were -2 and ￾ for the two ToStrings respectively, repeating for each character received.
|
|
|
|
|
What I suggest you try is after you do your FT_Read call, do the following:
printf("Byte values are as follows: ");<br />
for (counter = 0; counter < num_bytes_received; counter++)<br />
printf("%02x ", received_buffer[counter]);<br />
Looking at the numeric values may give you a clue. If they are repeating, it sounds like there is some problem. Or maybe the car CAN bus is waiting for you to send some command - until you do, it just sends its status values (never worked with them, no idea of the concept.)
|
|
|
|
|
hello i work on code that open a file and try to find how many times there is a CString inside this file . (compare fuction work perfectly thanks to Whitesky and prasad )
my problem everything work fine except while loop (when start the reading) and everything above this while (if i type str. it doesnt pop up menu of CString::member fuction
WArray and FArray already declarate before
and Compare (CString , CString) is that a problem ? because i give in this loop as 1 parameter a LPCSTR
CArray<cstring ,="" cstring=""> RArray;
CString FilePathName;
CString LineRead ;
CString str7;
int ntimes=0;
const int sz =100;
char buf[sz];
CString sl , slsl;
sl = "\\" ;
FilePathName = m_FolderName + FArray.GetAt(0);
m_List.AddString(FilePathName);
ifstream FileText(FilePathName);
while(FileText.get(buf,sz))
{
FileText.get();
LineRead = (LPCSTR) buf;
for ( int m = 0 ; m < WArray.GetSize() ; m++)
{
str7 = WArray.GetAt(m);
ntimes = ntimes + Compare(LineRead , str7);
}
}
FileText.close();
return;
CString str13;
str13.Format(_T("%d"),ntimes);
AfxMessageBox(str);
-- modified at 20:12 Friday 18th May, 2007
|
|
|
|
|
Hi,
Even I can see many problem in your code. But the problem you have mention is because of the "FileText.get(buf,sz))" in condition for the while.
Manoj
Never Give up
|
|
|
|
|
I'm reciveing the following warning:
nochkclr.obj : warning LNK4204: 'R:\Visual Studio\\\Debug\libc.pdb' is missing debugging information for referencing module; linking object as if no debug info
How can I solve this?
Thanking you in advance for your help and time.
|
|
|
|
|
Jerry Burns wrote: How can I solve this?
What happens if you recompile with the /Zi compiler switch?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I will be glad to try your suggestion but how do I compile with the /Zi switch?
I apologize for not knowing how to do that, but I am new to Visual C++ .NET.
Thanking you in advance for your help and time.
|
|
|
|
|
Jerry Burns wrote: ...Visual C++ .NET.
Of which I've not ever used. A Rebuild All should suffice.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You try Rebuild All option and i think that warnign will go away.
Manoj
Never Give up
|
|
|
|
|
I am trying to make an app compatible with vista, xp, win2000, and win98
using owner drawn caption bars. I have previously used the attached
DiLascia PaintCap.cpp to accomplish custom gradient title bars in the
app. Under Vista and XP, the sysmenu min/max/close gets screwed up by
calling DrawFrameControl. Apparently, VisualStyle Theme functions need
to be used here. Can this code snippet below (but for all sysmenu
buttons) be integrated into DrawButtons() function of PaintCap.cpp to
fix sysmenu buttons with an If IsXP test..
Snippet to incorporate into PaintCap.cpp
BOOL
PaintThemeCaptionMaxButtonNormal(
IN CONST HWND hWnd,
IN CONST HDC hDC,
IN CONST POINT ptTopLeft
)
{
BOOL bRet = FALSE;
if (hWnd && hDC)
{
HTHEME hTheme = OpenThemeData(hWnd, L"WINDOW");
if (hTheme)
{
SIZE sz;
if (S_OK == GetThemePartSize(
hTheme, hDC, WP_MAXBUTTON, MAXBS_NORMAL,
NULL, TS_TRUE, &sz))
{
RECT rc;
if (SetRect(&rc, 0, 0, sz.cx, sz.cy) &&
OffsetRect(&rc, ptTopLeft.x, ptTopLeft.y))
{
bRet = (S_OK == DrawThemeBackground(hTheme,
hDC,
WP_MAXBUTTON, MAXBS_NORMAL, &rc, &rc));
}
}
CloseThemeData(hTheme);
}
}
return bRet;
}
PaintCap.cpp below:
--------------------------------------------------------------------------
////////////////////////////////////////////////////////////////
// 1997 Microsoft Systems Journal.
// If this program works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#include "StdAfx.h"
#include "PaintCap.h"
#include "MetMix.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////
// Class used to get the caption rectangle of a window in window
coords.
// This is the area of the title bar inside the window frame,
including
// the icon and min/max/close buttons.
//
class CCaptionRect : public CRect {
public:
CCaptionRect(const CWnd& wnd); // use reference to deny NULL ptr
};
class CMenuRect : public CRect
{
public:
CMenuRect(const CWnd& wnd);
};
IMPLEMENT_DYNAMIC(CCaptionPainter, CSubclassWnd);
CCaptionPainter::CCaptionPainter()
{
Invalidate();
}
CCaptionPainter::~CCaptionPainter()
{
}
//////////////////
// Install caption handler. nPaintMsg is message I will send too frame
// when its caption needs painting.
//
BOOL CCaptionPainter::Install(CWnd* pFrameWnd,UINT nPaintMsg,BOOL
bMod)
{
ASSERT_KINDOF(CWnd, pFrameWnd);
m_nPaintMsg = nPaintMsg;
m_bModified=bMod;
return HookWindow(pFrameWnd);
}
//////////////////
// Message handler handles caption-related messages
//
LRESULT CCaptionPainter::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg) {
case WM_NCPAINT:
OnNcPaint(HRGN(wp));
return 0;
case WM_NCACTIVATE:
return OnNcActivate(wp);
case WM_SETTEXT:
OnSetText((LPCTSTR)lp);
return 0;
case WM_SYSCOLORCHANGE:
case WM_SETTINGCHANGE:
Invalidate();
m_pWndHooked->SendMessage(m_nPaintMsg, 0, 0L);
// return 0;
case WM_NCMOUSEMOVE:
case WM_SYSCOMMAND:
case WM_INITMENU:
case WM_HELP:
PaintCaption();
}
// I don't handle it: pass along
return CSubclassWnd::WindowProc(msg, wp, lp);
}
/////////////////
// Handle WM_NCPAINT for main window
//
void CCaptionPainter::OnNcPaint(HRGN hRgn)
{
ASSERT_VALID(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
CCaptionRect rc(wnd); // caption rectangle in window coords
CRect rcWin; // window rect
wnd.GetWindowRect(&rcWin); // .. get window rect
rc += rcWin.TopLeft(); // convert caption rect to screen coords
// Don't bother painting if the caption doesn't lie within the
region.
//
if ((WORD)hRgn > 1 && !::RectInRegion(hRgn, &rc)) {
Default(); // just do default thing
return; // and quit
}
// Exclude caption from update region
//
HRGN hRgnCaption = ::CreateRectRgnIndirect(&rc);
HRGN hRgnNew = ::CreateRectRgnIndirect(&rc);
if ((WORD)hRgn > 1) {
// wParam is a valid region: subtract caption from it
::CombineRgn(hRgnNew, hRgn, hRgnCaption, RGN_DIFF);
} else {
// wParam is not a valid region: create one that's the whole
// window minus the caption bar
HRGN hRgnAll = ::CreateRectRgnIndirect(&rcWin);
CombineRgn(hRgnNew, hRgnAll, hRgnCaption, RGN_DIFF);
DeleteObject(hRgnAll);
}
// Call Windows to do WM_NCPAINT with altered update region
//
MSG& msg = AfxGetThreadState()->m_lastSentMsg;
WPARAM savewp = msg.wParam; // save original wParam
msg.wParam = (WPARAM)hRgnNew; // set new region for DefWindowProc
Default();
DeleteObject(hRgnCaption); // clean up
DeleteObject(hRgnNew); // ...
msg.wParam = savewp; // restore original wParam
PaintCaption();
if(wnd.IsKindOf(RUNTIME_CLASS(CMDIFrameWnd))) // Now paint my
special caption
PaintMenu();
}
//////////////////
// Handle WM_NCACTIVATE for main window
//
BOOL CCaptionPainter::OnNcActivate(BOOL bActive)
{
ASSERT_VALID(m_pWndHooked);
CWnd& frame = *((CFrameWnd*)m_pWndHooked);
ASSERT_KINDOF(CWnd, &frame);
// Mimic MFC kludge to stay active if WF_STAYACTIVE bit is on
if (frame.m_nFlags & WF_STAYACTIVE)
bActive = TRUE;
if (!frame.IsWindowEnabled()) // but not if disabled
bActive = FALSE;
if (bActive==m_bActive)
return TRUE; // nothing to do
// In case this is a MDI app, manually activate/paint active MDI
child
// window, because Windows won't do it if parent frame is invisible.
// Must do this BEFORE calling Default, or it will not work.
//
if(frame.IsKindOf(RUNTIME_CLASS(CFrameWnd)))
{
CFrameWnd* pActiveFrame = ((CFrameWnd*)&frame)->GetActiveFrame();
if (pActiveFrame!=&frame)
{
pActiveFrame->SendMessage(WM_NCACTIVATE,bActive);
pActiveFrame->SendMessage(WM_NCPAINT);
}
}
// Turn WS_VISIBLE off before calling DefWindowProc,
// so DefWindowProc won't paint and thereby cause flicker.
//
DWORD dwStyle = frame.GetStyle();
if (dwStyle & WS_VISIBLE)
::SetWindowLong(frame, GWL_STYLE, (dwStyle & ~ WS_VISIBLE));
MSG& msg = AfxGetThreadState()->m_lastSentMsg;
msg.wParam = bActive;
Default();
if (dwStyle & WS_VISIBLE)
::SetWindowLong(frame, GWL_STYLE, dwStyle);
// At this point, nothing has happened (since WS_VISIBLE was off).
// Now it's time to paint.
//
m_bActive = bActive; // update state
frame.SendMessage(WM_NCPAINT); // paint non-client area (frame too)
return TRUE; // done OK
}
//////////////////
// Handle WM_SETTEXT for main window
//
void CCaptionPainter::OnSetText(LPCTSTR lpText)
{
ASSERT_VALID(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
// Turn WS_VISIBLE style off before calling Windows to
// set the text, then turn it back on again after.
//
DWORD dwStyle = wnd.GetStyle();
if (dwStyle & WS_VISIBLE)
SetWindowLong(wnd.m_hWnd, GWL_STYLE, dwStyle & ~ WS_VISIBLE);
Default();
if (dwStyle & WS_VISIBLE)
SetWindowLong(wnd.m_hWnd, GWL_STYLE, dwStyle);
wnd.SendMessage(WM_NCPAINT); // paint non-client (frame)
Invalidate(); // force new bitmap
PaintCaption();
}
//////////////////
// Paint custom caption. Flag tells whether active or not. Just blast
the
// bitmap to the title bar, but not if minimized (iconic).
//
void CCaptionPainter::PaintMenu()
{
ASSERT(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
if(wnd.IsIconic())
return;
CWindowDC dcWin(&wnd);
CDC dc;
dc.CreateCompatibleDC(&dc);
CMenuRect rc(wnd);
if(rc.Size() != m_szMenuCaption)
{
m_bmMenuCaption[0].DeleteObject();
m_bmMenuCaption[1].DeleteObject();
m_szMenuCaption = rc.Size();
}
}
void CCaptionPainter::PaintCaption()
{
ASSERT(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
// Get caption DC and rectangle
CWindowDC dcWin(&wnd); // window DC
CDC dc; // memory DC
dc.CreateCompatibleDC(&dcWin); // ...create it
CCaptionRect rc(wnd); // get caption rectangle
if (rc.Size() != m_szCaption) { // if size changed:
m_bmCaption[0].DeleteObject(); // invalidate bitmaps
m_bmCaption[1].DeleteObject(); // ...
m_szCaption = rc.Size(); // update new size
}
// Get active/inactive bitmap & determine if needs to be regenerated
CBitmap& bm = m_bmCaption[m_bActive!=0]; // get bitmap
BOOL bPaintIt = FALSE; // paint anew?
if (!(HBITMAP)bm) { // no bitmap:
bm.CreateCompatibleBitmap(&dcWin, rc.Width(), rc.Height()); //
create one
bPaintIt = TRUE; // and paint it
}
CBitmap* pOldBitmap = dc.SelectObject(&bm); // select bitmap into
memory DC
// If bitmap needs painting, call client to do it.
if (bPaintIt) {
PAINTCAP pc;
pc.m_pDC = &dc;
pc.m_szCaption = rc.Size();
pc.m_bActive=m_bActive;
if(m_nPaintMsg)
wnd.SendMessage(m_nPaintMsg, m_bActive, (LPARAM)&pc);
else
DrawNormalCaption(pc);
}
// blast bits to screen
dcWin.BitBlt(rc.left,rc.top,rc.Width(),rc.Height(),&dc,0,0,SRCCOPY);
dc.SelectObject(pOldBitmap); // restore DC
}
void CCaptionPainter::DrawNormalCaption(const PAINTCAP& pc)
{
ASSERT(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
UINT uFlags = DC_TEXT|DC_ICON;
if(pc.m_bActive)uFlags|=DC_ACTIVE;
CRect rc(CPoint(0,0),pc.m_szCaption);
::DrawCaption(wnd,*pc.m_pDC,&rc,uFlags);
DrawButtons(pc);
}
////////////////
// Draw caption icon. Returns width of icon.
//
int CCaptionPainter::DrawIcon(const PAINTCAP& pc)
{
ASSERT(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
// Within the basic button rectangle, Windows 95 uses a 1 or 2 pixel
border
// Icon has 2 pixel border on left, 1 pixel on top/bottom, 0 right
//
int cxIcon = GetSystemMetrics(SM_CXSIZE);
CRect rc(0, 0, cxIcon, GetSystemMetrics(SM_CYSIZE));
rc.DeflateRect(0,1);
rc.left += 2;
DrawIconEx(pc.m_pDC->m_hDC, rc.left, rc.top,
(HICON)GetClassLong(wnd.m_hWnd, GCL_HICONSM),
rc.Width(), rc.Height(), 0, NULL, DI_NORMAL);
return cxIcon;
}
////////////////
// Draw min, max/restore, close buttons.
// Returns total width of buttons drawn.
//
int CCaptionPainter::DrawButtons(const PAINTCAP& pc)
{
ASSERT(m_pWndHooked);
CWnd& wnd = *m_pWndHooked;
DWORD dwStyle = wnd.GetStyle();
if (!(dwStyle & WS_CAPTION))
return 0;
ASSERT(pc.m_pDC);
CDC& dc = *pc.m_pDC;
int cxIcon = GetSystemMetrics(SM_CXSIZE);
int cyIcon = GetSystemMetrics(SM_CYSIZE);
// Draw caption buttons. These are all drawn inside a rectangle
// of dimensions SM_CXSIZE by SM_CYSIZE
CRect rc(0, 0, cxIcon, cyIcon);
rc += CPoint(pc.m_szCaption.cx-cxIcon, 0); // move right
// Close box has a 2 pixel border on all sides but left, which is
zero
rc.DeflateRect(0,2);
rc.right -= 2;
dc.DrawFrameControl(&rc, DFC_CAPTION, DFCS_CAPTIONCLOSE);
// Max/restore button is like close box; just shift rectangle left
// Also does help button, if any.
BOOL bMaxBox = dwStyle & WS_MAXIMIZEBOX;
if (bMaxBox || (wnd.GetExStyle() & WS_EX_CONTEXTHELP)) {
rc -= CPoint(cxIcon, 0);
dc.DrawFrameControl(&rc, DFC_CAPTION,
bMaxBox ? (wnd.IsZoomed() ? DFCS_CAPTIONRESTORE :
DFCS_CAPTIONMAX) :
DFCS_CAPTIONHELP);
}
// Minimize button has 2 pixel border on all sides but right.
if (dwStyle & WS_MINIMIZEBOX) {
rc -= CPoint(cxIcon-2,0);
dc.DrawFrameControl(&rc, DFC_CAPTION, DFCS_CAPTIONMIN);
}
return pc.m_szCaption.cx - rc.left - 2;
}
//////////////////
// CCaptionRect Constructor computes caption rectangle in window
coords.
//
CCaptionRect::CCaptionRect(const CWnd& wnd)
{
// Get size of frame around window
DWORD dwStyle = wnd.GetStyle();
CSize szFrame = (dwStyle & WS_THICKFRAME) ?
CSize(GetSystemMetrics(SM_CXSIZEFRAME),
GetSystemMetrics(SM_CYSIZEFRAME)) :
CSize(GetSystemMetrics(SM_CXFIXEDFRAME),
GetSystemMetrics(SM_CYFIXEDFRAME));
int cxIcon = GetSystemMetrics(SM_CXSIZE); // width of caption icon/
button
// Compute rectangle
wnd.GetWindowRect(this); // window rect in screen coords
*this -= CPoint(left, top); // shift origin to (0,0)
left += szFrame.cx; // frame
right -= szFrame.cx; // frame
top += szFrame.cy;
bottom = top + GetSystemMetrics(SM_CYCAPTION)
- GetSystemMetrics(SM_CYBORDER); // minus gray shadow border
}
CMenuRect::CMenuRect(const CWnd& wnd)
{
DWORD dwStyle = wnd.GetStyle();
CSize szFrame = (dwStyle & WS_THICKFRAME) ?
CSize(GetSystemMetrics(SM_CXSIZEFRAME),
GetSystemMetrics(SM_CYSIZEFRAME)) :
CSize(GetSystemMetrics(SM_CXFIXEDFRAME),
GetSystemMetrics(SM_CYFIXEDFRAME));
int cxIcon = GetSystemMetrics(SM_CXSIZE); // width of caption icon/
button
// Compute rectangle
wnd.GetWindowRect(this); // window rect in screen coords
*this -= CPoint(left, top); // shift origin to (0,0)
left += szFrame.cx; // frame
right -= szFrame.cx; // frame
top += szFrame.cy + GetSystemMetrics(SM_CYCAPTION) +
(GetSystemMetrics(SM_CYBORDER) * 2);
bottom = top + GetSystemMetrics(SM_CYMENU)
- GetSystemMetrics(SM_CYBORDER); // minus gray shadow border
}
//////////////////
// Helper function to compute the luminosity for an RGB color.
// Measures how bright the color is. I use this so I can draw the
caption
// text using the user's chosen color, unless it's too dark. See MSDN
for
// definition of luminosity and how to compute it.
//
int CCaptionPainter::GetLuminosity(COLORREF color)
{
#define HLSMAX 240 // This is what Display Properties uses
#define RGBMAX 255 // max r/g/b value is 255
int r = GetRValue(color);
int g = GetGValue(color);
int b = GetBValue(color);
int rgbMax = max( max(r,g), b);
int rgbMin = min( min(r,g), b);
return (((rgbMax+rgbMin) * HLSMAX) + RGBMAX ) / (2*RGBMAX);
}
#define COLOR_WHITE RGB(255,255,255)
#define COLOR_BLACK RGB(0,0,0)
#define NCOLORSHADES 64 // this many shades in gradient
//////////////////
// Helper to paint rectangle with a color.
//
void CCaptionPainter::PaintRect(CDC& dc, int x, int y, int w, int h,
COLORREF color)
{
CBrush brush(color);
CBrush* pOldBrush = dc.SelectObject(&brush);
dc.PatBlt(x, y, w, h, PATCOPY);
dc.SelectObject(pOldBrush);
}
//////////////////
// Paint custom caption.
// This is the function that actually does the shading. It creates a
// bitmap that's used to paint the caption. It looks horrible, but
it's
// just a lot of bit-twiddling GDI stuff.
//
void CCaptionPainter::PaintMyCaption(WPARAM bActive, LPARAM lParam,
CString m_strTitle, BOOL bShowAppTitle /*= TRUE*/)
{
if (lParam == 0) {
// lParam = 0 means system setting change: invalidate fonts.
m_fontCaption.DeleteObject();
return;
}
const PAINTCAP& pc = *((PAINTCAP*)lParam);
ASSERT(pc.m_pDC);
CDC& dc = *pc.m_pDC;
int cxCap = pc.m_szCaption.cx;
int cyCap = pc.m_szCaption.cy;
COLORREF clrFrom; // the beginning color
COLORREF clrTo; // the ending color
// These are the default colors in Windows(R) 98
// Modify them to suit your needs.
if (bActive) {
// Active caption
clrFrom = ((CMetMixApp*)AfxGetApp())-
>m_crCaptionGradiantColorStart;//RGB(112,223,112);
clrTo = ((CMetMixApp*)AfxGetApp())->m_crCaptionGradiantColorEnd;//
RGB(0,0,0);
}
else
{
// Inactive caption
clrFrom = GetSysColor(COLOR_INACTIVECAPTION);
clrTo = RGB(184, 180, 184);
}
// Get the intensity values for the ending color
int r1 = GetRValue(clrTo); // red
int g1 = GetGValue(clrTo); // green
int b1 = GetBValue(clrTo); // blue
// Get the intensity values for the begining color
int r2 = GetRValue(clrFrom); // red
int g2 = GetGValue(clrFrom); // green
int b2 = GetBValue(clrFrom); // blue
int x = 5*cxCap/6; // start 5/6 of the way right
int w = x; // width of area to shade
int xDelta= max(w/NCOLORSHADES,1); // width of one shade band
// Paint far right 1/6 of caption the background color
PaintRect(dc, x, 0, cxCap-x, cyCap, clrTo);
int r, g, b;
while (x > xDelta) {
x -= xDelta;
if (r1 > r2)
r = r1 - (r1-r2)*(w-x)/w;
else
r = r1 + (r2-r1)*(w-x)/w;
if (g1 > g2)
g = g1 - (g1-g2)*(w-x)/w;
else
g = g1 + (g2-g1)*(w-x)/w;
if (b1 > b2)
b = b1 - (b1-b2)*(w-x)/w;
else
b = b1 + (b2-b1)*(w-x)/w;
// Paint bands right to left
PaintRect(dc, x, 0, xDelta, cyCap, RGB(r, g, b));
}
// Paint what's left of the caption with the beginning color
PaintRect(dc, 0, 0, x, cyCap, clrFrom);
// Use caption painter to draw icon and buttons
int cxIcon = DrawIcon(pc);
int cxButns = DrawButtons(pc);
// Now draw text. First Create fonts if needed
if (!m_fontCaption.m_hObject)
CreateFonts();
CString dt;
dt.Empty();
if(bShowAppTitle)
dt=CString(GetDocTitle());
CString s;
// app title
if(dt.IsEmpty())
s = " " + m_strTitle;
else
s = " " + m_strTitle + " - [" + dt + "]";
CRect rc(CPoint(0,0), pc.m_szCaption); // text rectangle
rc.left += cxIcon+2; // start after icon
rc.right -= cxButns; // don't draw past buttons
dc.SetBkMode(TRANSPARENT); // draw on top of our shading
// This is a trial and error value that sets the point
// where the caption background is too light/dark in
// order to display the text with white/black.
#define LUMINOSITY_MARK 120
if (GetLuminosity(clrFrom) > LUMINOSITY_MARK)
dc.SetTextColor(COLOR_BLACK);
else
dc.SetTextColor(COLOR_WHITE);
/* added */
CFont mFont;
mFont.CreateFont(-12,0,0,0,FW_BOLD, FALSE, FALSE, 0,0,0,0,0,0,
"Arial");
CFont* pOldFont = dc.SelectObject(&mFont);
// commented
/*CFont* pOldFont = dc.SelectObject(&m_fontCaption);*/
dc.DrawText(s, &rc, DT_LEFT|DT_VCENTER|DT_SINGLELINE|
DT_END_ELLIPSIS);
// Restore DC
dc.SelectObject(pOldFont);
}
//////////////////
// Helper function to build the fonts I need.
//
void CCaptionPainter::CreateFonts()
{
// Get current system caption font, just to get its size
//
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(ncm);
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0));
m_fontCaption.CreateFontIndirect(&ncm.lfCaptionFont);
}
// Private MFC function only sets the title if it's different
//
extern void AFXAPI AfxSetWindowText(HWND, LPCTSTR);
void CCaptionPainter::UpdateFrameTitle(HWND m_hWnd, CString
m_strTitle)
{
CString s = (m_strTitle + " " + GetDocTitle());
AfxSetWindowText(m_hWnd,(LPCTSTR)s);
}
//////////////////
// Get doc title: I use full path name or "untitled"
//
CString CCaptionPainter::GetDocTitle()
{
static CString s;
s.Empty();
CWnd *mFrame = (CFrameWnd *)AfxGetMainWnd();
if(mFrame)
{
if(mFrame->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
{
CFrameWnd *pFrame = ((CFrameWnd*)mFrame)->GetActiveFrame();
if(pFrame!=mFrame && pFrame)
{
pFrame->GetWindowText(s);
if(!s.IsEmpty())
{
if(m_bModified)
{
CDocument *pDoc = pFrame->GetActiveDocument();
if(pDoc)
{
if(pDoc->IsModified()&&s.GetAt(s.GetLength()-1)!='*')s+="*";
}
}
}
}
}
}
return s;
}
|
|
|
|
|
How to convert from CString to integer? and Vise versa?
Also, how can I display integer in message boxes? I keep getting errors, or are they always CString types?
I'm just learning MFC, so bear with me,And sorry if my questions are stupid
--Star
|
|
|
|
|
Here's a possible method for each direction...
int i = 12345;
CString str;
str.Format(_T("%d"), i);
i = _tstoi(str);
For MessageBox, I'm not sure which one you are using - MFC, Windows API, etc. but you can format
strings pretty much the same for all of them...
int i = 12345;
CString str;
str.Format(_T("The value of i is %d"), i);
int MessageBoxRet = AfxMessageBox(str, MB_ICONEXCLAMATION | MB_OK);
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
And also you can use of wsprintf .
|
|
|
|
|
Probably being dumb but is there a quick way to see the size of a dialog you've made in Resource Editor, and can it also show how much extra is added by the menu bar etc. I've seen the "guide spacing" in the Layout tab as 4 "DLU" but I dont know what DLU are, and I want to make sure the dialog fits to a 640*480 screen.
Yes, I can reset my desktop resolution to that, but do I really need to do that? Surely there is a quick/easy way to see the dimensions?
I can see this
IDD_PTWBEAMPROFILE_DIALOG DIALOGEX 0, 0, 554, 172
in the rc file as opened as a text file but the default action of clicking it actually opens my dialog resource GUI, I had to do a find files to get into the rc file in VC++ as a text file. I assume those numbers are the size but can I get at them more easily?
|
|
|
|
|
When you have the dialog open, look down on the status bar. There are several sets of numbers. The right most is the size, the next to the left is the location.
Larry J. Siddens
|
|
|
|
|
thanks Larry, I noticed this about a nanosecond before your reply, but appreciate the reply
|
|
|
|
|
Also, make sure that you have the whole dialog selected and not one of the controls. I have had many brain farts and not done this...
Larry J. Siddens
|
|
|
|
|
ldsdbomber wrote: but I dont know what DLU are
It stands for DiaLog Units. A DLU is based on the size of the dialog box font, normally 8-point MS Sans Serif. A horizontal DLU is the average width of the dialog box font divided by four. A vertical DLU is the average height of the font divided by eight.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi.I'm doing a Visual c++2005 project.
I've implemented a class A in a cpp file like this:
class A
{...constructor,methods,and so on
};
Then i've to use an object of this class in another file(my form.h file of the graphic interface)
and i want that the object is visible to all methods of this class so that i can use its properties.
I've put my #include a.h but where must i have to declare it to use it as "a global variable"?
I can use it only if i declare it in a method but it's not visible from the other methods.
If i declare it in the constructor of the class the methods don't see the object.
Thanks for answers, regards.
|
|
|
|
|
If I under stand your question correctly, you have something like this...
<pre>
class MyClass
{
public:
MyClass() { ... }
~MyClass() { ... }
void myFunction( ... );
int getInt();
void setInt( int x );
private:
int myInt;
}
</pre>
And you have your .cpp file. Then you do something like this (different source file):
<pre>
#include "myClass.h"
MyClass myObject;
... Other stuff...
</pre>
Then to have it global.
<pre>
#include "MyClass.h"
extern MyClass myObject;
</pre>
Is this what your trying to do?
Larry J. Siddens
|
|
|
|
|
I try to explain my problem...
class MyClass
{
public:
MyClass() { ... }
~MyClass() { ... }
void myFunction( ... );
int getInt();
void setInt( int x );
private:
int myInt;
}
in a .cpp file.
Then I've have my form.h where i want to use an object of Myclass
#pragma once
namespace WinCam {
using namespace System;
public ref class Form1 : public System::Windows::Forms::Form
{
private: System::Windows::Forms::TabPage^ tabPage1;
...
public:
Form1(void)
{
InitializeComponent();
//////......
}
protected:
~Form1()
{...
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
//here i want to use an object of the a class.
ob.Myfunction();
}
private: System::String^ loadtext(void){
//here i want to use the same object.
int n;
n=ob.getint();
}
....
Where and how must i have to declare Myclass ob=new Myclass()??
thanks, regards.
|
|
|
|
|
Do you want a global variable or a member variable accessible to the class it belongs to?
A global variable you define outside of any class...
A a;
A member variable is defined in a class...
class MyClass
{
protected: //public, private - whatever is appropriate
A a;
...
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I try to explain my problem...
class MyClass
{
public:
MyClass() { ... }
~MyClass() { ... }
void myFunction( ... );
int getInt();
void setInt( int x );
private:
int myInt;
}
in a .cpp file.
Then I've have my form.h where i want to use an object of Myclass
#pragma once
namespace WinCam {
using namespace System;
public ref class Form1 : public System::Windows::Forms::Form
{
private: System::Windows::Forms::TabPage^ tabPage1;
...
public:
Form1(void)
{
InitializeComponent();
//////......
}
protected:
~Form1()
{...
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
//here i want to use an object of the a class.
ob.Myfunction();
}
private: System::String^ loadtext(void){
//here i want to use the same object.
int n;
n=ob.getint();
}
....
Where and how must i have to declare Myclass ob=new Myclass()??
thanks, regards.
|
|
|
|
|
dodoxor wrote: Where and how must i have to declare Myclass ob=new Myclass()??
Here's one possible way - adding a MyClass pointer member object, allocated in the constructor,
freed in the destructor...
public ref class Form1 : public System::Windows::Forms::Form
{
private:
System::Windows::Forms::TabPage^ tabPage1;
...
protected:
MyClass *pMyClassObject;
public:
Form1(void)
{
InitializeComponent();
pMyClassObject = new MyClass();
}
protected:
~Form1()
{
delete pMyClassObject;
}
private:
System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
pMyClassObject->Myfunction();
}
System::String^ loadtext(void)
{
int n;
n=pMyClassObject->getint();
}
}
Here's another possible way - adding a MyClass member object...
public ref class Form1 : public System::Windows::Forms::Form
{
private:
System::Windows::Forms::TabPage^ tabPage1;
...
protected:
MyClass MyClassObject;
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
}
private:
System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
MyClassObject.Myfunction();
}
System::String^ loadtext(void)
{
int n;
n=MyClassObject.getint();
}
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|