nim_duilib/examples/proto_debuger/main.cpp
2022-03-13 01:50:44 +08:00

113 lines
2.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// basic.cpp : 定义应用程序的入口点。
//
#include "main.h"
#include "base_form.h"
#include"resource1.h"
#include <math.h>
#include "lua_wraper.h"
#include "loger.h"
#include "global.h"
enum ThreadId
{
kThreadUI
};
BasicForm* gMainWindow = nullptr;
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
#ifdef WIN32
WORD wdVersion = MAKEWORD(2, 2);//定义自己需要的网络库版本这里是2.2
WSADATA wdSockMsg;//这是一个结构体
int nRes = WSAStartup(wdVersion, &wdSockMsg);//打开一个套接字
if (0 != nRes) {
switch (nRes) {
case WSASYSNOTREADY:
printf("check your library");
break;
case WSAVERNOTSUPPORTED:
printf("need updated");
break;
case WSAEINPROGRESS:
printf("need reboot");
break;
case WSAEPROCLIM:
printf("sdfsdfsa");
break;
}
}
if (2 != HIBYTE(wdSockMsg.wVersion) || 2 != LOBYTE(wdSockMsg.wVersion)) {
printf("WSACleanup");
WSACleanup();
return 0;
}
#endif
LPTSTR CurrentPath = new wchar_t[255];
GetCurrentDirectory(255, CurrentPath);
AllocConsole();
freopen("CONOUT$", "w", stdout);
std::wcout << CurrentPath << std::endl;
LuaDelegate lua;
std::cout << std::endl;
// lua.CallFuntion< lua_Number>(std::string("sds"),
// 123.0);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// 创建主线程
MainThread thread;
// 执行主线程循环
thread.RunOnCurrentThreadWithLoop(nbase::MessageLoop::kUIMessageLoop);
return 0;
}
void MainThread::Init()
{
nbase::ThreadManager::RegisterThread(kThreadUI);
// 获取资源路径,初始化全局参数
std::wstring theme_dir = nbase::win32::GetCurrentModuleDirectory();
wprintf(L"%s\r\n", theme_dir);
#if 1
// Debug 模式下使用本地文件夹作为资源
// 默认皮肤使用 resources\\themes\\default
// 默认语言使用 resources\\lang\\zh_CN
// 如需修改请指定 Startup 最后两个参数
ui::GlobalManager::Startup(theme_dir + L"resources\\", ui::CreateControlCallback(), false);
#else
// Release 模式下使用资源中的压缩包作为资源
// 资源被导入到资源列表分类为 THEME资源名称为 IDR_THEME
// 如果资源使用的是本地的 zip 文件而非资源中的 zip 压缩包
// 可以使用 OpenResZip 另一个重载函数打开本地的资源压缩包
ui::GlobalManager::OpenResZip(MAKEINTRESOURCE(IDR_THEME2), L"THEME", "");
//ui::GlobalManager::OpenResZip(L"resources.zip", "");
ui::GlobalManager::Startup(L"resources\\", ui::CreateControlCallback(), false);
#endif
auto dpiManager = ui::DpiManager::GetInstance();
// dpiManager->SetAdaptDPI();
dpiManager->SetScale(1);
// 创建一个默认带有阴影的居中窗口
gMainWindow = new BasicForm();
gMainWindow->Create(NULL, BasicForm::kClassName.c_str(),
WS_OVERLAPPEDWINDOW & WS_SIZEBOX,0,true, ui::UiRect(0,0,1024,768));
gMainWindow->CenterWindow();
gMainWindow->ShowWindow();
gMainWindow->SetInitSize(1024,768);
}
void MainThread::Cleanup()
{
ui::GlobalManager::Shutdown();
SetThreadWasQuitProperly(true);
nbase::ThreadManager::UnregisterThread();
}