|
I try to create an image app based on Sam Teach Yourself Visual C++ in 21 Days chapter - 8 - Adding Flash--Incorporating Graphics, Drawing, and Bitmaps. The example shows that in order to load an image requires some kind of open file function, but I don’t want to use that function. I want to load my image that I’ve initialized. So I didn’t use some functions mentioned on the example, and it caused an error. The error is saying :
Debug Assertion failed. File afxwin1.inl. Line 418.
And the code is :
// ImageDlg.cpp : implementation file
void CImageDlg::OnBitmap()
{/*I did’t use this function to load the image
// Build a filter for use in the File Open dialog
static char BASED_CODE szFilter[] = "Bitmap Files (*.bmp)|*.bmp||";
// Create the File Open dialog
CFileDialog m_ldFile(TRUE, ".bmp", m_sBitmap,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
// Show the File Open dialog and capture the result
if (m_ldFile.DoModal() == IDOK)
{
// Get the filename selected
m_sBitmap = m_ldFile.GetPathName();
// Load the selected bitmap file
HBITMAP hBitmap = (HBITMAP) :LoadImage(AfxGetInstanceHandle(),
m_sBitmap, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);
// Do we have a valid handle for the loaded image?
if (hBitmap)
{
// Delete the current bitmap
if (m_bmpBitmap.DeleteObject())
// If there was a bitmap, detach it
m_bmpBitmap.Detach();
// Attach the currently loaded bitmap to the bitmap object
m_bmpBitmap.Attach(hBitmap);
}
*/the function to load the image end here
// But I used this function to load the image
m_bmpBitmap.LoadBitmap(IDB_BITMAP2);
// Invalidate the second dialog window
m_dlgImage.Invalidate();
}
}
// ImageDialog.cpp : implementation file
void CImageDialog::ShowBitmap(CPaintDC *pdc, CWnd *pWnd)
{
// Convert the pointer to a pointer to the main dialog class
CImageDlg *lpWnd = (CImageDlg *)pWnd;
BITMAP bm;
// Get the loaded bitmap
lpWnd->m_bmpBitmap.GetBitmap(&bm);
CDC dcMem;
// Create a device context to load the bitmap into
dcMem.CreateCompatibleDC(pdc);
// Select the bitmap into the compatible device context
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(lpWnd->m_bmpBitmap);
CRect lRect;
// Get the display area available
GetClientRect(lRect);
lRect.NormalizeRect();
// Copy and resize the bitmap to the dialog window
pdc->StretchBlt(10, 10, (lRect.Width() - 20),
(lRect.Height() - 20), &dcMem, 0, 0,
bm.bmWidth, bm.bmHeight, SRCCOPY);
}
void CImageDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// Get a pointer to the parent window
CImageDlg *pWnd = (CImageDlg *)GetParent();
// Do we have a valid pointer?
if (pWnd)
{
// Is there a bitmap selected and loaded? I didin’t use this function
//if (pWnd->m_sBitmap != "")
// I use this function to Display the image
ShowBitmap(&dc, pWnd);
}
}
what should I do if I don’t use the function (pWnd->m_sBitmap != "") .
Thanks a lot of for helping
Kathrin
|
|
|
|
|
// Delete the current bitmap
if (m_bmpBitmap.DeleteObject())
// If there was a bitmap, detach it
m_bmpBitmap.Detach();
Why do you delete the bitmap and then detach it ?
In any case, if you want to write an imaging program, buy Windows Graphics Programming by Feng Yuan.
As to your question - why can't you check if the filename is valid ? I'd probably suggest that if there is a possibility that your program does not have a bitmap loaded, that this is a flaw to start with, or are you using this filename for saving ? If the former, you could instead check that the bitmap itself is valid. The easiest way to do that is to make it a pointer and check if it is NULL ( don't forget to set it to NULL to start with ).
I'm sorry if I've missed the point, it's great you posted some code in reference to your question, but there is so much code that I'm not sure what you're asking.
Do I read this correctly that your program is dialog based and has two dialogs open ?
Final comment - Hungarian notation can be a bit redundant - m_bmpBitmap is a tautology.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Thank you for your e-mail.
Yes, you're right, my program is dialog based and has two dialogs open. But I don’t think you get my point.
I remarked the function you mentioned, so my code is like this:
// ImageDlg.cpp : implementation file
void CImageDlg::OnBitmap()
{
// I used this function to load the image
m_bmpBitmap.LoadBitmap(IDB_BITMAP2);
// Invalidate the second dialog window
m_dlgImage.Invalidate();
}
And the rest of my code is the same as my previous letter.
Now, can you tell me what’s wrong with my program?
Thank for your help.
Kathrin
|
|
|
|
|
Kathrin,
If you don't want to change too much of the code, update the oinit dialog method to include the m_bmpBitmap line. OnBitmap should only have the Invalidate line; comment out everything else in the OnBitmap method. Your child dialog window to which the painting is done should be as you have it in your thread posting.
BOOL CImageDlg::OnInitDialog()
{
//...
m_bmpBitmap.LoadBitmap(IDB_BITMAP2);
return TRUE;
}
void CImageDlg::OnBitmap()
{
// COMMENT out all other code.
m_dlgImage.Invalidate();
}
void CImageDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// Get a pointer to the parent window
CImageDlg *pWnd = (CImageDlg *)GetParent();
// Do we have a valid pointer?
if (pWnd)
{
ShowBitmap(&dc, pWnd);
}
}
This assumes that the dialog resource was loaded correctly. The Bitmap button on the application window then turns into a refresh button.
Cheers,
-Erik
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My thoughts are my own and reflect on no other.
|
|
|
|
|
Thank you for your response, I tried, and it works.
Now, what I want is to have a bitmap shown after I clicked a certain button which works as a trigger.
On the codes written in my previous letter, I put the trigger named onBitmap. That’s why I tried to load the image on the function : void CImageDlg::OnBitmap().
Thanks again for your help. Do I do it right, or do you have any other idea on how I can accomplish it.
|
|
|
|
|
In your main dialog class add a member variable of BOOL m_bShowImage. In your main dialog OnInitDialog initialize m_bShowImage to FALSE. In your main dialog OnBitmap method set m_bShowImage to not itself which will act as a toggle and call the secondary dialog Invalidate. In you OnPaint method for the second dialog where you originally had a string check for the file name replace that with the if (m_bShowImage == TRUE). Like below
class CImageDlg :CDialog
{
//...
public:
BOOL m_bShowImage;
};
BOOL CImageDlg::OnInitDialog()
{
//...
m_bmpBitmap.LoadBitmap(IDB_BITMAP2);
m_bShowImage = FALSE;
return TRUE;
}
void CImageDlg::OnBitmap()
{
// COMMENT out all other code.
m_bShowImage = !m_bShowImage; // Acts as toggle.
m_dlgImage.Invalidate();
}
void CImageDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// Get a pointer to the parent window
CImageDlg *pWnd = (CImageDlg *)GetParent();
// Do we have a valid pointer?
if (pWnd)
{
if (m_bShowImage)
ShowBitmap(&dc, pWnd);
}
}
Cheers,
-Erik
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My thoughts are my own and reflect on no other.
|
|
|
|
|
Well, thanks for your suggestion, I tried it and it works.
Now, can I bother you again? I hope I can……..(please…………… )
I’m sorry because I forgot to tell you that I what want is to have a bitmap shown after I input a code (in code named : m_strNumber) and I clicked a certain button which works as a trigger.
That’s why on the codes written in my previous letter I tried to load the image on the function : void CImageDlg::OnBitmap().
So my code looks like this:
void CImageDlg::OnBitmap()
{
// Load the image
UpdateData(TRUE);
if(m_strNumber=="001")
m_bmpBitmap.LoadBitmap(IDB_BITMAP1);
else if(m_strNumber=="002")
m_bmpBitmap.LoadBitmap(IDB_BITMAP2);
m_bShowImage = !m_bShowImage;
// Invalidate the second dialog window
m_dlgImage.Invalidate()
}
I have a strange result that if I input the number = 001, and then clicked the OK button, the bitmap is showing perfectly. But then, if I change the number to 002 and clicked the OK button without exiting my apps, my apps will results an error.
How did it happened, did I missed something again? Or do you have any other idea on how I can accomplish it.
Thanks again for your help.
Kathrin
|
|
|
|
|
I believe you'll get an assert if you call LoadBitmap withoutfirst freeing the bitmap that was there before. Can I ask why you're comparing a string instead of a number ? The best method IMHO for this sort of thing is an enum, because it means you can give each 'mode' a text name that makes sense to you but computationally it is fast because it is a number internally.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Some filename of files of specified folder(C:\ExUnder\Fx) have "_" of the name(ex; aa_b.txt, a_a_b.txt, _a.bmp).
I want to convert "_" to " ".
Namly, aa b.txt, a a b.txt, a.bmp.
Best regards.
|
|
|
|
|
first: Use the CString::Replace() for change the name of the file and
then use the CFile::Rename() function for change the file.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
please example !!
follow as bellow,
C:\ExUnder\Fx) have "_" of the name(ex; aa_b.txt, a_a_b.txt, _a.bmp, aa.bmp, ac-tt.bmp).
I really want to get the code using wildcard.
thank you very much.
mail : tomi34@hanmir.com
please, please !!
|
|
|
|
|
Perform a search using CFileFind, which excepts wild cards. And use the method described by Christian. It's all up to you. There is no magical Rename function that will do it for you.
|
|
|
|
|
Can anyone assist me I currently have a data-access layer written in VB and would like to port it over to C++ as I'm pretty sure there will be speed benefits in doing so...
This is the prototype of the function currently in VB:
Public Function RunSPReturnRS( ByVal sDSN As String, ByVal sSP As String, ParamArray params() As Variant) As ADODB.Recordset
I have no problems with the first two strings but can anyone give me the IDL and the function prototype to handle the ParamArray and returning the Recordset??? I have been able to find any good samples on these...
Many thanks,
William
|
|
|
|
|
William,
This should work for ya:
HRESULT RunSPReturnRS(
[in] BSTR sDSN,
[in] BSTR sSP,
[in, out] SAFEARRAY(VARIANT)* params,
[out, retval] _Recordset** );
You will also have to include the ADODB type library to compile in MIDL:
importlib("msado21.tlb");
Hope this helps
Richard Caetano
http://www.caetano.com/richard
---------------------------
Richard Caetano
richard@caetano.com
http://www.caetano.com/richard
|
|
|
|
|
Also I'd be curious to see how you're building that routine. It appears to be a routine to call stored procedures right?
Thanks!
Richard
---------------------------
Richard Caetano
richard@caetano.com
http://www.caetano.com/richard
|
|
|
|
|
Hello I was wondering if anyone out there has done any work with "waveform" functions? I have created and app the records, play's and pause's audio. Trying to get the audio to loop, seem to be having a little trouble specifying last chunck before loop starts again. MSDN say's to change the begin_loop and end_loop flags after prepareheader but before writing the chunck, this did not work for me set I set the flags before the prepareheader which worked but MSDN says that the flag param has to be zero for prepareheader to pass. Seems MSDN is incorrect. Does anyone have any knowledge in this area???
Help is ver appreciated.
Tracy
|
|
|
|
|
When I use the CMyAppDlg::m_hIcon icon the icon is big in the status bar... do I have to use a small or is there a code to make it small??
/*
BETA
*/
|
|
|
|
|
Rickard
unfortunately I do not have an answer for this, but a few observations that might help you to figure it out.
When you say the icon is big I assume that this is the 32 x 32 icon when you will be needing to display the 16 x 16 icon. CStatusBarCtrl::SetIcon doesn't seem to have any way to choose the icon size, and OnInitDialog uses CWnd::SetIcon to set the 32 x 32 and the 16 x 16 icon. CWnd::SetIcon returns a HICON so maybe if you create a member variable m_hSmallIcon and in OnInitDialog change the line to m_hSmallIcon = SetIcon(m_hIcon, FALSE) you can then use m_hSmallIcon in the call to CStatusBarCtrl::SetIcon.
Hope this helps.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
I'm trying to write a VB (yes, that's Visual Basic) Add-In using ATL. I've #import'ed MSO97.DLL and VB6EXT.OLB. Everything seems to compile fine, except for the following error:
error C2786: 'long (__stdcall *)(struct HWND__ *,void *,char *,struct _devicemodeA *,struct _devicemodeA *,unsigned long)' : invalid operand for __uuidof
This error refers to the following line, found in the created 'mso97.tlh' file:
_COM_SMARTPTR_TYPEDEF(DocumentProperties, __uuidof(DocumentProperties));
I've tried commenting out this line (since I have no intention of using DocumentProperties anyway), but it's re-inserted by the #import statement when I compile. If I remove the #import statement, and replace it with '#include "mso97.tlh"', then compiling fails miserably. Any ideas? I only desire access to the CommandBar and CommandBarControl interfaces.
Thanks in advance.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
OK, I noticed another thing. The GUID for DocumentProperties, as well as the DocumentProperties name itself, do not exist anywhere in my registry.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Try specifying that you only want the interfaces and not all the extra junk. In VC++ it looks like this: #import "mso97.dll" raw_interfaces_only
I'm not sure how to do it in VB as I am strictly VC++.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Hi all,
I want to know, can i make a report by Crystal Report 7.0 with deafult SQL query, that i'll can change the query in my program(run-time changing ...) ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
No...
Because the Crystal Report, take the fields from the General Query.
You can change the value of the parameter but not the query.
But you can make a Stored procedure that always returns the same fields, but this stored can make diferents querys depending the parameters, for example.
Good Luck!!!
Carlos Antollini.
|
|
|
|
|
Hi Carlos,
Yesterday, my friend said to me: "you can use of this: crystalreport1.sqlquery = "SELECT * FROM T1""
Of course, it is in VB ..
I want to know can i use of it in VC++ ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
I am trying to start an exe app from a dll. I've used both WinExec(..) and CreateProcess(..) with no results. Is it at all possible to call an exe from a dll and if so, is there another way to do this? Please help me
Junior
|
|
|
|
|