|
Derive a class say ButtonEx from CButton and over ride DrawItem( LPDRAWITEMSTRUCT lpDIS )
Create buttons as the object of ButtonEx
ButtonEx::DrawItem( LPDRAWITEMSTRUCT lpDIS )
{
if(( lpDIS->itemState & ODS_SELECTED ))
{
// means buton is clicked
}
}
|
|
|
|
|
This is a very strange way of going about things. The code in question will fire every time a clicked button is rendered and not just once when it's clicked.
Steve
|
|
|
|
|
Thank you for pointing out
I was only thinking about getting the selection status. My solution was poor.
|
|
|
|
|
I like to autosize the owner draw button depending upon the text that it load dynamically based on localization strings. so some strings are large than others. Keeping this I override DrawItem in the inherited class from CButton.
The sample code is below
void CMyGraphicButton::DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CString cs;
CString cslong;
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
if (!lpszText || lpszText == (LPCTSTR)-1)
{
GetWindowText (cs);
}
else
cs = lpszText;
// now i m trying to resize , so let try to increase the size of button unconditioally
// I get
//lpDrawItemStruct>rcItem.left =0
//lpDrawItemStruct>rcItem.right =75
//lpDrawItemStruct>rcItem.top = 0
//lpDrawItemStruct>rcItem.bottom = 25
//As my button is on extreme right side of dialog so i tried to extend/increase the size of
// button of the left side as follows
lpDrawItemStruct>rcItem.left -= 25 ;
// but the above causes the text to be moved on right side insead of resize/increase the
//button size.
Any idea or help is appriciated.
Thanks
Anil
}
[AKS]
|
|
|
|
|
u will receive a WM_COMMAND message(OnCommand) when any button is pressed. Also check the HIWORD of the wParam is BN_CLICKED to ensure that the message has arrived due to a button click.
nave
|
|
|
|
|
Handle the BN_CLICK notification in the parent window. This notification is packaged as a WM_COMMAND message.
Steve
|
|
|
|
|
Thanks! It worked
|
|
|
|
|
Hi again,
thanks for the reply last time....
Do you know how to do the same thing for the events where the user moves a scroll bar or clicks in a list box/list control?
I couldn't get it to work using the OnCommand method, so I used OnNotify. See code here...
BOOL CBaseFormView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) <br />
{<br />
NMHDR* pNMHDR = (NMHDR*)lParam;<br />
<br />
<br />
if(pNMHDR->code == 0xFFFFFFF4) <br />
{<br />
AsyncServicesUpdateInactivityTimer(this->m_hWnd);<br />
}<br />
<br />
return CFormView::OnNotify(wParam, lParam, pResult);<br />
}
Except I'm not sure what the notification codes for selecting something within a list box or list control, or moving the scrollbar are.
Thanks again
Skyapie
|
|
|
|
|
The WM_HSCROLL and WM_VSCROLL messages are sent when scrolling occurs in a Window's standard scroll bar. When the user clicks in a control it depends on the control. For example List View controls send the NM_CLICK notification.
Steve
|
|
|
|
|
|
when a button is clicked, the parent of the button will receive WM_COMMAND message. Check whether the high-order word of the wparam is BN_CLICKED.
if( message == WM_COMMAND && BN_CLICKED == HIWORD( wParam))
{
// button is clicked.
}
the lparam will be having the handle of button.
nave
|
|
|
|
|
but i want my button handle click, only use itself message.
LRESULT ButtonProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
........
}
return DefWindowProc(message, wParam, lParam);
}
|
|
|
|
|
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
|
|
|
|