mIRC Homepage
Posted By: Soul_Eater RichEdit Window Proc - 25/03/04 07:30 AM
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.
Posted By: Soul_Eater Re: RichEdit Window Proc - 25/03/04 11:40 PM
since these forums dont indent code:

http://www.nomorepasting.com/paste.php?pasteID=8236
Posted By: CtrlAltDel Re: RichEdit Window Proc - 26/03/04 03:10 AM
Code:
 
on 1:paste:message: {
  if (!you == click.the.word.code) { return }
  indent code
}
 

sorry .. couldn't resist it wink
Posted By: Rasqual Re: RichEdit Window Proc - 29/03/04 03:41 PM
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)
Posted By: Soul_Eater Re: RichEdit Window Proc - 29/03/04 04:49 PM
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.
Posted By: Rasqual Re: RichEdit Window Proc - 29/03/04 11:52 PM
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 >.< !
Posted By: Soul_Eater Re: RichEdit Window Proc - 30/03/04 12:25 AM
ok what should I be returning than, if not 0?
Posted By: Narusegawa_Naru Re: RichEdit Window Proc - 30/03/04 02:46 AM
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
Posted By: Epsilon Re: RichEdit Window Proc - 30/03/04 10:06 AM
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.
Posted By: Soul_Eater Re: RichEdit Window Proc - 30/03/04 04:57 PM
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);
}
  
© mIRC Discussion Forums