|
#include "stdafx.h"
#include <iostream.h>
int main(int argc, char* argv[])
{
int NumOfStr = 0, StringLength = 10;
//get number of strings from the user
cout << "Enter number of strings: ";
cin >> NumOfStr;
char **a;
a = new char * [NumOfStr];
for(int Index = 0; Index < NumOfStr; Index++)
{
a[Index] = new char [StringLength];
sprintf(a[Index], "string #%d", Index);
}
//clean-up the memory
for(Index = 0; Index < NumOfStr; Index++)
{
delete [] a[Index];
}
delete [] a;
return 0;
}
|
|
|
|
|
Hello,
I have a class CStaticEx, which is derived from CStatic and the text is drawn in the OnPaint() of CStaticEx.
I use SetDialogBkColor(...) to change the background and text color of the dialogs in my program.
But the text drawn in OnPaint of CStaticEx is black.
Is there any function to get the dialog background and text colors?
Thanks in advance.
-- modified at 6:36 Friday 26th August, 2005
|
|
|
|
|
GetSysColor(COLOR_3DFACE) should give you the dialog color.
GetSysColor(COLOR_WINDOWTEXT) should give you the right text color.
He is smart. He will make our Windows go.
|
|
|
|
|
Hello.,
I used CMonthCalCtrl to getting Selected Date.
But Date field is getting error .
Plz suggest me.,
*****How to get User selected date using CMonthCalCtrl
Plz Give the complete code.
Praveen Chowdam Kumar
|
|
|
|
|
if m_Cal is your control
COleDateTime odt;
m_Cal.GetCurSel(odt);
~RaGE();
|
|
|
|
|
parims wrote:
But Date field is getting error .
And what would that error be?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
can anybody help me out for it???
thanks n regards
Supriya Tonape.
|
|
|
|
|
NetGroupGetUsers or use ActiveDirectory more directly if you have it.
Hint: MSDN search 'group users members enumerat*'
Steve S
Developer for hire!
|
|
|
|
|
thank u David It did help.bye.
Supriya Tonape
|
|
|
|
|
|
If Administrators is a local group, use NetLocalGroupGetMembers() . Otherwise if it is a global group, use NetGroupGetUsers() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I'm using CTabCtrl in my application.
It works fine except when I apply TCS_BOTTOM style.
In this case, tabs get align properly at bottom but no controls on tab pages are visible.
Can anybody help, it's very urgent.
Thanks in advance.
|
|
|
|
|
I read a raw(without file info head)file from the hard driver. raw file is a 1024x1024 8bit graylevel data. I put the data into a memory and draw it on a memDC and add some text on the memDC,then I want to use GetDlBits to get the raw data from memDC, but the data I get is always wrong with some bytes. So the raw image can not display correctly. But if I use memDC.GetPixel then the result is right.I can not find any problem, who can help me!!!
CBitmap memBitmap
CBitmap* pOldBmp=NULL ;
CDC memDC;
OldPal=NULL;
HDC hDC=pDC->GetSafeHdc();
CDIBDoc* pDoc=GetDocument();
BOOL bSuccess=FALSE;
if(pDoc->hDIB ==NULL)
{
AfxMessageBox("wrong");
return;
}
LPBYTE m_lpImage=(LPBYTE)GlobalLock(pDoc->hDIB);
if(pDoc->hDIB)
{
OldPal=pDC->SelectPalette(&m_Palette,FALSE);
if(OldPal==NULL)
{
AfxMessageBox("palette choose error");
}
if(pDC->RealizePalette()==GDI_ERROR)
{
AfxMessageBox("palette realize error");
}
}
else
{
AfxMessageBox("image datum are empty");
return ;
}
SetStretchBltMode(hDC,COLORONCOLOR);
memDC.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC,1024,1024);
pOldBmp = memDC.SelectObject(&memBitmap);
bSuccess=::StretchDIBits(memDC,0,0,1024,1024,
0, 0,1024, 1024,
m_lpImage,(LPBITMAPINFO)bmhdr,
DIB_RGB_COLORS,
SRCCOPY);
::SetBkMode(memDC,TRANSPARENT);
::SetTextColor(memDC,RGB(220, 220, 220));
CString str="DOG ";
CRect rect(20,20,70,50);
::DrawText(memDC,str,sizeof(str),rect,DT_LEFT|DT_WORDBREAK);
if(bSuccess==GDI_ERROR)
{
AfxMessageBox("error");
}
pDC->BitBlt(0,0,1024,1024,&memDC,0,0,SRCCOPY);
ZeroMemory(pDoc->pTemp, pDoc->dwBitsSize);
/*******************************wrong*************************/
int nCount = GetDIBits(memDC.GetSafeHdc(), (HBITMAP)memBitmap.m_hObject, 0, 1024,
pDoc->pTemp, (BITMAPINFO*)bmhdr, DIB_RGB_COLORS);
/*******************************test*************************/
if don't use GetDIBits but use these then right:
int nCount = memBitmap.GetBitmapBits(1024*1024,(LPVOID)pDoc->pTemp);
int i,j;
for (i=0;i<1024;i++)
{
for (j=0;j<1024;j++)
{
*(pDoc->pTemp+j*1024+i) = (BYTE)memDC.GetPixel(i,j);
}
}
|
|
|
|
|
why no one answer my question?
|
|
|
|
|
My be this is your problem:
Try CDibData[^] the notes I wrote in the source file covers every thing I know about its usage.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
|
Write a test program that just does what you are testing.
I have not (and will not) test what you have given. Your example is trying to do more than what you are asking about. You know the size of the bitmap, so why call StretchDIBits()? It looks like you're drawing some text on the DC, but then drawing the bitmap over that. etc...
Just write a simple program or a test function that just does what you are testing for and single step throu it with the debugger. That is how we solve the problems we face.
INTP
|
|
|
|
|
From my test I think GetDIBits can not be used for 8bits raw data. It can not get 8bits data from memDc correctly.
|
|
|
|
|
If the DC contains a bitmap, then it can get the data bits. Working with some GDI bitmap functions can be tricky, at least one of them just fails without telling you why (it just takes 1-bit, in the parameter data).
Examine CDibData.cpp and try to see what it is doing. May be you could write a test file for your data using it. If it fails then you are correct, and there is a bug I need to fix. Which would mean I (and others) have the same problem you do, and havn't fixed it yet.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I m coding my server socket using CSocket.Everything goes right till the Accept (function of CSocket) is called.it shows Debug Assertion failed in File:sockcore.cpp
here is my code
BOOL CCSocketDlg::OnInitDialog()
{...
//AfxSocketInit() has been called
//CCSocketApp::InitInstance()
//default constructor creates TCP/IP so it is SOCK_STREAM
//this function will also binds the the socket with one //network card
BOOL bsocketcreate= socket.Create(36545);//create the //socket which will listen at port 36545
//if the socket is not created
if(!bsocketcreate)
{
::OutputDebugString(_T("socket couldnot be created"));
return FALSE;
}
else
::OutputDebugString(_T("socket created successfully"));
//SOCKET created then start listen socket
BOOL bsocketlisten= socket.Listen(5);
//if the socket is not able to listen at specified port
if(!bsocketlisten)
{
::OutputDebugString(_T("socket couldnot listen on specified port"));
return FALSE;
}
else
::OutputDebugString(_T("socket listens at specified port"));
// Begin the Socket thread
AfxBeginThread(fnMainThread,LPVOID(this));
return TRUE; // return TRUE unless you set the focus to a control
}
UINT fnMainThread(LPVOID p)
{
CCSocketDlg *m_Dlg=(CCSocketDlg*)p;
//create another CSocket variable to accept the connection
CSocket sockConnection;
//socket is listening it can know accept new connection
BOOL bsocketaccept=m_Dlg->socket.Accept(sockConnection);
if(!bsocketaccept)//if the connection with client is not //establish
{
::AfxMessageBox(_T("socket couldnot establish new connection with client"));
AfxEndThread(0);//end thread
return 1;
}
::OutputDebugString(_T("connection accepted on new socket"));
//Begin a new Socket thread AfxBeginThread(fnMainThread,LPVOID(p));
m_Dlg->socket.Close();
return 0;
}
thanx for help
-- modified at 4:10 Friday 26th August, 2005
|
|
|
|
|
1) try to change m_Dlg->socket.Accept(sockConnection); as
m_Dlg->socket.Accept(*sockConnection);
2) Or change CSocket sockconnection as CSocket* sockconnection = new CSocket()
redindian
|
|
|
|
|
i tried but same Debug Assertion has occurred
|
|
|
|
|
if i ignore the Debug Assertion then my server socket is connected to client and after that my program crashes.
|
|
|
|
|
Sunit,
This is repetetive problem when you use Windows Socket programing in Windows Operating system. As you know, MFC use asyncronous connection calls and request for scoket processing, MFC uses windows messagess for every new requests, data received etc...
Your problem is, you are created Windows socket in one thread, but using it on another thread. Bascially they will send messages which is irrelavant to another thread, hence assertion.
They are two appraches to solve this problem...
1. Create your server socket on UINT fnMainThread(LPVOID p) function. If you look at your function, there is no message handling is done. So you have to create a socket then you need to implement the message loop also for that thread.
2. When you use different thread for socket handling and creation,
first detach your socket handle from the main thread using Detach() method, copy that reference of socket and attach that reference to the new server socket object in another thread...
Please let me know if you need more help....
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
thanx for ur help
but still i want to clarify my doubts
what does asynchronous connection(used by MFC) means
|
|
|
|
|