Skip to main content

Featured

Build docker image from multiple build contexts

Build docker image from multiple build contexts Building a docker image requires specifying a source of truth to include in the image from a local directory or a remote git repository. In the previous version, the docker BuildKit allows users to specify the build context from a single source of truth only. However, the engineers may need to have the context from different locations based on the type of files. For instance, icons, images or other resources that are not included in the same package, including the resource from other docker images. Fortunately, the Docker Buildx toolkit supports multiple build context flag for Docker 1.4. Let's learn how to use this new feature. The following list is a shortcut for jumping into a specific topic handy. What version of Docker is this tutorial targeting? How to specify the version of Dockerfile frontend? Ho

[WinAPI]FindWindow在Vista的奇異事件

話說最近嘗試透過PostMessage(HWND hwnd, LPARAM lpParam)要將一比資料從一個視窗程式傳到另一個視窗程式,這時候由於第一個程式的hWnd第二隻並不知道。所以這邊在第二個程式啟動的時候,就利用FindWindow來尋找第一個程式的hWnd。

在XP x32/x64以及Vista x64的平台上測試,都可以正正確確的找到第一個程式的hWnd。但是在"某台特定"的Vista x32上卻發生第二個程式永遠抓到一組固定的hWnd,即使是第一個程式有重開過。

這個現象就非常的不合理,因為每次視窗重新產生的時候,都會有不同的hWnd,所以這邊的FindWindow抓到了誰,那就不得而知了。所以這邊在做PostMessgae的時候,想當然,資料就永遠傳不到第一個程式了。

後來在網路上搜尋了一下,發現還有EnumWindow(WNDENUMPROC EnumProc, LPARAM lParam)可以用來取得所有視窗的hWnd。這個API還須透過一個Callback function來使用,就是EnumWindowProc(HWND hWnd, LPARAM lParam)。第二個參數看個人需求可選擇自行傳遞,這邊是因為要取得第一個程式的hWnd,所以這邊是傳入第一個程式的PID。

由於這邊是使用PID來比對,所以還需要透過GetWindowThreadProcessId(HWND hWnd,LPDWORD lpdwProcessId)來取得目前所列舉的視窗的PID。

之後就可以利用取得之hWnd來進行PostMessage了。

Callback的範例如下
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD iPID = 0;

if ( GetWindowThreadProcessId(hwnd, &iPID) != NULL )
{
if ( iPID == (DWORD)lParam )
{
m_1sthWnd = hwnd;
return FALSE; //Find the PID and stop the callback function
}
}
return TRUE; //Continue the callback function
}


EnumWindow使用範例如下
::EnumWindows(&EnumWindowsProc, (LPARAM)m_1stPID);

2009/Sep/30-Add
不過這種方法在遇到會換hWnd的Dialog下就會出問題(目前我遇到的是切換combo會造成hWnd的變更),所以最保險的還是用FindWindow會比較好。

不過還是要找比較安全的作法才行。

Comments

Popular Posts