|
You can test the overflow flag with the _asm instructions jno and jo. You can also explicitly invoke the integer overflow trap if you want to use exceptions:
void CTestDirDlg::OnButton2()
{
int a, b, c;
a = INT_MAX - 4;
b = INT_MAX - 25;
try {
c = a + b;
_asm {
jno wereOk;
int 4;
}
}
catch(...) {
MessageBox( "Overflow!", "Error");
}
wereOk:
return;
}
I realize there is the issue of portability here, but its one possible solution - could be refined. Using SEH you might be able to identify the EXCEPTION_INT_OVERFLOW exception with more certainty than the catch(...), and avoid the _asm.
You might not even want to throw the exception, just test the flag.
I think there is code out there somewhere that can convert these kinds of traps to C++ exceptions - or perhaps it would be better to just throw our own exception object, rather than invoking the processor trap. The trap might be useful if you want to enable first-chance exception handling for c0000095.
I can't seem to find a way to enable this trap in the way that we can enable floating point exceptions with controlfp.
|
|
|
|
|
OK, works fine. But what is with other operations like multiplication, and other data type like long or __int64?
|
|
|
|
|
How can I change resource for dialog form a meny in that dialog.
|
|
|
|
|
hi,
i am using MFC, i create a CDialogBar in a CRebar and my CDialogBar has 3~4 editboxes, however, i cannot uses ctrl+c or ctrl+v in these textboxes anymore and also cannot tabs thru the controls. the problem is so obvious so i think it must be something i missed.
pls help!!
gordon
|
|
|
|
|
Can someone please enlighten me about how to maximize the app's mainframe at startup? I have tried calling ShowWindow() from the InitInstance() and that doesn't do it. I've looked through the MS docs in the Visual Studio 6 and not come accross anything relevant (like a code snippet, for example!) Some pointers would be greatly appreciated!
One person suggested setting the style to WS_MAXIMIZE in PreCreateWindow() but that does not do it.
|
|
|
|
|
In the CWinApp descendent:
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
SW_SHOWMAXIMIZED does it for you.
Also in the Application wizard in step 4 of 6 there's an Advanced Button. Follow that button to the Windows Style Tab and check the Maximized box.
|
|
|
|
|
Both of them are correct!!
but only if you join both of their answers
at InitInstanse there is a variable called
p_MainWnd
do the following
p_MainWnd->ShowWindow(WS_MAXIMISE);
a good place to put it is at the end of that function
|
|
|
|
|
You don't want to pass WS_MAXIMIZE, a style code, to ShowWindow.
You're supposed to do as Mr. Warg pointed out:
Change
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
to
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
Note the WS_* in front means a *W*indow *S*tyle code, whereas the SW_* in front means a *S*how*W*indow code.
AppWizard supplies the
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
code for you; all you have to do is to replace the m_nCmdShow with SW_SHOWMAXIMIZED, and you're in business!!
Brian Hart
|
|
|
|
|
I'm trying to find out from an application if another one has blocked (ie. "Not responding" in the NT Task Manager). How do I do that?
Thanks
|
|
|
|
|
Do any of these extra macros for code formatting do word wrapping on comment blocks? I would really like something like this. So when you have a large comment block like:
// blah blah blah blah blah blah blah blah blah
// blah blah blah blah blah blah blah blah blah
// blah blah blah blah blah blah blah blah blah
And you have to edit it a lot, you don't have to manually word wrap it. Anyone know a macro that does this?
|
|
|
|
|
Can anyone explain the situations in which SelectObject will return NULL? I'm writing code to print a bitmap (see my message in the discussion for the article "Printing Made Easy") and it is returning NULL. My bitmap and memDC appear to be fine.
Thanks in advance.
|
|
|
|
|
I am trying to capture the Tree Item the cursor is over and when I use the below code in the "Right-Click"...It always returns NULL??? Can anyone help me???
CPoint MousePosition;
GetCursorPos(&MousePosition);
TVHITTESTINFO HitInfo;
HitInfo.pt = MousePosition;
if (m_ctrlTree.HitTest(&HitInfo) != NULL) {
int Mask = TVHT_ONITEM | TVHT_ONITEMRIGHT;
if (HitInfo.flags & Mask) {
m_ctrlTree.Select(HitInfo.hItem, TVGN_CARET);
CString csTest = m_ctrlTree.GetItemText(HitInfo.hItem);
MessageBox(csTest);
}
}
Dan
|
|
|
|
|
GetCursorPos() returns screen coordinates. You need to convert that point to client coordinates of the tree control:
m_ctrlTree.ScreenToClient ( &MousePosition );
|
|
|
|
|
Thanks Mike...That was it, I guess sometimes it takes a new set of eyes to see clearly. I actually used this before but had commented out the "GetCursorPos()" instead of leaving it there???
Thanks again,
Dan
|
|
|
|
|
I'm developing an app that usues msvfw32.dll and avicap32.dll in Win98. If either when running under debig mode I press SHIFT+F5 (end debug) or something I wrote causes the app to crash the two DLLs stay loaded. In then need to reset my PC for everthing to work again.
Does anyone know how I can remove loaded DLLs in win98 please? It's a pitty the CTRL+ALT+DEL window doesn't list them!
Thanks
|
|
|
|
|
I have made a custom CPrintDialog and I want touse it instead of the default one, without manage the whole printing process.
Can I tell MFC to use my dialog just before the beginning of the process?
Thanks, ...
|
|
|
|
|
You will likely need to implement in your CView derived class, a DoPreparePrinting() method and do *NOT* call the base class method. You will still need to set all of the PRINTINFO structure members as required, but instead of using CPrintDialog member, you can instantiate your own dialog instead. Have a peek at the MFC source in VIEWPRNT.CPP for what the base class does and that should help you figure out the stuff you need to do instead.
HTH.
|
|
|
|
|
Project: Write a simple program that will sit in background and alow easy and reliable transfer of files from computer to computer on a windows network.
Problem: At first I thought it would be a simple task of slight modifications to an old pascal IPX chat program that I wrote mainly in assembly a year or so ago. BUT I now found out that I can not use inturrupts in Inline Assemebly in VC6++.
Does this mean that I have got to learn WinSock if I want to program a network program or is there another way to send IPX data over a network using VC6++?
|
|
|
|
|
I don't think there is any "Built In" IPX functionality in MFC or in the Platform SDK, but I may be wrong.
What about downloading the Novell SDK from developer.novell.com?
|
|
|
|
|
Hi Markus,
Why don't you like the Windows Sockets...? It is not complicated at all...
We do sell lots of C++ classes and ActiveX controls which can make your life much easier. Check TCP/IP product at www.dundas.com
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
Markus,
What are you trying to do exactly? There are lots of communications options for networking under Windows, and certainly IPX is one of them.
I've seen a few IPX programming toolkits around, but I don't think it's a popular way to approach communication these days (even Novell has gone TCP/IP).
|
|
|
|
|
I'm trying to write a program that will enable easy transfer of files from one computer to another. Because when I try and back up files over a windows network with network neighbourhood it has a tendency to hang all way though copying the data.
My final program will ideally sit in the taskbar dealing with any relevant packets that are received and automatically deal with them, ie requests for files of that computer. It will also allow you to view all available uses and there shared files.
My reason for using IPX was that I have already got experience with the protocol as I have written a number of dos programs in Pascal that use IPX. As I can not use interrupts in a win32 executable I can not use the assembly I used in these Pascal programs.
as far as I was aware TCP/IP was used for the internet an not for LANs. So if any one can suggest a good protocol for this type of problem and were I could get some information on it. It would be much appreciated.
|
|
|
|
|
|
Can anyone give me a hint on how to display splash screen on a dialog-based app, please?
Thanks a lot in advance.
|
|
|
|
|
Hello?
First, Make Bitmap Resource, for example IDB_SPLASH
Second, Add Next Class to your Project(Dialog-Based)
/////////////////////////////////////////////
MySplashWnd.h
#if !defined(AFX_MYSPLASHWND_H__08C608F3_1FB3_11D1_830E_58A47E000000__INCLUDED_)
#define AFX_MYSPLASHWND_H__08C608F3_1FB3_11D1_830E_58A47E000000__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// MySplashWnd.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMySplashWnd window
class CMySplashWnd : public CWnd
{
// Construction
public:
CMySplashWnd(UINT nBitmapID, UINT nDuration = 2500);
// Attributes
public:
BOOL Create();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMySplashWnd)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
// Implementation
public:
// Generated message map functions
protected:
//{{AFX_MSG(CMySplashWnd)
afx_msg void OnPaint();
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
protected:
BOOL GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal);
protected:
UINT m_nBitmapID;
UINT m_nDuration;
UINT m_nTimerID;
CBitmap m_bitmap;
CPalette m_pal;
CWnd m_wndInvisible;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MYSPLASHWND_H__08C608F3_1FB3_11D1_830E_58A47E000000__INCLUDED_)
MySplashWnd.cpp
// MySplashWnd.cpp : implementation file
//
#include "stdafx.h"
#include "RichEdit.h"
#include "SplashWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMySplashWnd
CMySplashWnd::CMySplashWnd(UINT nBitmapID, UINT nDuration /*= 2500*/)
{
m_nBitmapID = nBitmapID;
m_nDuration = nDuration;
}
BEGIN_MESSAGE_MAP(CMySplashWnd, CWnd)
//{{AFX_MSG_MAP(CMySplashWnd)
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CMySplashWnd::Create()
{
if( !GetBitmapAndPalette(m_nBitmapID, m_bitmap, m_pal) )
{
TRACE1( "Could not load bitmap resource - %d\n", m_nBitmapID );
return FALSE;
}
BITMAP bm;
m_bitmap.GetObject(sizeof(BITMAP), &bm);
// First create an invisible window
m_wndInvisible.CreateEx(WS_EX_TOPMOST,
AfxRegisterWndClass(CS_CLASSDC),
_T(""), WS_POPUP, 0, 0,
bm.bmWidth, bm.bmHeight, NULL, NULL);
// Create the the splash window with invisible parent as parent
BOOL bRetVal = CWnd::CreateEx(WS_EX_TOPMOST,
AfxRegisterWndClass(CS_CLASSDC),
_T(""), WS_POPUP, 0, 0,
bm.bmWidth, bm.bmHeight, m_wndInvisible.m_hWnd, NULL);
CenterWindow();
ShowWindow(SW_SHOW);
UpdateWindow();
//Create the timer.
m_nTimerID = SetTimer(1, m_nDuration, NULL);
ASSERT(m_nTimerID);
return bRetVal;
}
BOOL CMySplashWnd::GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal)
{
LPCTSTR lpszResourceName = (LPCTSTR)nIDResource;
HBITMAP hBmp = (HBITMAP)::LoadImage( AfxGetInstanceHandle(),
lpszResourceName, IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTION );
if( hBmp == NULL )
return FALSE;
bitmap.Attach( hBmp );
// Create a logical palette for the bitmap
DIBSECTION ds;
BITMAPINFOHEADER &bmInfo = ds.dsBmih;
bitmap.GetObject( sizeof(ds), &ds );
int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 << bmInfo.biBitCount;
// Create a halftone palette if colors > 256.
CClientDC dc(NULL); // Desktop DC
if( nColors > 256 )
pal.CreateHalftonePalette( &dc );
else
{
// Create the palette
RGBQUAD *pRGB = new RGBQUAD[nColors];
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject( &bitmap );
::GetDIBColorTable( memDC, 0, nColors, pRGB );
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries = nColors;
for( int i=0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = pRGB[i].rgbRed;
pLP->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
pLP->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
pLP->palPalEntry[i].peFlags = 0;
}
pal.CreatePalette( pLP );
delete[] pLP;
delete[] pRGB;
}
return TRUE;
}
void CMySplashWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
// Create a memory DC compatible with the paint DC
CDC memDC;
memDC.CreateCompatibleDC( &dc );
CBitmap *pBmpOld = memDC.SelectObject( &m_bitmap );
// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && m_pal.m_hObject != NULL )
{
dc.SelectPalette( &m_pal, FALSE );
dc.RealizePalette();
}
// Window is same size as bitmap
CRect rcWnd;
GetWindowRect( &rcWnd );
dc.BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &memDC, 0, 0,SRCCOPY);
// Restore bitmap in memDC
memDC.SelectObject( pBmpOld );
// Do not call CWnd::OnPaint() for painting messages
}
void CMySplashWnd::OnTimer(UINT nIDEvent)
{
if (m_nTimerID == nIDEvent)
{
//Destroy the timer and splash window
KillTimer(m_nTimerID);
m_wndInvisible.DestroyWindow();
delete this;
return;
}
CWnd::OnTimer(nIDEvent);
}
BOOL CMySplashWnd::PreTranslateMessage(MSG* pMsg)
{
ASSERT(pMsg != NULL);
if (pMsg->message == WM_KEYDOWN ||
pMsg->message == WM_SYSKEYDOWN ||
pMsg->message == WM_LBUTTONDOWN ||
pMsg->message == WM_RBUTTONDOWN ||
pMsg->message == WM_MBUTTONDOWN )
{
//Destroy the timer and splash window
KillTimer(m_nTimerID);
m_wndInvisible.DestroyWindow();
delete this;
return 1;
}
return CWnd::PreTranslateMessage(pMsg);
}
Third, Insert next code at Initinstance().
if( cmdInfo.m_bShowSplash ) {
CMySplashWnd * pSplashWnd = new CMySplashWnd(IDB_SPLASH, 3000);
pSplashWnd->Create();
}
It's All!!
Good Luck
|
|
|
|