How do I resize a bitmap to fit into a Windows button, in Dev C++? - c++

At the moment I am using the following code:
hwndB11 = CreateWindow ("BUTTON", "",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_BITMAP,
B11x, B11y, B11l, B11h, hwnd, (HMENU) BUTTON11,
NULL, //((LPCREATESTRUCT) lParam)->hInstance,
NULL);
SendMessage(hwndB11,
BM_SETIMAGE,
IMAGE_BITMAP,
(LPARAM)LoadBitmap(g_hInst, MAKEINTRESOURCE(SWITCH_OFF)));
How do I modify the code so that the bitmap is stretched to fit onto a Windows button? Any help would be gratefully received.

Related

WinApi Color Listbox

I am trying to modify the color of items in my Listbox.
I use WinApi C++ in Visual Studio 2017.
To create my listbox, I wrote that code:
hListbox = CreateWindowW(L"Listbox", L"My Listbox", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP | WS_BORDER | LBS_EXTENDEDSEL, 100, 60, 300, 2400, hWnd, NULL, NULL, NULL);
Add the items:
SendMessage(hListbox, LB_ADDSTRING, NULL, (LPARAM)Text); (...)
Is it possible to change the color of the text or the background, without changing the type of my object? Or is there an other easy way to create a listbox with colored items?

Edit text on text window

I want to change the text that appears on a window. I seem to be able to do it okay but it messes up the area around it and hides the other text. Am I doing it the wrong way perhaps?
So I initialise the variables like this:
static wchar_t socketstatText1T[256];
static wchar_t socketstatText2T[256];
static HWND socketstatText1;
HWND socketstatText2;
I create my text windows like this:
socketstatText1 = CreateWindowW(L"Static", L"Not Connected",
WS_CHILD | WS_VISIBLE | SS_LEFT,
310, 50, 200, 130, hwnd, (HMENU) 0, NULL, NULL);
socketstatText2 = CreateWindowW(L"Static", L"Inactive",
WS_CHILD | WS_VISIBLE | SS_LEFT,
310, 80, 200, 130, hwnd, (HMENU) 0, NULL, NULL);
And then I edit the text like this:
wcsncpy(socketstatText1T, L"Connected to socket", 18);
SetWindowTextW(socketstatText1, socketstatText1T);
This is the same way I change text for a text area and I've had no issues. I've also read that it works the same on text windows. So here a before and after the text change (this happens on a button press).
Before
After
Does anyone know what I may be missing or doing wrong? Any help is much appreciated.

Child window disappears on scrolling

HWND hwndDlg=GetDesktopWindow();
HWND hImage=CreateWindow(_T("STATIC"), _T(""), SS_CENTERIMAGE | SS_REALSIZEIMAGE | SS_BITMAP | WS_CHILD | WS_VISIBLE,
550, 480, 10, 10, hwndDlg, NULL,
(HINSTANCE)GetWindowLong(hwndDlg, GWLP_HINSTANCE),
NULL);
LPWSTR imgPath = getImagePath();
HBITMAP bitmap = (HBITMAP)LoadImageW(NULL,imgPath, IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
SendMessage(hImage, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)bitmap);
With this piece of code i'm able to create a child window to the current window and make a picture appear on that window. It works as expected. But my problem is when i scroll the child window and the picture disappear. What am I doing wrong? I'm totally new with windows programming. Please help me out.
http://i.stack.imgur.com/VO0uD.png
You may see the screenschot in the above link

Win 32 API, drawing two child windows with vertical splitter bar

Below is code, which I am using for creating child windows:
case WM_CREATE:
hInst = ((LPCREATESTRUCT) lParam) -> hInstance;
hWnd1 = CreateWindowEx( WS_EX_CLIENTEDGE | WS_EX_LEFT,
"edit", NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_MULTILINE | WS_VSCROLL,
0, 0, 0, 0,
hWnd, (HMENU) 1,
hInst, NULL );
hWnd2 = CreateWindowEx( WS_EX_CLIENTEDGE | WS_EX_LEFT,
"edit", NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_MULTILINE | WS_VSCROLL,
0, 0, 0, 0,
hWnd, (HMENU) 2,
hInst, NULL );
But this code produces horizontal splitter, and I want vertical splitter.
First I thought, if I change height and width parameters, I could create vertical splitter. But it was of no use.
For full code and sample example (in order to save space on SO):
http://old.sumitbirla.com/software/src/splitter.c
So, what is exactly keyword/parameter, which would produce vertical splitter bar.
The code you posted just creates two child windows. It has nothing to do with vertical or horizontal splitter. Handle the WM_SIZE message in the parent window to position and size the child windows for a vertical or horizontal split.

EDIT control text overflow

This is simple. I created an EDIT control like this:
HWND MYTEXT= CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
WS_CHILD|WS_VISIBLE|ES_LEFT|ES_MULTILINE,
20, 120, 150, 20, hWnd, NULL, hInst, NULL);
but when I type text inside of it I can't type more text than the width of the EDIT control. When I reach the end it's like there's no more space and I get a beep. How can I make the text scroll in this situation?
You can give your edit control the WS_HSCROLL and/or WS_VSCROLL window styles. For instance:
HWND myText
= CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | ES_LEFT | ES_MULTILINE,
20, 120, 150, 20, hWnd, NULL, hInst, NULL);
Alternately, as Matthew T. Staebler rightfully suggests, use ES_AUTOHSCROLL and/or ES_AUTOVSCROLL (note the ES_ prefix, as these are edit styles, not window styles).