|
I am reading "Windows Graphics Programming", by Feng Yuan, and in the beginning he writes his own custom Window class to demonstrate a number of code techniques. It's C++, and looks a lot like the classic style of Petzold (I'm sure many of you are familiar with Petzold). Anyway, he writes two Windows Procedures for his class, one virtual and one static, (this is kind of confusing) so that the Windows system will dispatch messages to the correct message handler (he subclasses his child windows from this class).
Anyway, forget all that, my question is about something else entirely. In his header file for this custom window class, he lists the usual function calls you would make: the two Windows Procedures, constructor(void), destructor, Create, RegisterClass, and sets up the default message loop. Then, and this is what I don't understand, he does this:
BOOL ShowWindow(int nCmdShow) const<br />
{<br />
return ::ShowWindow(m_hWnd, nCmdShow); <br />
}<br />
<br />
BOOL UpdateWindow(void) const<br />
{ <br />
return ::UpdateWindow(m_hWnd);<br />
}<br />
What exactly do those return statements do?
Oh, sorry, m_hWnd is the handle to the Window(type HWND). In his constructor, he does this:
KWindow(void)
{<br />
m_hWnd = NULL; <br />
}
|
|
|
|
|
I assume this isn't MFC related code. He is wrapping global Windows API functions as functions within his class. The :: in ::ShowWindow() means call the global function, not one in a class. By wrapping these functions he doesn't need to a) use ::FuncName everywhere and b) doesn't need to pass m_hWnd as the wrapped function does this for him.
Hope that helps.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Neville,
Thanks for the response. And, yes, it is non-MFC code.
The ShowWindow and UpdateWindow calls are standard Win32 functions, I recognize the same calls from Petzold.
But, what I don't understand is: Why return anything? Typically, when creating a window, you just write the same code as above, but without a return statement. I'm thinking that he intends to make the two variables (the HWND and the int type) available for some other potential action, I don't know what.
I realize that it's an insignificant issue, but, his return statements are often of this style (and he never returns a this*). Weird.
|
|
|
|
|
Hi NB,
From the ShowWindow() docs:
Return Values
If the window was previously visible, the return value is nonzero.
If the window was previously hidden, the return value is zero.
And for UpdateWindow()
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Windows NT: To get extended error information, callGetLastError.
So returning the same value as the wrapped function makes perfect sense to me.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
2 questions about VC++:
first, when I close VC++ and then reopen an MFC project in VC++, my resources file is gone...where did it go. I clicked on the .dsw to open my workspace but the resource folder doesn't even show up.
second, I get the following message in my debug window:
"fatal error LNK1104: cannot open file "nafxcwd.lib""
It appears that my library is not linked properly, no? How do I remedy this problem?
tanks much, Dave
|
|
|
|
|
From Michael Dunn's C++ Forum FAQ:
2.8: Why do I get an unresolved external on nafxcw.lib or uafxcw.lib? (top)
The files nafx*.lib and uafx*.lib are the static LIB versions of MFC. The files beginning with "n" are the ANSI version, and the files beginning with "u" are the Unicode version. By default, only the ANSI files are installed on your hard drive. If the linker cannot find these LIB files, copy them from your Visual C++ CD to your <vcdir>\vc98\mfc\lib directory.
If those files are not on your CD, then you have an edition of Visual C++ that does not support static linking to MFC. You will need to change your project settings to use the DLL version of MFC. Click Project->Settings and go the General tab. In the Microsoft Foundation Classes combo box, select Use MFC in a Shared DLL.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Thanks...I'm glad you showed me the fax area...lots of good stuff.
|
|
|
|
|
In MFC, the function AfxGetInstanceHandle returns the instance handle to the dll you are currently in... What is the equivalent win32 API call? I can't seem to find it, but there must be a way... I need it for SetWindowsHookEx parameter inside a dll...
|
|
|
|
|
I don't think there is one for that. MFC plays a trick by saving the DLL handled at DLLMain, and gives it back to you.
I expect that you need to save the handle somewhere at DLLMain?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Doh. yeah, DllMain will do. Thanks.
|
|
|
|
|
See GetModuleHandle(NULL) in the docs...
onwards and upwards...
|
|
|
|
|
Hi.
I am working on a project that features socks v4 and socks v5 communication over winsock. I am using raw winsock. I need to know the format of packages coming and going to a socks server. Here are reference I have read and techniques I have tested.
http://www.faqs.org/rfcs/rfc1928.html
http://jonathanclark.com/diary/firewalls/
Please look over those websites. As you can see, socks server communicate requires a very specific format. In C++, we generally use a structure.
Anyways, I can send packages to the socks server, however, the data that it sends back does not make any sense.
In sum, I need someone who has successful worked with socks using raw winsock to give me an example of how to *interpret* data from the sock server during negotiation.
Thanks,
Kuphryn
|
|
|
|
|
I bought the toolkit and never looked back.
I bought an SDK from Permeo -- it was done, installed, and worker perfectly in 1 day. I swear. And I've never gotten a bug back from my QA group relating to SOCKS problems.
The SDK is a function-for-function map of winsock functions into their toolkit.
Check Out: http://www.socks.permeo.com/[^]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks
|
|
|
|
|
I am trying to create an array of structures (struct TSimSignal) that are of the size of SignalCount in the TSimHeader struct
Below is the structure that I have created:
<br />
struct TSimSignal<br />
{<br />
<br />
double Value[45];<br />
int SimWriteFlag;<br />
int data_index;<br />
int DisplayReadFlag;<br />
long TimeStamp;<br />
<br />
};<br />
<br />
<br />
struct TSimHeader<br />
{<br />
char *Name[45];<br />
char *Unit[45];<br />
double Min[45]; <br />
double Max[45]; <br />
int SignalCount; <br />
int SimStatus;<br />
<br />
};<br />
<br />
<br />
struct TSimSignal signal_str[TSimHeader.SignalCount];<br />
int *data_index_ptr[TSimHeader.SignalCount];<br />
double *data_ptr[TSimHeader.SignalCount];<br />
<br />
How can I create these arrays with the size of SignalCount?
I know that I have to have a const to set the size of the array, but not sure how to make the const = to SignalCount;
SignalCount is set when A file is read in. It does a count and then sets the number for SignalCount.
thanks,
sj
|
|
|
|
|
struct TSimSignal *signal_str = new struct TSimSignal[TSimHeader.SignalCount];
int *data_index_ptr = new int[TSimHeader.SignalCount];
double *data_ptr = new double[TSimHeader.SignalCount];
|
|
|
|
|
And don't forget to call delete on the pointers when you are done with the arrays, i.e.
delete []signal_str;
delete []data_index_ptr;
delete []data_ptr;
-Dean
|
|
|
|
|
Thanks Dean,
sj
|
|
|
|
|
David,
I get the same error when I try it this way.
Any ideas?
d:\....h(42) : error C2275: 'TSimHeader' : illegal use of this type as an expression
d:\....h(19) : see declaration of 'TSimHeader'
sj
|
|
|
|
|
Figured it out, I just made a pointer to the structure and accessed the data using the pointer
sj
|
|
|
|
|
Welp, i got myself in a little mess and i cant figure out how to fix it.
I want to import data from a text file, and have a string appear in an Edit Control.
Basically, the problem is this: if i define my variable of the edit contol as CEdit, it says it can't convert to string when i try to write to my file. (i have a function that accepts a string, and im passing the edit control variable into it.)
if i try to define my edit control variable as a 'variable' and make it of type CString, i get yelled at because, evidently, ifstream doesn't work properly, or the syntax im using isnt happy.
any ideas? how can i pass a CEdit or a CString variable into a function that requires a string variable?
*.*
|
|
|
|
|
keegan wrote:
how can i pass a CEdit or a CString variable into a function that requires a string variable?
void someFunction( LPCTSTR lpszSomeString )
{
AfxMessageBox(lpszSomeString);
}
...
CString str = "This is some text";
someFunction(str);
|
|
|
|
|
ok, thanks for that. it accepted passing CEdit variable into a function that takes a LPCTSTR string.
However, i still cant infile >> a LPCTSTR.
Ie, here's my code:
void function(LPCTSTR stringthing)
{
string filename = "stringdata.dat";
ifstream inFile(filename.c_str());
inFile >> stringthing;
}
this returns the error
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'LPCTSTR' (or there is no acceptable conversion)
i tried using inFile >> into a string variable, then setting my LPCTSTR = to that string contents...but that said it cant convert.
*.*
|
|
|
|
|
void function(LPTSTR stringthing)
{
string filename = "stringdata.dat", str;
ifstream inFile(filename.c_str());
inFile >> str;
strcpy(stringthing, str.c_str());
}
|
|
|
|
|
thanksa again, but that code returned an erro saying i cant convert from LPCSTR to char*.
i've foudn a way (the only way that my program can be run in another area of the code) where all i have to do is return a CString. but, this takes me back to teh beginning, because i cant use infile>> for a cstring object, i cant convert a string into a cstring if i try infile >> string, and i cant convert from a string to an LPCSTR if i try inFile >> string.
buggar this is annoying. why cant i just go
CString foo;
string bar;
infile >> bar;
foo = bar;
return foo;
*.*
|
|
|
|
|
I don't know what it is you are trying to do, but all of my suggestions have been tried and tested with positive results. I'm sure there are better ways of accomplishing the task but these are answers to your question(s) nonetheless.
void function( LPTSTR stringthing )
{
string filename = "stringdata.dat", str;
ifstream inFile(filename.c_str());
inFile >> str;
strcpy(stringthing, str.c_str());
}
void main( void )
{
char buf[1024];
function(buf);
printf("]%s[\n", buf);
}
When the answer appears to be wrong, don't discount the possibility that the wrong question was asked! - Anonymous
|
|
|
|
|