Pelles C forum

C language => User contributions => Topic started by: TimoVJL on May 04, 2017, 07:34:23 pm

Title: Unicode2DW
Post by: TimoVJL on May 04, 2017, 07:34:23 pm
Small example of dialog based program.
Convert UNICODE text for poasm.

Example:
Code: [Select]
Здравствуйте!
Code: [Select]
x dw 417h,434h,440h,430h,432h,441h,442h,432h,443h,439h,442h,435h,21h,0
Code: [Select]
#define UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#pragma pack(push, 2)
typedef struct {
DLGTEMPLATE lpDlg;
WORD menu;
WORD class;
WORD title[11];
WORD wFontSize;
WORD font[7];
DLGITEMTEMPLATE lpItem1;
DWORD dwClass1; // class, numeric
WORD szText1[2]; // text + align
WORD w1;
DLGITEMTEMPLATE lpItem2;
DWORD dwClass2; // class, numeric
WORD szText2[2];
WORD w2;
DLGITEMTEMPLATE lpItem3;
DWORD dwClass3; // class, numeric
WORD szText3[3];
WORD w3;
} MINDLGTEMPLATE, *PMINDLGTEMPLATE;
#pragma pack(pop)

INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
void Convert(HWND hwndDlg);

static MINDLGTEMPLATE Dlg = {
{DS_SETFONT|WS_POPUP|DS_CENTER|WS_CAPTION|WS_SYSMENU,0,3,2,0,300,30},
0,0,L"Unicode2DW",10,L"Tahoma", // Dialog
{WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_BORDER|ES_AUTOHSCROLL,0,1,2,200,12,4001},
0x0081FFFF,L"",0, // edit 1
{WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_BORDER|ES_AUTOHSCROLL,0,1,15,295,12,4002},
0x0081FFFF,L"",0, // edit 2
{WS_CHILD|WS_VISIBLE|WS_TABSTOP,0,205,2,50,12,1},
0x0080FFFF,L"OK",0};
int __cdecl WinMainCRTStartup(void)
{
ExitProcess(DialogBoxIndirectParam(GetModuleHandle(NULL), (LPDLGTEMPLATE)&Dlg, 0, MainDlgProc, 0));
}

INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (wParam) {
case IDOK:
Convert(hwndDlg);
return 0;
case IDCANCEL:
EndDialog(hwndDlg, wParam);
return 0;
}
break;
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}

void Convert(HWND hwndDlg)
{
TCHAR szTmp[260], szTmp2[260];
HWND hEdit1, hEdit2;
hEdit1 = GetDlgItem(hwndDlg, 4001);
hEdit2 = GetDlgItem(hwndDlg, 4002);
int nLen = GetWindowText(hEdit1, szTmp, sizeof(szTmp));
if (nLen) {
TCHAR *pPtr = szTmp2+5;
lstrcpy(szTmp2, TEXT("x dw "));
for (int i=0; i<nLen; i++) {
int nCh = wsprintf(pPtr, TEXT("%0Xh,"), szTmp[i]);
pPtr += nCh;
}
*pPtr++ = '0';
*pPtr = 0;
SetWindowText(hEdit2, szTmp2);
}
}
Title: Re: Unicode2DW
Post by: Grincheux on May 05, 2017, 08:16:46 pm
MS dixit :

Quote
Use WideCharToMultiByte to convert a Unicode string to an ANSI string. The MultiByteToWideChar function converts an ANSI string to a Unicode string.

WideCharToMultiByte (https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130(v=vs.85).aspx)
MultiByteToWideChar  (https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx)

Title: Re: Unicode2DW
Post by: TimoVJL on May 05, 2017, 08:33:43 pm
Why?
No need for conversion function, just save some bytes to object file with poasm.
This was just an example of dialog creating code.
Title: Re: Unicode2DW
Post by: Vortex on May 07, 2017, 03:53:52 pm
Hi Timo,

Nice work.
Title: Re: Unicode2DW
Post by: d3dx on February 24, 2019, 08:52:20 pm
Thanx! :)
Title: Re: Unicode2DW
Post by: bitcoin on April 06, 2019, 08:12:28 pm
Спасибо )

Thank you, very good tool.