i am working on my first win32 GUI application and i want to send message to the ListBox to add text but the text appears in chines character in the ListBox. The same thing happened to Combo Box Here is the code :
#include <windows.h>
#include <winbase.h>
#include <stdio.h>
#include "resource.h"
#define DEFAULT_BUTTON_WIDTH 100
#define DEFAULT_BUTTON_HEIGHT 20
HINSTANCE GlobalInstance;
HWND Window;
HWND bCreateWall;
HMENU Menu;
HMENU PopupMenu;
LRESULT CALLBACK MapDetailsDlgProc(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG:
{
SetDlgItemText (hWnd, IDC_MAP_DETAILS_NAME, L"Map Name");
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_RULES, LB_ADDSTRING,0, (LPARAM)"Erase Me");
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_RULES, LB_RESETCONTENT,0, 0);
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_RULES, LB_ADDSTRING,0, (LPARAM)"Exit");
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_RULES, LB_ADDSTRING,0, (LPARAM)"Get Fragged");
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_RULES, LB_SETCURSEL,0, 1);
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_TYPE, CB_ADDSTRING,0, (LPARAM)"Erase Me");
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_TYPE, CB_RESETCONTENT,0, 0);
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_TYPE, CB_ADDSTRING,0, (LPARAM)"Single Player");
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_TYPE, CB_ADDSTRING,0, (LPARAM)"Multi Player");
SendDlgItemMessage (hWnd, IDC_MAP_DETAILS_LEVEL_TYPE, CB_SETCURSEL,0, 1);
} break;
case WM_COMMAND:
{
if (wParam == IDOK)
{
long level_rule = SendDlgItemMessage (hWnd,IDC_MAP_DETAILS_LEVEL_RULES, LB_GETCURSEL, 0, 0);
long level_type = SendDlgItemMessage (hWnd,IDC_MAP_DETAILS_LEVEL_TYPE, CB_GETCURSEL, 0, 0);
char temp[500];
sprintf (temp, "Level Type: %i\r\nLevel Rule: %i\r\nOK Button!",level_type, level_rule);
MessageBox (hWnd, (LPCWSTR)temp, L"OK", MB_OK);
EndDialog (hWnd, 0);
}else if (wParam == IDCANCEL)
{
MessageBox (hWnd, L"Cancel Button!", L"Cancel", MB_OK);
EndDialog (hWnd, 0);
}
} break;
}
return (0);
}
void WMCommand(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (lParam == (LPARAM)bCreateWall) MessageBox (Window, L"You PressedbCreateWall", L"Congrats!", MB_OK);
else if (wParam == ID_FILE_EXIT) PostQuitMessage(0);
else if (wParam == ID_DRAWING_WIREFRAME)
{
CheckMenuItem (Menu, ID_DRAWING_WIREFRAME, MF_CHECKED);
CheckMenuItem (Menu, ID_DRAWING_SOLID, MF_UNCHECKED);
}
else if (wParam == ID_DRAWING_SOLID)
{
CheckMenuItem (Menu, ID_DRAWING_SOLID, MF_CHECKED);
CheckMenuItem (Menu, ID_DRAWING_WIREFRAME, MF_UNCHECKED);
}
else if (wParam == ID_MAP_DETAILS) DialogBox (GlobalInstance,MAKEINTRESOURCE(IDD_MAP_DETAILS), NULL, (DLGPROC)MapDetailsDlgProc);
else if (wParam == ID_POPUP_MOVE) MessageBox (Window, L"Move", L"Click", MB_OK);
else if (wParam == ID_POPUP_DELETE) MessageBox (Window, L"Delete", L"Click",MB_OK);
else if (wParam == ID_POPUP_TEXTURE) MessageBox (Window, L"Texture", L"Click",MB_OK);
else if (wParam == ID_POPUP_DUPLICATE) MessageBox (Window, L"Duplicate",L"Click", MB_OK);
}
void DisplayPopupMenu(long x, long y)
{
HMENU temp = GetSubMenu(PopupMenu, 0);
TrackPopupMenu(temp, TPM_LEFTALIGN|TPM_RIGHTBUTTON, x, y, 0, Window, NULL);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY: PostQuitMessage(0); break;
case WM_COMMAND: WMCommand (hWnd, msg, wParam, lParam); break;
case WM_RBUTTONUP: DisplayPopupMenu(LOWORD(lParam), HIWORD(lParam)); break;
}
return (DefWindowProc(hWnd, msg, wParam, lParam));
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR lpCmdString,int CmdShow)
{
GlobalInstance = hInstance;
WNDCLASS wc;
MSG msg;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L"ME";
wc.lpszMenuName = NULL;
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&wc))
{
MessageBox (NULL,L"Error: Cannot Register Class",L"ERROR!", MB_OK);
return (0);
}
Window = CreateWindow(L"ME", L"Map Editor", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, NULL, NULL, hInstance, NULL);
if (Window == NULL)
{
MessageBox (NULL,L"Error: Failed to Create Window", L"ERROR!", MB_OK);
return (0);
}
bCreateWall = CreateWindow(L"BUTTON", L"Create Wall", WS_CHILD | WS_VISIBLE,0, 100, DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT, Window,NULL, hInstance, NULL);
Menu = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_MENU));
SetMenu (Window, Menu);
PopupMenu = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_POPUP_MENU));
while (1)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage (&msg);
}
}
return (1);
}
i think the problem is with (lparam)
How can i fix this problem ????
Well it seems to me that you're using the Unicode API, therefore you would have to pass UTF-16 strings using
L""
syntax:And so on