|
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
|
|
|
|
|
MyApp draws into a memory bitmap and copies it to the real device, in order to avoid the screen flashing.
In my app, the bitmap’s size depends on the screen resolution. When the app runs with high resolutions It needs big bitmaps and “CreateCompatibleBitmap” fails to create the bitmap. I thing this is due the fact that there is not enough memory to create the bitmap. Also fails earlier when many apps are running on the same time.
So, I am happy enough with an app that uses 256 colours only, reducing the memory required. I tried to change the CreateCompatibleBitmap by CreateBitmap call, specifying 8-bit colours.
m_pBitmap->CreateBitmap(rectMax.right, rectMax.bottom,1,8,NULL); // 256-Colour bitmap
The above line doesn’t work. The line below works well, specifying a black and white bitmap, so I think this issue is something to do with palettes.
m_pBitmap->CreateBitmap(rectMax.right, rectMax.bottom,1,1,NULL); // Black&White bitmap.
Please Help!.
Thanks in advance.
David Bru.
----
This is the my code:
void CMyAppView::OnInitialUpdate()
{
if (m_pdcMemory->GetSafeHdc() == NULL)
{
CClientDC dc(this);
OnPrepareDC(&dc);
CRect rectMax(0, 0, sizeTotal.cx, -sizeTotal.cy);
dc.LPtoDP(rectMax);
VERIFY(m_pdcMemory->CreateCompatibleDC(&dc));
VERIFY(m_pBitmap->CreateCompatibleBitmap(&dc, rectMax.right, rectMax.bottom));
}
}
void CMyAppView::OnPaint()
{
…
CBrush backgroundBrush (m_Bkg.m_pDoc->m_pCurrentSch->m_BkgColor);
CBrush* pOldBrush = m_pdcMemory->SelectObject(&backgroundBrush);
m_pdcMemory->PatBlt(rectUpdate.left,rectUpdate.top,rectUpdate.Width(),rectUpdate.Height(), PATCOPY);
OnDraw (m_pdcMemory);
dc.BitBlt(rectUpdate.left,rectUpdate.top,rectUpdate.Width(),rectUpdate.Height(), m_pdcMemory,rectUpdate.left,rectUpdate.top, SRCCOPY);
m_pdcMemory->SelectObject(pOldBrush);
…
}
|
|
|
|
|
How can I get "OnTop" func?
|
|
|
|
|
Set extended style WS_EX_TOPMOST for the window.
|
|
|
|
|
I wanna implement magnetic effect to ControlBar.
So, I override OnWindowPosChanging() member function.
But WM_WINDOWPOSCHANGING Message did not enter.
that is, the message entered to CMiniDockFrameWnd, but
did not ControlBar class.
I want another method...
thanks for read this message...
|
|
|
|
|
I suppose you want to implement the "magnetic" effect for the floating bars, because the docked ones already snap to the dockbars.
Well, you guessed right - CMiniDockFrameWnd is the best place to do this. You can derive your own floating miniframe class from CMiniDockFrameWnd and register it by setting the CMainFrame's m_pFloatingFrameClass right after you call EnableDocking() for the main frame (usually in OnCreate()) :
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//...
EnableDocking(CBRS_ALIGN_ANY);
m_pFloatingFrameClass = RUNTIME_CLASS(CMyMiniDockFrameWnd);
//...
}
|
|
|
|
|
Hi,
I want to execute dos commands from my app, such as "dir", or "copy".
Sorry if this is a "stupid" question...and yes, I did RTFM.
**FOLLOW UP AND ANSWER**
Found the best way to do this from a Win32 app is:
WinExec ( "cmd.exe /c doscommand /switch parameters", SW_HIDE )
By doing cmd.exe the next command is executed in a new process and the cmd.exe window will close after execution. Also, by using WinExec, you get the added benefit of hiding the MS-DOS window.
Thanks for everyone's suggestions and help!
|
|
|
|
|
One Way is This
UINT WinExec(
LPCSTR lpCmdLine, // address of command line
UINT uCmdShow // window style for new application
);
|
|
|
|
|
Unfortunately, I've tried this and it doesn't expose the dos commands available at the Ms-dos prompt, such as dir, copy, etc. Thanks for your reply.
|
|
|
|
|
Did you try ShellExecute or ShellExecuteEx?
|
|
|
|
|
Tried that and it doesn't work. I've tried executing cmd.exe (nt) with dir as a parameter, and that doesn't work either. Any other ideas?
|
|
|
|
|
cmd.exe has number of switches you have to use in order to make it execute a DOS command. For example:
cmd.exe /c dir
This will execute dir and will close dos window.
cmd.exe /k dir
This will execute dir and will dos window will remain open.
I hope this helps.
|
|
|
|
|
void CTestDirDlg::OnButton1()
{
STARTUPINFO startInfo;
PROCESS_INFORMATION procInfo;
startInfo.cb = sizeof(STARTUPINFO);
startInfo.lpReserved = NULL;
startInfo.lpTitle = NULL;
startInfo.lpDesktop = NULL;
startInfo.dwX = startInfo.dwY = startInfo.dwYSize = startInfo.dwXSize = 0;
startInfo.dwFlags = STARTF_USESHOWWINDOW;
startInfo.hStdInput = NULL;
startInfo.hStdOutput = NULL;
startInfo.hStdError = NULL;
startInfo.wShowWindow = SW_SHOW;
startInfo.lpReserved2 = NULL;
startInfo.cbReserved2 = NULL;
if (!CreateProcess ( NULL,
"c:\\command.com /k dir",
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&startInfo,
&procInfo
))
{
int err = GetLastError();
}
}
You can play with this a bit - the next thing to add is
the mechanism for passing the stdin, out, and error handles so that you can get the results...
|
|
|
|
|