Question on WM_CHAR

Just starting out? Need help? Post your questions and find answers here.
CaddMan
User
User
Posts: 21
Joined: Sat Jul 10, 2004 8:05 pm
Location: USA (East Coast)

Question on WM_CHAR

Post by CaddMan »

Hello,
My cadd application sends a WM_CHAR message to my DLL when a key on the keyboard is pressed. The WaitWindowEvent() does recognize when the WM_CHAR event occurs. I am having a problem capturing which key has been pressed using the wparam. Below is my attempt that does not work. What I would like to accomplish is if the ESC key is pressed (ascii 27) have the program go do something. Any suggestions?

Thanks
Ken

Code: Select all

GetState.w = 0
Toggle.w = 0

PrevWinFunction.l
hwnd.l
msg.l
wparam.l
lparam.l

Structure Point2D
  x.double
  y.double
EndStructure

Dim StartLine.Point2D(1)
Dim EndLine.Point2D(1)

Declare WmCharCallBack(hwnd, msg, wparam, lparam) 
  
ProcedureDLL DrawLine()

OpenLibrary (0,"vcmain32.dll")
OpenLibrary (1,"vctool32.dll")

;Tells CADD application to send this DLL all Windows messages & capture mousedown and abort events
  CallFunction (0,"VCSetAlertAppDll",@iError,"Test","DrawLine",ALERT_APP_ALL)

    
;User tool prompt 
  CallFunction (1,"VCSetUserTool",2,"DrawLine","Enter lower left corner")
  CallFunction (1,"VCSetPrompt",1,"Enter lower right corner")
  ToolState.w = 1
  
  Repeat 
  Event=WaitWindowEvent()
  
  ;Getkeyboard input such as enter & escape keys
  If Event = #WM_CHAR
  WmCharCallBack(hwnd, msg, wparam, lparam) 
  
    ;Get 1st mouse down point
  ElseIf Event = #WM_LBUTTONDOWN And ToolState = 1
  CallFunction (0,"VCGetUserToolLBDown",@iError,StartLine())
  ToolState = ToolState + 1
  
  ;Get 2nd mouse button down point
  ElseIf Event = #WM_LBUTTONDOWN And ToolState = 2
  CallFunction (0,"VCGetUserToolLBDown",@iError,EndLine())
  ToolState = ToolState + 1
  
  EndIf 
  Until ToolState  = 3
   
 ;Draw a line    
  CallFunction (0,"VCAddLineEntityBP",@iError,-1,StartLine(),Endline())
  CallFunction (0,"VCLastEntity",@iError,@lH)
  CallFunction (0,"VCSetCurrentEntity",@iError,lH)
  CallFunction (0,"VCDrawCurrentEntity",@iError)
  CallFunction (0,"VCClearAlertAppDll",@iError,"Test","DrawLine")
  CloseLibrary(1)
  CloseLibrary(0)
 
 EndProcedure    


ProcedureDLL WmCharCallBack(hwnd, msg, wparam, lparam)
    result = CallWindowProc_(PrevWinFunction, hwnd, msg, wparam, lparam)
    Select msg
    Case #WM_CHAR
      ;wparam holds the character code
    If wparam = 27 
    MessageRequester("Test", "Esc key(27) was pressed", 0)
    ElseIf MessageRequester("Test", "Not working",0)
  EndIf
  EndSelect
  ProcedureReturn result
  EndProcedure
  Return  
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post by filperj »

Code: Select all

If Event = #WM_CHAR
      WmCharCallBack(hwnd, msg, wparam, lparam)
Shouldn't this be:

Code: Select all

If Event = #WM_CHAR
    WmCharCallBack(WindowID(),#WM_CHAR,EventwParam(),EventlParam())
?
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Yes, or even maybe:

Code: Select all

If Event = #WM_CHAR
    WmCharCallBack(EventWindowID(),#WM_CHAR,EventwParam(),EventlParam()) 
And there's some code outside the procedures. AFAIK, if this is a DLL, code outside procedures is not allowed. And looks like PrevWinFunction should be global (I guess there's some code stripped, I just note this in case there isn't).
El_Choni
CaddMan
User
User
Posts: 21
Joined: Sat Jul 10, 2004 8:05 pm
Location: USA (East Coast)

Post by CaddMan »

Please excuse how long it takes to me to reply. It just takes me a couple of days to try to figure out what is going on after somebody replies :lol:

@El_Choni, What part of my code did you see out of procedure? I was under the impression that I could declare variables, structures and declarations outside of procedure. Is this incorrect? There is really not any code stripped. I am new at this windows progamming so anything you notice out of sorts is probably wrong. I believe you are correct about PrevWinFunction should be global.

Question 1

Code: Select all

If Event = #WM_CHAR
  WmCharCallBack (EventWindowID(),#WM_CHAR,EventwParam(),EventlParam())
Aren't EventWindowID() EventwParam() etc functions. I thought when when writing arguments to a procedure they needed to be variables. When I try to compile the above I receive a syntax error in the procedure arguments

Question2
EventwParam() seems quite interesting. I have been through all the help files but could not find a reference to it. I have googled it on the internet but only receive info on it in the German language. My dll is windowless so I would like to use something like, After #WM_CHAR has been sent my dll -- wParam=EventwParam()-- If wParam = some ascii number go do something. Is there anyplace that explains EventwParam?

Thanks Ken
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

1. The code you put outside the procedures that won't be run in a DLL is this:

Code: Select all

GetState.w = 0
Toggle.w = 0
;...
Dim StartLine.Point2D(1)
Dim EndLine.Point2D(1)
;...
This is code that actually does something, so it must be inside one of the procedures. Variables are initiallized to 0, so you don't need to initialize them yourself. Just put the arrays in some initialization procedure, like AttachProcess(Instance). Check "Building a DLL" in the Help file.

2. You shouldn't get a syntax error for this line:

Code: Select all

If Event=#WM_CHAR
  WmCharCallBack(EventWindowID(), #WM_CHAR, EventwParam(), EventlParam()) 
You can pass function results as arguments for a procedure. It's just like doing this, but without keeping the variables values:

Code: Select all

If Event=#WM_CHAR
  EventWindowID = EventWindowID()
  EventwParam = EventwParam()
  EventlParam = EventlParam()
  WmCharCallBack (EventWindowID, #WM_CHAR, EventwParam, EventlParam) 
El_Choni
Post Reply