NO

Author Topic: Unicode2DW  (Read 4320 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Unicode2DW
« 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);
}
}
May the source be with you

Grincheux

  • Guest
Re: Unicode2DW
« Reply #1 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
MultiByteToWideChar

« Last Edit: May 05, 2017, 08:19:02 PM by Grincheux »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Unicode2DW
« Reply #2 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.
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 797
    • http://www.vortex.masmcode.com
Re: Unicode2DW
« Reply #3 on: May 07, 2017, 03:53:52 PM »
Hi Timo,

Nice work.
Code it... That's all...

d3dx

  • Guest
Re: Unicode2DW
« Reply #4 on: February 24, 2019, 08:52:20 PM »
Thanx! :)

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: Unicode2DW
« Reply #5 on: April 06, 2019, 08:12:28 PM »
Спасибо )

Thank you, very good tool.