|
See this series.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello,
I am trying to load a bitmap into one of my dialog boxes in the program I am coding. I have found much help in this area provided that the file I am going to load is already defined as a resource. However, my problem is that the *.BMP that I have to load will be selected by the user. I was wondering if anyone could give me a little instruction on how I am able to take a Bitmap from a *.BMP whose properities I am unaware of and get it to appear in the dialog box.
Thank you,
Joe
|
|
|
|
|
take a look at ::LoadImage
|
|
|
|
|
Yes I understand that Load Image is the function I am going to be using, however, it returns a HANDLE, can I cast that as an HBITMAP and just move on?
|
|
|
|
|
yep. it's a HANDLE because you can load cursors and icons with that function, too. but, if you're using the IMAGE_BITMAP flag, you get a HANDLE to a bitmap (aka HBITMAP) back.
|
|
|
|
|
Ok but when I load a BMP from a file, it has to be a DIB? Could you possibly point out what doesn't seem to work here?
BOOL LoadBitmapFromBMPFile( LPTSTR szFileName, HBITMAP hBitmap,HPALETTE hPalette )
{
BITMAP bm;
//*phBitmap = NULL;
//*phPalette = NULL;
// Use LoadImage() to get the image loaded into a DIBSection
hBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_LOADFROMFILE );
if (hBitmap == NULL )
return FALSE;
// Get the color depth of the DIBSection
GetObject(hBitmap, sizeof(BITMAP), &bm );
// If the DIBSection is 256 color or less, it has a color table
if (( bm.bmBitsPixel * bm.bmPlanes ) <= 8 )
{
HDC hMemDC;
HBITMAP hOldBitmap;
RGBQUAD rgb[256];
LPLOGPALETTE pLogPal;
WORD i;
// Create a memory DC and select the DIBSection into it
hMemDC = CreateCompatibleDC( NULL );
hOldBitmap = (HBITMAP)SelectObject( hMemDC, hBitmap );
// Get the DIBSection's color table
GetDIBColorTable( hMemDC, 0, 256, rgb );
// Create a palette from the color tabl
pLogPal = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY)) );
pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = 256;
for (i = 0 ; i < 256 ; i++)
{
pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
pLogPal->palPalEntry[i].peFlags = 0;
}
hPalette = CreatePalette( pLogPal );
// Clean up
free(pLogPal);
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);
}
else // It has no color table, so use a halftone palette
{
HDC hRefDC;
hRefDC = GetDC( NULL );
hPalette = CreateHalftonePalette( hRefDC );
ReleaseDC( NULL, hRefDC );
}
return TRUE;
}
Thanks a bunch in advance,
Joe
|
|
|
|
|
TheDelChop wrote: Ok but when I load a BMP from a file, it has to be a DIB?
nope. you can read it to a 'normal' HBITMAP.
TheDelChop wrote: Could you possibly point out what doesn't seem to work here?
the hBitmap and hPalette parameters should probably be references or pointers, if you want to set them so the calling function can use them.
|
|
|
|
|
Assuming that the resourse IDB_BITMAP1 is stored in C:\BITMAP1.BMP, any difference on what these two functions will return?
hbm = (HBITMAP)LoadImage(NULL,"C:\BITMAP1.BMP",IMAGE_BITMAP,0,0, LR_LOADFROMFILE);
hbm = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
|
|
|
|
|
|
The returned handle is ALWAYS a DDB if you dont set the flag LR_CREATEDIBSECTION and a DIB if u do set the flag. So, if your working on 24+ bits per pixel display you dont even have to worry abou the palette and other stuff.. just load it and enjoy
Peace!
|
|
|
|
|
If you want to load file you can use LoadImage or CImage class
|
|
|
|
|
In my application (which is running fine except one warning) a main sdi window creates a modeless dialog when user selects an option from menu. If the modeless option is not created there is no warning but if modeless dialog is created then the above warning is shown at the end of program in output window. It means it has something to do with modeless dialog, but i cant figure it out.
please help.
|
|
|
|
|
That message is normally shown when you have a menu or toolbar command that does not have a message line associated with it. Normally when you create a command, you also specify a line of text to be shown on the Status Bar, and the framework automatically looks this up (as a String Table entry with the same ID as the command) and use it.
Try making sure that all menu/TB commands text in their "Prompt:" field (on VC6, not sure what it is called in VS.Net).
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
I have a CString loaded with a RGB value (255,0,0 or 0,255,00, etc). I am trying to parse out the three parts into three int variables to use in a RGB() function. Is there an easy way to do this in MFC?
-- modified at 11:33 Thursday 28th September, 2006
|
|
|
|
|
|
The CString class has the Tokenize function that you can use to parse the comma-separated strings. You will need to convert the individual value strings to integers yourselft though (_ttoi()??).
I Dream of Absolute Zero
|
|
|
|
|
efriese1 wrote: Is there an easy way to do this in MFC?
Sure, just use AfxExtractSubString() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Well, if you want to drop down to the RTL, you can use sscanf(...) and its variants to scan the values out.
int iRed = 0;
int iGreen = 0;
int iBlue = 0;
int iTokens = ::_stscanf( _T( "255,0,0" ), _T( "%d,%d,%d" ), &iRed, &iGreen, &iBlue ); That should scan the three values into the three variables.
Generally, if you can build a string using sprintf(...) you can scan it using scanf(...) .
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hello,
is it possible to create an Button or Button's for an MSAccess.mdb ?
I think it is to use ActiveX?
Is there any Tutorial's or democode ?
Thanks for Tip's an Help.
Greating from Bremen (Ger)
Fanker
|
|
|
|
|
I think you will have to explain furthur exactly what you mean by this. I mean what exactly is this button to do? Launch msaccess with some file? Actually view and modify a database?
John
|
|
|
|
|
Hi John,
thank for your answer. I mean it general: Some button to open Forms, ok-button to save input's in database and view, modify database.
I will have the same button in my forms, without to copy the button in each form of the Access.mdb. I hope also to create my own button - looks like better than Access-button.
The method(on-click, dblclick) for the button should be in the Access-VBA.
Thanks a lot for your time.
Fred
|
|
|
|
|
01fanker wrote: I hope also to create my own button - looks like better than Access-button.
Search Office ActiveX controls http://www.codeproject.com/com/officeatlprint.asp[^] is an example.
What is it about the standard buttons in Access you don’t like? As memory serves they are highly customizable. I believe the office controls can also be sub-classed in vb (which would be much easier than creating an add in which would need to be installed on the target machines).
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
i wonder if someone can help me with the creaion of a COM object. I am trying to
I am trying to create an object of CDOMessage but am failing at the 1st hurdle.
Firstly, information about the COM object can be found here.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/c138a402-4842-4bb3-988e-43cb9917e94b.asp
At the bottom of the page the example has VB and C++ mixed in one but the c++ example looks like this:
<br />
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only<br />
#import <cdosys.dll> no_namespace raw_interfaces_only<br />
#include <cdosysstr.h>
#include <iostream.h><br />
<br />
main(){<br />
CoInitialize(NULL);
IMessage* pMsg = NULL;<br />
<br />
HRESULT hr = CoCreateInstance(__uuidof(Message),<br />
NULL,<br />
CLSCTX_INPROC_SERVER,<br />
__uuidof(IMessage),<br />
reinterpret_cast<void**>(&pMsg));<br />
However when i try to compile the above code i get the error:
Error 1 error C2065: 'IMessage' : undeclared identifier c:\c++localprojects\cdomessage\cdomessage\cdomessagedlg.cpp 103
Now if i fire up OLE/COM Viewer that you get with Visual Studio and do a search in "All Objects" for CDOMessage i find
that it is all registered ok with my system.
notice in the example above __uuidof & __uuidof is being used. I have not come across these before so went about calling
CoCreateInstance the normal way passing interface id's and class id's
for example here is a call from a com intro article here on cp: http://www.codeproject.com/com/comintro.asp
<br />
HRESULT hr;<br />
IShellLink* pISL; <br />
<br />
hr = CoCreateInstance ( CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void**) &pISL );
Now for me to create a CDOMessage COM object i need know:
1) the CLSID of the coclass
2) the IID (interfaceid)
3) an interface pointer
however using OLE/COM Viewer the CLSID is {CD000001-8B95-11D1-82DB-00C04FB1625D} instead of a readable form like CLSID_ShellLink.
Is it ok for me to just pass through CD000001-8B95-11D1-82DB-00C04FB1625D?? Secondly, OLE/COM Viewer does not show me the IID for me
to pass through.. And finally what interface pointer should i use?
|
|
|
|
|
flippydeflippydebop wrote: Error 1 error C2065: 'IMessage' : undeclared identifier
this compiles without error for me. Are you sure there is not a previous error about not finding a file or something?
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include <cdosysstr.h>
class CDOTest
{
CDOTest()
{
IMessage* pMsg;
HRESULT hr = CoCreateInstance(__uuidof(Message),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IMessage),
reinterpret_cast<void**>(&pMsg)); }
};
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|