IPC C示例

IPC C示例

AC示例使用WM_COPYDATA将搜索查询发送到Everything并检索结果。

 

发送查询

#define COPYDATA_QUERYCOMPLETE 0 

BOOL sendquery(HWND hwnd,DWORD max_results,WCHAR * search_string,BOOL regex,BOOL match_case,BOOL match_whole_word,BOOL match_path)
{ 
  EVERYTHING_IPC_QUERY * query; 
  DWORD len; 
  DWORD大小; 
  HWND everything_hwnd; 
  COPYDATASTRUCT cds; 
  
  everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS,0); 
  if(everything_hwnd)
  { 
    len =(int)wcslen(search_string); 
    
    size = sizeof(EVERYTHING_IPC_QUERY) -  sizeof(WCHAR)+ len * sizeof(WCHAR)+ sizeof(WCHAR); 
    
    query =(EVERYTHING_IPC_QUERY *)HeapAlloc(GetProcessHeap(),0,size); 
    if(query)
    { 
      query-> max_results = max_results; 
      query-> offset = 0;
      query-> reply_copydata_message = COPYDATA_QUERYCOMPLETE; 
      query-> search_flags =(regex?EVERYTHING_IPC_REGEX:0)| (match_case?EVERYTHING_IPC_MATCHCASE:0)| (match_whole_word?EVERYTHING_IPC_MATCHWHOLEWORD:0)| (?match_path EVERYTHING_IPC_MATCHPATH:0); 
      query-> reply_hwnd = hwnd; 
      
      CopyMemory的(查询- > search_string的,search_string的,(LEN + 1)*的sizeof(WCHAR)); 
      
      cds.cbData = size; 
      cds.dwData = EVERYTHING_IPC_COPYDATAQUERY; 
      cds.lpData = query; 
      
      if(SendMessage(everything_hwnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)&cds)== TRUE)
      { 
        HeapFree(GetProcessHeap(),0,query); 
        
        返回TRUE; 
      } 
      else 
      { 
        //所有IPC服务都没有运行
      }
      
      HeapFree(GetProcessHeap(),0,查询); 
    } 
  } 
  else 
  { 
    //找不到所有窗口。
    //我们可以选择RegisterWindowMessage(“EVERYTHING_IPC_CREATED”)和
    //等待Everything将此消息发布到所有顶级窗口时启动并运行。
  } 
  
  返回FALSE; 
}

 

检索结果

void DisplayPathName(TCHAR * path,TCHAR * filename)
{ 
	// ... 
	//执行路径和文件名
	// ... 
} 

LRESULT CALLBACK window_proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{ 
	DWORD i ; 
	EVERYTHING_IPC_LIST * list 
	
	switch(uMsg)
	{ 
		case WM_COPYDATA:
		{ 
			COPYDATASTRUCT * cds =(COPYDATASTRUCT *)lParam; 
			
			switch(cds-> dwData)
			{ 
				case COPYDATA_QUERYCOMPLETE:
				
				list =(EVERYTHING_IPC_LIST *)cds-> lpData; 
				
				for(i = 0; i <list-> numitems; i ++)
				{ 
					DisplayPathName(EVERYTHING_IPC_ITEMPATH(list,&list-> items [i]),EVERYTHING_IPC_ITEMFILENAME(list,&list-> items [i]))
				} 
				
				return TRUE; 
			} 
			
			打破; 
		} 
	} 
	
	返回DefWindowProc函数(HWND,味精,wParam中,LPARAM); 
}

评论功能已经关闭。

0%