|
Why do you want to modify the window style at runtime? It is easier to modify the dialog template in the resource editor and set the dialog as child there.
|
|
|
|
|
I have tried out with time interval 1 minute in vista as
NOTIFYICONDATA m_tnd;
m_tnd.uFlags = NIF_INFO;
m_tnd.dwInfoFlags = dwIcon;
m_tnd.uTimeout = uTimeout * 1000;
BOOL bSuccess = Shell_NotifyIcon (NIM_MODIFY, &m_tnd);
But in vista it always take OS settings. In OS it is set to 5 seconds and hence it disappears after 5 seconds.
Can my application control over it ? how ?
|
|
|
|
|
Hello all,
This is a macro from stdarg.h. I am trying to understand how does this work? But i got no idea.
<br />
#define STACKITEM int<br />
<br />
#define VA_SIZE(TYPE) \<br />
((sizeof(TYPE) + sizeof(STACKITEM) - 1) \<br />
& ~(sizeof(STACKITEM) - 1))<br />
In its definition, it says, it gives the size of object on the stack. I did not understand how is
this working.
Can anyone describe it for me?
Thanks
|
|
|
|
|
This macro rounds up the size of a variable type passed into variable length parameter list ...
The variable is rounded up to the size of a stack item, which will be the size of an int, 4 bytes on a 32-bit system. So even if you pass a char as one of the parameters, it will take up 4 bytes on the stack.
The extra code with the (sizeof(STACKITEM) -1) is meant to insure that if you pass in an item with size 0, you still get a 0.
This will happen on C when you pass in an empty struct or union.
C++ returns 1 for an empty class, struct, or union.
|
|
|
|
|
I assume that the expression
<br />
(sizeof(TYPE) + sizeof(STACKITEM) - 1)<br />
gives result 0 when there is no more data in stack(I may be wrong). But what about
<br />
& ~(sizeof(STACKITEM) - 1))<br />
what does that do altogether??
Thanks
|
|
|
|
|
~ is a bitwise NOT operation on a value.
So if you have x = binary 00110101, ~(00110101) => 11001010
if you use a bitwise & like this (x & (~x)) the result is 0
x: 00110101
~x: 11001010
------------
& 00000000
That would represent the case where the sizeof() returned 0.
To see how the macro will work with a different type:
(32-bit system)
sizeof(int) := 4
sizeof(short) := 2
VA_SIZE(short) =>
Start: ((2 + 4 - 1) & ~(4 - 1)) =>
Simplify: (5) & ~(3) =>
Convert To Binary: (101) & ~(011) =>
BitWise NOT: (101) & (100) =>
BitWise AND: (100) =>
Convert to Decimal: 4 bytes used on stack
The whole point of the macro is to round up the arguement to the size of stack entries, while returning 0 if the size of the parameter is 0 rather than automatically adding an empty stack item.
|
|
|
|
|
Hi guys, I am not sure why I got heap corruption error in this chunk of code. Anyone can help?
-inputEdits is a CArray of CEdit pointers
-the error I got is "HEAP CORRUPTION DETECTED after normal block at
CRT DETECTED that the application wrote to memory after end of heap buffer"
Thanks
CString msg;
for (int i =0 ; i < inputEdits.GetSize(); i++)
{
CString txt;
inputEdits.GetAt(i)->GetLine(0,txt.GetBuffer());
CString temp;
temp.Format("%s", msg);
msg.Format("%s%s,",temp, txt);
txt.ReleaseBuffer();
}
AfxMessageBox(msg);
|
|
|
|
|
Your CEdit, they are multiline (ES_MULTILINE) ?
the first Format looks wrong, there's nothing in msg in the first loop.
see the example on MSDN : http://msdn.microsoft.com/en-us/library/s7zy7cwk%28v=VS.80%29.aspx[^]
They seem to favor using the 2nd prototype of CEdit::GetLine (with the length or the line in the CEdit.
M.
Watched code never compiles.
|
|
|
|
|
Try:
inputEdits.GetAt(i)->GetLine(0, txt.GetBuffer());
txt.ReleaseBuffer();
...
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
You are directly manipulating the internal buffer of CString using GetBuffer(). You are wring some unknown number of characters into it using GetLine(). How do you know the buffer is big enough to contain all that data? Heap corruptions are often caused by "buffer overruns" and this smells like one.
According to the documentation, you need to tell it the size of the buffer you require for direct manipulation by specifying GetBuffer(size_needed) but you don't do that.
In most situations, you should use CString member functions to modify the contents of a CString object or to convert the CString to a C-style character string.
However, there are certain situations, such as working with operating-system functions that require a character buffer, where it is advantageous to directly modify the CString contents.
The GetBuffer and ReleaseBuffer member functions allow you to gain access to the internal character buffer of a CString object and modify it directly. The following steps show how to use these functions for this purpose:
Call GetBuffer for a CString object and specify the length of the buffer you require.
Use the pointer returned by GetBuffer to write characters directly into the CString object.
Call ReleaseBuffer for the CString object to update all the internal CString state information, such as the length of the string. After modifying a CString object's contents directly, you must call ReleaseBuffer before calling any other CString member functions.
|
|
|
|
|
The line:
inputEdits.GetAt(i)->GetLine(0,txt.GetBuffer());
is stomping all over the internal buffer of the CString. If you want to do this use something like CString::GetBufferSetLength to make sure there enough characters in the buffer for the edit control to overwrite. Remember to call CString::ReleaseBuffer afterwards to set the size of the string correctly.
Cheers,
Ash
|
|
|
|
|
Does anyone know if there is a topic or forum on this subject?
If not, is there much interest? I've had some success with this using Intel compiler tools and would like to see if others are on this path.
Many thanks!
Rob.
|
|
|
|
|
I'm all for multi-platforming including 64-bit multi-core
I haven't heard much about parellel though
-- Modified Monday, August 2, 2010 5:19 AM
|
|
|
|
|
Thanks for the feedback. I'd like to start a thread or something here about the topic. I had a project that really needed the performance boost and with some study was able to get the 64 bit running parallel.
I have an example program I'm planning to post after I sterilize my customers stuff.
If you want to get a head start, download Intel's 30 free trials of Parallel studio toolset and read up on OpenMP. Don't let it intimidate you cause there is alot of stuff. I switched to the Intel compiler a year ago and haven't looked back. It works great with MSVS 2008/2010.
The code I write of late is managed and native; just tons of fun.
Thanks!
Rob.
|
|
|
|
|
Hi there...Im a newbie
While using this function, how can I know things like
1) Manufacturer Identifier for Device Driver
2) Product Identifier for waveform input device
and other things similar to it...?? thanx
|
|
|
|
|
I have a MDI screen and I'm trying to display child CMDIChildWndEx windows with their own menus. I've seen on-line where "it's easy, just call SetMenu in CMDIChildWndEx::OnCreate".
int CChildFrame::OnCreate (LPCREATESTRUCT lpCreateStruct) {
if (CMDIChildWndEx::OnCreate (lpCreateStruct) == -1)
return -1;
m_menu.LoadMenu (IDR_POPUP_EDIT);
SetMenu (&m_menu);
return 0;
}
Apparently, I'm doing something wrong because I do that and I'm still not seeing a menu in my child window. I understand that child windows of a MDI are supposed to share a common menu but I have a specific case where I would like the child window to have its own menu. Anybody have any insight?
|
|
|
|
|
I don't think you can do this as child windows do not have menus of their own but share the menu of the frame window.
It's time for a new signature.
|
|
|
|
|
There is a classical way with the constructor of CMultiDocTemplate[^] ,
I see it as the primary mapping "DocumentToMenu"
Please try to find the construction in your code
or in the code generated by the application wizard.
virtual void BeHappy() = 0;
|
|
|
|
|
Hey i made connections between clients and server by threads made of createthread function with some button click in mfc. Now i want to kill the threads- disconnect clients from server by another button. Any ideas how to deal with this?
|
|
|
|
|
Okay, since you are going down the path of an interactive user interface (you mentioned a chat application, not just a simple tool)... I would highly recommend to use non-blocking sockets. Of course, everything can be done with blocking sockets, but that would require thread synchronisation between UI and socket, which very likely is more work than just using an existing asynchronous networking class. Does this help?
In case you want to continue with blocking sockets and multi-threading have a look at thread communication in C++[^], e.g. http://www.codeproject.com/KB/threads/[^]. Perhaps others can give more tips on how to do a multi-threaded GUI application...
Happy coding!
/M
|
|
|
|
|
if they are worker threads, use events to synchronise their termination.
in each thread
while(WaitForSingleObject(hEvent, 0) == WAIT_TIMEOUT))
{
read some data from connection asynchronously
}
close connection and exit thread
in main UI thread,
has an event handle initially set to non signalled.
creates 'n' number of threads and store their handles in an array hThreads[]
button_click()
{
SetEvent(m_hEvent)
WaitForMultipeObject(n, hThreads, 1, INFINITE)
}
and if they are UI threads or has a message quee, use PostThreadMessage(), and wait from the main thread for their termination.
|
|
|
|
|
what if i want to terminate some specified threads? all i want to do is this: i am creating threads for clients connect to servers by createthread function; i call this function in my onclickconnect() button call, for each selected server in the listbox, i create a thread and do the operations; startconnection, receive message from server etc. I pass the connected ip-ports in some other list and I want to have a disconnect button. when i select ip-ports in the "successful connections" list and click on the button, i want the corresponding threads to terminate. I have done some coding and this works fine for several steps. When I try to connect the server, it connects. When I try to disconnect from the server the thread is terminated. HOWEVER when I try to connect to the disconnected server it gives an error and my program terminates. I dont want such things. If you can examine my code and give me some advice, I will be grateful. Thanks
Here is my connect/disconnect button:
if(m_con1dis2 == 1)
{
m_fails.ResetContent();
m_success.ResetContent();
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];
CString *ptr= 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;
}
}
for(int i=0;i<Selected;i++)
{
--diziPtr;
Client_Thread[Selected-i-1]=CreateThread(NULL,0,ClientThread,(void *)diziPtr,0,&Client_ThreadID);
}
while(done==true)
{
}
for(int i=0; i< m_ctlServerList.GetCount();i++)
{
if(m_ctlServerList.GetCheck(i) == 1 )
{
_itoa_s(i,str,10);
svar = str;
*ptr = lines[i]+_T(":")+svar;
if(connected[i] == 2)
{
m_success.AddString(*ptr);
}
else if(connected[i] == 1)
{
m_fails.AddString(*ptr);
}
++ptr;
UpdateData(false);
}
}
thread = 0;
done = true;
}
if(m_con1dis2 == 2)
{
CString strTxt,thnum;
int tnum;
toDisconnect = 0;
for(int i=0; i< m_success.GetCount(); i++)
{
if(m_success.GetSel(i) == 1)
{
toDisconnect++;
m_success.GetText(i,strTxt);
MessageBox(strTxt);
AfxExtractSubString(thnum, strTxt, 2, ':');
tnum = _wtoi(thnum);
TerminateThread(Client_Thread[tnum],0);
CloseHandle(Client_Thread[tnum]);
AfxMessageBox(L"You terminated thread!");
}
}
for(int i=0; i< m_success.GetCount(); i++)
{
if(m_success.GetSel(i) == 1)
{
m_success.DeleteString(i);
m_fails.AddString(strTxt);
}
}
UpdateData(false);
if(m_success.GetCount() == 0)
{ m_ctlConnect.SetWindowTextW(_T("Connect"));
m_con1dis2 = 1;
}
}
}
here is my clientthread function:
DWORD WINAPI ClientThread(void * num)
{
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);
if(sockClient.ConnectToServer(ip, port,socknum)== 0)
{ connected[socknum] = 1;
thread++ ;
}
else
{
connected[socknum] = 2;
thread++ ;
sockClient.timefile(ipAddress,ports,savepath);
sockClient.RecvData(ipAddress,ports,socknum,savepath);
}
if(thread == Selected)
{
done = false;
}
return 0;
}
the index of the Client_Thread is the threadno given in the creation.
|
|
|
|
|
when I try to connect to the disconnected server it gives an error and my program terminates.
Please debug in this scenario to find out the point where the program crashes and post it here.
TerminateThread doesn't give the thread an opportunity to clean up the resources. So use some other mechanisms to terminate thread.
|
|
|
|
|
hi,
i am facing C4309 warning while compiling my program. can anyone help me how to solve this warning?
--------------
code snippet:
CString ws;
if (ws.ReverseFind( '>>' ) > -1 )
----------------------------
Thanks,
Rakesh.
|
|
|
|
|
Rakesh5 wrote: i am facing C4309 warning
Please, next time post the full error message, it would avoid people to have to google to know what it is exactly (we don't know all the error codes by heart you know).
Rakesh5 wrote: if (ws.ReverseFind( '>>' ) > -1 )
You have to use ">>" instead of '>>' . Simple quotes (') are used for characters and double quotes (") are used for strings. Here your string will be truncated to a single character.
|
|
|
|