Child window disappears on scrolling - c++

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

Related

Detect mouse click outside child window

I want to destroy a child window when user click somewhere outside its window. I tried to use SetCapture() to detect mouse click. Here is the code:
HWND textbox;
//IN case WM_CREATE:
CreateWindowEx(NULL, L"BUTTON", L"button!",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 10, 150, 40, hwnd,
(HMENU)IDC_TEXTBOX, NULL, NULL);
textbox = CreateWindowEx(
NULL, L"EDIT", NULL,
WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_BORDER,
100, 100, 300, 200, hwnd, (HMENU)ID_TEXTBOX, NULL, NULL
);
SetWindowText(textbox, L"the initial text");
//IN CASE WM_ONLBUTTONDOWN:
if (textbox != NULL) {
if (SetCapture(textbox) == NULL) {
ReleaseCapture();
DestroyWindow(textbox);
textbox = NULL;
}
}
The window did get destroyed when i clicked outside its region. HOWEVER, when i click the button it didn't get destroyed as i expected. I want the child window to get destroyed when user clicks WHEREVER outside its window. Why did my code fail? And how do i do this right?
EDIT: Here is a screenshot to make things clear. The window only have an edit window with initial text and a button. As mentioned above, the child window disappears when i click outside its window but when i click the button (which is also outside window), the edit window remains.
According to this thread, I find the EN_KILLFOCUS notification which will work for you in the Edit Control Document.

How can i put icon on button in c++?

I have a window and there is a button on it. I want to put a icon of question mark on that button,how can i do this??
To create button:-
HWND button = CreateWindow(TEXT("button"), NULL,
WS_VISIBLE | WS_CHILD | BS_ICON, 20, 50, 200, 25,
hWnd, NULL, NULL, NULL);
To load question mark icon:-
HICON hIcon = LoadIcon(NULL, IDI_QUESTION);
To put the icon on button:-
SendMessage(button, WM_SETICON, IMAGE_ICON, (LPARAM)hIcon);
But icon is not appearing on button.
You are using the wrong message to set the icon to the button. You need to use BM_SETIMAGE.

How do I resize a bitmap to fit into a Windows button, in Dev 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.

Drawing image over static control

I'm trying to paint a Picture Box over Static Control, yet the image is not appearing.
The image do exist at the location.
Here is my code :
HWND hwn = CreateWindow(TEXT("static"), NULL, WS_CHILD | WS_VISIBLE, 5, 10, 470, 100, hwnd, NULL, NULL, NULL);
HBITMAP hBmp = (HBITMAP)LoadImage(NULL, "D:\\Pic.bmp", IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE);
SendMessage(hwn, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp);
First I'm creating a static control (just as the guides in google said), and then I'm painting the image over it... Why isnt it working ? It only draws the static control, but the image isnt being loaded at all...
Thanks!
You need SS_BITMAP style when creating the static control.

Layered window: Why's the edge rounded automatically?

I am trying to draw a hbitmap with a layeredwindow directly onto the screen. this also works now how it should, yet the left upper corner of the image is always rounded.
I'm creating the window with:
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT
, szWindowClass, 0,
WS_VISIBLE
, 150,250, width, height, 0, NULL, hInstance, NULL);
Could anyone help me please to solve this problem?
You are using WS_VISIBLE as the window style, which is equivalent to WS_OVERLAPPED | WS_VISIBLE. Overlapped windows have rounded corners at the top.
Use WS_POPUP | WS_VISIBLE instead.