|
in that case u must find the click event by handling the WM_LBUTTONDOWN and WM_LBUTTOUP messages.
nave
|
|
|
|
|
The basic technique used to subclass a window using straight Win32 is as follows:
- Declare a variable of type WNDPROC to point to the old window procedure before subclassing. i.e.
WNDPROC g_pSuperClass;
- Write a replacement window procedure which defers all unhandled messages to the old one. i.e.
LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return CallWindowProc(g_pSuperClass, hwnd, uMsg, wParam, lParam);
}
- Now subclass the window with code like this:
g_pSuperClass = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hwndButton, GWLP_WNDPROC));
SetWindowLongPtr(hwndButton, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&MyWindowProc));
Now to specialize the window alter the code in MyWindowProc .
To handle the click event however you don't need to subclass the window. The button sends the BN_CLICK notification to its parent when it's clicked. This messages is packaged in a WM_COMMAND message.
Steve
|
|
|
|
|
Hi all,
I currently have a website running that I built in the programming Language C/C++ using Microsoft Visual C++ and built it to run as CGI. Everything works good, except I have grown tired of using conventional methods of input/outputting data to just dat and txt files, so I was wondering where or how I could learn to incorporate MySQL into my CGI app to store the data for my users on my website. I got mySQL server and installed it, I just more or less need to know how I can read/write to it from my code. Any help is appreciated. Thanks.
|
|
|
|
|
What benefits does this approach give you compared to using C#/ASP.NET ( which has data provider code built in ) ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Possibly it's already built - this is a huge benefit!
Steve
|
|
|
|
|
I just recently learnt how to program in C/C++ and hense I have never done any coding in C# or ASP.NET... I have heard that there is a way to do this so I wanted to give it a try. I just need a head start as all.
|
|
|
|
|
S0uthy wrote: I have heard that there is a way to do this so I wanted to give it a try
Well, if the site doesn't exist yet, my strong advice is not to bother with a method that, frankly, has been out of date for at least 8 years now. You're looking to do things in a way that is
a - hard
b - not well supported
c - has no real frameworks to support it
If you know C++ syntax, C# won't be a big ask for you, and the .NET framework will do all sorts of cool stuff for you that you're never going to be able to do in c++
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,all.
Here I have a project which needs the client transmit 4MB per second to server.I use CSocket and CArchive model in MFC with stream type socket.After it works for a while, the client can not send data any more, it seems that it has been blocked by the server's reading because the socket is set to work synchronously. Meanwhile the server is waiting for client's data, which leads to a deadlock in communication.However, no CMemoryException, CArchiveException or CFileException has been thrown out, but the client can not response any message any more (but the server remains OK).So is there any methods to avoid this?or do you all have some suggestions to improve the transmission?
|
|
|
|
|
I have declared:
typedef void (CMyClass::*LPFN_MYMETHOD)();
elsewhere in my code I have Something like:
void Func(){
CMyClass* pMyClass=(CMyClass*)GetMyClass();
LPFN_MYMETHOD pMethod=(LPFN_MYMETHOD)GetMyMethod();
// Now I want to do: pMyClass->pMethod();
// Easy symantics for humans, but aparently NOT for a compiler
}
I tried various variants, which either yielded that pMethod is not a member of CMyClass, or, that pMethod does not evaluate to a function
Does anyone know what the correct syntax is.
LateNightsInNewry
|
|
|
|
|
Further to the above, I've gotten away sofar with writing something that works well for my compiler:-
void Func(){
DWORD pMyClass=(DWORD)GetMyClass(); //Note Declaration Changed to DWORD
DWORD pMethod=(DWORD)GetMyMethod(); //Note Declaration Changed to DWORD
__asm{
mov ecx,pMyClass;
call pMethod;
}
}
This however cuts out all the expensive type checking features, and becomes highly compiler dependent. I am looking for a Syntax to do this, which fits within the language. Somewhere, deep within MSVC, Bill Gates uses this syntax to call MessageMap functions.
LateNightsInNewry
|
|
|
|
|
Try this:
(pMyClass->*pMethod)()
This is logical as pointers should be dereferenced to yield the pointee: in this case a pointer to a function should be dereferenced to yield a function.
Another comment; lose the LPFN_MYMETHOD cast: it's destructive and not needed. With this cast you disable the compiler's type checking.
Steve
|
|
|
|
|
Thanks Steve, Works as Advertised. As for the cast,I agree in the example given. Won't work in my current project, as the type to cast to is determined elsewhere in the process.
LateNightsInNewry
|
|
|
|
|
Dear Steve,
Your Answer Works,and I am gratefull for the help you gave . No Doubts or Complaints in the Making it Work Department,BUT I totally fail to see how it's logical. In Simple Language, and avoiding language used by CompilerCompiler Authors, could you explain 'how' this syntax should immediately spring to mind when face with the problem as stated.
Much Appreciated
LateNightsInNewry
|
|
|
|
|
A pointer to an integer:
int *pInt;
To refer to the integer pointed to (the "pointee") in previous example:
*pInt
A pointer to a function which returns nothing and has no parameters:
void (*pFunc)();
To call through the pointer in previous example:
(*pFunc)();
Note that in this case the star is optional but leaving it out is not consistent with the use of pointers in all other contexts.
A pointer to a class of type CFoo :
CFoo *pFoo;
To call a member function through the pointer in the previous example:
pFoo->AFunctionInCFoo();
A pointer a member function of class CFoo that returns nothing and has no parameters:
void (CFoo::*pFunc)();
To call through the pointer in the previous example:
pFoo->*pFunc();
In all cases you use the * operator to turn a pointer into a pointee (the object it points to). Just like it makes no sense to multiply a pointer to an int by 2 but it makes perfect sense to multiply the integer pointed to by 2 so it is with the pointer to a member function: you don’t call the pointer you call what it points to (a function) and the * operator is how you move from a pointer to its pointee.
Steve
|
|
|
|
|
Steve,
Never looked at this pointer resolution and declaration syntax issue from the point of view you just showed. The Logical step I Missed was the Optional Star, which I understand now, becomes a syntactical requirement where the compiler would not otherwise be able to determine the level of indirection of the Memberfunction.
thanks;P
LateNightsInNewry
|
|
|
|
|
anyone have a clue, how to perform a simple search through a ms access db in a VC++
|
|
|
|
|
You've asked this question several times now. The answer is to use ADO or DAO to connect to the database and perform SQL on it. Realistically, if you have a project that requires you to do this, you'd do better to buy a book if you have no idea how to do it from start to finish. Are you already connected to the DB ? Then you should read the MSDN reference on the classes you're using.
What version of VC++ are you using ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I am trying to create and then use a VC++ DLL in C#. I created the DLL in Visual Studio 2005. I just built the dll without adding any function of mine to it. That is, it is a dll that exports symbols and has the following pre-defined export symbols/functions.
// This is an example of an exported variable
TEST_API int ntest=0;
// This is an example of an exported function.
TEST_API int fntest(void)
{
return 42;
}
where,
#define TEST_API __declspec(dllexport)
Then I created a simple VC# empty project ( in Visual Studio 2005) and added the class "test" to it. When I add the VC++ dll as a reference I get this error .... "A reference to "../test.dll" could not be added. Please make sure that the file is accessible, that it is a valid assembly or COM component".
Even though I dont think it needs a conversion from COM to COM+, I even tried doing "tlbimp". I went to the command prompt for Visual Studio 2005, followed the path to where my dll resides and used the tlbimp command. But I got the error that test.dll is not a valid type library.
Someone told me that I need to register the dll using regsrv32 and it would show in my COM list when I am adding it as a reference. But that didnt work either. When I run the regsrv32, I get the error message as "..\test.dll was loaded, but the DLLRegisterServer entry point was not found" ...
I just want to know that what is it that I am doing wrong? Is there something else that I should be doing ?
All I did for creating the test.dll was ...... I went to File->New->Project. Under Visual C++ I selected Win32 and then Win32 Project. In the Application settings I selected the DLL and then checked the export symbol box. I simply built the project and was trying to use it.
Thanks for your time.
Saania
|
|
|
|
|
OK, you're a bit lost here.
You are not creating a COM dll, let alone COM+. You're writing a plain, vanilla, dll. You need to use p/invoke to call methods on this dll. If you're writing it from scratch, I'd be more inclined to use C++/CLI to write a DLL that IS an assembly and which can be imported.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for the reply, but there is one problem still .... I am not creating a DLL from scratch. I have a project in VC++ (written by someone else) and I want to use it from my VC# code, so for that I first have to convert the VC++ project to a dll ~ right !! Or is there some other way I can use the project in my VC# code.
Thanks once again.
|
|
|
|
|
If you're converting to a dll, I assume you're hoping to access some classes in there, not execute any sort of UI ? You can compile with /clr and write a managed layer that you can import into C#. Which is easier really depends on the code you're working on.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi I have two 'LPSTR' (or char *) variables and I need some help in figuring out how to insert a number inbetween these two and join (strcat) the two LPSTR variables. I apperciate any help I can get, Thanks!
Ex:
LPSTR test1;
LPSTR test2;
test1 = "hello";
test2 = "world";
int x = 9;
char buffer[10];
itoa(x,buffer,10);
//I need to end up with 'hello 9 world'
|
|
|
|
|
You can do this:
char test1[256];
char test2[256];
sprintf(test1, "hello");
sprintf(test2, "world");
int x = 9;
char buffer[256];
sprintf(buffer, "%s %d %s", test1, x, test2);
the buffer will contain 'hello 9 world'
Chipper Martin
|
|
|
|
|
|
I have a network device app that resides in the system tray. I added a context menu to this app to enable and disable the device. Right now I'd like to add an additional context menu item to display the Windows "Network Connections' dialog box. This is the same dialog that one sees on clicking "Network Connections" in the Control Panel.
Has anyone tried this before? Would appreciate any help in this regard.
Thanks.
|
|
|
|