|
Use CreateProcess and set the wShowWindow member of the STARTUPINFO member to SW_HIDE.
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I have a download function that returns the contents in a CString (it mostly downloads text), for simplicities sake I would like to use it to download JPGs (binary content) how can I get the binary contents from teh download function without messing it up when it downloads text and be able to send it to WriteBinaryToFile as the correct size.
CString Download(CString m_strURL); //returns the content
void WriteBinaryToFile(CString m_strFileName, CString m_strFileContents);
(this is specifies the binary flag in the CFile options)
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
Steve,
Please be aware that if the file contents contains a zero (null) within the contents, then CString will only give you contents upto the null value.
Do you know the lengths of the files you're downloading?
If I was you, I'd look at CHttpFile. Here's the MSDN link.
Hope this helps,
Andy
|
|
|
|
|
You should not use binary value with CString, must use a buffer of TCHAR to collect the info.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Personally, I would modify your Download function to return an object, something like the following:
class DownloadObject {
public:
DownloadObject(char *text);
DownloadObject(unsigned char *data,int size);
~DownloadObject();
enum Type { Text, Binary };
Type GetType() const;
bool GetAsText(CString &text) const;
bool GetAsBinary(unsigned char **binary,int *size);
private:
Type _Type;
unsigned char *_Data;
int _Size;
}; This object contains an arbitrary sequence of bytes, that the creator of the object (e.g. the Download function) can specify to be of type 'Text' or 'Binary'. The creator specifies the type of object based on which constructor he uses. When the object is returned to the caller of the Download function, that function can determine the type of data using the supplied member functions, something like this:
DownloadObject *Download(CString URL);
DownloadObject *object = Download(example_URL);
CString text;
unsigned char *data;
int size;
if (object != NULL) {
switch (object->GetType()) {
case DownloadObject::Text:
object->GetText(text);
break;
case DownloadObject::Binary:
object->GetBinary(&data,&size);
break;
}
delete object;
} Note that I've modified the definition of the Download function to return a pointer to a DownloadObject. If the return value is NULL, that can be an error indication.
I think this is a better approach than overloading the CString class. While CString does let you store binary data of arbitrary length which includes '\0' characters, it's primary purpose is to hold text data. Using it to contain binary data confuses the programmers who come after you.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote:
Using it to contain binary data confuses the programmers who come after you.
Hehehehe (evil grin)
I'll have to go about it this way (the object route). Thanks!
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
Does the default CIMageList support 32 bpp images?
I have tried using a 32 bpp image and the background comes out black all the time, no matter what flags I use
How does IE 6 (XP anyways) render it's toolbar so nicely?
Any ideas
Cheers
How do I print my voice mail?
|
|
|
|
|
Hockey wrote:
How does IE 6 (XP anyways) render it's toolbar so nicely?
Its XP theme.
I guess its got to do with Manifest. There are few articles discribing how to use it.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
I do not know about CIMageList, but usualy when an image comes out black there it an error in the code; these can be frustrating to solve.
INTP
|
|
|
|
|
Hey,
Im working on a menu-type dialog-based program. Basically, the user can select a button and it'll run a program. The user can define what program to run by clicking Browse for each button.
What I have is a dialog box with 2 buttons, Run "CFloatDlg::OnRun()", and App1 "CFloatDlg::OnApp1()". Here is my code:
void CFloatDlg::OnApp1()
{
CFileDialog fd(TRUE,"exe",NULL,OFN_HIDEREADONLY,
"Programs (*.exe)|*.exe|All Files (*.*)|*.*||",this);
if (fd.DoModal() == IDOK)
{
m_sFilename = fd.GetPathName();
UpdateData(FALSE);
}
}
void CFloatDlg::OnRun()
{
_execlp(m_sFilename, NULL);
}
When the user clicks the App1 button, the open commondialog opens and the user can select an .exe. Then the user clicks run, and the program is executed. The program itself also closes.
How can I make the program save, (internal or external), what the user has selected so that the program selected will be there each and everytime until the user changes it? Also, how can I make it so that the dialog does not close when another program is executed from it?
P.S.: I just wanted to thank everyone for all their work and time here. I've been quiet here, but I love all the code. Everyone is doing awesome work. I do plan on providing back to the community with my own code soon. Thanks to all.
DNFSB
|
|
|
|
|
DNFSB wrote:
Also, how can I make it so that the dialog does not close when another program is executed from it?
how is OnRun called?
in OnRun are you calling baseclass OnOk()??
Your code is incomplete to discribe your problem.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
My OnRun is just:
_execlp(m_sFilename, NULL);
when the user clicks the that button, the m_sFilename selection is ran, but the dialogbox that the button is on closes as the m_sFilename is ran.
DNFSB
|
|
|
|
|
Hey,
Got another question about Menus, I have the menu and it works fine, but I created a New function, and I know in Non Dialog based options it has it done for you already, in Dialog ones, how do you have it reload the program so it is new, after clicking on the new option ni the menu.
Thanks
|
|
|
|
|
I've written a background UI COM plugin for WMP9 that does some neat stuff, but I've been hobbled somewhat by the apparent lack of a way to respond to keyboard commands. No way I've tried has worked, including creating a worker thread and calling GetAsyncKeyState. Is there something that I might be missing, or will I have to resort to keyboard hook (like "An All-Purpose Keyboard Hooker")?
|
|
|
|
|
|
That was the first thing I tried: that function is never called! To see for yourself if you want, use the wizard and make a UI/Background plugin for WMP. It's never called, possibly because it's a "background" plugin?
|
|
|
|
|
Not knowing anything about WMP9, but could you possibly hijack the window message handler for the main application window to intercept all the messages it is getting? You could respond to the ones you wanted and call the regular window handler for those you did not want?
|
|
|
|
|
I have no idea how I'd go about doing that, though; my plugin never gets a HWND.
I've actually worked around the no-hotkey problem by intuitively tying the function (don't skip this commercial) to the seekbar: if the user seeks twice inside a section containing a commercial within a few seconds, that commercial section is internally ignored.
|
|
|
|
|
Hello.
I have posted a question about this before but i wrote it bad. So i try again.
I'm working with a program that storage BMP and WAV files in one file. I'm almost finished with it but I want to make it show BMP files directly from the packed file without extracting it.
I have tried many times but I can't make function to put BITMAPINFOHEADER and BITMAPINFO correct data.
///////////////////////////////////////////////////////////////////////////////
LPTSTR szFileName = "C:\\Min Projekt\\MittPixelTest\\3_16.bmp";
CFile test;
test.Open(szFileName, CFile::modeRead);
DWORD m_nMaxSize = test.GetLength();
void *pBuf = (BYTE *) malloc(sizeof(BYTE) * m_nMaxSize);
test.ReadHuge((LPVOID) pBuf, m_nMaxSize);
LoadBMPImage(pBuf, m_nMaxSize, myBmp, &myPalette);
///////////////////////////////////////////////////////////////////////////////
BOOL CMyArchiveDlg::LoadBMPImage(void* vBits, DWORD len, CBitmap &bitmap, CPalette *pPal)
{
BITMAPFILEHEADER bmfHeader;
// Read file header
if (!memcpy((LPSTR)&bmfHeader, vBits, sizeof(bmfHeader)))
return FALSE;
// File type should be 'BM'
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
return FALSE;
// Get length of the remainder of the file and allocate memory
DWORD nPackedDIBLen = len - sizeof(BITMAPFILEHEADER);
HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nPackedDIBLen);
if (hDIB == 0)
return FALSE;
// Read the remainder of the bitmap file.
if (!memcpy((LPSTR)hDIB, vBits, nPackedDIBLen))
{
::GlobalFree(hDIB);
return FALSE;
}
BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ; // Gets wrong data
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;
// If bmiHeader.biClrUsed is zero we have to infer the number
// of colors from the number of bits used to specify it.
int nColors = bmiHeader.biClrUsed ? bmiHeader.biClrUsed :
1 << bmiHeader.biBitCount; // Color value is to high!!
LPVOID lpDIBBits;
if( bmInfo.bmiHeader.biBitCount > 8 )
lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) +
((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
else
lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);
// Create the logical palette
if( pPal != NULL )
{
// Create the palette
if( nColors <= 256 )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries = nColors;
for( int i=0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = bmInfo.bmiColors[i].rgbRed;
pLP->palPalEntry[i].peGreen = bmInfo.bmiColors[i].rgbGreen;
pLP->palPalEntry[i].peBlue = bmInfo.bmiColors[i].rgbBlue;
pLP->palPalEntry[i].peFlags = 0;
}
pPal->CreatePalette( pLP );
delete[] pLP;
}
}
CClientDC dc(NULL);
CPalette* pOldPalette = NULL;
if( pPal )
{
pOldPalette = dc.SelectPalette( pPal, FALSE );
dc.RealizePalette();
}
HBITMAP hBmp = CreateDIBitmap( dc.m_hDC, // handle to device context
&bmiHeader, // pointer to bitmap size and format data
CBM_INIT, // initialization flag
lpDIBBits, // pointer to initialization data
&bmInfo, // pointer to bitmap color-format data
DIB_RGB_COLORS); // color-data usage
bitmap.Attach( hBmp ); // Here it's stops. Debug error!
if( pOldPalette )
dc.SelectPalette( pOldPalette, FALSE );
::GlobalFree(hDIB);
return TRUE;
}
I guess I use wrong type to put bitmap data but if anyone knows what's wrong with this function it would be great
|
|
|
|
|
First:
if (!memcpy((LPSTR)hDIB, vBits, nPackedDIBLen))
well normaly I would have called GlobalLock() to get the pointer, but hDIB is realy a pointer so this should work ( LPSTR should be LPVOID ).
The problem with the line is that vBits points to the start of the buffer, where the BITMAPFILEHEADER is stored and you are trying to copy the information following it:
if (!memcpy((LPSTR)hDIB, (LPBYTE)vBits + sizeof(BITMAPFILEHEADER), nPackedDIBLen))
That should fix the following:
BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ; // Gets wrong data
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;
(interesting use of references!)
Try takeing a look at the CDibData article; I wrote the class so that it could take a handle to a DIB (see CDibData::Attach()) just like the clipboard.
INTP
|
|
|
|
|
Hi!
I keep getting a "User Breakpoint called from code at 0x......." I do not have any breakpoints set, but my execution seems to keep halting.
I notice if i comment out a few function function calls, my program works ok. So it seems like this error occurs when my DLL becomes a certain size.
I've never seen this before and dont know where to start trying to figure out where/how to debug it. I'm not doing anything fancy: My project is a multithreaded dll, using MFC as a shared dll. I have classes defined w/ normal inheritance and I'm including version.lib and ws2_32.lib for libraries.
I've never seen my execution simply halt. Any help would be GREATLY appreciated!! TIA.
-C
|
|
|
|
|
what about using a debugger to trace the breakpoint? it is prolly a simple assert statement.
Don't try it, just do it!
|
|
|
|
|
Apparently CFormView doesn't handle Keyboard Accelerators. that is until you have selected a form element like a textbox or list. But since I would rather have the formview recognize an accelerator without having to go in this direction is there a way I can work around this.
I have this solution, but I don't think it is working the way it should or perhaps is the wrong solution. In a nutshell I have the following code which when a document in opened and the form appears, OnInitialUpdate() is called and I call LoadAccelerators and load the handle into a variable. Later I override PreTranslateMessage() and check for this handle then call ::TranslateAccelerator() which I'm thinking takes in a window handle, thus I used my main window handle where at the accelerator keys work, the accelerator handle then the message. Here is the code.
void CFormGameOnView::OnInitialUpdate()
{
m_haccel=LoadAccelerators(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_FORMGAMEONVIEW_TMPL));
...
}
BOOL CFormGameOnView::PreTranslateMessage(MSG* pMsg)
{
CMainFrame *pMain = (CMainFrame*)AfxGetMainWnd();
if(m_haccel)
{
if(::TranslateAccelerator(pMain->m_hWnd, m_haccel, pMsg))
return TRUE;
}
return CFormView::PreTranslateMessage(pMsg);
}
Is this the right approach or is there a better approach?
Thanks!
|
|
|
|
|
I've never posted in this board before. This is actullay the first time i've clicked on it.
Anyways, I was reading that in C# the only way to get parallel port access in Windows XP is via a kernal mode driver. Now, I did this and it worked fine.
But, i'm messing around with C, right now and I was using the _inp and _outp functions in conio.h
So, here's my question: Can I get hardware access directly with C in windows XP? Like on 95 and 98 where I can just to _outp and it goes to whatever port I say.
/\ |_ E X E GG
|
|
|
|
|
In case of C too you need a kernel mode driver in win2k and xp
|
|
|
|