Wine >> C/C++ >> Dialog >> Common Dialog

FindText


參考資訊:
1. win32
2. petzold
3. tutorial
4. examples_win32

main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

UINT uFindID = 0;
HWND hFindWnd = 0;
char pWhat[255] = {0};
FINDREPLACE stFindData = {0};

HWND hWin = NULL;
WNDPROC defWndProc = NULL;

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 == uFindID) {
        if (stFindData.Flags & FR_FINDNEXT) {
            MessageBox(hWnd, pWhat, "main", 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, 0, 0, 300, 300,
                        NULL, NULL, NULL, NULL);
    defWndProc =
        (WNDPROC)SetWindowLongPtr(hWin, GWLP_WNDPROC, (long int)WndProc);
    ShowWindow(hWin, SW_SHOW);

    stFindData.lStructSize = sizeof(FINDREPLACE);
    stFindData.Flags = FR_DOWN;
    stFindData.hwndOwner = hWin;
    stFindData.lpstrFindWhat = pWhat;
    stFindData.wFindWhatLen = sizeof(pWhat);
    uFindID = RegisterWindowMessage("commdlg_FindReplace");
    hFindWnd = FindText(&stFindData);

    MSG msg = {0};
    while (GetMessage(&msg, NULL, 0, 0)) {
        if (!IsDialogMessage(hFindWnd, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    ExitProcess(0);
    return 0;
}

編譯、執行

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



返回上一頁