Skip to content

Commit

Permalink
add AtlDialogApp sample
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Sep 19, 2023
1 parent 30012cf commit 199d667
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 2 deletions.
9 changes: 9 additions & 0 deletions samples/AtlDialogApp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# AtlDialogApp.exe
add_executable(AtlDialogApp WIN32 main.cpp main_res.rc)
target_compile_definitions(AtlDialogApp PRIVATE ${RATL_DEFINITIONS})
target_include_directories(AtlDialogApp PRIVATE ${RATL_INCLUDE_DIRS})
target_link_libraries(AtlDialogApp PRIVATE ${RATL_LIBRARIES} comctl32)
if(MSVC)
target_link_options(AtlDialogApp PRIVATE /MANIFEST:NO)
endif()
154 changes: 154 additions & 0 deletions samples/AtlDialogApp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>

#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>

#include "resource.h"

//////////////////////////////////////////////////////////////////////////////////////////////////

class CMyExeModule : public ATL::CAtlExeModuleT<CMyExeModule>
{
};
CMyExeModule g_my_exe;

//////////////////////////////////////////////////////////////////////////////////////////////////

class CMainWindow : public CDialogImpl<CMainWindow, CWindow>
{
public:
enum { IDD = IDD_MAIN };
CMainWindow();
virtual ~CMainWindow();

VOID ResetSettings();
BOOL LoadSettings();
BOOL SaveSettings();

BEGIN_MSG_MAP(CMainWindow)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
END_MSG_MAP()

LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
return 0;
}

LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
::PostQuitMessage(0);
return 0;
}

LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(IDOK);
break;
case IDCANCEL:
EndDialog(IDCANCEL);
break;
}
return 0;
}

LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
PAINTSTRUCT ps;
if (HDC hDC = BeginPaint(&ps))
{
RECT rc;
GetClientRect(&rc);

::MoveToEx(hDC, rc.left, rc.top, NULL);
::LineTo(hDC, rc.right, rc.bottom);

::MoveToEx(hDC, rc.right, rc.top, NULL);
::LineTo(hDC, rc.left, rc.bottom);

UINT uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;
::DrawText(hDC, TEXT("Hello, RATL"), -1, &rc, uFormat);

EndPaint(&ps);
}
return 0;
}
};

CMainWindow::CMainWindow()
{
}

CMainWindow::~CMainWindow()
{
}

VOID CMainWindow::ResetSettings()
{
// TODO: Reset settings
}

BOOL CMainWindow::LoadSettings()
{
ResetSettings();

CRegKey appKey;
LONG error;

error = appKey.Open(HKEY_CURRENT_USER, TEXT("Software\\ReactOS\\AtlDialogApp"));
if (error)
return FALSE;

// TODO: Load settings

return TRUE;
}

BOOL CMainWindow::SaveSettings()
{
CRegKey companyKey, appKey;
LONG error;

error = companyKey.Create(HKEY_CURRENT_USER, TEXT("Software\\ReactOS"));
if (error)
return FALSE;

error = appKey.Create(companyKey, TEXT("AtlDialogApp"));
if (error)
return FALSE;

// TODO: Save settings

return TRUE;
}

//////////////////////////////////////////////////////////////////////////////////////////////////

INT WINAPI
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow)
{
InitCommonControls();

CMainWindow mainWnd;
mainWnd.LoadSettings();

if (mainWnd.DoModal(NULL, 0) == IDOK)
{
// TODO: Do something
}

mainWnd.SaveSettings();

return 0;
}
69 changes: 69 additions & 0 deletions samples/AtlDialogApp/main_res.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// main_res.rc
// This file is automatically generated by RisohEditor 5.7.7.
// † <-- This dagger helps UTF-8 detection.

#include "resource.h"
#define APSTUDIO_HIDDEN_SYMBOLS
#include <windows.h>
#include <commctrl.h>
#undef APSTUDIO_HIDDEN_SYMBOLS
#pragma code_page(65001) // UTF-8

//////////////////////////////////////////////////////////////////////////////

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL

//////////////////////////////////////////////////////////////////////////////
// RT_GROUP_ICON

IDI_MAINICON ICON "res/Icon_100.ico"

//////////////////////////////////////////////////////////////////////////////
// RT_MANIFEST

1 24 "res/Manifest_1.manifest"

//////////////////////////////////////////////////////////////////////////////

LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT

//////////////////////////////////////////////////////////////////////////////
// RT_DIALOG

IDD_MAIN DIALOG 0, 0, 215, 135
CAPTION "AtlDialogApp"
STYLE DS_CENTER | DS_MODALFRAME | WS_POPUPWINDOW | WS_CAPTION
FONT 9, "MS Shell Dlg"
{
DEFPUSHBUTTON "OK", IDOK, 35, 115, 60, 14
PUSHBUTTON "Cancel", IDCANCEL, 115, 115, 60, 14
}

//////////////////////////////////////////////////////////////////////////////
// TEXTINCLUDE

#ifdef APSTUDIO_INVOKED

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include <windows.h>\r\n"
"#include <commctrl.h>\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED

//////////////////////////////////////////////////////////////////////////////
Binary file added samples/AtlDialogApp/res/Icon_100.ico
Binary file not shown.
15 changes: 15 additions & 0 deletions samples/AtlDialogApp/res/Manifest_1.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>
18 changes: 18 additions & 0 deletions samples/AtlDialogApp/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ Compatible
// This file is automatically generated by RisohEditor 5.7.7.
// main_res.rc

#define IDD_MAIN 100

#define IDI_MAINICON 100

#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 100
#define _APS_NEXT_COMMAND_VALUE 100
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 300
#endif
#endif
2 changes: 0 additions & 2 deletions samples/AtlWindowApp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ BOOL CMainWindow::LoadSettings()
error = appKey.QueryValue(TEXT("x"), NULL, &dwValue, &cbValue);
if (!error)
m_x = dwValue;
else
::MessageBoxA(NULL, "OK", NULL, NULL);

cbValue = sizeof(dwValue);
error = appKey.QueryValue(TEXT("y"), NULL, &dwValue, &cbValue);
Expand Down
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(AtlDialogApp)
add_subdirectory(AtlWindowApp)

0 comments on commit 199d667

Please sign in to comment.