Button to clear main chat.

Problems compiling? Don't understand the source code? Don't know how to code your feature? Post here.

Moderator: Moderators

Locked
TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Button to clear main chat.

Post by TheParanoidOne » 2004-05-14 18:35

I am trying to add a button to the hub window that will clear the text from main chat. Basically, a GUI equivalent of "/clear". I am using the current DC++ CVS code (current = updated half an hour ago).

I have been able to add the button to the window but the stumbling point comes in getting it to actually do anything.

The relevant portions of code I have added are given below:

Code: Select all

Index: windows/HubFrame.h
===================================================================
RCS file: /cvsroot/dcplusplus/dcplusplus/windows/HubFrame.h,v
retrieving revision 1.45
diff -u -r1.45 HubFrame.h
--- windows/HubFrame.h  30 Apr 2004 07:14:56 -0000      1.45
+++ windows/HubFrame.h  14 May 2004 23:14:56 -0000
@@ -71,6 +73,7 @@
                COMMAND_ID_HANDLER(IDC_ADD_AS_FAVORITE, onAddAsFavorite)
                COMMAND_ID_HANDLER(IDC_COPY_NICK, onCopyNick)
                COMMAND_ID_HANDLER(IDC_CLOSE_WINDOW, onCloseWindow)
+               COMMAND_ID_HANDLER(IDC_CLEAR, onClear)
                CHAIN_COMMANDS(ucBase)
                CHAIN_COMMANDS(uibBase)
                CHAIN_MSG_MAP(baseClass)
@@ -100,6 +103,7 @@
        LRESULT onTabContextMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
        LRESULT onChar(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled);
        LRESULT onShowUsers(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled);
+       LRESULT onClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
        LRESULT onFollow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
        LRESULT onLButton(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
        LRESULT onEnterUsers(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/);

I have not included any code that related to the GUI. IDC_CLEAR exists. I have absolutely no idea what the parameters in the method signature mean, but I copied them from the buttons in the Download Queue window (Find, etc).

Code: Select all

Index: windows/HubFrame.cpp
===================================================================
RCS file: /cvsroot/dcplusplus/dcplusplus/windows/HubFrame.cpp,v
retrieving revision 1.61
diff -u -r1.61 HubFrame.cpp
--- windows/HubFrame.cpp        3 May 2004 12:38:05 -0000       1.61
+++ windows/HubFrame.cpp        14 May 2004 23:14:56 -0000
@@ -314,6 +318,11 @@
        return 0;
 }
 
+LRESULT HubFrame::onClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
+       ctrlClient.SetWindowText("");
+       return 0;
+}
+
 
 bool HubFrame::updateUser(const User::Ptr& u) {
        int i = findUser(u);
Again, no GUI code included. I've tried putting a number of different things in this method (such as message boxes) to see if I can get it to do something but to no avail.

Can anyone point out the simple mistake I am making?

If you need any more details, such as the GUI code and so on, let me know.

Cheers :)

EDIT: Hmm. Interesting offtopic thing I noticed. In the post preview page, the post is allowed to be as wide as necessary, so the code doesn't span multiple lines and is therefore legible. In the final post though, the post is restricted to a fixed width, making te code a bitch to read.
The world is coming to an end. Please log off.

DC++ Guide | Words

Qbert
Posts: 73
Joined: 2003-06-07 03:12

Re: Button to clear main chat.

Post by Qbert » 2004-05-14 22:25

TheParanoidOne wrote:EDIT: Hmm. Interesting offtopic thing I noticed. In the post preview page, the post is allowed to be as wide as necessary, so the code doesn't span multiple lines and is therefore legible. In the final post though, the post is restricted to a fixed width, making [the] code a bitch to read.
I always like it when I see code segments that span large either horizontally or vertically to have scroll bars. I have no idea what bulletin board software does this though.
My Visual Studio .NET 2003 is licensed under my name, and the same for my operating system... What about you?
I surf on an OC3 without limitations, two to be exact, and I'm not joking.

Gratch06
Posts: 141
Joined: 2003-05-25 01:48
Location: USA

Post by Gratch06 » 2004-05-15 01:35

Does IDC_CLEAR have a unique number assigned in resource.h? I've had issues with VS duplicating some of those entries when it automatically adds them in and intermixes with the ones I've manually added, therefore causing the command to get picked up by another handler.

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-15 04:09

Gratch06 wrote:Does IDC_CLEAR have a unique number assigned in resource.h?
Yes, it does. At the moment it uses up one the free numbers in the existing range (1224 IIRC) but I did try it before with a number beyond the existing range, with the same (lack of) results.

I've just noticed though, that the previous two entries both have 1223. That may or may not be a problem. I'll try another number though, just in case.
The world is coming to an end. Please log off.

DC++ Guide | Words

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-16 09:03

I tried changing the value of IDC_CLEAR to a few of the other available numbers. Same outcome.

Any other suggestions?
The world is coming to an end. Please log off.

DC++ Guide | Words

joakim_tosteberg
Forum Moderator
Posts: 587
Joined: 2003-05-07 02:38
Location: Sweden, Linkoping

Post by joakim_tosteberg » 2004-05-16 11:58

Have you tried to set breakpoints on different code places that might be called then you click the button?
Have you make sure that the button really calls something then you click it?

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-16 12:36

joakim_tosteberg wrote:Have you tried to set breakpoints on different code places that might be called then you click the button?
Putting a breakpoint on onClear does nothing, indicating that the method is never called, but then I already knew that. The debugging *is* working because if I put a breakpoint somewhere like onClose, it takes me to the code at the appropriate time. I'm not really sure where else a breakpoint would be relevant.
joakim_tosteberg wrote:Have you make sure that the button really calls something then you click it?
Well, I'm not sure how I would do that as I'm not entirely sure how event handling is done in C++. My analysis of the code shows me that it should be done in the following way:
* Create a new resource, with a unique ID number. (In my specific case, then create a button based on the resource).
* Add it to the message map, associating it with a method.
* Create the method referenced in the previous step.

Is that the correct procedure? How would I make sure the button really calls something?
The world is coming to an end. Please log off.

DC++ Guide | Words

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2004-05-16 17:33

I'm also learning by example - the button in the directory listing is contained inside another window (statusContainer), which has its own message map. Perhaps you should copy that swathe of code as well, and move over your handler into a new map? :)

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-16 17:43

Is this the map you are talking about?

Code: Select all

ALT_MSG_MAP(STATUS_MESSAGE_MAP)
  COMMAND_ID_HANDLER(IDC_FIND, onFind)
  COMMAND_ID_HANDLER(IDC_NEXT, onNext)
  COMMAND_ID_HANDLER(IDC_MATCH_QUEUE, onMatchQueue)
END_MSG_MAP()
I wasn't sure what the ALT_MSG_MAP meant, but now that I see all the buttons from that window are there, I'll try something similar in the Hub window. Let's see what happens ...
The world is coming to an end. Please log off.

DC++ Guide | Words

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2004-05-16 19:11

Yup, and in the constructor for DirectoryListingFrm:

Code: Select all

statusContainer(STATUSCLASSNAME, this, STATUS_MESSAGE_MAP)
and later on, in onCreate:

Code: Select all

statusContainer.SubclassWindow(ctrlStatus.m_hWnd);

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-17 04:24

Well it finally works, based on some of the things you said. Thanks. :)

I'm not particularly happy about it though as the changes I made are not intuitive in any way. I attribute it to random coding rather than any form of understanding or programmer skill on my part, which doesn't bode well for future changes. :(

If anyone cares, I can post the complete changes I made. Otherwise, I'll be off to clean up the code. Thanks to all who helped. :)
The world is coming to an end. Please log off.

DC++ Guide | Words

raym0nd
Posts: 11
Joined: 2004-02-13 12:04

Post by raym0nd » 2004-05-17 10:03

TheParanoidOne wrote: If anyone cares, I can post the complete changes I made.
go for it, or you can PM it to me. A nice little button I ddin't have to add myself would do me nicely....

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-17 16:54

raym0nd wrote:go for it, or you can PM it to me. A nice little button I ddin't have to add myself would do me nicely....
OK. Here you go. Note that there are some minor peripheral changes that I made as well that aren't strictly necessary. Let me know if you have questions about the code.

Patch
Last edited by TheParanoidOne on 2004-05-18 09:49, edited 1 time in total.
The world is coming to an end. Please log off.

DC++ Guide | Words

joakim_tosteberg
Forum Moderator
Posts: 587
Joined: 2003-05-07 02:38
Location: Sweden, Linkoping

Post by joakim_tosteberg » 2004-05-18 00:18

Perhaps you should have uploaded them in files somewhere and posted links instead? Not taking som much place in te post and easir to just download and appply using some paych utility.

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-18 04:19

Yes, that's what I was thinking last night. I'll replace all that ugly line-wrapped code with a link at some point today.
The world is coming to an end. Please log off.

DC++ Guide | Words

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-05-18 09:50

Posted code changed to a link.

Oh, and I hadn't realised I had posted the whole lot twice. Oops! :oops:
The world is coming to an end. Please log off.

DC++ Guide | Words

raym0nd
Posts: 11
Joined: 2004-02-13 12:04

Post by raym0nd » 2004-05-19 20:50

nice - i like buttons =)

thanks for taking the time.

Locked