|
I have finally found the problem. In one of my base classes I have over written the OnDraw() and OnEraseBkgnd() to draw a custom background. Instead of using the MFC message entry macro,
ON_WM_ERASEBKGND(), ON_WM_PAINT(),
I used the API one: ON_MESSAGE(WM_PAINT, ...) etc.
This all worked fine in debug mode, but crashed in release.
Now everything works fine
bum... and I thought I´d got rid of all the bugs
|
|
|
|
|
Hello there,
Once a dll is loaded into the address-space of an application is there a delay in the execution of code from the DLL itself? I mean is code from the DLL executed slower then when that same code would have been compiled in the application itself?
Regards
|
|
|
|
|
Calls within the dll itself will be same as calls within the exe only.
But may be the calls between the exe and the dll could be slow coz the calls go through the CALL Gates i.e far calls.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
There will be no noticeable difference, and certainly not anything worth bothering about. The kernel is a DLL after all!
|
|
|
|
|
Hi guys,
This is my first post so excuse the low level of expertise, I've only been playing with DirectDraw for just over a week.
Anyway, the thing I want to do is read several bitmap files from a directory and display them consecutivley (like a movie). I've been searching the internet for useful files and have been using several tutorials and code snippets to get the job done. I basically started with this project (http://www.codeproject.com/directx/basicdd.asp) and edited from there. I got the bitmaps to play full screen and then made the transition to windowed mode. I followed the tutorials and everything actually works, the only thing is that I get garbage on my screen! I get a pinkinsh/whiteish mix of a distorted plain and everey now and then I can seet he bitmap which is loaded flicker on the screen but only for an extremely short time. I'm wondering if anyone can spot my mistake, here's my source:
BasicDD.cpp
///////////////////////////////////////////////////////////////////
// BasicDD.cpp : Defines the entry point for the application. //
/////////////////////////////////////////////////////////////////
//Includes
#include "stdafx.h"
#include <ddraw.h>#include "csurface.h"
#include "resource.h"
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;
//Declarations
HWND hMainWnd;
HINSTANCE hInst;
LPDIRECTDRAW7 DD = NULL; // DirectDraw object
LPDIRECTDRAWSURFACE7 FrontBuffer = NULL; // DirectDraw frontbuffer surface
LPDIRECTDRAWSURFACE7 BackBuffer = NULL; // DirectDraw backbuffer surface
LPDIRECTDRAWCLIPPER Clipper = NULL;
cSurface BitmapSurface;
long i = 0;
string FileName;
ostringstream FileNameStream;
int ScreenWidth = 720;
int ScreenHeight = 576;
//Prototypes
HWND InitWindow(int iCmdShow);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void ProcessIdle(char *File);
int InitDirectDraw();
void CleanUp();
//Main class
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//Declarations
hInst = hInstance;
hMainWnd = InitWindow(nCmdShow);
//Error checking
if(!hMainWnd)
return -1;
if(InitDirectDraw() < 0)
{
CleanUp();
MessageBox(hMainWnd, "Could start DirectX engine in your computer. Make sure you have at least version 7 of DirectX installed.", "Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
//Create a Bitmap surface
BitmapSurface.Create(DD, ScreenWidth, ScreenHeight);
//Loop while the program runs
while( TRUE )
{
//Declarations
MSG msg;
//Check if a message is found
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
// Check for a quit message
if( msg.message == WM_QUIT ){
break;
}
TranslateMessage( &msg );
DispatchMessage( &msg );
}
//No message found? Start drawing
else
{
//Reset variable i
if(i==11)
i=0;
//Create the name of the file to be drawn
FileNameStream.str("");
FileNameStream << i;
FileName = "c:/temp/temp/hart_";
FileName += FileNameStream.str();
FileName += ".bmp";
//Envoke the drawing of the file
char* File = new char[FileName.size() + 1];
strcpy(File, FileName.c_str());
ProcessIdle(File);
delete File;
i++;
}
}
//Clean up the mess we made
CleanUp();
return 0;
}
//Als er niet gevraagd wordt om het bestand te beeindigen, teken dan naar het scherm
void ProcessIdle(char* File)
{
//Declarations
HRESULT hRet;
RECT rect;
static iLastBlit;
if(GetTickCount() - iLastBlit < 50)
{
return;
}
//Load the bitmap
BitmapSurface.LoadBitmap(hInst, File, ScreenHeight, ScreenWidth);
BitmapSurface.Draw(FrontBuffer);
//Get the screen size
ZeroMemory(&rect, sizeof( rect ));
GetClientRect(hMainWnd, &rect);
POINT p1;
POINT p2;
p1.x = rect.left;
p1.y = rect.top;
p2.x = rect.right;
p2.y = rect.bottom;
ClientToScreen(hMainWnd, &p1);
ClientToScreen(hMainWnd, &p2);
rect.left = p1.x;
rect.top = p1.y;
rect.right = p2.x;
rect.bottom = p2.y;
//Blit the image
while( 1 )
{
hRet = FrontBuffer->Blt(&rect, BackBuffer, NULL, DDBLT_WAIT, NULL);
if( hRet == DD_OK )
{
break;
}
if( hRet == DDERR_SURFACELOST )
{
FrontBuffer->Restore();
}
if( hRet != DDERR_WASSTILLDRAWING )
{
break;
}
}
iLastBlit = GetTickCount();
}
//A function to create the window used to view the video
HWND InitWindow(int iCmdShow)
{
HWND hWnd;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = TEXT("");
wc.lpszClassName = TEXT("Streaming DICOM - player");
RegisterClass(&wc);
hWnd = CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
TEXT("Streaming DICOM - player"),
TEXT("Streaming DICOM - player"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
ScreenWidth,
ScreenHeight,
NULL,
NULL,
hInst,
NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
SetFocus(hWnd);
return hWnd;
}
//Is the window getting feedback from the keyboard? Respond here
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
//If escape is pressed exit the application
case WM_KEYDOWN:
if(wParam == VK_ESCAPE)
{
PostQuitMessage(0);
CleanUp();
return 0;
}
break;
//When the screen is destroyed exit the application
case WM_DESTROY:
PostQuitMessage(0);
CleanUp();
return 0;
}
//Geef een waarde terug
return DefWindowProc(hWnd, message, wParam, lParam);
}
//Create the DirectDraw enviroment
int InitDirectDraw()
{
DDSURFACEDESC2 ddsd;
HRESULT hRet;
// Create the main DirectDraw object.
hRet = DirectDrawCreateEx(NULL, (VOID**)&DD, IID_IDirectDraw7, NULL);
if( hRet != DD_OK )
return -1;
// Set the cooperativelevel
hRet = DD->SetCooperativeLevel(hMainWnd, DDSCL_NORMAL); //| DDSCL_MULTITHREADED);
if( hRet != DD_OK )
return -1;
// Prepare to create the primary surface by initializing the fields of a DDSURFACEDESC2 structure.
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
// Create the primary surface.
hRet = DD->CreateSurface(&ddsd, &FrontBuffer, NULL);
if( hRet != DD_OK )
return -1;
// Prepare to create the backbuffer surface by initializing the fields of a DDSURFACEDESC2 structure.
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = ScreenWidth;
ddsd.dwHeight = ScreenHeight;
// Create the backbuffer surface.
hRet = DD->CreateSurface(&ddsd, &BackBuffer, NULL);
if( hRet != DD_OK )
return -1;
//Create the clipper
hRet = DD->CreateClipper(0, &Clipper, NULL);
if( hRet != DD_OK )
return -1;
//Asign the clipper to the main window
hRet = Clipper->SetHWnd(0, hMainWnd);
if( hRet != DD_OK )
return -1;
//Asign the clipper to the front buffer
hRet = FrontBuffer->SetClipper(Clipper);
if( hRet != DD_OK )
return -1;
//End the function
return 0;
}
//This function cleanse up the mess which is made
void CleanUp()
{
//Destroy the Bitmap drawing surface
BitmapSurface.Destroy();
//Destroy the backbuffer
if(BackBuffer){
BackBuffer->Release();
BackBuffer=NULL;
}
//Destroy the front buffer
if(FrontBuffer){
//Destroy the clipper
FrontBuffer->SetClipper(NULL);
Clipper = NULL;
//Destroy the buffer
FrontBuffer->Release();
FrontBuffer=NULL;
}
//Destroy the DirectDraw Element
if(DD){
DD->Release();
DD=NULL;
}
}
cSurface.cpp:
///////////////////////////////////////////////////////////////////
// cSurface.cpp: implementation of the cSurface class. //
/////////////////////////////////////////////////////////////////
//Includes
#include "stdafx.h"
#include "cSurface.h"
// Constructors
cSurface::cSurface()
{
m_pSurface = NULL;
}
cSurface::cSurface(LPDIRECTDRAW7 hDD, HINSTANCE hInst, char nResource[], int nWidth, int nHeight)
{
m_pSurface = NULL;
Create(hDD, nWidth, nHeight);
this->LoadBitmap(hInst, nResource);
}
// Deconstructor
cSurface::~cSurface()
{
if(m_pSurface != NULL)
{
OutputDebugString("Surface Destroyed\n");
m_pSurface->Release();
m_pSurface = NULL;
}
}
//A function which loads a bitmap into the systems memory.
BOOL cSurface::LoadBitmap(HINSTANCE hInst, char nRes[], int nWidth, int nHeight)
{
//Declarations
HDC hdcImage;
HDC hdc;
BITMAP bm;
DDSURFACEDESC2 ddsd;
HRESULT hr;
int nX = 0;
int nY = 0;
HBITMAP hbm;
//Load the image into a variable
hbm = (HBITMAP) LoadImage(NULL, nRes, IMAGE_BITMAP, nWidth, nHeight, LR_LOADFROMFILE | LR_DEFAULTCOLOR);
if (hbm == NULL || m_pSurface == NULL)
return FALSE;
// Make sure this surface is restored.
m_pSurface->Restore();
// Select bitmap into a memoryDC so we can use it.
hdcImage = CreateCompatibleDC(NULL);
if (!hdcImage)
return FALSE;
SelectObject(hdcImage, hbm);
// Get size of the bitmap
GetObject(hbm, sizeof(bm), &bm);
if(nWidth == 0)
nWidth = bm.bmWidth;
if(nHeight == 0)
nHeight = bm.bmHeight;
// Get size of surface.
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
m_pSurface->GetSurfaceDesc(&ddsd);
//Resize the image to the size of the surface
if ((hr = m_pSurface->GetDC(&hdc)) == DD_OK)
{
StretchBlt(hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, nX, nY,
nWidth, nHeight, SRCCOPY);
m_pSurface->ReleaseDC(hdc);
}
DeleteDC(hdcImage);
//Set variables to know stuff about the input file
m_srcInfo.m_hInstance = hInst;
m_srcInfo.m_nResource = nRes;
m_srcInfo.m_iX = nX;
m_srcInfo.m_iY = nY;
m_srcInfo.m_iWidth = nWidth;
m_srcInfo.m_iHeight = nHeight;
//End the function
return TRUE;
}
//A function which creates the surface on which to draw the bitmap
BOOL cSurface::Create(LPDIRECTDRAW7 hDD, int nWidth, int nHeight)
{
//Declarations
DDSURFACEDESC2 ddsd;
HRESULT hRet;
//Delcare the surface
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
ddsd.dwWidth = nWidth;
ddsd.dwHeight = nHeight;
//Create the surface
hRet = hDD->CreateSurface(&ddsd, &m_pSurface, NULL );
if( hRet != DD_OK )
{
//Is there a lack of video memort? Use the system memory
if(hRet == DDERR_OUTOFVIDEOMEMORY)
{
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
hRet = hDD->CreateSurface(&ddsd, &m_pSurface, NULL );
}
//Is there still a problem? End the program
if( hRet != DD_OK )
{
return FALSE;
}
}
//Set some variables
m_Width = nWidth;
m_Height = nHeight;
//End the function
return TRUE;
}
//Draw the image to the surface
BOOL cSurface::Draw(LPDIRECTDRAWSURFACE7 lpDest)
{
//Declarations
RECT rcRect;
HRESULT hRet;
int iDestX=(GetSystemMetrics(SM_CXSCREEN)-m_srcInfo.m_iWidth)/2;
int iDestY=(GetSystemMetrics(SM_CYSCREEN)-m_srcInfo.m_iHeight)/2;
int nWidth=m_srcInfo.m_iWidth;
int nHeight=m_srcInfo.m_iHeight;
//Set the rectangle
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = nWidth;
rcRect.bottom = nHeight;
//Run this loop while drawing
while(1)
{
//Blit the image to the surface
hRet = lpDest->Blt(&rcRect, m_pSurface, NULL, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT, NULL);
//Error checking
if(hRet == DD_OK)
break;
if(hRet == DDERR_SURFACELOST)
{
Restore();
}
else
{
if(hRet != DDERR_WASSTILLDRAWING)
return FALSE;
}
}
//End the function
return TRUE;
}
//A function which destorys the stuff we made
void cSurface::Destroy()
{
if(m_pSurface != NULL)
{
m_pSurface->Release();
m_pSurface = NULL;
}
}
//Get the height of the local surface
UINT cSurface::Height()
{
return m_Height;
}
//Get the width of the local surface
UINT cSurface::Width()
{
return m_Width;
}
//Get the local surface
LPDIRECTDRAWSURFACE7 cSurface::GetSurface()
{
return m_pSurface;
}
//Restore the local surface
void cSurface::Restore()
{
m_pSurface->Restore();
}
cSurface.h
//////////////////////////////////////////////////////////////////
// cSurface.h: interface for the cSurface class. //
////////////////////////////////////////////////////////////////
#if !defined(AFX_CSURFACE_H__0C439CBB_20C0_487F_84A6_31D8F436B74A__INCLUDED_)
#define AFX_CSURFACE_H__0C439CBB_20C0_487F_84A6_31D8F436B74A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
#include <ddraw.h>//Create a structure that defines the information of the video source
struct SURFACE_SOURCE_INFO
{
HINSTANCE m_hInstance;
char *m_nResource;
int m_iX;
int m_iY;
int m_iWidth;
int m_iHeight;
};
//Create variables and prototypes
class cSurface
{
public:
SURFACE_SOURCE_INFO m_srcInfo;
void Restore();
LPDIRECTDRAWSURFACE7 GetSurface();
UINT Width();
UINT Height();
void Destroy();
BOOL Draw(LPDIRECTDRAWSURFACE7 lpDest);
BOOL Create(LPDIRECTDRAW7 hDD, int nWidth, int nHeight);
BOOL LoadBitmap(HINSTANCE hInst, char nRes[], int nWidth = 0, int nHeight = 0);
cSurface(LPDIRECTDRAW7 hDD, HINSTANCE hInst, char nResource[], int nWidth, int nHeight);
cSurface();
virtual ~cSurface();
protected:
UINT m_Height;
UINT m_Width;
LPDIRECTDRAWSURFACE7 m_pSurface;
};
#endif
StdAfx.cpp
// stdafx.cpp : source file that includes just the standard includes
// BasicDD.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
StdAfx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
Can anyone help?
|
|
|
|
|
I need to create a modeless dialog but when I use Create() the dialog quickly appears and disappears.
As an expirement I tried cerating a quick dialog-based app using the C++ wizard and created a button that brings up the about box (as created by the wizard) without using DoModal.
Does anyone know how to do this please? It's quite frustrating.
|
|
|
|
|
If you could post the code how you are creating the modeless dialog box may be that would pin point the prob.
any ways here how i would create the modeless dialog.
CMydialog *pDialog;
pDialog = new CMydialog;
pDialog->Create(CMyDialog::IDD);
pDialog->ShowWindow(SW_SHOW);
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Your code works fine. It was exactly the same as mine only you used a pointer to a dialog and I used an instance directly. Doesn't really make much sense to me but as long as it works, I'm happy right now
Thanks for your help.
|
|
|
|
|
But do remember that the dialog object is created using new so there should be a corresponding delete as well.
usally the modeless dialogs are self deleteing,
you put
delete this
in OnDestroy event.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Mr.Prakash wrote:
...in OnDestroy event.
Actually, the this pointer should be deleted in PostNcDestroy() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
yeah correct.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Don't forget to override the OnCancel() member function and call DestroyWindow() from within it. Don’t call the base class CDialog::OnCancel() , because it calls EndDialog() , which will make the dialog box invisible but will not destroy it.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
well your problem might be as it seems from the description :
You are creating the dialog variable in the OnButtonXXX() function, and when you create the modeless dialog, means CreateDialog returns at that very moment, and so does your funtion ( after calling ::ShowWindow(...)). And when your function ends, scope of your dialog ends (this is the reason for flashing, it creates, then ShowWindow() gets called and then scope ends. ), Try to make the variable outside the function (class variable or global), and try the same code, hopefully it will work.
Regards,
Bilal Anjum
|
|
|
|
|
Thanks... That makes perfect sense
|
|
|
|
|
I am unable to find the right combination to open a file on a server using a unc path in VC++ 6.0.
From the Run command I would enter "\\server\share\folder\test.txt"
If I use this with the ShellExecute open command it does not work. (I double-up the backslashes and send "\\\\server\\share\\folder\\test.txt")
If I send "F:\\folder\\test.txt" it does work, but that is not what I need as I do not know the local drive letter for the server.
I have found that if I send the Directory as "\\server\\share" and the File as "folder\\test.txt" this works. This is odd as the backslashes for the server have not been doubled.
What is the trick to sending the full unc path to open a file with ShellExecute.
Sara
|
|
|
|
|
Sara Burns wrote:
What is the trick to sending the full unc path to open a file with ShellExecute.
The following trick-free code worked for me:
ShellExecute(GetSafeHwnd(), "open", "\\\\server\\share\\Users\\ijs\\ijsfmt.doc", NULL, "", SW_SHOWNORMAL);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
DavidCrow wrote:
The following trick-free code worked for me:
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Thank you for confirming that this should work. I was able to enter a string of that format and it worked for me.
After much experimentation I have realised that if I send the data as a variable I do not need to double the backslashes as C++ does not strip out the extra ones - which is why it didn't work.
Therefore I pass from my form the standard format \\server\share\folder\file and it works.
Thanks for helping me find the obvious.
Sara
|
|
|
|
|
I need a list control like in the left pane of the FileOpen dialog(you can see it in left of the MS WORD open file dialog), which list the Histroy, Desktop, My computer etc.
it like a OutlookBar, but not a OutlookBar.
Thanks!
i am a good guy
|
|
|
|
|
What you want is not possible using CFileDialog . You'll need to use GetOpenFileName() instead, specifying the OFN_EXPLORER flag.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi,
Maybe this is a too complex question but I will try to explain.
I have a CRichEditView derived class, to add text to that view I use getsel and setsel(gets the text add new and then set it back, maybe this is the wrong way?!). Anyway what I want to do now is let the user to scroll around in the text with arrow keys and so on while the text is still coming in. I have tried to disable autoscroll but then I removed the possibility to scroll with arrows and select text with the mouse beyond the views limits. What I'm trying to simulate is kind of the way the debug window in visual studio 6.0 works. Where the scrolling stops when the user navigates through the text.
Did I make any sense here?
Regards
|
|
|
|
|
hi,
I created an IE browser using CLSID_INTERNETEXPLORER.I wish to change the registry settings for this particular browser.For this the IDocHostUIHandler
interface is to be implemented.Is it possible to use this for browser created using CLSID_INTERNETEXPLORER or it works only for browser control created using CLSID_WEBBROWSER ?
|
|
|
|
|
HI ALL,
Is there any way to monitor File creation/Copying over W2K?
VikramS
|
|
|
|
|
Well, using external tool you have Filemon.
|
|
|
|
|
Does anyone know a book about automation?
Thanks
|
|
|
|
|