News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Unicode2DW

Started by TimoVJL, May 04, 2017, 07:34:23 PM

Previous topic - Next topic

TimoVJL

Small example of dialog based program.
Convert UNICODE text for poasm.

Example:Здравствуйте!x dw 417h,434h,440h,430h,432h,441h,442h,432h,443h,439h,442h,435h,21h,0#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

#1
MS dixit :

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

WideCharToMultiByte
MultiByteToWideChar


TimoVJL

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

Vortex

Code it... That's all...

d3dx


bitcoin

Спасибо )

Thank you, very good tool.