|
Thanks steve. i didn't know that
nave
|
|
|
|
|
As said by Naveen, you can use CreateThread. But it requires some practise before knowing exactly how to use it in a good way (specifically if you don't want to break your OO design).
But you said that your project is non-MFC, does that means it's a console app or is it a win32 application ? If it's a console app, I don't think you can use CreateThread as it is part of the windows SDK. You'll need to use _beginthread.
Anyway, if you want to keep your OO design, the best way IMO is to make your thread run a function of your class and use a boolean to keep the status of the process (finished or not). You could also post a message to your GUI window to specify that the process is finished (or even that the process has increased of 1%). To make your thread run a member function of your class, you'll have to use a little trick: you cannot supply directly the function to the thread because it doesn't have the same prototype as a global function (implicit this parameter). Thus, you can instead use a static member functino of the class (no this parameter because static functions are shared among all instances of your class) and pass the this pointer in the parameters you can pass in the CreateThread function. Then you get it back in your static function and it lets you call a member function of the class in which you can make your process.
In this way you don't break your OO design.
If its not clear, ask and I can post some code.
|
|
|
|
|
Thanks for your comments. My current project is a Win32 application. One day I may venture into the MFC domain, but not today. I understand the concept of the this pointer in regards to using a thread, I suppose it is pretty much the same as using a timer within a class.
At the moment I am not sure where to start or how to approach this problem. I have a folder containg any number of files which need to read, the time required to do this is quite lengthy. Now I can either stick to my first idea of displaying a splash screen on startup, or I can run this in a seperate thread. If I opt for the first option I would still have problems when it comes to saving data or loading additional user defined files.
I would prefer to keep my OO design as I find it very comfortable. All my data, variables and functions are kept close together, seperated in a way from the main loop.
At the moment I am stuck in a web, I just don't know where to start.
|
|
|
|
|
Where are you stuck exactly ?
Why don't you make a thread that will process the data ? Where is the problem exactly ?
|
|
|
|
|
If you are going to use any of the C-Runtime, use _beginthreadex.
To check if it's done, you can call WaitForSingleObject on the return value of CreateThread or _beginthreadex (which is the thread handle). Or you could just have the parsing thread post a message back to the main window (which you'd probably be doing anyway to update the progress bar.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
for the testing sort() .... what kind of the header can I use for my
program.
yaaqub
|
|
|
|
|
There is an example for sort in MSDN.
The header file used is <algorithm>
Nibu thomas
Software Developer
|
|
|
|
|
Here is an example of how to use std::sort:
-------------------------------------------
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
// Our data.
struct Blah
{
Blah(int Type, const char* pName) :
m_Type(Type), m_pName(pName)
{
}
int m_Type;
const char* m_pName;
};
// Print out a blah.
ostream& operator<<(ostream& s, const Blah& b)
{
s << "Type: " << b.m_Type << ", Name: \"" << b.m_pName << "\"";
return s;
}
// Sort functors.
struct SortByType
{
bool operator()(const Blah& l, const Blah& r) const
{
return l.m_Type < r.m_Type;
}
};
struct SortByName
{
bool operator()(const Blah& l, const Blah& r) const
{
return strcmp(l.m_pName, r.m_pName) < 0;
}
};
struct SortByTypeThenName
{
bool operator()(const Blah& l, const Blah& r) const
{
return SortByType()(l, r) | (!SortByType()(r, l) && SortByName()(l, r));
}
};
// The data.
Blah g_Blahs[] =
{
Blah(1, "George"), Blah(2, "Liam"), Blah(2, "Hank"),
Blah(0, "Abigail"), Blah(1, "Bob"), Blah(0, "Jessica"),
Blah(2, "Con"), Blah(1, "Kyle"), Blah(0, "Faye")
};
int main(int argc, char* argv[])
{
Blah* pBegin = &g_Blahs[0];
Blah* pEnd = &g_Blahs[sizeof(g_Blahs)/sizeof(g_Blahs[0])];
ostream_iterator<Blah> oi(cout, "\n");
// Sort by type.
cout << "Type:\n";
sort(pBegin, pEnd, SortByType());
copy(pBegin, pEnd, oi);
cout << "\n";
// Sort by name.
cout << "Name:\n";
sort(pBegin, pEnd, SortByName());
copy(pBegin, pEnd, oi);
cout << "\n";
// Sort by type and name.
cout << "Type and name:\n";
sort(pBegin, pEnd, SortByTypeThenName());
copy(pBegin, pEnd, oi);
cout << "\n";
return 0;
}
Steve
|
|
|
|
|
Hi Guys,
I have a list control containing 3 columns, When i click on any item in the list box it again pops up a combo box having 3 values.If you select a valu in that combobox then it sets that value to the 2nd column of the list control. But problem is that when i am tring to increase the height of the combo box it's not increasing and reamain same always. I am giving you the whole code. please tell me how to fix this problem. I am trying to increase the rect.bottom in the code -> "PLEASE SEE THIS". This code is not complicated at all and you can ignor many things as the last portion is only important and i have given the comment there.
void CListAgr::OnListLButton(WPARAM wParam, LPARAM lParam)
{
UINT nFlags = lParam;
int iItem = wParam;
int iItem = m_list_Agr.GetNextItem(-1, LVNI_SELECTED);
if (iItem >= 0) // If any item in the list box is selected
{
CRect rect;
int offset = 0;
// Make sure that the item is visible
m_list_Agr.GetSubItemRect(iItem, 1, LVIR_BOUNDS, rect);
// Now scroll if we need to expose the column
CRect rcClient;
m_list_leaseabs.GetClientRect(rcClient);
// Set the scroll size. You can ignore this as it is always false and not
// executed
if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
{
CSize size;
size.cx = rect.left;
size.cy = 0;
m_list_leaseabs.Scroll(size);
rect.left -= size.cx;
}
//Checks if the right edge of combo box is greater than the list control
//and if that is true then it will make right edge of combobox equal to
// right edge of list control
rect.left += offset;
rect.right = rect.left + m_list_Agr.GetColumnWidth(1);
if(rect.right > rcClient.right)
rect.right = rcClient.right;
// Here i am setting the length(bottom) of the combo box,creating it and
// displaying it. I think there is some problem in the code below.
rect.NormalizeRect();
rect.bottom += 10 * rect.Height();//dropdown area "PLEASE SEE THIS"
rect.left += 10;
rect.right += 10;
rect.top += 30;
CStringList lstItems;
lstItems.AddTail("X");
lstItems.AddTail("Y");
lstItems.AddTail("Z");
CComboBox *pADFList = new CComboInListView(iItem, 1, &lstItems);
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL |
WS_HSCROLL|CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL;
pADFList->Create(dwStyle, rect, this, IDC_COMBOBOXINLISTVIEW);
pADFList->ModifyStyleEx(0,WS_EX_CLIENTEDGE);
pADFList->SetHorizontalExtent(m_list_Agr.GetColumnWidth(1));
pADFList->ShowDropDown();
pADFList->SelectString(-1, m_list_Agr.GetItemText(iItem, 1));
} // End of outer if Statement
}
-- modified at 1:46 Thursday 2nd March, 2006
|
|
|
|
|
To change the height of the combobox change the font height of that combo box.
nave
|
|
|
|
|
I am currently try to do a dialog based application using the serial port to communicate and control some equipment. However, i find that the behaviour of the windows dialog based application is different from the win32 console application which i written. The win32 application was able to send all instructions and read all the recieved transmission without error. However, when i used back the same functions and write back an almost similar program for my dialog based application, some of the instructions were not sent properly thru the serial port and the recieved transmissions were not read properly. I managed to solve the program of reading the recieved transmission by purging the port before i send an instruction that expect the feedback. However, the dialog based application still causes the equipment to act with a delay, unlike its win32 counter part.
My quesitons are:
1) Why is it for the dialog based application i need to purge the port before i expect a feedback in order to read my feedback properly (but i dont have to do so for the win32 app) ?
2) Is there a difference in using serial port for win32 console apps and dialog based apps ?
|
|
|
|
|
First, win32 console applications doesn't exist. It is either a console application or either a win32 application.
Second, there will be no difference between how the serial port is handled in both cases. You probably did something wrong. Maybe post some code and explai us what exactly the problem is.
|
|
|
|
|
|
But it is still a console app. It is not because you make calls to some functionalities of the Win32 API that your application becomes a WIN32 application.
Or am I wrong ?
|
|
|
|
|
i have to show multiple images on a dialog and move these images as marque in HTML.
so please guide me what i have to do first for this.
Bankey Khandelwal
Software Engineer
|
|
|
|
|
Bankey Khandelwal wrote: i have to show multiple images on a dialog and move these images as marque in HTML.
Change the X and Y co-ordinates of these images hence they will appear as moving.
Another option:
Show these images in static controls and move these controls using MoveWindow(...)
Nibu thomas
Software Developer
|
|
|
|
|
can you give me link where i can saw one example for this
Bankey Khandelwal
Software Engineer
|
|
|
|
|
Hello all,
I am new to Windows programming and VStudio.Net.
I am just trying to assess COM1 by writing a simple win32 console project using VS.Net. I built an empty console project and add the files from the MSDN MTTTY example.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp
but I have the following error while compiling:
Linking...
Init.obj : error LNK2019: unresolved external symbol __imp__InitCommonControls@0 referenced in function _GlobalInitialize
Transfer.obj : error LNK2019: unresolved external symbol __imp__timeSetEvent@20 referenced in function _TransferRepeatCreate
Transfer.obj : error LNK2019: unresolved external symbol __imp__timeKillEvent@4 referenced in function _TransferRepeatDestroy
LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Debug/Serial_win32.exe : fatal error LNK1120: 4 unresolved externals
Did I miss anything here? How can I get these 4 error fixed?
Besides, I just want to assess the COM ports using DOS style programs and not GUIs, should I must learn win32 API programming?
Thanks very much!
|
|
|
|
|
Hi All,
I have a Exe which needs to be converted into Dll...
I dont know how to proceed on this..Any help please..
Thanks,
Nithya
|
|
|
|
|
i don't think it is possible. Better u create a new Dll workspace and copy paste the function or class u want to export.
nave
|
|
|
|
|
how can i show images on window
Bankey Khandelwal
Software Engineer
|
|
|
|
|
Bankey Khandelwal wrote: how can i show images on window
What kind of window?
Take a look at BitBlt(...)
Nibu thomas
Software Developer
|
|
|
|
|
its easy to show a bitmap on the widnow.
just place a picture control.
create a member variable for that control.
Load the bitmap using the API LoadImage()
Pass the handle obtained from the LoadImage fuction to the SetBitmap() function of the picture control
nave
|
|
|
|
|
This way is not very good but it's a draw image
for draw image use WM_PAINT
Like this
CBitmap m_Bmp;
CBrush *m_brush;
m_Bmp.LoadBitmap('FileName');
//for other formats graphic use OleLoadPicture or cimage
m_brush=new CBrush(&m_Bmp);
m_Bmp.Detach();
HBRUSH CMyCpp::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//if((pWnd->==this)
hbr = (HBRUSH)m_brush->m_hObject;
return hbr;
}
WM_PAINT is good for draw I suggestion WM_PAINT
OnPaint
First
/*
m_dcSource.CreateCompatibleDC(GetDC());
Bmp.CreateCompatibleBitmap(GetDC(),x,y);
m_dcSource.SelectObject(&Bmp);
then Load bmp file
and ....
*/
CPaint dc(this)
dc.BitBlt(0,0,800,600,m_dcSource,0,0,SRCCOPY)
or
dc.StretchBlt()
dc is destination for draw And m_dcSource is source
|
|
|
|
|
my project title is walking robot vision ...
the purpose of this project is to detect obstacle( develop software). we assume that the obstacle are not moving like chair, table and box. only the web cam that move.
so now i'm looking for any source code that can detect non moving obstacle (camera moving). I've tried run source code that i got, but it not work ...
thanks ...
|
|
|
|
|