Steward
分享是一種喜悅、更是一種幸福
程式語言 - Wine - C/C++ - Edit
參考資訊:
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 <stdbool.h>
#include <windows.h>
#include <richedit.h>
#define ID_EDIT 1000
static HWND hWin = NULL;
static HWND hEdit = NULL;
static HFONT hFont = NULL;
static WNDPROC defWndProc = NULL;
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_CLOSE:
DeleteObject(hFont);
DestroyWindow(hEdit);
DestroyWindow(hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
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);
hFont = CreateFont(16,
0,
0,
0,
FW_BOLD,
false,
false,
false,
0,
OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
"Arial"
);
hEdit = CreateWindow("EDIT", "Test", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE, 50, 50, 100, 100, hWin, (HMENU)ID_EDIT, NULL, NULL);
defWndProc = (WNDPROC)SetWindowLongPtr(hWin, GWLP_WNDPROC, (long int)WndProc);
SendMessage(hEdit, WM_SETFONT, (WPARAM)hFont, TRUE);
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
if (IsDialogMessage(hEdit, &msg)) {
if ((msg.message == WM_CHAR) && (msg.wParam == 13)) {
char buf[255] = { 0 };
GetWindowText(hEdit, buf, sizeof(buf));
MessageBox(hWin, buf, "", MB_OK);
}
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
編譯、執行
$ winegcc main.c -o main -lgdi32 $ wine main.exe.so

按下Enter鍵就會顯示目前Edit的內容