|
Dear Friends,
Please let me know how to access USB data. Not only USB what are the methods in VC++ to access USB or RS232 port and system hardware.
Please help me and give me ur valuable suggession ASAP.
Thanking you in advance.
Bilar
|
|
|
|
|
Hello,
I have created a Win32 Windows application that uses a WinMain() and WndProc(). Currently, my application runs within the application Window. I want to see the output of variables, but not inside my application window. Instead, I want to use the console window. Basically, I want to run my application and then if the programs debug flag is on then I want to open up a console window and start printing variables. How do I do this, because if I choose a console application there is no WinMain?
In addition, how do I call an .exe from within my Win32 windows program. Like the cmd.exe and then another custom.exe within that console window? I do not wish to use MFC at this time.
Thanks.
|
|
|
|
|
its better if u go for a console based application.
why do u need WinMain- its better to use main().
but, if u need a win32 application, then u have to start a win32 application project.
i u wish to see the current values of various variables, add a listbox and print then all...
but, i suggest to use the DEBUGGING procedures inside the IDE... use Ctrl-F10 for running to cursor, etc...
u can set WATCHES, etc....
for calling an EXE from inside ur win32 application, use the WinExec or ShellExecute
API... or u can go for the CreateProcess API...
my suggestion is to use the ShellExecute API..
its very simple and powerfull...
one more thing, its better not to use MFC , if ur more into SYstem Side Programming.....
|
|
|
|
|
Thanks for the response. I will look at ShellExecute.
I need to create a win32 window for my graphics application. Can I still create a window with a console application. Currently I am using winmain, but I want to simultaneously launch a console. How do I do this? Can I use a console based application with a main and then create a win32 window?
Thanks
|
|
|
|
|
You can use the AllocConsole() API to create a console for your application
|
|
|
|
|
nope,
u cannot use the console based application project and then create a win32 application...
i guess u can, but u will have to change the compiler setting and other linker options....
some other person gave u a reply on using allocconsole() api, go for that, search it in MSDN... or google it....
|
|
|
|
|
i think the TRACE(...) may be what you want;
used like printf, and output to the IDE's output-window only when debugging;
hope this helps
|
|
|
|
|
check out debugview from sysinternals.com
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Hi.
Usual question. How can I load an Icon into my main MFC window. I already searched on this web site for answers but obviously they won't work for me. I tried several differnt ways:
I then tried this :
BOOL CMyAppView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
m_hIconFrame = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME));
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<hbrush>(COLOR_WINDOW+1), m_hIconFrame );
return TRUE;
}
Then I tried :
in MyApp::InitInstance()
{
AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); <--- this wont work
CWinApp::LoadIcon(IDR_MAINFRAME ); <------------------------- this wont work too
m_pMainWnd = pFrame;
// create and load the frame with its resources
pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
}
Then I tried in int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct). Still no luck..
However same function call ie. AfxGetApp()->LoadIcon(IDR_MAINFRAME); in my dialog class displays the bloody icon ok.
what is going on? Why can't I see this icon in my main window caption bar? ARGH....
Can somebody help please. thank you.
|
|
|
|
|
I'm pretty sure you just need to add an icon as a resource and then name it:
IDR_MAINFRAME
Then when you create the mainframe it should be there. I don't think you need to manually load.
Look here to help out in MFC:
http://www.adminmod.org/karel/2/index.htm
|
|
|
|
|
|
Ok thank you. Cwnd::SetIcon() solved my problem
|
|
|
|
|
Hi.
Can anyone please advise on how I can specify a class member function as the 'Cmp' function in the above call.
I would like to be able to call the sort() function from within a class member function and to be able to specify another class member function( of the same class and instantiation ).
I do not want to declare a struct that defines a comparison operator etc.. I would like to be able to keep the whole process private to a class that defines a 'Cmp' type function that I can provide as an argument.
Thanks in advance.
James.
|
|
|
|
|
hi
Yes it is possible, provided the user-defined binary predicate function shud b static. Otherwise u know, while linking a class, every member function will get an _this pointer automatically. This changes the function signature of a predicate function and will show error while compilation. If it is static the parameter list will remain unchanged. c the sample class.
rgds..mil10
using namespace std;<br />
class TstClass<br />
{<br />
public:<br />
vector<int> _data;<br />
void loaddata()<br />
{<br />
_data.push_back(20);<br />
_data.push_back(10);<br />
_data.push_back(30);<br />
}<br />
<br />
static bool UDgreater ( int elem1, int elem2 )<br />
{<br />
return elem1 > elem2;<br />
}<br />
<br />
void displaysorted()<br />
{<br />
sort(v.begin(),v.end(),UDgreater);<br />
vector<int>::iterator it;<br />
<br />
for( it=v.begin(); it!=v.end(); it++ )<br />
cout<<(*it); <br />
}<br />
};
|
|
|
|
|
Mil10 wrote:
Yes it is possible, provided the user-defined binary predicate function shud b static. Otherwise u know, while linking a class, every member function will get an _this pointer automatically. This changes the function signature of a predicate function and will show error while compilation.
From Section 11.5 in "The C++ Programming Language, 3rd":
An ordinary member function declaration specifies three logically distinct things:
(1) The function can access the private part of the class declaration, and
(2) the function is in the scope of the class, and
(3) the function must be invoked on an object (has a this pointer).
By declaraing a member function static ($10.2.4), we can give it the first two properties only. By declaring a function a friend, we can give it the first property only.
Maxwell Chen
|
|
|
|
|
Thanks very much for the help.
James.
|
|
|
|
|
From Section 11.5 in "The C++ Programming Language, 3rd":
An ordinary member function declaration specifies three logically distinct things:
(1) The function can access the private part of the class declaration, and
(2) the function is in the scope of the class, and
(3) the function must be invoked on an object (has a this pointer).
By declaraing a member function static ($10.2.4), we can give it the first two properties only. By declaring a function a friend, we can give it the first property only.
very nice explanation - thanx Chen.
rgds...mil10
|
|
|
|
|
I think you want the mem_fun adapter function, which returns an appropriate functor object (typically a mem_fun1_t object).
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Do you mean something like,
class Sort1
{
private :
std::vector<int> v_ ;
static bool Cmp ( const int l, const int r )
{
return l > r ;
}
public :
Sort1 ()
{
v_.resize ( 10 ) ;
for ( int i = 0; i < 10; ++i )
{
v_ [ i ] = i ;
}
}
void DoSomething ()
{
std::sort ( v_.begin (), v_.end (), Cmp ) ;
}
void PrintV_ ()
{
for ( unsigned i = 0; i < v_.size (); ++i )
{
std::cout << v_ [ i ] << " " ;
}
std::cout << "\n" ;
}
} ;
int main()
{
Sort1 s ;
s.PrintV_ () ;
s.DoSomething () ;
s.PrintV_ () ;
return 0;
}
Or are you trying to use a member of the sortable class as the comparison function?
class Sortable
{
private :
int val_ ;
public :
Sortable ()
{
}
static bool Cmp ( const Sortable& l, const Sortable& r )
{
return l.val_ > r.val_ ;
}
} ;
...
std::vector<Sortable> vs ;
...
std::sort ( vs.begin (), vs.end (), Sortable::Cmp ) ;
Paul
|
|
|
|
|
Hi.
I have looked at all the updates to this thread and I am a little unsure as to how to proceed.
I appreciate all the advice and the different types of approach. However, if I may describe the problem with some additional constraints.
I cannot use the static member function approach as I need to be able to access a set of compound sort ranges defined in a vector table declared privately within the class.
I therefore need a mechanism that would allow me to specify a non-static class member function as the comparison function on the sort call.
Any more advice would be most welcome.
James.
|
|
|
|
|
Hi.
If no one has a solution to this particular situation, then I might be better served by simply writing my own sort routine. That way I can provide a comparison function with the operands and access that I require. I have written numerous sort routines before, especially in the days before C++ and the STL ( as you might have guessed, I am quite new to C++). I was hoping, prehaps naively, that the STL could solve all my algorithmic problems elegantly but maybe that is just not the case.
Thanks for the contributions.
James.
|
|
|
|
|
You may consider this too ugly...
template <typename C, typename S> struct MemFunCmp_t
{
bool (C::*pmf_ )( const S&, const S& ) ;
C& rC_ ;
MemFunCmp_t ( C& rC, bool (C::*f)( const S&, const S& )) : rC_ ( rC ), pmf_ ( f )
{
}
bool operator () ( const S& l, const S& r )
{
return (rC_.*pmf_) ( l, r ) ;
}
} ;
template <typename C, typename S> MemFunCmp_t< C, S > MemFunCmp ( C& c, bool (C::*f)( const S&, const S&))
{
return MemFunCmp_t <C, S>( c, f ) ;
}
class Sort2
{
private :
std::vector<int> v_ ;
bool Cmp2 ( const int& l, const int& r )
{
return l > r ;
}
public :
Sort2 ()
{
v_.resize ( 10 ) ;
for ( int i = 0; i < 10; ++i )
{
v_ [ i ] = i ;
}
}
void DoSomething ()
{
std::sort ( v_.begin (), v_.end (), MemFunCmp ( *this, Cmp2 )) ;
}
void PrintV_ ()
{
for ( unsigned i = 0; i < v_.size (); ++i )
{
std::cout << v_ [ i ] << " " ;
}
std::cout << "\n" ;
}
} ;
int main()
{
Sort2 s ;
s.PrintV_ () ;
s.DoSomething () ;
s.PrintV_ () ;
return 0;
}
But I think it does what you're asking for.
It builds and runs on VC7.1, I believe it's standard C++. YMMV.
Paul
|
|
|
|
|
Hi.
Thanks for the update. The 'work around' is not at all ugly but prehaps slightly convoluted. Nevertheless, I have incorporated it into my application and it works prefectly. I like your solution because I have learnt something new from it.
Best Regards.
James.
|
|
|
|
|
Ok, im a complete newb at C++ and am just starting off. I wanna make a program MFC of course and when i click button "Create" i want it to bring up Dialog "B" which is the other dialog besides "A" can someone tell me the quickest and eastesy way of doing this? If it wouldnt be too much trouble of course...
Thanks
|
|
|
|
|
You create a dialog in your resource editor, and then it will create a class derived from CDialog, say you call the class CNewDlg. Then the code looks like this:
OnClickCreate() // this method is created by the IDE for you on request, I'm not sure of it's signature anymore, it's been too long
{
CNewDlg dlg;
if (dlg.DoModal() == IDOK) //OK was clicked
{
//respond to the OK button being clicked. At this point, any member variables in the CNewDlg instance
// you created are still accessible, but anything in windows ( edit boxes, etc. ) isn't, as they have been destroyed.
}
}
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|