delphi封裝了消息.雖然可以寫消息處理事件,
但我現在有一個想法就是能不能用一個函數來接管所有的
對本程序的消息..
如在form上還有edit,button等我要怎么知道消息是發給哪個控件的呢?
嫌分少可再加,但請給出個sample
但我現在有一個想法就是能不能用一個函數來接管所有的
對本程序的消息..
如在form上還有edit,button等我要怎么知道消息是發給哪個控件的呢?
嫌分少可再加,但請給出個sample
解决方案 »
- 求教GroupBox1的控制属性问题
- 已知某点像素颜色值,怎么知道他所在屏幕的坐标位置
- labview 与delphi 开发数采系统的问题,在线等。。
- delphi 怎么ping计算机名或ip 地址
- 请问Combobox里怎么把TreeView放进去?我看到有些软件都有这个东东!!!
- 哪有delphi插件for powerdesigner
- file类型怎么不可以作为参数?怎么办?
- 如何将应用程序缩身于系统的“任务栏”上?
- 如何随机的从一个表中取出一些记录保存到一个数组中
- 将record型的值按顺序存入array中,怎么用指针实现。
- 报表问题!有如下结构表,不知道怎么实现要求的报表,将字段作为记录值输出
- 散分~~
設定新的窗口過程
在YourProc中處理所有消息
我知道用setwindowlong可以設置函數..
但我舉個實例,我有兩個edit .edit1,edit2
當我收到信息是wm_settext時我要怎么識別是發給誰的.
但是我不清楚MESSAGE的参数具体表示的意义.有哪位能赐教
WM_CREATE:
hwndEdit1=CreateWindow("EDIT","edit1",WS_BORDER|WS_VISIBLE,0,0,100,60,hWnd,NULL,hInst,NULL);
preWndproc=SetWindowLong(hwndEdit1,GWL_WNDPROC,(LPARAM)(WNDPROC)Edit_Proc);
break;LRESULT CALLBACK Edit_Proc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
LRESULT lresult=0;
switch(message)
{
case WM_SETTEXT:
MessageBox(hWnd,(LPCTSTR)lParam,"info",MB_OK);
//SetWindowText(hWnd,(LPCTSTR)lParam);
default:
lresult=CallWindowProc((WNDPROC)GetClassLong(hWnd,GCL_WNDPROC),hWnd,message,wParam,lParam);
}
return lresult;
}
接管Application.OnMessage 就行了!!
//BOOL PeekMessage(
// LPMSG lpMsg, // 消息记录的指针
// HWND hWnd, // 窗口句柄
// UINT wMsgFilterMin, // 第一个消息
// UINT wMsgFilterMax, // 最后一个消息
// UINT wRemoveMsg // 标志 Value Meaning
// ); PM_NOREMOVE 处理后保留在消息队列中
// PM_REMOVE 处理后从消息队列中清除
//要做的第一件事是检查是否有消息在等待。
//使用PeekMessage()可以在不锁住我们的程序的前提下对消息进行检查。
//许多程序使用GetMessage(),也可以很好的工作。
//但使用GetMessage(),程序在收到paint消息或其他别的什么窗口消息之前不会做任何事。
If (PeekMessage(msg, 0, 0, 0, PM_REMOVE)) Then //检查是否有消息
// wMsgFilterMin,wMsgFilterMax 这两个参数都为0,返回所有可用的消息
Begin
If (msg.message = WM_QUIT) Then // 如果是退出消息
finished := True //改变循环条件,退出
Else
Begin // 否则处理消息
// 翻译消息,然后发送消息,使得WndProc() 或 Windows能够处理他们。
TranslateMessage(msg); //翻译消息
DispatchMessage(msg); //发送消息
End;
End
方法如下:
这是在类中的声明:
procedure OnPosChange(var Msg: TWmWindowPosChanging);
message WM_WINDOWPOSCHANGING;这是具体实现:
procedure TfrmTJZongTi.OnPosChange (var Msg: TWmWindowPosChanging);
begin//frm是另一个窗口
if msg.WindowPos.x > frmMain.ClientRect.Right - frmMain.clbMenu.Width - width - 4 then
msg.WindowPos.x := frmMain.ClientRect.Right - frmMain.clbMenu.Width - width - 4;
if msg.WindowPos.x < frmMain.ClientRect.Left then
msg.WindowPos.x := frmMain.ClientRect.Left;
if msg.WindowPos.y > frmMain.ClientRect.Bottom - frmMain.stbStatus.Height - height - 4 then
msg.WindowPos.y := frmMain.ClientRect.Bottom - frmMain.stbStatus.Height - height - 4;
if msg.WindowPos.y < frmMain.ClientRect.Top then
msg.WindowPos.y := frmMain.ClientRect.Top;
end;
var
j, i:integer;
begin
gMainMenu:=mm;
for i:=0 to mm.Items.Count -1 do begin
for j:=0 to mm.Items[i].Count -1 do begin
if not Assigned(mm.Items[i].Items[j].OnClick) then
begin
mm.Items[i].Items[j].OnClick:=proc;
if mm.Items[i].Items[j].Name = 'mmView' then
mm.Items[i].Items[j].tag := WMN_VIEW;
if mm.Items[i].Items[j].Name = 'mmEdit' then
mm.Items[i].Items[j].tag := WMN_EDIT;
if mm.Items[i].Items[j].Name = 'mmSearch' then
mm.Items[i].Items[j].tag := WMN_SEARCH;
if mm.Items[i].Items[j].Name = 'mmAddRef' then
mm.Items[i].Items[j].tag := WMN_ADDREF;
if mm.Items[i].Items[j].Name = 'mmBack' then
mm.Items[i].Items[j].tag := WMN_BACK;
if mm.Items[i].Items[j].Name = 'mmNewFrom' then
mm.Items[i].Items[j].tag := WMN_NEWFROM;
end;
end;
end;
end;
这个一定是你想要的