mIRC Home    About    Download    Register    News    Help

Print Thread
RichEdit Window Proc #76606 25/03/04 07:30 AM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
Recently, I released a DLL
http://www.mircscripts.org/comments.php?id=2357
that takes advantage of the rich editbox feature of mIRC 6.14. At the point of my release, I was having trouble with a subclass issue, so a certain feature wasnt included. This feature was when someone presses 'control+b' the text turns bold, and 'control+u', the text becomes underlined. Tonite, I completed that feature in my proc, finally, heh. Except for a few minor issues.

1. When the control code is pressed, the following text becomes bold or underlined like it should, however, when the closing control code is pressed, for some reason 2-3 characters afterward are bold(if control+b is pressed), when they shouldnt be. I cant figure out why.

2. The backspace and arrow keys dont work in the richedit under the Proc. I cant figure out why either.

Any assistance will help, here is the full proc:
Code:
LRESULT CALLBACK RichProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp)
{
   switch(msg)
   {
     {
      case WM_KEYDOWN:
		  if(wp == VK_CONTROL) {
			  cd++;
		  }
	 break;
   case WM_KEYUP:
	   if(wp == 0x42 && cd !=0) {
		   if(!bc) {
		         CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
                                                          SendMessage( hwnd, EM_GETCHARFORMAT,
                    (WPARAM)SCF_SELECTION, (LPARAM)&cfm );
                     cfm.dwMask = CFM_PROTECTED | CFM_BOLD;
                     cfm.dwEffects = CFE_BOLD;

                                                          SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&cfm );
					bc++;
					cd--;
			  }
		   else if(bc != 0) {
		      	  CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
                     cfm.dwMask = CFM_PROTECTED;
                                                          SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&cfm );
					bc--;
					cd--;
			  }
	   }
	  else if(wp == 0x55 && cd !=0) {
		  if(!uc) {
	               CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
                                                          SendMessage( hwnd, EM_GETCHARFORMAT,
                    (WPARAM)SCF_SELECTION, (LPARAM)&cfm );
                     cfm.dwMask = CFM_UNDERLINE;
                     cfm.dwEffects = CFE_UNDERLINE;

                                                          SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&cfm );
					uc++;
					cd--;
			   }
		   else if(uc != 0) {
		      	  CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
                     cfm.dwMask = CFM_PROTECTED;
                                                          SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&cfm );
					uc--;
					cd--;
			  }
	  }
         break;
	  case WM_DESTROY:
          SubclassWindow(hwnd,NULL);
		  PostMessage(hwnd,WM_DESTROY,0,0);
		  break;
      default:
		   int blah = Search(hwnd);
           CallWindowProc(AllProcs[blah].procold,hwnd,msg,wp,lp);
                break;
			}
			int blah = Search(hwnd);
           return CallWindowProc(AllProcs[blah].procold,hwnd,msg,wp,lp);
	 }
    return 0L;

}

EDIT: Added [[/b]code] [[/b]/code] tags.

Last edited by Hammer; 26/03/04 08:11 AM.
Re: RichEdit Window Proc #76607 25/03/04 11:40 PM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
since these forums dont indent code:

http://www.nomorepasting.com/paste.php?pasteID=8236

Re: RichEdit Window Proc #76608 26/03/04 03:10 AM
Joined: Jun 2003
Posts: 994
C
CtrlAltDel Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Jun 2003
Posts: 994
Code:
 
on 1:paste:message: {
  if (!you == click.the.word.code) { return }
  indent code
}
 

sorry .. couldn't resist it wink


I refuse to engage in a battle of wits with an unarmed person. wink
Re: RichEdit Window Proc #76609 29/03/04 03:41 PM
Joined: Jan 2003
Posts: 10
R
Rasqual Offline
Pikka bird
Offline
Pikka bird
R
Joined: Jan 2003
Posts: 10
Two remarks:
mIRC crashes because when it tries to call the RichEdit proc from your dll, it's too late : it's already been unloaded (see http://www.mircscripts.org/forums.php?cid=6&id=31468)

Second remark, the Ctrl+B combination will never make it to the control, because mIRC handles it. Maybe Khaled could do something about this.

Oh yeah, and third remark: catch key combos like this:
Code:
       case WM_KEYDOWN:
          {
                 if (wp == _T('B') && GetAsyncKeyState(VK_CONTROL) < 0 ) {

the counter way is... bah, ugly.

Hope it helped

(Edit: typo)

Last edited by Rasqual; 29/03/04 03:51 PM.
Re: RichEdit Window Proc #76610 29/03/04 04:49 PM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
I'm sorry but you didnt understand what I said. mIRC doesnt crash with my proc. My DLL does not unload, I programmed it accordingly. My problems are:

1. When the control code is pressed, the following text becomes bold or underlined like it should, however, when the closing control code is pressed, for some reason 2-3 characters afterward are bold(if control+b is pressed), when they shouldnt be. I cant figure out why.

2. The backspace and arrow keys dont work in the richedit under the Proc. I cant figure out why either.

Quote:
Second remark, the Ctrl+B combination will never make it to the control, because mIRC handles it. Maybe Khaled could do something about this.


Unfortunately youre wrong, everything works in order. Like I said, my proc works fine except for the above mentioned errors.

and finally, your method of key-catching doesnt work. I tried that(along with many variations of it) for 4 days, and nothing. My way works properly for what I want to do.

Last edited by Soul_Eater; 29/03/04 04:50 PM.
Re: RichEdit Window Proc #76611 29/03/04 11:52 PM
Joined: Jan 2003
Posts: 10
R
Rasqual Offline
Pikka bird
Offline
Pikka bird
R
Joined: Jan 2003
Posts: 10
To begin, sorry for the confusion. I tested with my method and Ctrl+B didn't seem to reach the Message loop, hopefully it works for you...

As for the keys not working... could the reason be you return 0 (= Message handled) for *all* WM_KEYDOWN messages, even if they don't correspond to a keybord shortcut?
Try returning 0 only when you do handle the message.

For prob. 1 sorry I cannot help >.< !

Re: RichEdit Window Proc #76612 30/03/04 12:25 AM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
ok what should I be returning than, if not 0?

Re: RichEdit Window Proc #76613 30/03/04 02:46 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
for messages you do not handle (or arguments to a particular message) you should always return the value returned by the original prcoedure. A simple return CallWindowProc(arrguments,here,...); will do it


Have Fun smile
Re: RichEdit Window Proc #76614 30/03/04 10:06 AM
Joined: Oct 2003
Posts: 12
E
Epsilon Offline
Pikka bird
Offline
Pikka bird
E
Joined: Oct 2003
Posts: 12
you can look in the source of x-GUI, I made my own mIRC code parser for custom richedits, and I had no problems with it.


Re: RichEdit Window Proc #76615 30/03/04 04:57 PM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
OK, I now no longer have space, arrow key, backspace/enter key problems at all, however as I said before, for some reason after typing, 2-3 characters remain bold or underlined afterward. Here's my new proc:
Code:
LRESULT CALLBACK RichProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp)
{
   switch(msg)
   {
     {		
    case WM_KEYDOWN:
		  if(wp == VK_CONTROL) {
			  cd++;
		  }
	 break;
  case WM_KEYUP:
	   if(wp == 0x42 &amp;&amp; cd !=0) {
		   if(!bc) {
		         CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
					SendMessage( hwnd, EM_GETCHARFORMAT,
                    (WPARAM)SCF_SELECTION, (LPARAM)&amp;cfm );
                     cfm.dwMask = CFM_PROTECTED | CFM_BOLD;
                     cfm.dwEffects = CFE_BOLD;

                    SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&amp;cfm );
					bc++;
					cd--;
			  }

		   else if(bc != 0) {
		      	  CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
                     cfm.dwMask = CFM_PROTECTED;
                    SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&amp;cfm );
					bc--;
					cd--;
			  }
	   }
	  else if(wp == 0x55 &amp;&amp; cd !=0) {
		  if(!uc) {
	               CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
					SendMessage( hwnd, EM_GETCHARFORMAT,
                    (WPARAM)SCF_SELECTION, (LPARAM)&amp;cfm );
                     cfm.dwMask = CFM_UNDERLINE;
                     cfm.dwEffects = CFE_UNDERLINE;

                    SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&amp;cfm );
					uc++;
					cd--;
			   }
		   else if(uc != 0) {
		      	  CHARFORMAT2 cfm;
                    cfm.cbSize = sizeof(cfm);
                     cfm.dwMask = CFM_PROTECTED;
                    SendMessage( hwnd, EM_SETCHARFORMAT,
                   (WPARAM)SCF_SELECTION, (LPARAM)&amp;cfm );
					uc--;
					cd--;
			  }
	  }
         break;
	  case WM_DESTROY:
          SubclassWindow(hwnd,NULL);
		  PostMessage(hwnd,WM_DESTROY,0,0);
		  break;
			}
			int blah = Search(hwnd);
           return CallWindowProc(AllProcs[blah].procold,hwnd,msg,wp,lp);
	 }
   int blah = Search(hwnd);
     return CallWindowProc(AllProcs[blah].procold,hwnd,msg,wp,lp);
}