|
|
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...
|
|
|
|
|
#include <stdlib.h>
system("dir C:\\windows");
Bam, there ya go.
|
|
|
|
|
Does anybody know as how to migrate my projects from
visual C++ to Borland C++. Does Borland C++ builder include
Foundation Classes like MFC??
|
|
|
|
|
Yes, BCB 4 has what seems to be the version of MFC that shipped with VC 5.0 (may be updates), and can convert a VC 6 project.
I tried the Visual C++ Project Conversion Utility from the Tools menu, and converted a VC6 project (The Wizard2000 demo, available here) - or rather one build configuration.
The build balked only once, at #include <afxdtctl.h>, which is new to VC6.
You might be slightly better off moving the projects back
to VC5 before conversion - or at least setting the debug info settings back a notch to 'Program database' from 'Program database for edit and continue' but since (I think) you basically work with a single config in BCB this may not be an issue - you can edit these in BCB.
Tim
|
|
|
|
|
Does anybody knows about Borland C++ site just like "Code Tools".
I will appreciate response from readers
|
|
|
|
|
Hey James,
Why don't you talk to Chris about you starting one as part of CodeProject? (this site btw is codeproject.com)
I'm not a big Borland C++ guy, but I can't see how it would be that tough to open a forum for BC questions, and make a place to post BC code examples.
|
|
|
|
|
Adding a Borland C++ forum is a piece of cake - but how many people would use it?
|
|
|
|
|
In trying to manage PCH effectively on a large project and keeping track of and minimizing dependencies, I've often wanted a good tool for viewing the include tree of a file.
An ideal thing would be a add-in, you hit a button, it pops up a tree-view of the all included files (direct or indirect).
Anyone seen anything remotely like this?
-Philip
|
|
|
|
|
I know this is not what you are looking for, but might be a possible source of info.
I used the message pragma to instrument four headers of a simple dialog app with:
#if defined(SHOW_DEPENDANCIES)
#pragma message(" testDir.h included\n")
#endif
Then did a rebuild all -
Compiling resources...
Compiling...
StdAfx.cpp
stdafx.h included
Compiling...
TestDir.cpp
TestDirDlg.cpp
testDir.h included
resource.h included
TestDirDlg.h included
Generating Code...
testDir.h included
resource.h included
TestDirDlg.h included
Linking...
Seems to show that stdafx.h is included only once for all translation units, but the output seems staggered somehow... hmmm - perhaps compilation is multi-threaded in some way - maybe the preprocessor is spawned separately.
Would this effectvely track PCH usage during rebuilds?
You would think a compiler could offer some sort of 'verbose' switch to do this for us.
|
|
|
|
|
Your output is correct, because with PCH stdafx.h is read only once. There is no multi-threaded compilation, sadly, except in the sense the rest of MSDEV stays usable while you are compiling.
Your idea would be a start, but for a large project you need to represent the output as a tree somehow, not just a list of what is included, in order to make sense of it.
I saw some add-in that claimed to do this a while ago, and some of the "code browsers" claim to, but I've never gotten any of them to work for me.
-Philip
|
|
|
|
|
Hello gurus,
I am trying to develop a dll which will add a window to IE same as Web Search Assistant. Any ideas? I cant use Frames.
regards,
Mahesh
|
|
|
|
|