Creating a window without a caption - winapi

I am calling CreateWindowExW like this (simplified):
CreateWindowExW(0, "classname", 0, WS_DLGFRAME, 0, 0, 0, 0, 0, 0, 0, 0);
After the window is created, it has WS_BORDER, WS_CAPTION and a few other styles that I didn't give it. According to the MSDN docs, WS_DLGFRAME shouldn't have a caption, so why is WS_CAPTION being added? Am I missing something here?

You don't want a caption bar or border? Use WS_POPUP

Related

Win32 - Change background color under ENTIRE 'Static' control area?

VS2019 c++
This is how I'm declaring a 'Static' label in my humble Win32 application:
hLabel = CreateWindowW(L"Static", L"My Application Text", WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 20, 50, 700, 50, hWnd, NULL, NULL, NULL);
Each line of text uses about 25 pixel worth vertically. So I effectively have room for two lines worth of text in this control since it is declared as 50 pixels high.
I would like to override the default colors used to paint the control, so I experiment with this code:
case WM_CTLCOLORSTATIC:
{
HDC hEdit = (HDC)wParam;
SetTextColor(hEdit, RGB(0, 255, 0));
SetBkColor(hEdit, RGB(0, 0, 255));
return 0;
}
This works "great" except it does not paint the entire area of the control?
As you can see above, the Text color is applied to the characters and the 'Background' color is applied not to the entire area of the control, enclosed by the WS_BORDER, but only to the extent of the characters. I start by filling the control with 100 characters. That's why you only see "one" line of text. My question is "how should I go about filling the entire are of the control"? Which is declared as having an area of 700 pixel wide by 50 pixel high.
I confess I searched around quite a bit but I feel I'm going in circle.
The answer is "42" -- kidding!
This is how I changed my code :
case WM_CTLCOLOREDIT:
{
HDC hEdit = (HDC)wParam;
SetTextColor(hEdit, RGB(0, 0, 255));
SetBkColor(hEdit, RGB(255, 255, 0));
SetBkMode(hEdit, TRANSPARENT);
BackEDIT = CreateSolidBrush(RGB(255, 255, 0));
return (INT_PTR)BackEDIT;
}
And then I added :
case WM_DESTROY:
DeleteObject(BackEDIT);
PostQuitMessage(0);
return 0;
So, adding a BRUSH and deleting the BRUSH. Works perfect!

MFC: Scrollbar gripper has a flashing cursor?

I am using the following code to draw a scrollbar gripper for resizing window.
// create a gripper in the bottom-right corner
if (m_bShowGripper && ((GetStyle() & WS_THICKFRAME) != 0))
{
SMovingChild s;
s.m_rcInitial.SetRect(-GetSystemMetrics(SM_CXVSCROLL), -GetSystemMetrics(SM_CYHSCROLL), 0, 0);
s.m_rcInitial.OffsetRect(rcClient.BottomRight());
m_hGripper = CreateWindow(_T("Scrollbar"), _T("size"), WS_CHILD | WS_VISIBLE | SBS_SIZEGRIP,
s.m_rcInitial.left, s.m_rcInitial.top, s.m_rcInitial.Width(), s.m_rcInitial.Height(),
this->GetSafeHwnd(), NULL, AfxGetInstanceHandle(), NULL);
ASSERT(m_hGripper != NULL);
if (m_hGripper != NULL)
{
s.m_hWnd = m_hGripper;
s.m_dXMoveFrac = 1.0;
s.m_dYMoveFrac = 1.0;
s.m_dXSizeFrac = 0.0;
s.m_dYSizeFrac = 0.0;
m_MovingChildren.push_back(s);
// put the gripper first in the z-order so it paints first and doesn't obscure other controls
::SetWindowPos(m_hGripper, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
}
}
Originally from here: How to create a resizable CDialog in MFC?. The code runs OK, but the gripper has a flashing block like cursor (figure below).
This issue can be addressed by commenting the last statement of ::SetWindowPos(...). But I am wondering what the real cause is and whether it is OK to remove this statement, or any better fix.

How can hide blue color background of selected text in notepad programmaticaly delphi, vc++

I need to copy paste text from notepad but i wish that blue background of selected text remain white, is that possible?
Following code selects and copies notepad text to clipboard
Wnd := FindWindowHandleByTitle('Notepad');
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(ord('A'), 0, 0, 0);
keybd_event(ord('A'), 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
sleep(200);
//
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(ord('C'), 0, 0, 0);
keybd_event(ord('C'), 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);

MOUSEEVENTF_ABSOLUTE doesn't work

I want to make my program click specific mouse coordinates, so I am using
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, point.x, point.y, 0, 0);
where point.x and point.y are normalized between 0 and 65535.
However, it always clicks where the cursor is instead of the coordinates that I pass. Why is that happening?
You might be missing MOUSEEVENTF_MOVE flag.
If that doesn't work - I suggest you just use SetCursorPos() to set the location. Then your mouse_move event should work just fine.
simulate all the mouse events
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, point.x, point.y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

child window blinking

My application is dll which is injected into 3rd party GUI application. There dll creates child window containing few controls on the main window of the application. The problem is that my window and its controls blink when the main window is redrawn. I've already read many articles about similar problems but could not fix it. Here is some code
hwndContainer = CreateWindowEx( WS_EX_TOPMOST, PANEL_CLASS_NAME, "", WS_CHILD | WS_VISIBLE, 0, 0, width, height, hwnd, 0, g_hInstance, cd );
CreateWindowEx( WS_EX_TOPMOST, "button", "Click me", WS_CHILD | WS_VISIBLE | WS_TABSTOP, x, y, w, h, hwndContainer, 0, 0, 0 );
...
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hwndPanel, &ps );
RECT r;
GetClientRect( hwndPanel, &r );
SelectObject( hdc, hpenBorder );
SelectObject( hdc, GetStockObject( NULL_BRUSH ) );
RoundRect( hdc, 0, 0, r.right, r.bottom, 5, 5 );
EndPaint( hwndPanel, &ps );
return 0;
I tried adding WS_CLIPCHILDREN to the main window style, processed WM_PAINT of the main window etc. Any thoughts?
You may give WS_CLIPSIBLINGS a try... It's been a long time since I've done anything with window styles directly but I seem to remember this style required to help reduce redraw flicker in non-top level windows. Good luck.

Resources