程式語言 - Wine - C/C++ - Use ReplaceText Dialog



參考資訊:
http://www.winprog.org/tutorial/
http://winapi.freetechsecrets.com/win32/
https://github.com/gammasoft71/Examples_Win32
http://masm32.com/board/index.php?topic=3584.0
https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles

main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
 
static UINT uReplaceID = 0;
static HWND hReplaceWnd = 0;
static char pWhat[255] = { 0 };
static FINDREPLACE stReplaceData = { 0 };
static HWND hWin = NULL;
static WNDPROC defWndProc = NULL;
 
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg) {
    case WM_CLOSE:
        DestroyWindow(hWnd);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
 
    if (uMsg == uReplaceID) {
        if ((stReplaceData.Flags & FR_FINDNEXT) ||
            (stReplaceData.Flags & FR_REPLACE) ||
            (stReplaceData.Flags & FR_REPLACEALL))
        {
            MessageBox(hWnd, pWhat, "", MB_OK);
        }
        return 0;
    }

    return CallWindowProc(defWndProc, hWnd, uMsg, wParam, lParam);
}
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    hWin = CreateWindow(WC_DIALOG, "main", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 320, 240, NULL, NULL, NULL, NULL);
    defWndProc = (WNDPROC)SetWindowLongPtr(hWin, GWLP_WNDPROC, (long int)WndProc);
 
    stReplaceData.lStructSize = sizeof(FINDREPLACE);
    stReplaceData.Flags = FR_DOWN;
    stReplaceData.hwndOwner = hWin;
    stReplaceData.lpstrFindWhat = pWhat;
    stReplaceData.wFindWhatLen = sizeof(pWhat);
    stReplaceData.lpstrReplaceWith = pWhat;
    stReplaceData.wReplaceWithLen = sizeof(pWhat);
    uReplaceID = RegisterWindowMessage("commdlg_FindReplace");
    hReplaceWnd = ReplaceText(&stReplaceData);
 
    MSG msg = { 0 };
    while (GetMessage(&msg, NULL, 0, 0)) {
        if (!IsDialogMessage(hReplaceWnd, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return 0;
}

編譯、執行

$ winegcc main.c -o main -lcomdlg32
$ wine main.exe.so