I need to learn with WinAPI.... #383
-
Hello I am here now. I axam about initial For X11 has many seperated libaries like X11, Xext, XRender, Xaw etc.. How do I find good tutorial for WinAPI? Like books or online documentations? I made initial test with WinAPI. Why does it shows Chinese or Japanese Language? I know far but why does WinAPI have built sometimes features like HMenu, HButton or HDialog or HBrush etc... namespace DeafMan1983.Examples.WinAPI;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.Windows.Windows;
using static TerraFX.Interop.Windows.WM;
using static TerraFX.Interop.Windows.WS;
using static TerraFX.Interop.Windows.SW;
using static TerraFX.Interop.Windows.CS;
using static TerraFX.Interop.Windows.IDC;
using static TerraFX.Interop.Windows.IDI;
using static TerraFX.Interop.Windows.PAINTSTRUCT;
using System.Runtime.InteropServices;
using System.Text;
unsafe class Program
{
static string DesktopAppStr = "DesktopApp";
static string TitleStr = "Windows Desktop Guided Tour Application";
static HINSTANCE hInst;
static int WinMain(HINSTANCE hInstance, HINSTANCE hInstPrev, sbyte* cmdline, int nCmdShow)
{
fixed (char* szWindowClass = DesktopAppStr)
fixed (char* szTitle = TitleStr)
fixed (char* registerClassErrorMsg = "Call to RegisterClassEx failed!")
fixed (char* msgboxTitle = "Windows Desktop Guided Tour")
fixed (char* createWindowFailedMsg = "Call to CreateWindow failed!")
{
var wcex = new WNDCLASSEXW
{
cbSize = (uint)sizeof(WNDCLASSEXA),
style = CS_HREDRAW | CS_VREDRAW,
lpfnWndProc = &WndProc,
cbClsExtra = 0,
cbWndExtra = 0,
hInstance = hInstance
};
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(HINSTANCE.NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(5 + 1);
wcex.lpszMenuName = null;
wcex.lpszClassName = (char*)szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (RegisterClassEx(&wcex) == 0)
{
MessageBox(HWND.NULL,
registerClassErrorMsg,
msgboxTitle,
0);
return 1;
}
hInst = hInstance;
HWND hWnd = CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
(char*)szWindowClass,
(char*)szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
500, 100,
HWND.NULL,
HMENU.NULL,
hInstance,
null
);
if (hWnd == HWND.NULL)
{
MessageBox(HWND.NULL,
createWindowFailedMsg,
msgboxTitle,
0);
return 1;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, HWND.NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
}
static int Main(string[] args)
{
hInst = GetModuleHandleW(null);
return WinMain(hInst, HINSTANCE.NULL, null, SW_SHOWDEFAULT);
}
[UnmanagedCallersOnly]
static LRESULT WndProc(HWND hWnd, uint message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
fixed (char* greeting = "Hello, Windows desktop!")
{
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,
5, 5,
greeting, "Hello, Windows desktop!".Length);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
}
} Kind regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yeaaahh I am very excited to my own UTF16 converter :D I would like to support your own I give you nice own 3 functions for Please do not forget to put my credit! See Nuget Package DeafMan1983.Utilities PS Please remove my copyrighted sourtce thank you! For Example I have replaced fixed statements to normal converter-functions namespace WinAPP;
using static DeafMan1983.Utilities.UtilitiesForUTF16;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.Windows.Windows;
using static TerraFX.Interop.Windows.WM;
using static TerraFX.Interop.Windows.WS;
using static TerraFX.Interop.Windows.SW;
using static TerraFX.Interop.Windows.CS;
using static TerraFX.Interop.Windows.IDC;
using static TerraFX.Interop.Windows.IDI;
using static TerraFX.Interop.Windows.PAINTSTRUCT;
using System.Runtime.InteropServices;
unsafe class Program
{
static string DesktopAppStr = "DesktopApp";
static string TitleStr = "Windows Desktop Guided Tour Application";
static string CreateWindowFailureMessage = "Call to CreateWindow failed!";
static string RegisterClassFailureMessage = "Call to RegisterClassEx failed!";
static string MessageBoxTitle = "Windows Desktop Guided Tour";
static HINSTANCE hInst;
static int WinMain(HINSTANCE hInstance, HINSTANCE hInstPrev, sbyte* cmdline, int nCmdShow)
{
var wcex = new WNDCLASSEXW
{
cbSize = (uint)sizeof(WNDCLASSEXA),
style = CS_HREDRAW | CS_VREDRAW,
lpfnWndProc = &WndProc,
cbClsExtra = 0,
cbWndExtra = 0,
hInstance = hInstance
};
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(HINSTANCE.NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(5 + 1);
wcex.lpszMenuName = null;
wcex.lpszClassName = StringToCharPointer(DesktopAppStr);
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (RegisterClassEx(&wcex) == 0)
{
MessageBox(HWND.NULL,
StringToCharPointer(RegisterClassFailureMessage),
StringToCharPointer(MessageBoxTitle),
0);
return 1;
}
hInst = hInstance;
HWND hWnd = CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
StringToCharPointer(DesktopAppStr),
StringToCharPointer(TitleStr),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
500, 100,
HWND.NULL,
HMENU.NULL,
hInstance,
null
);
if (hWnd == HWND.NULL)
{
MessageBox(HWND.NULL,
StringToCharPointer(CreateWindowFailureMessage),
StringToCharPointer(MessageBoxTitle),
0);
return 1;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, HWND.NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
static int Main(string[] args)
{
hInst = GetModuleHandleW(null);
return WinMain(hInst, HINSTANCE.NULL, null, SW_SHOWDEFAULT);
}
[UnmanagedCallersOnly]
static LRESULT WndProc(HWND hWnd, uint message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
string MessageGreeting = "Hello, Windows desktop!";
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,
5, 5,
StringToCharPointer(MessageGreeting), CharPointerLength(StringToCharPointer(MessageGreeting)));
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
} Enjoy your relief and happy Pentecost/Whitsun! |
Beta Was this translation helpful? Give feedback.
Yeaaahh I am very excited to my own UTF16 converter :D
I would like to support your own
char*
-string
converterI give you nice own 3 functions for
CharPointerToString()
,StringToCharPointer()
andCharPointerLength()
Please do not forget to put my credit!
And It works fine like String UTF8 to CharPointer UTF16
See Nuget Package DeafMan1983.Utilities PS Please remove my copyrighted sourtce thank you!
For Example I have replaced fixed statements to normal converter-functions