|
HICON hICon = AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION);<br />
PICTDESC pictDesc;<br />
pictDesc.cbSizeofstruct = sizeof(PICTDESC);<br />
pictDesc.icon.hicon = hICon;<br />
pictDesc.picType = PICTYPE_ICON;<br />
IPicture *pPicture = NULL;<br />
IStorage *pStg = NULL;<br />
IStream *pStream = NULL;<br />
LONG lSize = 0;<br />
<br />
HRESULT hr = OleCreatePictureIndirect(&pictDesc,IID_IPicture,TRUE,(void**)&pPicture);<br />
hr = StgCreateDocfile(L"c:\\My.ico",STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,0,&pStg);<br />
hr = pStg->CreateStream(L"icoStream",STGM_CREATE |<br />
STGM_WRITE |<br />
STGM_DIRECT |<br />
STGM_SHARE_EXCLUSIVE ,0,0,&pStream);<br />
hr = pPicture->SaveAsFile(pStream,TRUE,&lSize);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
BMP approach HICON -> BMP
// IconTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void WriteBMPFile(HBITMAP bitmap, LPTSTR filename, HDC hDC)
{
BITMAP bmp;
PBITMAPINFO pbmi;
WORD cClrBits;
HANDLE hf; // file handle
BITMAPFILEHEADER hdr; // bitmap file-header
PBITMAPINFOHEADER pbih; // bitmap info-header
LPBYTE lpBits; // memory pointer
DWORD dwTotal; // total count of bytes
DWORD cb; // incremental count of bytes
BYTE *hp; // byte pointer
DWORD dwTmp;
// create the bitmapinfo header information
if (!GetObject( bitmap, sizeof(BITMAP), (LPSTR)&bmp)){
printf("Could not retrieve bitmap info");
return;
}
// Convert the color format to a count of bits.
cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
if (cClrBits == 1)
cClrBits = 1;
else if (cClrBits <= 4)
cClrBits = 4;
else if (cClrBits <= 8)
cClrBits = 8;
else if (cClrBits <= 16)
cClrBits = 16;
else if (cClrBits <= 24)
cClrBits = 24;
else cClrBits = 32;
// Allocate memory for the BITMAPINFO structure.
if (cClrBits != 24)
pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1<< cClrBits));
else
pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));
// Initialize the fields in the BITMAPINFO structure.
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
if (cClrBits < 24)
pbmi->bmiHeader.biClrUsed = (1<<cClrBits);
// If the bitmap is not compressed, set the BI_RGB flag.
pbmi->bmiHeader.biCompression = BI_RGB;
// Compute the number of bytes in the array of color
// indices and store the result in biSizeImage.
pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 7) /8 * pbmi->bmiHeader.biHeight * cClrBits;
// Set biClrImportant to 0, indicating that all of the
// device colors are important.
pbmi->bmiHeader.biClrImportant = 0;
// now open file and save the data
pbih = (PBITMAPINFOHEADER) pbmi;
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);
if (!lpBits) {
printf("writeBMP::Could not allocate memory");
return;
}
// Retrieve the color table (RGBQUAD array) and the bits
if (!GetDIBits(hDC, HBITMAP(bitmap), 0, (WORD) pbih->biHeight, lpBits, pbmi,
DIB_RGB_COLORS)) {
printf("writeBMP::GetDIB error");
return;
}
// Create the .BMP file.
hf = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, (DWORD) 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
if (hf == INVALID_HANDLE_VALUE){
printf("Could not create file for writing");
return;
}
hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
// Compute the size of the entire file.
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
pbih->biSize + pbih->biClrUsed
* sizeof(RGBQUAD) + pbih->biSizeImage);
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
// Compute the offset to the array of color indices.
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
pbih->biSize + pbih->biClrUsed
* sizeof (RGBQUAD);
// Copy the BITMAPFILEHEADER into the .BMP file.
if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER),
(LPDWORD) &dwTmp, NULL)) {
printf("Could not write in to file");
return;
}
// Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER)
+ pbih->biClrUsed * sizeof (RGBQUAD),
(LPDWORD) &dwTmp, ( NULL))){
printf("Could not write in to file");
return;
}
// Copy the array of color indices into the .BMP file.
dwTotal = cb = pbih->biSizeImage;
hp = lpBits;
if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL)){
printf("Could not write in to file");
return;
}
// Close the .BMP file.
if (!CloseHandle(hf)){
printf("Could not close file");
return;
}
// Free memory.
GlobalFree((HGLOBAL)lpBits);
}
int _tmain(int argc, _TCHAR* argv[])
{
HBITMAP hBitmap;
HICON hIcon = LoadIcon( NULL,IDI_EXCLAMATION);
ICONINFO IconInfo;
GetIconInfo(hIcon, &IconInfo);
BITMAP bm;
GetObject(IconInfo.hbmColor, sizeof(bm), &bm);
HDC hDC= NULL;
HDC dcScreen = ::GetDC(NULL);
hDC = CreateCompatibleDC(dcScreen);
hBitmap = CreateCompatibleBitmap(dcScreen, bm.bmWidth,bm.bmHeight);
::ReleaseDC(NULL, dcScreen);
HBITMAP bmOld = (HBITMAP)SelectObject(hDC, hBitmap);
DrawIcon(hDC, 0, 0, hIcon);
SelectObject(hDC, bmOld);
WriteBMPFile(hBitmap, _T("C:\\bitmaptest.bmp"), hDC );
}
- MATT
|
|
|
|
|
|
System Image List. You have to read the article and study source codes located in this article.
|
|
|
|
|
Is there any program that could tell me on a specified DLL or EXE, in what language it was originally written?
Thanks.
|
|
|
|
|
For example C++ or Delphi,...
|
|
|
|
|
who is given you 1 vote every now or then.. let me square it out again! keep up your good work!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Thnaks again Alok.
|
|
|
|
|
Hi,
I have a window which I want to see as always visible and active to the users. I have placed the window on top portion of the screen. Now I want all other windows(could be any window) below that window. I guess there should be an API which sets a region(boundary) for windows to be placed in. Can some one help me.
Thanks.
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
- Bjarne Stroustrup
|
|
|
|
|
You can set your window to be a topmost window, so all other not topmost window will be under your window!
Use SetWindowPos() API.
|
|
|
|
|
We are preparing to upgrade our C/C++ apps from Visual Studio 6.0 to VS 2005. We have heard that VS 2005 no longer supports the standard C language calls (memcpy, memcmp, strcpy, etc) that we use frequently in most of our source code, and have used since back in the 1980's. Does anyone know if VS 2005 no longer allows these function calls directly?
Thanks, Mike
|
|
|
|
|
|
However, they are not actually deprecated according to the C++0x standard.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Those functions are fine -- they'll generate warnings.
The warning states what the 'better function' is and also how to disable the warning...
Before you decide though, you really should do a test compile under VS2005 to determine what other issues you might run into.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
I posted this in the VS forum, but I guess its more specific to C++...
I'm using VS.NET 2005 and building a large application with about 100 projects.
There is one project in the solution that compiles to a DLL that I need to debug. (i.e. break, and step into the code) However I can't. In the modules tab of the IDE, it says that no symbols have been loaded for that module. I know the pdb is being generated though, has the same filename as my dll, and is being generated in the same directory as the dll. The timestamps match as well, and I'm building the debug configuration.
When I right click on the module in the modules tab and goto "Load Symbols" and point it to my pdb it says that "The symbol file xyz.pdb does not match the module"
What could possibly be going wrong?
|
|
|
|
|
It is possible that the pdb is stripped of its symbols. This is done in deployment to lessen the install footprint. It is also possible that the pdb is not generated from the code that generated the dll.
Pax Domini sit semper vobiscum
|
|
|
|
|
I found the problem,
I had the VTune plugin installed in my VS install, when I removed it, I was able to debug ok. My guess is that the VTune plugin somehow messed up the pdb generation.
|
|
|
|
|
I'm trying to save a file to a fixed location. The would like file to be saved in the same folder as the executable, so I am using a relative path. However, I get mixed results. Sometimes it saves to the proper folder, sometimes to desktop, and sometimes to C:\.
If I use an absolute path, the problem goes away. So my question is whether the path specified when opening the file is required to be absolute? And if so, how can I get an absolute path from a relative path not knowing where the executable will be installed?
Here is my code:
CStdioFile LcfIniFile;
CString LcsTempStr;
if (LcfIniFile.Open("test.ini", CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite | CFile::typeText | CFile::shareDenyWrite))
{
...
LcfIniFile.WriteString(LcsTempStr);
LcfIniFile.Close();
}
Thanks.
Edit: MSDN says path can be relative, absolute, or network name. So now I really don't know what I'm doing wrong.
Edit2: I should also note that reading the file using the relative path did not cause any problems, it was only during write.
-- modified at 15:49 Wednesday 24th October, 2007
|
|
|
|
|
I think it all depends on what the current directory is.
And that all depends on how you run it....
Why not construct an explicit path to the file -- that way you can be sure.
use GetModuleFileName to determine the path of the exe...
split off the name and add "test.ini"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
How do I terminate my CWinThread from my main UI thread -- without blocking anything.
I was thinking I'd try something like:
PostThreadMessage( WM_QUIT, 0, 0 );
MSG msg;
while( PeekMessage(&msg, NULL, 0,0, PM_REMOVE ) )
{
if ( WaitForSingleObject(m_hThread,0) == WAIT_OBJECT_0 )
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
But that doesn't seem to work...
Any suggestions?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
or what about:
if I set m_bAutoDelete to FALSE
and:
PostThreadMessage( WM_QUIT, 0, 0 );
while ( PumpMessage() )
{
if ( WaitForSingleObject(m_hThread,0) == WAIT_OBJECT_0 )
break;
}
delete this;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
An example:
In your class which creates the thread:
private:
HANDLE m_StopThread;
HANDLE m_WaitThread;
static UINT ThreadFunction(LPVOID pvParam);
When you create your thread:
// Create events
m_StopThread = CreateEvent(0, TRUE, FALSE, 0);
m_WaitThread = CreateEvent(0, TRUE, FALSE, 0);
// Start thread
AfxBeginThread(ThreadFunction, this);
When you want to terminate the thread:
// Trigger thread to stop
::SetEvent(m_StopThread);
// Wait until thread finished
::WaitForSingleObject(m_WaitThread, INFINITE);
// Close handles
::CloseHandle(m_StopThread);
::CloseHandle(m_WaitThread);
//Your thread procedure
UINT CFoo::ThreadFunction(LPVOID* pvParam)
{
CFoo *pParent = static_cast<cfoo*>(pvParam);
while(true)
{
// Check event for stop thread
if(::WaitForSingleObject(pParent->m_StopThread, 0) == WAIT_OBJECT_0)
{
// Set event
::SetEvent(pParent->m_WaitThread);
return 0;
}
// Do your processing
}
}
Hope this helps you out!
|
|
|
|
|
That will only work if the thread has a message pump - i.e. is created as a UI thread. If it is a worker thread, I usually do the following (error checking removed for the sake of brevity):
in the main UI thread:
m_hTermEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
m_pThread = AfxBeginThread (ThreadFunction, &m_hTermEvent);
SetEvent (m_hTermEvent);
WaitForSingleObject (m_pThread->m_hThread, INFINITE);
in the worker thread:
UINT __cdecl ThreadFunction( LPVOID pParam )
{
HANDLE hEvent;
hEvent = *((HANDLE *) pParam);
while (true)
{
if WaitForSingleObject (hEvent, 0) == WAIT_OBJECT_0)
break;
};
return 0;
}
Judy
|
|
|
|
|
That is NOT the case. This works as it should for worker threads!
Please, show me what in my code would not work!
|
|
|
|
|
pierre_ribery wrote: That is NOT the case. This works as it should for worker threads!
Please, show me what in my code would not work!
Calm down dude. No need to get snippy. I wasn't responding to your post, I was responding to the original poster. The presence of my post does not imply that yours is wrong. If you'll check the time stamp, we were posting at the same time. Your post didn't exist when I started mine.
Judy
|
|
|
|
|