|
make the brush a member of your Window class!
what is the purpose of OnCtlColor=> RTFM
Greetings from Germany
|
|
|
|
|
i need to change the color of the the entire dialog not only the controls on that dialog.
regards
sudhakar
|
|
|
|
|
The background can you paint in OnEraseBkgnd()
Greetings from Germany
|
|
|
|
|
I guess you are creating a new brush in every time in OnCtlColor function.
if yes a simple solution would be to
1>make the brush object as a memeber of a classs
2>create thebrush object only once say in the constructor.
3>return the same handle every time in the function.
4>delete the object in the destructor.
Thanks
Rizwan
|
|
|
|
|
Hi all,
Lets say one has created a thread using _beginthread() and now that thread is active and running. Now one wants to pass arguments to that thread function, but remember that the thread was already created. Now ... how can one (if it is possible) call that thread function, without calling _beginthread() again.
I.E
int callThreadFunc()
{
}
void myThread(void* a)
{
while (1)
{
Sleep(1000);
}
}
void main()
{
_beginthread(myThread, NULL, 0);
...
}
Many Thanks
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
with global variables, but you have the problem of syncronizing. If threads work together you need to syncronize them!!! Everything else is crap. For instance with WaitForMultipleEvent()
Greetings from Germany
|
|
|
|
|
|
You can't really pass arguments to your thread the way you describe. Instead, what you do, is pass a pointer to a certain object when you start your thread. Then, your thread can check this object to retrieve information (now, how it is done really depends on your app). Basically, it doesn't change anything to the fact that it is a separate thread. EXCEPT, that you need to secure the access to the variables using critical sections (for example), so that only one thread will access a variable at a time.
|
|
|
|
|
Thanks Cédric,
Cedric Moonen wrote: that you need to secure the access to the variables using critical sections (for example), so that only one thread will access a variable at a time.
If I understand you correctly ... would it be a good idea using global variables, but keeping it in sync ?
Many Thanks
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
There are two common ways:
- With a UI-thread you post a message with the information you want to pass to the thread
- With a worker thread (like your example) you have a place where the thread knows it can find information, such as a queue, a struct on the heap or class member variables. When the thread is supposed to get the new information you signal an event or semaphore that the thread is waiting on with
::WaitForMultipleObjects(...) .
Don't forget to synchronize the threads to avoid data corruption.
For more info on workerthreads, read this article[^].
For more info on semaphores and queues between workerthreads, read this article[^].
You will find a third alternative with I/O completion ports here[^]. The article also discuss when thread synchronization isn't needed, or could be avoided.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: When the thread is supposed to get the new information you signal an event or semaphore that the thread is waiting on
Never though of that, thank you very much Rodger
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
hi i am using the below code for dummy multithreading application.
first function listens request and the thread started with thread function
but some client start receving data but some one not get the single respomnse back . can any one help me what's gona wong with this code
thanks
///////the server function//////////////////
void thread::startserver()
{
DWORD dwStatus;
WSAEVENT handles[1];
struct sockaddr_in cli_addr;
int clilen = sizeof(cli_addr);
memset(&cli_addr,0,sizeof(struct sockaddr));
printf("***********server started****************\n");
while (TRUE)
{
handles[0] = WSACreateEvent();
WSAEventSelect(m_hSockethndl, handles[0], FD_ACCEPT);
dwStatus = WSAWaitForMultipleEvents(1, handles, TRUE, 50, FALSE);
if (dwStatus == WSA_WAIT_EVENT_0)
{
SOCKET cli_socket;
cli_socket=-1;
cli_socket = accept(m_hSockethndl, (struct sockaddr *) &cli_addr, &clilen);
// set linger option
LINGER linger;
linger.l_onoff = 1;
linger.l_linger = 0;
setsockopt(cli_socket, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(LINGER));
//setsockopt(cli_socket, IPPROTO_TCP, TCP_NODELAY, NULL, 0);
int flag = 1;
int result = setsockopt(cli_socket, /* socket affected */
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(char *) &flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
if (result < 0)
{
printf("Client Socket No Delay Option Failed");
}
//printf("Thread started with the server socket=%d and client port=%d and ip=%s\n",cli_socket,cli_addr.sin_port,inet_ntoa(cli_addr.s in_addr));
/*threadParmas thparam;
memset(&thparam,0,sizeof(threadParmas));
thparam.cli_addrth=cli_addr;
thparam.threadsocket=cli_socket;*/
//CreateThread(NULL, 0, StartThread, &thparam, 0, &dwThreadID);
CreateThread(NULL, 0, StartThread, &cli_socket, 0, &dwThreadID);
FD_SET(cli_socket, &set_sockets);
}
WSACloseEvent(handles[0]);
}
}
//////////////////the thread function////////////////////
DWORD WINAPI thread::StartThread (void * thparam)
{
/* struct threadParmas threadparam;
threadparam.threadsocket=((struct threadParmas *)thparam)->threadsocket;
threadparam.cli_addrth=((struct threadParmas *)thparam)->cli_addrth;*/
SOCKET socket_handle;
u_short Clientport;
//socket_handle=threadparam.threadsocket;
socket_handle=*(SOCKET *)thparam;
//Clientport=ntohs(threadparam.cli_addrth.sin_port);
char data[256];
char Resdata[512];
memset(data,0,256);
memset(Resdata,0,512);
int counter=1;
int bytes =1;
while(bytes)
{
WSAEVENT we = WSACreateEvent();
WSAEVENT handles[1];
handles[0] = we;
WSAEventSelect(socket_handle, we, FD_READ | FD_CLOSE);
//receiving data from client
for (int i = 0; i < WAIT_MULTIPLE; i++)
{
DWORD available = WSAWaitForMultipleEvents(1, handles, TRUE, WAIT_TIME, FALSE);
if (available == WSA_WAIT_EVENT_0)
{
if ((bytes = recv(socket_handle, data, 256, 0)) < 0)
{
int er = WSAGetLastError();
printf("Error=%d while receive data from socket %d\n",er,socket_handle);
bytes = 0;
break;
}
else
break;
}
}
WSACloseEvent(we);
strcpy_s(Resdata,512,"Response send Ack");
if(bytes)
{
//printf("socket %d Message %3d received client port=%d, ip=%s size=%d\n",socket_handle,counter,Clientport,inet_ntoa(thread param.cli_addrth.sin_addr),bytes);
//go to sleep for internal processing
//printf("socket %d Message %3d received size %d %s\n",socket_handle,counter,bytes,data);
Sleep(2000);
//sending the dummy response to the client
if (send(socket_handle, Resdata, strlen(Resdata), 0) != strlen(Resdata))
{
int er = WSAGetLastError();
printf("ERROR %d IN SENDING %d RESPONSE by socket =%d\n",er,counter,socket_handle);
return 0;
}
//printf("***Response %3d send by the server socket=%d, client port=%d, ip=%s\n",counter,socket_handle,Clientport,inet_ntoa(thread param.cli_addrth.sin_addr));
//printf("***Response %3d send by the server socket=%d\n",counter,socket_handle);
}
//keeping track how many packets this specific client sends
counter++;
}
return 1;
}
|
|
|
|
|
Hai All,
I'm working in VC++ 6.0.There I've created a dialog based appl in MFC.
1.I've created a CButton and placed a bitmap over it using LoadBitmap function,say,IDB_BITMAP1.
2.Now I need the button to be resized along with the Dailog.
3.I've written the code for the buttton resizing in OnSize ();
4.Now my trouble starts.I want to use the same already loaded bitmap (IDB_BITMAP1)to be resized according to the button size.But now onlt the button is resizing and not the bitmap.
So please tell me is there any way to resize(ie,streach or skew) the bitmap according to the content size.
Thanks in advance
|
|
|
|
|
You need a ownerdrawn Button. So look for samples here at CP or write a own one. Override OnPaint() with a StretchBlt
Greetings from Germany
|
|
|
|
|
Hello thanks for your kind reply,
Can you please explain to me in depth how to streach the Bitmap image.I've used the ownerdrawn button.I'm able to resize the control.But the bitmap remains of the same size.
Can you please tell me how to use StrechBlt() function in a much more detailed way.I tried but not getting it correctly.I'm new to to MFC.So please help me.
Thanking You in Advance and appriciating your kindness,
Robshere
|
|
|
|
|
No the StretchBlt() yoi gotta do on your own. You need to learn that.
PS: Ask an experienced programmer to explain you my answer
Greetings from Germany
|
|
|
|
|
Hi all,
I am trying to read a particular bit on the kernel memory. That page belongs to a driver, say cdrom.sys.
Jus before proceeding further, i jus tried to read the contents in the physical memory where the driver is loaded. i.e. i found the driver load address and tried reading that location from kernel memory.
But it simply returns 'FF'.
Any thoughts??? I am using ZwOpenSection to open the memory and lock the pages, then read. Is there any other way of doing it..
Are there any tools which can read the kernel memory location....
Thanks in advance....
Selva
|
|
|
|
|
It doesn't work because the OS is designed so that it doesn't work. User mode programs cannot access kernel mode areas except through the exposed interfaces. In general, those interfaces do not give direct access to the kernel area but copy kernel info into a user space address. The only time user mode can directly access kernel mode is with the help of a cooperating driver and, even then, user mode can only safely direct access the kernel area of the specific driver.
General answer - can't do it.
Judy
|
|
|
|
|
Thanks for your reply Judy,
But i am reading the kernel only thru a driver (created for physical memory reading)..
all the functions are returning true (analyzed thru dbgview)..
any thoughts???
Selva
|
|
|
|
|
Not without seeing your code and, even then, I probably can't provide too much help since this is something I haven't done. Also, your problem is probably in the driver and drivers are not within the purview of this site. Try a driver development site. If you do go to a driver site, be warned: Providing unfettered user access to kernel memory is highly frowned upon since it is a huge security hole and invites BSODs. There is almost always a better safer way and one of the first responses you will get will be "why this way instead of the proper way".
Judy
|
|
|
|
|
Good morning... My query is......
After user selects PRINT menu one message box(usr created)will appear.
The message box consists of 2 command button controls.
one is OK and the other is CANCEL.
If the user presses OK it should take snapshot of the background and should create a BITMAP IMAGE without the message box. That means IMAGE shouldn't contain the message box. For this I am calling EndDialog() function. But now the problem message box is creating some empty space in the background and IMAGE is coming with that empty space. But it shouldn't come.
The code is as folows.
After selecting PRINT menu it will execute the following code.... i.e.,
**************************************************************************8
CSaiMessage m_objMsg;
m_objMsg.m_strMSG = "\n\n\nPress Print to Print the Screen or Cancel To Quit";
m_objMsg.DoModal();
****************************************************************************
Know the message box will appear. If the user selects PRINT button it will execute the following code.....
****************************************************************************
void CSaiMessage::OnClickCmdbtnPrint()
{
CSaiMessage::EndDialog(10);
snap();
}
****************************************************************************
void CSaiMessage::snap()
{
CWnd* pWnd = AfxGetApp()->m_pMainWnd;
if (windowtobmp("ShipStatus.bmp",pWnd)==FALSE)
{
MessageBox("ERROR");
}
}
BOOL CSaiMessage::windowtobmp(CString filename,CWnd* pwnd)
{
CWindowDC dc(pwnd);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CRect rect;
pwnd->GetWindowRect(rect);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height()-150);
CBitmap* poldbmp = memdc.SelectObject(&bmp);
memdc.BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
memdc.SelectObject(poldbmp);
HANDLE hdib = ConvertDDBToDIB(bmp);
writebmp(filename,hdib);
GlobalFree(hdib);
CString strPrintFilePath = FindPrintFilePath();
HINSTANCE hInstancePrint;//,hInstanceEditor;
hInstancePrint = ShellExecute(this->m_hWnd,"print","ShipStatus.bmp",NULL,NULL,SW_HIDE);
return TRUE;
}
Thanks in Advance
Sairam
|
|
|
|
|
I don't know how do you are showing the information into that window that you "windowtobmp", but could it be a problem in the redrawing of that information? have you tried something like a pWnd->Invalidate() just at the first line of "windowtobmp"?
Hope this helps...
|
|
|
|
|
hi how to do unit testing in mfc. is there any article to unit test my mfc code. pls help me
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
Unit testing is meant for developer to check whether the functionality implemented is working according to what was planned. If there are any discrepancies in the fn'lity the developer must resolve it before a release is sent to the Testing team. This ensures that the testing team finds least number of bugs.
So in order to perform a unit testing you should know exactly what you want your code to do. Once you know this go ahead and execute the application to check if there is any bug that needs to be resolved. You can write test cases for yourself to check the execution and then perform a run.
For eg:
If you want your edit box to accept only chars and no special characters, number you would need to enter such values in the edit box and see it for yourself.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Dear all
after i built my simulation, compiler showed "can't open include file 'afxres.h'.how to resolve this issue. thanks.
before i installed VC++ 2005 express, but i already uninstalled. any affection for this issue?
but i make sure my simulation is right. urgent!!!.thanks very much.
regards
-- modified at 23:47 Wednesday 27th June, 2007
Li Zhiyuan
28/06/2007
|
|
|
|
|