Wine >> C/C++ >> Dialog >> Resource

Icon


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

main.c

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <windows.h>
#include "resource.h"

HWND hWin = NULL;
HANDLE hIcon = 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;
    case WM_PAINT:
        PAINTSTRUCT ps = {0};
        HDC hdc = BeginPaint(hWnd, &ps);
        DrawIcon(hdc, 100, 100, hIcon);
        EndPaint(hWnd, &ps);
        break;
    }
    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);
    hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
    SetClassLong(hWin, GCLP_HICON, (LONG)hIcon);
    ShowWindow(hWin, SW_SHOW);

    MSG msg = {0};
    while (GetMessage(&msg, NULL, 0, 0)) {
        DispatchMessage(&msg);
    }
    ExitProcess(0);
    return 0;
}

main.rc

#include <windows.h>
#include "resource.h"

IDI_ICON ICON "main.ico"

resource.h

#define IDI_ICON 101

main.ico


編譯、執行

$ x86_64-w64-mingw32-windres main.rc -o main.res
$ winegcc main.c main.res -o main -lgdi32
$ wine ./main.exe


返回上一頁