|
I agree with Sauro. If I'd seen the question here before I went to the effort of answering it in QA, I wouldn't have taken the trouble.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I have an CListCtrl object on an CFormView and on button click I want to rezise CListCtrl object ... here is my trial code :
void CTestView::OnButton1()
{
CRect Rect;
m_List1.GetWindowRect(Rect);
Rect.DeflateRect(Rect.left,Rect.top - 10,Rect.right,Rect.bottom);
m_List1.MoveWindow(Rect);
}
I want to short to 10 m_List1 less tall but keep bottom position ... but , when I clicked button , m_List1 disappear ... what I am doing wrong ?
I try in another way but with the same result :
void CTestView::OnButton1()
{
CRect Rect;
m_List1.GetWindowRect(Rect);
Rect.DeflateRect(Rect.left,Rect.top - 10,Rect.right,Rect.bottom);
m_List1.SetWindowPos(GetParent(),Rect.top - 10,Rect.left,Rect.Width(),Rect.Height() - 10,SWP_NOZORDER);
}
Can anybody help me ? Thank you.
|
|
|
|
|
I solve the problem , and here is my approach , in case that anybody needed :
I decrease tall with 10 of the list constrol :
void CTestView::OnButton1()
{
CRect Rect1,Rect2;
GetWindowRect(&Rect1);
m_List1.GetWindowRect(&Rect2);
int x = Rect2.left - Rect1.left - 2 * GetSystemMetrics(SM_CXBORDER);
int y = Rect2.top - Rect1.top - 2 * GetSystemMetrics(SM_CYBORDER);
m_List1.MoveWindow(x,y + 10,Rect2.Width(),Rect2.Height() - 10);
}
Here I increase tall with 10 of the list control :
void CTestView::OnButton2()
{
CRect Rect1,Rect2;
GetWindowRect(&Rect1);
m_List1.GetWindowRect(&Rect2);
int x = Rect2.left - Rect1.left - 2 * GetSystemMetrics(SM_CXBORDER);
int y = Rect2.top - Rect1.top - 2 * GetSystemMetrics(SM_CYBORDER);
m_List1.MoveWindow(x,y - 10,Rect2.Width(),Rect2.Height() + 10);
}
|
|
|
|
|
Hi guys,
As i am working on MDI application on VS2008, it had few modeless dialogs and tabbed views. During work, i found that if a modelless dialog is there and i invoked some context menu from the view, and now i clicked on the button of the modeless dialog, the dialog gets activated but the menu is not gone.
I guess i am clear what is the problem. as this is a normal problem and can be reproduced easily, no reelevent code snippet can be given.
Expecting some quick help..
HARSH
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.
|
|
|
|
|
Hi, I have a dialogue-based MFC project. A user can input some inputs and I do the calculation behind the scene. After the calculation ( I might get 5 or 10 or 20 results), I want to display each result as CEdit control. Is it possible that I add those controls at runtime? Anyone has an example of how to do that?
Thanks
|
|
|
|
|
use CEdit::Create member function to create edit control at runtime.
|
|
|
|
|
It would be better to show the results in some other type of control like a list or multi-line edit/static control.
If using edit boxes created dynamically, there would be blank spaces on the dialog which may not look nice.
|
|
|
|
|
smengl wrote: I want to display each result as CEdit control. Is it possible that I add those
controls at runtime? Anyone has an example of how to do that?
CEdit *edit = new CEdit();
edit->Create();
"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
|
|
|
|
|
Hi!
I need to convert UCHAR array to UINT array.
Example:
0 8 16 24 32 0 32
+------+------+------+------+ +------------+
INDATA | 0x11 | 0x22 | 0x33 | 0x44 | == CONVERT ==> | 0x11223344 | OUTDATA
+------+------+------+------+ +------------+
I have this two functions.
UINT uchar2uint(UCHAR * in)
{
return ((*in << 24) | (*(in + 1) << 16) | (*(in + 2) << 8) | *(in + 3));
}
void uchar2uinta(UCHAR * in, UINT * out, size_t outlen)
{
while(outlen--)
{
*out++ = uchar2uint(in);
in += 4;
}
}
int main(void)
{
int i;
UCHAR indata[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
UINT outdata[2];
uchar2uinta(indata, outdata, 2);
for(i = 0; i < 8; ++i)
printf("%#x ", indata[i]);
printf("\n");
for(i = 0; i < 2; ++i)
printf("%#x ", outdata[i]);
printf("\n");
return 0;
}
at the console displays the following text:
0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88
0x11223344 0x55667788
It's OK!
But, i can have a problems, when working in other system with different endianness (big-endian or little-endian)?
May be existed more correct way to convert?
Sorry for my poor English
Best regards, Alexander S.
|
|
|
|
|
What you have done will work in big- or little-endian systems. It is correct. There may be more *efficient* ways to do the conversion, depending on quirks of the hardware, compilers, etc.
Regards,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Many Thanks. I was primarily interested in portability of the code.
Regards,
Alexander S.
|
|
|
|
|
fasked wrote:
void uchar2uinta(UCHAR * in, UINT * out, size_t outlen)
{
while(outlen--)
{
*out++ = uchar2uint(in);
in += 4;
}
}
Try this instead, its simpler and will do the same you are looking for
void uchar2uinta(UCHAR * in, UINT * out, size_t outlen)
{
while(outlen--)
{
*out++ = *(UINT*)in;
in += 4;
}
}
HARSH
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.
|
|
|
|
|
thanks, but thus result will be different in systems with big-endian and little-endian.
Regars,
Alexander S.
|
|
|
|
|
This code will not achieve the results required; take a look at your indexing.
It's time for a new signature.
|
|
|
|
|
|
Please post your question in the forum at the end of the article for the author to be notified of it.
It's time for a new signature.
|
|
|
|
|
Hi all,
Please let me know how to give the publisher name to my sample MFC application.
Currently it is displaying "Unknown" when i try to start it.
I am using Visual Studio 2008.
To see the publisher name -> Run an application as administrator in windows 7 machine and check the UAC dialog.
-Cvaji
|
|
|
|
|
|
Nice of you to post your finding. Not many people do that. Good Luck with your new Publisher Name
|
|
|
|
|
this[^] should be your first step.
|
|
|
|
|
Hey guys,
I have a project which connects the TVs(with socket connection) to a computer and saves the log files. I achieve the connection by multithreading but I want to see whether the connection is established or not in the main dialog page that i built in VC++ MFC. Here are my codes:
void CDilaraDlg::OnBnClickedConnect()
{
int Selected = 0;
for(int i=0; i< m_ctlServerList.GetCount();i++)
{
if(m_ctlServerList.GetCheck(i) == 1 )
{
Selected++;
}
}
if(Selected == 0)
AfxMessageBox(L"No Server is Selected!");
CString *diziPtr= new CString[Selected];
char str[2];
CString svar;
for(int i=0; i< m_ctlServerList.GetCount();i++)
{
if(m_ctlServerList.GetCheck(i) == 1 )
{
_itoa_s(i,str,10);
svar = str;
*diziPtr = lines[i]+_T(":")+svar+_T("-")+m_savepath;
++diziPtr;
}
}
m_fails.ResetContent();
m_success.ResetContent();
CString abc;
for(int i=0;i<Selected;i++)
{
--diziPtr;
Client_Thread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ClientThread,(void *)diziPtr,0,&Client_ThreadID);
}
m_fails and m_success stand for the control variables of two list boxes that i want to write down the succeed and failed connections.
For the multithreading :
DWORD WINAPI ClientThread(void * num)
{
signal( SIGINT, &signal_handler );
signal( SIGTERM,&signal_handler );
signal( SIGABRT,&signal_handler );
CString ipport= *(CString * ) num;
CString ipAddress,savepath;
CString ports,socknums;
int port,socknum;
AfxExtractSubString(ipAddress, ipport, 0, ':');
AfxExtractSubString(ports, ipport, 1, ':');
port = _wtoi(ports);
AfxExtractSubString(socknums, ipport, 2, ':');
AfxExtractSubString(savepath, ipport, 1, '-');
socknum = _wtoi(socknums);
CStringA ip(ipAddress);
Socket sockClient(socknum);
sockClient.timefile(ipAddress,ports,savepath);
if(sockClient.ConnectToServer(ip, port,socknum)==0)
return -1;
sockClient.RecvData(ipAddress,ports,socknum,savepath);
return 0;
}
in the ConnectToServer function of the Socket, it returns 0 if the connection is not achieved and 1 otherwise.
int Socket::ConnectToServer( const char *ipAddress, int port,int i)
{
myAddress.sin_family = AF_INET;
myAddress.sin_addr.s_addr = inet_addr( ipAddress );
myAddress.sin_port = htons( port );
if (connect( mySocket[i], (SOCKADDR*) &myAddress, sizeof( myAddress )) ==SOCKET_ERROR )
{
CString msg = _T("ClientSocket: Failed to connect: Error Value: ");
CString error;
int a = WSAGetLastError();
error.Format(_T("%d"),a);
msg+=error;
AfxMessageBox(msg);
system("pause");
return 0;
}
return 1;
}
How to get 0 or 1 return values in my dialog.cpp to do the listbox operations? or any other suggestions??
Thanks
|
|
|
|
|
dilara semerci wrote: How to get 0 or 1 return values in my dialog.cpp to do the listbox operations? or any other suggestions??
I could think of two alternatives. First, use PostMessage() to notify the user interface that something has happened (e.g. socket connected, status changes), therefore you need to give your worker thread the window handle of your dialog. Second, use non-blocking sockets and your can handle everything in a single-thread context with event handlers (e.g. OnConnect , OnReceive ).
The first alternative can be added to your existing application and should be running quickly. The second requires code refactoring, but probably is easier to extend and maintain in the long run... so it really depends on your application requirements/features what's better.
Hope this gives you some ideas.
/M
|
|
|
|
|
I checked PostMessage() but i could not find a way to use it in application.. all the thread kind of examples are done by non-blocking asyn.sockets. can you help me to understand and use PostMessage() method? what else do i need to add my code and where of course?
|
|
|
|
|
Here is a brief guide:
- Give window handle to the worker thread (typically from a dialog or the main view)
- Send a custom message with PostMessage (WM_APP + something) when a socket signals a certain status
- Add a handler for your custom message to the dialog, update the listbox with the status
|
|
|
|
|
Hi all,
I am trying to read a port using CreateFile() and ReadFile() Function using overlapped parameter, but my problem is when i debug the program number of bytes read is coming correct and when i run my program bytes read is coming less... I am not getting why is this happening...
Can anybody help me in this...
Thanks in advance
|
|
|
|
|