Skip to content

Commit

Permalink
implement win32 gui-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan200101 authored and doZennn committed Oct 9, 2024
1 parent ff14336 commit 23f6257
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 8 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
x64/Release/SGDBoop.exe
x64/Release/libcurl.dll
x64/Release/zlib1.dll
x64/Release/iup.dll
- uses: actions/upload-artifact@v3
with:
Expand Down
21 changes: 15 additions & 6 deletions SGDBoop-VS.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<LibraryPath>C:\Users\mnsxx\source\repos\SGDBoop\lib;$(LibraryPath)</LibraryPath>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDebugSymbols>false</CopyLocalDebugSymbols>
<PublicIncludeDirectories>
</PublicIncludeDirectories>
<LibraryPath>$(SolutionDir)\lib\windows;$(LibraryPath)</LibraryPath>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LibraryPath>$(SolutionDir)\lib\windows;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Label="Vcpkg">
<VcpkgEnableManifest>true</VcpkgEnableManifest>
Expand All @@ -95,7 +99,7 @@
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>freetype6.lib;ftgl.lib;iup.lib;iupcd.lib;iupcontrols.lib;iupfiledlg.lib;iupgl.lib;iupglcontrols.lib;iupim.lib;iupimglib.lib;iupole.lib;iuptuio.lib;iupweb.lib;iup_mglplot.lib;iup_plot.lib;iup_scintilla.lib;zlib1.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>freetype6.lib;ftgl.lib;zlib1.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -121,10 +125,11 @@
<Link>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
<AdditionalDependencies>freetype6.lib;ftgl.lib;iup.lib;iupcd.lib;iupcontrols.lib;iupfiledlg.lib;iupgl.lib;iupglcontrols.lib;iupim.lib;iupimglib.lib;iupole.lib;iuptuio.lib;iupweb.lib;iup_mglplot.lib;iup_plot.lib;iup_scintilla.lib;zlib1.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>freetype6.lib;ftgl.lib;zlib1.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy /Y "$(SolutionDir)lib\windows\iup.dll" "$(TargetDir)iup.dll" </Command>
<Command>
</Command>
</PostBuildEvent>
<ProjectReference>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
Expand All @@ -136,13 +141,15 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PostBuildEvent>
<Command>copy /Y "$(SolutionDir)lib\windows\iup.dll" "$(TargetDir)iup.dll" </Command>
<Command>
</Command>
</PostBuildEvent>
<Link>
<AdditionalDependencies>freetype6.lib;ftgl.lib;iup.lib;iupcd.lib;iupcontrols.lib;iupfiledlg.lib;iupgl.lib;iupglcontrols.lib;iupim.lib;iupimglib.lib;iupole.lib;iupstub.lib;iuptuio.lib;iupweb.lib;iup_mglplot.lib;iup_plot.lib;iup_scintilla.lib;zlib1.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>freetype6.lib;ftgl.lib;zlib1.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>copy /Y "$(SolutionDir)lib\windows\iup.dll" "$(TargetDir)iup.dll" </Command>
<Command>
</Command>
</PreBuildEvent>
<ClCompile />
<Manifest>
Expand All @@ -152,12 +159,14 @@
<ItemGroup>
<ClCompile Include="crc.c" />
<ClCompile Include="curl-helper.c" />
<ClCompile Include="gui-helper-win.c" />
<ClCompile Include="sgdboop.c" />
<ClCompile Include="string-helpers.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="crc.h" />
<ClInclude Include="curl-helper.h" />
<ClInclude Include="gui-helper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="string-helpers.h" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion SGDBoop.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ END

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "SGDBoop.exe.manifest"
IDI_ICON1 ICON "res\\icon.ico"

#endif // English (United States) resources
Expand All @@ -68,4 +69,3 @@ IDI_ICON1 ICON "res\\icon.ico"

/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

167 changes: 167 additions & 0 deletions gui-helper-win.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include <windows.h>
#include <CommCtrl.h>

#include "gui-helper.h"
#include "resource.h"

const char szClass[] = "winWindowClass";

#define IDC_BUTTON_OK 101
#define IDC_BUTTON_CANCEL 102

static HWND hWndList;
static HWND hWndButtonOk;
static HWND hWndButtonCancel;
static int selected_index = -1;

static LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_CREATE:
{
HFONT hfFont = GetStockObject(DEFAULT_GUI_FONT);
hWndList = CreateWindowExA(
WS_EX_CLIENTEDGE | WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
WC_LISTBOX, NULL,
LBS_NOTIFY | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE | WS_VSCROLL,
0, 0, 100, 100,
hWnd, NULL,
GetModuleHandle(NULL), NULL
);
SendMessage(hWndList, WM_SETFONT, (WPARAM)hfFont, 0);

hWndButtonOk = CreateWindowExA(
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
WC_BUTTON, "OK",
BS_PUSHBUTTON | BS_TEXT | WS_CHILD | WS_MAXIMIZEBOX | WS_OVERLAPPED | WS_TABSTOP | WS_VISIBLE,
0, 0, 30, 40,
hWnd, (HMENU)IDC_BUTTON_OK,
GetModuleHandle(NULL), NULL
);
SendMessage(hWndButtonOk, WM_SETFONT, (WPARAM)hfFont, 0);

hWndButtonCancel = CreateWindowExA(
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
WC_BUTTON, "Cancel",
BS_PUSHBUTTON | BS_TEXT | WS_CHILD | WS_MAXIMIZEBOX | WS_OVERLAPPED | WS_TABSTOP | WS_VISIBLE,
0, 0, 30, 40,
hWnd, (HMENU)IDC_BUTTON_CANCEL,
GetModuleHandle(NULL), NULL
);
SendMessage(hWndButtonCancel, WM_SETFONT, (WPARAM)hfFont, 0);

break;
}

case WM_SIZE:
{
HWND hEdit;
RECT rcClient;

GetClientRect(hWnd, &rcClient);
SetWindowPos(hWndList, NULL, rcClient.left + 10, rcClient.top + 10, rcClient.right - 20, rcClient.bottom - 60, SWP_NOZORDER);
SetWindowPos(hWndButtonOk, NULL, rcClient.right - (80 * 2), rcClient.bottom - 45, 70, 30, SWP_NOZORDER);
SetWindowPos(hWndButtonCancel, NULL, rcClient.right - 80, rcClient.bottom - 45, 70, 30, SWP_NOZORDER);
}
case WM_COMMAND:
switch (HIWORD(wParam))
{
case LBN_SELCHANGE:
EnableWindow(hWndButtonOk, TRUE);
break;
}

switch (LOWORD(wParam))
{
case IDC_BUTTON_OK:
{
LRESULT res = SendMessage(hWndList, LB_GETCURSEL, (WPARAM)NULL, (LPARAM)NULL);
if (res != LB_ERR)
{
selected_index = res;
PostQuitMessage(WM_QUIT);
}
break;
}

case IDC_BUTTON_CANCEL:
selected_index = -1;
PostQuitMessage(WM_QUIT);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
}

return DefWindowProc(hWnd, Msg, wParam, lParam);
}

int ShowMessageBox(const char* title, const char* message)
{
return MessageBox(NULL, title, message, MB_OK | MB_ICONEXCLAMATION);
}

int SelectionDialog(const char* title, int count, const char** list, int selection)
{
InitCommonControls();

MSG Msg;
HWND hWnd;

HINSTANCE hInstance = GetModuleHandle(NULL);

WNDCLASSEXA wc;
wc.cbSize = sizeof(WNDCLASSEXA);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = (HICON)LoadImageA(
hInstance,
MAKEINTRESOURCEA(IDI_ICON1), IMAGE_ICON,
0, 0,
LR_DEFAULTSIZE | LR_DEFAULTCOLOR | LR_SHARED
);
wc.hIconSm = (HICON)LoadImage(
hInstance,
MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR | LR_SHARED
);
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClass;

RegisterClassExA(&wc);

hWnd = CreateWindowExA(
WS_EX_CLIENTEDGE,
szClass,
title,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
454, 388,
NULL, NULL,
hInstance, NULL
);

for (int i = 0; i < count; ++i)
{
SendMessage(hWndList, LB_ADDSTRING, (WPARAM)NULL, (LPARAM)list[i]);
}

ShowWindow(hWnd, SW_SHOWNORMAL);

while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

return selected_index;
}

0 comments on commit 23f6257

Please sign in to comment.