|
|
Read my article on modeless dialogs :-
http://www.codeproject.com/useritems/gettingmodeless.asp
Nish
Oh, I don't know why she's
leaving, or where she's gonna go
I guess she's got her reasons but I just don't wanna know
'Cos for 24 years I've been living next door to Alice
24 years just waitin' for a chance
To tell her how I feel and maybe get a second glance
Now I gotta get used to not living next door to Alice
|
|
|
|
|
Search for something about Modal (on showing the dialog) ! The dialog must not be MODAL !
icounter
|
|
|
|
|
Hi,
I'm doing multithread in my program. Due to some reasons, the thread needs to be suspended, and wait for some return signals to go on. However, it is possible that there is no return signal. I would like to add a time-out feature, so that the thread can resume after waiting for a period of time and doesn't have to wait indefinitely. (let say 5000ms).
Does anyone know how to do it?
Can I use QueryPerformanceCounter()........and how to use it?
Thanks
|
|
|
|
|
You can use this function:
DWORD WaitForSingleObject(
HANDLE hHandle,
DWORD dwMilliseconds
);
Set the time-out interval, and the handle that you use may be for the certain event that you are waiting for, here is a list of objects that this function will wait for:
- Change notification
- Console input
- Event
- Job
- Mutex
- Process
- Semaphore
- Thread
- Waitable timer
Look at msdn.micorsoft.com for more details on this function.
|
|
|
|
|
kilowatt wrote:
You can use this function:
DWORD WaitForSingleObject( HANDLE hHandle, // handle to object DWORD dwMilliseconds // time-out interval);
Where should this WaitForSingleObject() put? Should I put it in the thread function ?? Or......
More clear on my question:
My thread function needs to wait (suspend) a boolean value (T/F) from another function in order to go on. If my thread has been waiting too long, I want to resume this thread.
Thank you so much!!!!!!
|
|
|
|
|
kilowatt wrote:
You can use this function:
DWORD WaitForSingleObject( HANDLE hHandle, // handle to object DWORD dwMilliseconds // time-out interval);
Where should this WaitForSingleObject() put? Should I put it in the thread function ?? Or......
More clear on my question:
My thread function needs to wait (suspend) a boolean value (T/F) from another function in order to go on. If my thread has been waiting too long, I want to resume this thread.
Thank you so much!!!!!!
|
|
|
|
|
In the thread that should wait you use WaitForSingleObject. Instead of setting a boolean, you can set an event.
In other words...
In you main thread.
1. ::CreateEvent (...)
2. Start thread
3. Started thread waits on the event with a timeout using ::WaitForSingleObject
4. Main thread sets the event (::SetEvent) when the created thread should wake up.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
You will have to have two threads in order to do this. There are many ways of doing this. I will give you a simple example of how to do this in the SDK. If you are using MFC then there are objects that you can use to make it easier.
1) Create your worker thread proc, this will be the function that returns true or false, that your main thread waits on. If there are more than one input parameters to your worker thread function
then you will need to create a struct to hold these values. Here is an example, say your current
function looks like this:
BOOL function(int x, int y, float power);
Create a structure like this:
typedef struct FUNCTION_PARAMS
{
int x;
int y;
float power;
}; FUNCTION_PARAMS;
The address of this structure will be passed into the lpParameter of the WorkerThreadProc in order to get the initial parameters of the function.
DWORD WINAPI WorkerThreadProc(LPVOID lpParameter)
{
if (!lpParameter)
{
return FALSE;
}
FUNCTION_PARAMS *fp = (FUNCTION_PARAMS*)lpParameter;
float z = fp.x + f.y * fp.power;
...
return TRUE;
}
2) This is the thread that calls a function in thread two. Here are the actions that this thread should take:
FUNCTION_PARAMS fp;
fp.x = 1;
fp.y = 2;
fp.power = 100.0;
HANDLE hWorkerThread;
DWORD dwThreadID;
hWorkerThread = ::CreateThread(NULL, 0, WorkerThreadProc, &fp, &dwThreadID);
::ResetEvent(hThread);
DWORD dwState;
dwState = ::WaitForSingleObject(hWorkerThread, 5000);
if (WAIT_OBJECT_0 == dwState)
{
DWORD dwExitCode;
GetExitCodeThread(hWorkerThread, &dwExitCode);
if (TRUE == dwExitCode)
{
...
}
else
{
...
}
}
else
if (WAIT_TIMEOUT == dwState)
{
...
}
|
|
|
|
|
// OnInitialUpdate()
m_pSet = &GetDocument()->m_TestSet;
m_pSet->OpenAll();
// Save Button
CString mValue;
GetDlgItemText(IDC_EDIT_FIRST, mValue);
strcpy(m_pSet->m_First,mValue);
m_pSet->SetData();
m_pSet->Update();
The problem is that the new value for m_pSet->m_First does not save to the SQL Server 7.0 Database. When I trace, I can see the new value in the m_pSet->m_First.
Thanks
Peace in Christ
Marco Napoli
|
|
|
|
|
If anyone out there is feeling particularly adventuresome and has VC7 I could use some help. I have a C++ framework that I have been working on in VC 6 called the Visual Component Framework. However I have heard from some people who have downloaded it that it doesn't compile under VC7. I don't have the cash to get VC7 and I was wondering if there might be someone here who might be willing to give it a go ? The framework is free and can be found at http://sourceforge.net/projects/vcf
If you want to help out on this and have questions feel free to contact me.
Thanks
|
|
|
|
|
Hi,
I have an application which when run, starts with a menu, IDR_menu1. When I open a dialog box from the menu how can I change the menu from IDR_menu1 to say IDR_menu 2 which contains options for the dialog box. E.g (the original menu has File,Edit,View,Options,Test,Window and help and the new menu I want to replace it with has only File,Options,Window and Help)
Thanks in advance
|
|
|
|
|
Use LoadMenu to load your menu from the resource file, you will receive an HMENU from this function. Then you can call SetMenu(hWnd, hMenu) and this will set the new menu.
Then you may have to call DrawMenuBar in order to make sure that the menubar gets refreshed.
|
|
|
|
|
Hi,
I need a timer to count how long the program has been waiting:
e.g.
if (x=10)
{
pause indefinitely //i want the function pause for 1000ms......
if (timer = 1000ms) //function pause for 1000 ms already
continue to do stuff here....
}
How can i implement this timer??? Any example!????
Thanks!!!!
|
|
|
|
|
use QueryPerformanceCounter.
here is an example.
LARGE_INTEGER liFrequency;
LARGE_INTEGER liStart;
LARGE_INTEGER liEnd;
if (FALSE == QueryPerformanceFrequency (&liFrequency))
{
MessageBox("Your computer will not support this test. It does not contain a high resolution timer.", "Error", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
QueryPerformanceCounter(&liStart)
...
QueryPerformanceCounter(&liEnd)
LARGE_INTEGER liDiff;
double dTime;
liDiff.LowPart = liEnd.LowPart - liStart.LowPart;
liDiff.HighPart = liEnd.HighPart - liStart.HighPart;
dTime = (double)liDiff.LowPart / (double)liFrequency.LowPart;
I cannot remember what units dTime is in at this point, but if you test it in your debugger you should be able to figure it out. Then use dTime to test if it has been the second that you are looking for.
|
|
|
|
|
Thanks..........;P
|
|
|
|
|
Anonymous wrote:
if (x=10)
{
pause indefinitely //i want the function pause for 1000ms......
if (timer = 1000ms) //function pause for 1000 ms already
continue to do stuff here....
}
I'm not sure I understand entirely. The first comment says you want the function to pause for 1000ms. If that's the case, you can call Sleep(1000);
If, however, you want to know how long the pause was, you can do a fairly cheap & sleazy trick here, depending on the granularity you require:
DWORD dwThen = GetTickCount();
DoSomethingYouWantToTime();
DWORD dwElapsedMilliseconds = GetTickCount() - dwThen;
Be advised that GetTickCount() has a granularity of the system quanta, which is 10ms under NT and 55ms under 9x. If that granularity isn't good enough, then the performance counter example will definatly do the trick for you.
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|
|
Hello , I`ve just signed in and I want to ask a question:
How can I get the progress in a webbrowser control... I mean:
I know how to get it when i push "load" or something like that,but
I want to know how to get the progress when I am browsing
I hope you get it
hihi
|
|
|
|
|
This referes to Chris's Grid Control.
How can I lock the CGridCellCombo box from typed user input. I just want a list box. Only selecting, no typing.
Thank You,
DS
|
|
|
|
|
I'm not sure but I think it is derived from CComboBox and you would do it the same. If it is there was mention of that not to long ago in this forum.
- Matt Newman / Anti-Linux Activist
-Sonork ID: 100.11179:BestSnowman
†
|
|
|
|
|
Change the style of the cell like this :
CGridCellCombo *pCell = (CGridCellCombo*) m_ListZone.GetCell( pItem->iRow + 1, 0 );
pCell->SetStyle(CBS_DROPDOWNLIST);
Hope this help
|
|
|
|
|
Hi, I have a stupid question.
How to make a timer? For example, I want to check the waiting time. If my program has been waiting for 1000 millisecond already, terminate the program.
Thanks
|
|
|
|
|
Anonymous wrote:
If my program has been waiting for 1000 millisecond already, terminate the program.
What du you mean by waiting?
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
For example, due to some reasons I want to "force" my program to pause for 1000 millisecond.......how can i count this 1000ms, and let it go again after 1000ms.
e.g.
if (x=10)
{
pause for 1000ms
continue to do stuff here....
}
thanks!!!!
|
|
|
|
|
with Sleep() you can pause the timer.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|