|
Toni78 wrote:
//wincl.cbSize = sizeof (WNDCLASSEX);
//wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wow. As you say, it was very ugly and so I only skimmed it, but I'm still amazed I missed an error like that !!!
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
Christian Graus wrote:
wow. As you say, it was very ugly and so I only skimmed it, but I'm still amazed I missed an error like that !!!
I still like your signatures.
Come on, everyone would have missed those errors! It's the format. It was just pure luck for me to spot comment lines at a place where they normally shouldn't be.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
I have the Petzold book ,the book include this code. I studying this book .As Toni78 say,my program runs well,I thinked your for your reply. thinks!
Welcom come to china.
I am like programing
|
|
|
|
|
Just to reiterate - Petzold style Windows programming is more complex and more difficult than MFC. Very few people do it that way today. MFC is not perfect, but it's a lot easier than what you're learning, and if you persist in trying to learn from the Petzold book without first learning C++, you will never become a programmer.
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
First,I must know windows system,
I know this point that Very few people do it that way today.As you say ,I know, I need study a lot of thing,(about C++ and VC++),very think you!
I am like programing
|
|
|
|
|
Hi there,
I want to rotate an image and then save it in a file using GDI+. Is that possible? I don't want to draw the rotated image.
Thanks!
|
|
|
|
|
Hi
if you want to make a simple rotation (90, 180, 270 or flip), you can use :
pBmp->RotateFlip(Rotate180FlipNone);
// Rotate180FlipNone is an exemple
if you want to rotate it, use this
Bitmap* Rotate ( Bitmap* pSrcBmp, REAL rRot )
{
int w = pSrcBmp->GetWidth();
int h = pSrcBmp->GetHeight();
Bitmap* pDstBmp = new Bitmap( (w+h)*2, (w+h)*2, PixelFormat32bppARGB );
// (w+h)*2 max width and height, you can optimize it(?)
Graphics graphics(pDstBmp);
graphics.Clear(Color(0,255,255,255));
Pen pen(Color(255, 255, 0, 0));
graphics.TranslateTransform((REAL)w+h, (REAL)w+h);
graphics.RotateTransform(rRot);
graphics.DrawImage(pSrcBmp, 0, 0);
return pDestBmp;
}
save this image with
{
GetCodecClsid(L"image/tiff", &mClsid);
// you can use L"image/jpeg", L"image/gif", ...
pBmp->Save(L"img.tif", &mClsid);
}
int GetCodecClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
return j; // Success
}
} // for
return -1; // Failure
}
|
|
|
|
|
Thanks a lot, I got the idea.
|
|
|
|
|
My source file is tif, grayscale, PixelFormat8bppIndexed.
I can't create Graphics object from image with such pixel
format. So I have to use PixelFormat32bppARGB for example.
Can I convert that image to image with 8 bpp indexed pixel
format before I save it in a file? I am concern about the
size of the output file.
Thanks!
|
|
|
|
|
you can use this code (with some -fast- asm)
{
Bitmap* pDstBmp = Convert_Bmp32_Bmp8( pSrcBmp );
}
Bitmap* CMdiPrjDoc::Convert_Bmp32_Bmp8( Bitmap *mBmpSrc )
{
int x = mBmpSrc->GetWidth();
int y = mBmpSrc->GetHeight();
Bitmap* mBmpDest = new Bitmap(
x,
y,
PixelFormat8bppIndexed );
SetPaletteGrayScale(mBmpDest);
BitmapData bitmapData, tBitmapData;
Rect rect(0, 0, x, y);
BYTE *pixels;
DWORD *tPixels;
mBmpDest->LockBits(
&rect,
ImageLockModeWrite,
PixelFormat8bppIndexed,
&bitmapData);
mBmpSrc->LockBits(
&rect,
ImageLockModeRead,
PixelFormat32bppARGB,
&tBitmapData);
pixels = (BYTE*)bitmapData.Scan0;
tPixels = (DWORD*)tBitmapData.Scan0;
DWORD rD;
int iLineJmp, iTLineJmp;
for(UINT yi=0; yi<y; yi++)
="" {
="" ilinejmp="yi" *="" bitmapdata.stride;
="" itlinejmp="(yi" tbitmapdata.stride)="" 4;
="" for(uint="" xi="0;" xi<x;="" xi++)
="" rd="tPixels[" +="" xi];
="" __asm
="" xor="" ebx,="" ebx;
="" mov="" eax,="" rd;
="" bl,="" al;
="" shr="" ax,="" 8;
="" add="" bx,="" ax;
="" 16;
="" and="" 00ffh;
="" rd,="" }
="" pixels[="" xi]="(BYTE)(rD/3);
" mbmpsrc-="">UnlockBits(&tBitmapData);
mBmpDest->UnlockBits(&bitmapData);
return mBmpDest;
}
void SetPaletteGrayScale(Bitmap* pBmp)
{
if(!pBmp) return;
ColorPalette* cp = (ColorPalette*)malloc(sizeof(ColorPalette)+256*4);
cp->Flags = PaletteFlagsGrayScale;
cp->Count = 256;
DWORD argb;
BYTE b;
for(int i=0; i<256; i++)
{
b = i;
_asm
{
mov ah, 255
mov al, b
shl eax, 16
mov ah, b
mov al, b
mov argb, eax
}
cp->Entries[i] = argb;
}
pBmp->SetPalette(cp);
free (cp);
}
|
|
|
|
|
I just started C++ not more than a few days ago, and I'm familiar with the input, output, and string functions. I want to learn how to work with the registry through a C++ application, and I've looked everywhere on the Internet for a simple explanation! -- But, no luck. All I can find are these complicated guides that "assume" the reader already knows a ton about working with the registry in C++.
This is what I want to learn how to do:
1) Write a key (and it's value) to the registry
2) Read the value of a key in the registry
3) Change the value of a key in the registry
If any of you can please write a step-by-step [beginner's] guide to using the registry, or if you already know of one available on the Internet, your help would be GREATLY appreciated.
Thanks.
|
|
|
|
|
One solution is via Win32 API. Here is a good referenc efor registry API.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry_functions.asp
Kuphryn
|
|
|
|
|
(1)(3)RegSetValueEx
(2)RegQueryValueEx
see other functions in msdn:
RegCloseKey
RegConnectRegistry
RegCreateKey
RegCreateKeyEx
RegDeleteKey
RegDeleteValue
RegEnumKey
RegEnumKeyEx
RegEnumValue
RegFlushKey
RegGetKeySecurity
RegLoadKey
RegNotifyChangeKeyValue
RegOpenKey
RegOpenKeyEx
RegQueryInfoKey
RegQueryMultipleValues
RegQueryValue
RegQueryValueEx
RegReplaceKey
RegRestoreKey
RegSaveKey
RegSetKeySecurity
RegSetValue
RegSetValueEx
RegUnLoadKey
|
|
|
|
|
I am working on a COM Object in a non MFC framewrok . I have a Multimedia timer to do the timing . I am unable to access(code crashes ) certain pointers when accessed from the TImer procedure.
Is there are conflict with the Threaded model of the TimerProc thread and is there any initialization that can be done ?
If no can I have something similar to Postmessage that will notfiy my main thread from the Timer proc so that I can carry on Business !!! . IF yes how will the syntax be ?
Please help !
|
|
|
|
|
Yes, messages is one solution given that the process has a message loop.
Kuphryn
|
|
|
|
|
Hello
CSocket of mfc70 and mfc71 works properly under Win98 and WinXP, but have a bug with CSocket::OnReceive() under Win2k.
is there any solution ?
thank you.
|
|
|
|
|
what bug?
return value error?
|
|
|
|
|
Hello
I tested some apps like CHATSRVR/CHATTER (vc++ sample) under win98, winxp and win2k (with mfc70 and mfc71).
on win2k CSocket::OnReceive() receives only 5 to 10 messages, then nothing will be captured.
but if we build the same apps with vc++ 6.0 (mfc42), it will be ok.
thank you.
|
|
|
|
|
Oh, I am still working with VC++ 6.0 (mfc42) and cannot help you. And I have a problem, too. Could you do me a favor?
When I use winsock (CSockect e.g.) to recieve the message of websites by sending "Get ...", majority are no problem but others can't work. I opened these ones in IE, They displayed a Security Alert messagebox with "Information you exchange with this site cannot be viewed or changed by others. However, there is a problem with the site's security certificate."
Why I recieve nothing under this condition?
|
|
|
|
|
I have tried using the select font dialog box to select a font for an edit control and it doesn't work. The edit control goes into the default font. Here's the code i used:
void CDocBar::InitFontDlg()
{
CFont myfont;
LOGFONT lf;
CFontDialog dlgChooseFont;
COLORREF g_rgbText = RGB(0, 0, 0);
CEdit *editControl;
//GetObject(myfont.Detach(), sizeof(LOGFONT), &lf);
dlgChooseFont.m_cf.lpLogFont = &lf;
dlgChooseFont.m_cf.rgbColors = g_rgbText;
if (dlgChooseFont.DoModal() == IDOK)
{
myfont.CreateFontIndirect(dlgChooseFont.m_cf.lpLogFont);
g_rgbText = dlgChooseFont.m_cf.rgbColors;
editControl = (CEdit *) GetDlgItem(IDD_EDIT1);
editControl->SetFont(&myfont, TRUE);
}
}
What could be wrong? I have little experience with fonts.
-- Steve
|
|
|
|
|
It's a scope-problem - make myfont member of CDocBar and I'm pretty sure it'll work.
Regards,
Michael Mogensen, mm it-consult dk.
|
|
|
|
|
Thanks! I hate when these kinds of problems are caused by such a small thing. It works great!
-- Steve
|
|
|
|
|
I have built a program in using VC++ 6.0 that will parse out the URL's from an AOL .pfc(personal filling cabient) file. The .pfc is full of garbage(terminators, little boxes kinda looks like encryption, misc chars, and URL's) The program works just fine on most .pfc files. The problem Im having with some .pfc files are that the program will not read the entire file. I have reason to believe that my troubles lie in the eof(end of file) terminating condition. Here is the code that reads in the file char by char adding it to a string:
if(! inStream.eof()) {<br />
<br />
if(! iscntrl(cSymbol))<br />
m_strBeforeParse += (CString)cSymbol;<br />
<br />
inStream.get(cSymbol);<br />
}
For some reason the eof function is returning "true" when it reaches a certain part of the file. This certain part of the file is the little boxes in the file that I described earlier as what I thought looked like encyrption. If I erase these little boxes, I can read whole filwe just fine. If anyone has any ideas Id be greatful to hear them.
|
|
|
|
|
how are you opening the file? What flags do you pass in to the file constructor/open code?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks
|
|
|
|
|
I've had the same problem before (just dealt with it today in fact). The little boxes you see are non-printing ascii characters. When I ran into the problem, the char was decimal 26, hex 1A. You are reading a binary file as a text file, and that's why you are having a problem. If you read the file as binary, you won't have the EOF problem, you'll just have to change your code a little bit.
--Dean
|
|
|
|
|