 |

|
You can copy the buffer to a global memory buffer, then use CreateStreamOnHGlobal[^] to get the image buffer as a stream, which can then be passed to Image.FromStream[^]. The following should (I hope) help to clarify it:
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
PVOID pvData = GlobalLock(hGlobal);
CopyMemory(pvData, pImageData, dwFileSize); GlobalUnlock(hGlobal);
IStream* pStream;
HRESULT hResult = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
Image* pImage = Image::FromStream(pStream);
pStream->Release();
RectF destRect; Graphics graphics(hDC);
graphics.DrawImage(pImage, destRect);
delete pImage;
|
|
|
|

|
Hi Toms, you could use the CxImage library - which allows you to specify the image bits when constructing an image, or you could use CreateDIBSection to create a bitmap using the image data you already have, then display it using an HDC.
|
|
|
|

|
Although MFC only supply very little controls, it will need too much time to make its own directUI controls.
I donot know if anyother advantage if using directUI.
|
|
|
|

|
When I used CFileDialog in MFC Dialog Project, it ran correctly. But when CFileDialog is used in DLL Projects(MFC Dll and Win32 Dll) it didn't run.
In detail, DoModal() function didn't run. program stopped.
Please Help me.
Thank you for reading my question.
|
|
|
|

|
LeeUnSong wrote: program stopped. You need to provide more detail than this, we cannot guess what your code is doing.
|
|
|
|

|
Thank you for your kindness. sorry for my poor english.
I created project with "Regular Dll with MFC statically linked".
Then I added new class "CMainDlg" to project. Of course, this class has resource "IDD_MAINDLG".
I put button control on my dialog and made event function "CMainDlg::OnBnClickedOpenfile".
After that, I added code as follow.
void CMainDlg::OnBnClickedOpenfile()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CFileDialog OpenDlg(TRUE);
if (OpenDlg.DoModal() != IDOK)
{
AfxMessageBox("Clicked Cancel");
return;
}
AfxMessageBox("Clicked OK");
}
Build my project and loaded my dll file from other project.
Then MainDlg appeared.
But after clicking "OpenFile" button, no messagebox appeared.
What is wrong in my code???
|
|
|
|

|
LeeUnSong wrote: What is wrong in my code? I am not sure. The best solution is to use your debugger to step through the code and check what happens at each line.
|
|
|
|

|
I need help deciphering how to use manipulators to put together this output statement correctly. (setprecision, setw, right...etc.). This is just one small part of my homework, but if I can see this worked out I should be able to put the rest together myself. My professor has no communication or teaching skills and leaves me confused.
Output fourth with four digits, with the sign shown at the left, and the value right aligned. The decimal point must also appear.
Here is the program my professor is having us go by:
cout << "Enter bool, int, long, float, float, and double values: ";
cin >> first >> second >> third >> fourth >> fifth >> sixth;
modified 20 Feb '13 - 18:10.
|
|
|
|

|
ok, we understand the pain ...but what have you tried so far Sarah ?
We try not to do people's homework by just giving them an answer - copying and pasting isnt going to help you learn, is it ?
So, Im going to give you the start of the answer ...
cout << setprecision(x) << fourth << endl;
Why dont you type it in, (note, you need to replace the (x) in setprecision with a number - think carefully, or just try multiple output statements), compile and run it ..
Its probably bad form to have the 'using namespace' clause below, but for testing something quick, Im going to close my eyes and just do it the simple way, so, you'll also need
#include <iostream>
#include <iomanip>
using namespace std;
at the top of your program.
try it ...
|
|
|
|

|
Thank you this is what I was asking, just a start because I have litterally never written code in C++ only pseudocode. I am just trying to put together how each line will appear. He provided the entire program we have to fill in our solution. Here, I'll show you...
Exercise 3:
Objectives: using the iomanip library to format screen output.
Complete the provided main() program with statements to accomplish each of the following. In each case you must use the appropriate I/O stream manipulators to produce the appropriate output wherever possible. Refer to the sample output below as a guide for proper output alignment.
Output first first as an integer value, followed by a space, then in its written form.
Output second as a base ten value, followed by a space, then as a hexadecimal value, followed by a space, then as an octal value. Make sure the appropriate base indicator prefix is shown in the output.
Output third.
Output fourth with four digits, with the sign shown at the left, and the value right aligned. The decimal point must also appear.
Output fourth with four significant figures.
Output fifth with seven significant figures. (Must be left-aligned)
Output fifth with three digits to the right of the decimal point.
Output third.
Output fourth with two digits to the right of the decimal point.
Output sixth with no decimal portion showing
Output fourth with eight digits to the right of the decimal point.
Output sixth with six digits.
You must start your coding by using exactly the following program. You may not modify it, except to add the required code between the Solution starts, and Solution ends comments.
#include <iostream>
#include <iomanip>
using namespace std;
int
main()
{
bool first;
int second;
long third;
float fourth;
float fifth;
double sixth;
cout << "Enter bool, int, long, float, float, and double values: ";
cin >> first >> second >> third >> fourth >> fifth >> sixth;
cout << endl;
// ***** Solution starts here ****
// ***** Solution ends here ****
cin.get();
return 0;
}
SAMPLE PROGRAM OUTPUT (assume user inputs values shown in bold):
Enter bool, int, long, float, float, and double values:
1 69 1464878 6443.39 -7.273 -6443.39
1 true
69 0x45 0105
1464878
+ 6443.
6.4434e+03
-7.2729998e+00
-7.273
1464878
6443.39
-6443
6443.39013672
-6443.39
|
|
|
|

|
ok, I suggest you comment each section you're working on, between the
Sarah Trattner wrote: // ***** Solution starts here ****
marks, it'll make it easier ... so it'll look like
cout << something << first << " " << something-else << first << endl;
cout << third << endl;
But you'll see in Part 1, Ive deliberately used 'something' and 'something-else' ... ok, so, you're outputting a boolean value - you need to pick the two flags that work particularly well with booleans, and, there's an obvious hint - one starts with 'bool' .. once you find the flags - they'll be in your notes for sure, put them into the statement .. you'll also see Ive commented out the start for Part 2 - you can comment lines out that you're experimenting with or jotting down ideas, so that if they are wrong, your program will still compile ..
do you follow so far ?
|
|
|
|

|
btw - commenting skills are a MUST .. I cant teach you your own style .. but consider each of these
cout << something << first << " " << something-else << first << endl;
and
cout << something << first << " " << something-else << first << endl;
which is easier for someone else to read ?
|
|
|
|

|
Is it required to add the BOM code (BOM = 0xFeFF) at the beginning of a .txt file in order for it to be opened as a UNICODE one, by notepad?
|
|
|
|

|
Read here for more on the subject.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|

|
Thanks. That really helps!
|
|
|
|

|
I'm writing a program to display multiple images on character select:
my code is on
case WM_CHAR:
{
switch((char)wParam)
{
case 'A': case 'a':
hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
break;
case 'B': case 'b':
hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP3));
break;
case 'C': case 'c':
hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP4));
break;
default:
break;
}
}
break;
case WM_PAINT:
{
hDC = GetDC(picBoxDisp);
MemDCExercising = CreateCompatibleDC(hDC);
SelectObject(MemDCExercising, hbmp);
BitBlt(hDC, 0, 0, 200, 200, MemDCExercising, 0, 0, SRCCOPY);
DeleteObject(hbmp);
DeleteDC(MemDCExercising);
SendMessage(picBoxDisp,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hbmp);
Images are displayed correctly but second image overlapps first...
|
|
|
|

|
DeleteObject(hbmp);
DeleteDC(MemDCExercising);
SendMessage(picBoxDisp,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hbmp);
You are sending a handle to a deleted object in the last line of this code. What does the recipient of this message expect to do with it?
|
|
|
|

|
That doesn't explain the images overlapping. The overlapping might be a result of none identical size of the images.
|
|
|
|

|
Hello Friends
I am creating a MFC application using VS2010 on WinXP.
i am using CFileDialog with Preview functionality while opening a file.It is working Fine in WinXP but in Win7,it is not showing any preview.
Do i need to change in MFC header Files? As I Found that,we need to chahnge #define WINVER to 0X501 from 0X00600. But I didnt get any clear result.
Any Ideas?
Regards
Yogesh Sikri
|
|
|
|

|
Version for Windows 7 is 0x0601, but that will not necessarily fix the problem. I'm also not sure what you mean by Preview in this context (not used MFC for a while).
|
|
|
|

|
I derived class CFileDialog and Customize File Open Dialog by adding Preview option in OpenDialog[flags used OFN_ENABLETEMPLATE].
But this is not working in Win7.
I found on net tht we need to use Common File Dialog to Customize open File dialog in Windows7. But there should be way for Existing Applications which is using CFileDialog.
Regards
Yogesh
|
|
|
|

|
yogeshs wrote: I derived class CFileDialog and Customize File Open Dialog Then you need to debug your custom code.
|
|
|
|

|
I debug My Code In Win7 too and its working Fine. The prob is tht Open Dialog in Win7 is not resizing.Then Only Preview Window will Appear.How can I Achieve that ?
Y
|
|
|
|

|
Sorry, I don't understand what you are saying.
|
|
|
|

|
This may be in the wrong forum – but here goes. I have a 32-bit application that I've been maintaining for about 12 years and it runs on every Windows platform up to Windows 7. In all that time I've been using CWinApp::GetProfileXxxx() and CWinApp::WriteProfileXxxx() calls to read and write my program settings (about 70 settings) in the Registry. The settings are read from the Registry at start-up and written to the Registry when the program closes. There is also a method for the user to read and write the program settings to an INI file using the same code as the Registry access. On my Windows 7 system the Registry read/write works just like it always has on all previous Windows versions. However, on some customer's Windows 7 machines there appears to be a problem with the Registry access. The program settings are either not being read from the Registry or are not being written to the Registry. I think the settings are not being written – but I don't know that. When the user uses the INI file the settings appear to be read and written. The customer has complained a bit (I'd complain too) but doesn't have the time or doesn't want to take the time to run some simple tests for me to find out what's going on with his Windows 7 system. So here is my question: Are there any user account settings or permissions that can block the program's access to the Registry? He claims he is an Administrator but I can't even get him to verify that. Thanks, Mike
|
|
|
|

|
Member 9199754 wrote: So here is my question: Are there any user account settings or permissions that can block the program's access to the Registry? Yes, UAC can. It was introduced with Vista but changed somewhat with Win7. Turn it off and see if that makes a difference.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|

|
I don't think UAC is the answer. I looked at my UAC settings and didn't see anything other than how to set the warning levels. Mine is set to: "Default: Notify me only when programs try to make changes to my compputer". Even with this setting my program never causes the UAC to display the notification. I think the problem lies in the Registry p0ermission settings, but I don't know yet.
|
|
|
|

|
You should be looking at the customer's settings, not your own. That's where the problem is.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|

|
I KNOW I sould be looking at the customer's setting. The problem is that I'm not getting any support from him. So, I need to understand the settings on my computer so I can run some tests and make suggestions to him. My problem is that I'm not very well versed in "security" settings in Windows 7. I still think it is a user permission setting in Registrey - but I'm not sure where to look yet.
|
|
|
|

|
Member 9199754 wrote: Are there any user account settings or permissions that can block the program's
access to the Registry?
Yes.
Member 9199754 wrote: The program settings are either not being read from the Registry or are not
being written to the Registry. I think the settings are not being
written – but I don't know that
You should look into logging, just as a general programming idiom. With logging you would know, rather than attempting to guess, what was happening.
|
|
|
|

|
jschell wrote: With logging you would know, rather than attempting to guess, what was happening
Wise words indeed.
|
|
|
|

|
Well, this is what I have found so far. The Registry key permission setting does indeed stop my program from writing to its Registry key. On my two WinXP and my Win7 systems the Registry key permissions are set to "full control". Registry editor does not allow me to manually change the "full control" permission to "Read". The "full control" permission is checked but disabled (dimmed) so I can't change it and I don't know why. I had to find a utility that changed the permission outside of registry editor. When the key permission was changed to "read" then writing to the Registry failed. CWinApp:WriteProfileInt() fails with a "read" permision but there is no error code associated with the failure (i.e. GetLastError() doesn't return an error code). I think the only thing I can do is detect the Registry write failure, report it to the user, and use an INI file instead of the Registry. I don't particularily like it but I think that's my only choice.
|
|
|
|

|
When changing permissions on registry keys using regedit, make sure you select your user name to see which permissions you have. Programmatic changes to the registry are done using either your user account or the system user account, or some similar named account on the system. My bet is that the read or write permission is not set for all the accounts on your system. This is easy to check, open your regedit, navigate to the key in question, right click the key, select permissions. This should show a registry permissions dialog. Select each user account on the top section of the dialog and watch how the related permissions change for the different accounts. When you find the account with the missing permission, you will have your culprit. Hope this helps.
|
|
|
|

|
I'm wanting to batch edit the ID3V2 tags in around 1660 CDs worth of tracks, as I have metadata stored elsewhere.
Part of this process involves adding a APIC tag with the contents of a JPEG file.
Now, I have jumped through the various hoops to get everything working except one thing, namely, the artwork. Everything else (genre, album, track number, etc) work fine, and the tags are visible to iTunes and Windows Media Player. However, I am stumped as to how to add the artwork
I thought that the sequence
TagLib::MPEG::File f(filename);
TagLib::ID3v2::Tag*t = f.ID3v2Tag();
TagLib::ID3v2::AttachedPictureFrame* pF = new TagLib::ID3v2::AttachedPictureFrame();
pF->setData(jpegData);
pF->setMimeType("image/jpeg");
pF->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover);
t->addFrame(pF);
f.save(TagLib::MPEG::File::ID3v2,false,3);
should work, but it does not save my artwork
If anyone has working C++ code that does work, I'd be very grateful.
Steve S
Developer for hire
|
|
|
|

|
(cough)
Actually, it works properly when you remember to call the right member function.
Instead of pF->setData(...), I should have called pF->setPicture(...)
Sigh. That's another hour's debugging time I'll never get back, for want of proper reading of the underlying code....
Steve S
Developer for hire
|
|
|
|

|
The jpeg image is bigger than the Picture Control, and the jpeg file is in the local disk. It is no problem to show jpeg image, I can use the CImage to load the jpeg image and then user Picture Control's SetBitmap() method to display this image.
But how to zoom to display this jpeg?
|
|
|
|

|
Maybe this[^] article might help.
|
|
|
|

|
Thank you jeron1,
I set the Picture Control's Type property as "Frame", and then use the Graphic to Graphics's DrawImage to draw iamge.
+5
|
|
|
|

|
If you only need the image to fit the window (without adding zoom in and zoom out capabilities), just set the image control attribute "Real Size Image" to FALSE.
|
|
|
|

|
how i open and use glut project in code blocks
|
|
|
|
|

|
who to create exe file in code blocks?
|
|
|
|

|
compile and link source code... the result is an exe file...
|
|
|
|

|
Huh?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|

|
Hi, I want to know what compiler does WDK 7 use to compile files when we try to build any WDK sample?
Regards
msr
|
|
|
|
|

|
Hi,
I am using a modal dialog box to gather some inforamtion one the peices of info I need is
a filename so in myokhandler I invoke CFileDialog I get an exception when I do the the domdal
My question is can invoke a modal whtin a modal and if so what is the parent window
Thanks
|
|
|
|

|
of-course yes. You can invoke a modal dialog from another modal dialog. Coming to your problem there is something wrong with the usage of CFileDialog. can you paste the complete exception stack/message so that we can able find what went wrong.
I took this sample from here[^] hope you are doing the same. if not give a try.
CFileDialog dlgFile(...);
...
CString fileName;
dlgFile.GetOFN().lpstrFile = fileName.GetBuffer(<very large number&>);
dlgFile.GetOFN().nMaxFile = <very large number >;
INT_PTR nResult = dlgFile.DoModal();
fileName.ReleaseBuffer();
Read these lines carefully
The destruction of CFileDialog objects is handled automatically. It is not necessary to call CDialog::EndDialog.
To allow the user to select multiple files, set the OFN_ALLOWMULTISELECT flag before calling DoModal. You need to supply your own filename buffer to accommodate the returned list of multiple filenames. Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal.
When the user allocates their own buffer to accommodate OFN_ALLOWMULTISELECT, the buffer can't be larger than 2048 or else everything gets corrupted (2048 is the maximum size).
Additionally, you must set m_ofn.nMaxFile with the number of characters in the buffer pointed to by m_ofn.lpstrFile. If you set the maximum number of files to be selected to n, the necessary buffer size is n*(_MAX_PATH + 1) + 1.
|
|
|
|

|
Thanks for the suggestion however I am still getting an exception on the CFileDialog.Domodal
Here is the the code from the main window when a user selects Debug Program the following
ON_COMMAND handler is invoked
Cprogdialog progdlg(this);
nRet = progdlg.DoModal();
return;
}
Then the follwing code is the on okay handler to this modal dialog box
void Cprogdialog::Process()
{
UpdateData(TRUE); CFileDialog dlg(TRUE, _T("asm"), _T("*.asm"), NULL);
dlg.m_ofn.lStructSize = sizeof(OPENFILENAME);
dlg.m_ofn.lpstrFilter = (LPCTSTR)"*.asm,*.cbl,*.c";
dlg.m_ofn.lpstrInitialDir = (LPCTSTR)"F:\\";
dlg.m_ofn.lpstrTitle = (LPCTSTR)"Program Source Code";
dlg.m_ofn.lpstrFile = new char[50];
dlg.SetParent(this);
if (dlg.DoModal() == IDOK)
AfxMessageBox((LPCTSTR)"Waiting for program " || (LPCTSTR)progname || (LPCTSTR)" In JobName " || (LPCTSTR)jobname,MB_OK);
The exception occurs at dlg.DoModal
Thanks again
|
|
|
|

|
There are many problems in your code.
The main problem that I see is the typecast to LPCTSTR.
I've said it before and I will say it again - Typecasting is evil.
Here is a sample code that you can use to correct your mistakes -
CFileDialog fOpenDlg(TRUE, L"txt", L"",
OFN_FILEMUSTEXIST|OFN_EXPLORER|OFN_HIDEREADONLY ,
L"All Image Files (*.jpg;*.jpeg;*.bmp;*.png)|*.jpg; *.jpeg; *.bmp ; *.png|Bitmap Files (*.bmp)|*.bmp|PNG Files (*.png)|*.png|JPEG Files (*.jpg;*.jpeg)|*.jpg; *.jpeg||", this);
fOpenDlg.DoModal();
|
|
|
|
 |