NO

Author Topic: Unicode2DW  (Read 294 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1600
Unicode2DW
« on: May 04, 2017, 06: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, 07: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, 07:19:02 PM by Grincheux »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1600
Re: Unicode2DW
« Reply #2 on: May 05, 2017, 07: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: 487
    • http://www.vortex.masmcode.com
Re: Unicode2DW
« Reply #3 on: May 07, 2017, 02:53:52 PM »
Hi Timo,

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