I am working on a mixed VC++/asm windows program,but at the same time getting more skilled in winapi is good for both masm and C++ skill
here it works to set another text,not work with set the small icon
buttontext is a WCHAR
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
HWND hwndButton = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"THE ANY_KEY", // Button text
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles
10, // x position
10, // y position
100, // Button width
100, // Button height
hWnd, // Parent window
(HMENU)B1, // No menu.
(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
NULL); // Pointer not needed.
HWND hwndButton2 = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"THE 2ND KEY", // Button text
BS_ICON | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles
120, // x position
10, // y position
100, // Button width
100, // Button height
hWnd, // Parent window
(HMENU)B2, // No menu.
(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
NULL); // Pointer not needed.
SendMessageW(hwndButton2, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IDI_SMALL);
HWND hwndButton3 = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"THE 3rd KEY", // Button text
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_BITMAP, // Styles
240, // x position
10, // y position
100, // Button width
100, // Button height
hWnd, // Parent window
(HMENU)B3, // No menu.
(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
NULL); // Pointer not needed.
HWND hwndButton4 = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"THE 4th KEY", // Button text
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_AUTO3STATE, // Styles
360, // x position
10, // y position
300, // Button width
100, // Button height
hWnd, // Parent window
(HMENU)B4, // No menu.
(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
NULL); // Pointer not needed.
SendMessageW(hwndButton4, WM_SETTEXT, NULL, (LPARAM)buttontext);// (LPARAM)IDI_SMALL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}this same code doesnt respond,but destroywindow worked and quits program
buttons constants are named B1,B2,B3,B4
/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case B1:
//handle button here
//SendMessageW(hwndButton, WM_SETTEXT, NULL, &buttontext);
SendMessageW(hwndButton, WM_SETTEXT, NULL, (LPARAM)buttontext);
//DestroyWindow(hWnd);
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code that uses hdc here...
paint(hdc);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.