How to really set foreground window using Winapi? - qt

OS: Windows 10
I have very simple GUI application in Qt. In this app I only set the window name to "tmpAppName".
Now I would like to run the second app which set the first App to foreground ( tmpAppName ).
My second App:
auto hwndAppToForeground = FindWindowExA(0,0,0,"tmpAppName");
if(!hwndAppToForeground)
{
qDebug()<<"No window with name tmpAppName";
exit(0);
}
auto foregroundWindow = GetForegroundWindow();
Sleep(5000);
if(foregroundWindow!=hwndAppToForeground)
{
SetForegroundWindow(hwndAppToForeground);
SetActiveWindow(hwndAppToForeground);
SetFocus(hwndAppToForeground);
SetWindowPos(hwndAppToForeground, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
I using Sleep(5000) because during that time I set other application in the foreground ( for example Audacity ).
The line:
SetWindowPos(hwndAppToForeground, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
is very helpfull, but I get window in the foreground but not active and when I check which window is in the foreground I get something different then "tmpAppName":
And I would like to achieve:

Related

Halcon - Set image brightness/exposure

I'm trying few things in Halcon for the first time. But couldnt figure out, not even in the documentation, how to set the exposure for the image aquisition... my code so far is this, but my test environment is dark, and would like to brighten up the image a little bit:
open_framegrabber ('uEye', 1, 1, 0, 0, 0, 0, 'default', -1, 'default', -1, 'default', 'default', 'default', -1, -1, AcqHandle)
dev_open_window (0, 0, 500, 300, 'light gray', WindowHandleButton)
i := 0
create_bar_code_model ([], [], BarCodeHandle)
while (i < 100)
grab_image (Image, AcqHandle)
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)
get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', BarCodeResults)
i:= i+1
endwhile
close_framegrabber (AcqHandle)
You can set the exposure with:
set_framegrabber_param (AcqHandle, 'exposure', 10.0)
Using Halcon assistants is an easy way of finding and setting the parameters Assistants->Open New Image Acquisition->Source(uEye)->Connect->Parameters:
You could change the parameters there and use the last tab to generate the code automatically.
Also using the example program examples/hdevelop/Image/Acquisition/ueye_parameters.hdev will give you the list of all available parameters on your camera:

how to keep shadow in borderless window

I'm trying to drop a shadow on a borderless window using Qt in windows.
I succeeded in dropping the shadow when launching the application, referring to the following article.
Borderless Window Using Areo Snap, Shadow, Minimize Animation, and Shake
Borderless Window with Drop Shadow
But I encountered the problem that the shadow will disappear if the application is deactivated and reactivated (
In other words, click the other applications, and click my application again.)
Perhaps my implementation is not good enough.
I'm glad if you have some ideas for this issue.
I'm trying to imprement Qt with Go bindings
Here is the code snippet:
package qframelesswindow
import (
"unsafe"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"
win "github.com/akiyosi/w32"
)
func (f *QFramelessWindow) SetNativeEvent(app *widgets.QApplication) {
filterObj := core.NewQAbstractNativeEventFilter()
filterObj.ConnectNativeEventFilter(func(eventType *core.QByteArray, message unsafe.Pointer, result int) bool {
msg := (*win.MSG)(message)
lparam := msg.LParam
hwnd := msg.Hwnd
var uflag uint
uflag = win.SWP_NOZORDER | win.SWP_NOOWNERZORDER | win.SWP_NOMOVE | win.SWP_NOSIZE | win.SWP_FRAMECHANGED
var nullptr win.HWND
shadow := &win.MARGINS{0, 0, 0, 1}
switch msg.Message {
case win.WM_CREATE:
style := win.WS_POPUP | win.WS_THICKFRAME | win.WS_MINIMIZEBOX | win.WS_MAXIMIZEBOX | win.WS_CAPTION
win.SetWindowLong(hwnd, win.GWL_STYLE, uint32(style))
win.DwmExtendFrameIntoClientArea(hwnd, shadow)
win.SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, uflag)
return true
case win.WM_NCCALCSIZE:
if msg.WParam == 1 {
// this kills the window frame and title bar we added with WS_THICKFRAME and WS_CAPTION
result = 0
return true
}
return false
case win.WM_GETMINMAXINFO:
mm := (*win.MINMAXINFO)((unsafe.Pointer)(lparam))
mm.PtMinTrackSize.X = int32(f.minimumWidth)
mm.PtMinTrackSize.Y = int32(f.minimumHeight)
return true
default:
}
return false
})
app.InstallNativeEventFilter(filterObj)
}
All source code is in my repository;
akiyosi/goqtframelesswindow
WM_NCCALCSIZE:
If wParam is TRUE, the application should return zero or a combination
of the following values.(In document)
And also:
When wParam is TRUE, simply returning 0 without processing the
NCCALCSIZE_PARAMS rectangles will cause the client area to resize to
the size of the window, including the window frame. This will remove
the window frame and caption items from your window, leaving only the
client area displayed.
Starting with Windows Vista, simply returning 0 does not affect extended frames, only the standard frame will be removed.
EDIT:
Set the return value with the DWL_MSGRESULT instead of result = 0.

how to set margin for PrintLayout in javafx?

i have a javaFx application and am working on the Printer module , in the software am done with other things, like installed printer list , taking print from the specific printer but getting issue in the layout , now am having 80mm printer and when i get print from this printer then there are lots of margin in left side and right side, please help me to get correct print.
am using following code for print:-
PageLayout pageLayout = prnterForJob.createPageLayout(Paper.MONARCH_ENVELOPE,
PageOrientation.PORTRAIT, 0, 0, 0, 0);
PrinterJob job = PrinterJob.createPrinterJob(prnterForJob);
job.getJobSettings().setCopies(nmbrOfCopies1);
if (job != null) {
//boolean success = job.printPage(node);
weOrderPrint.print(job);
job.endJob();
}
Aren't you just forgetting to set the page layout you created?
job.getJobSettings().setPageLayout(pageLayout);

Changing UITabBarItem image's color

I'm having an hard time trying to change the color of my UITabBarItem's icon. I used the code below to initialize all the parameters:
// Settings Tab
tabBarController?.tabBar.translucent = false
tabBarController?.tabBar.barTintColor = dark_color
let titoli:[String] = ["Feed","Categorie","Info"]
for (var i:Int=0; i<titoli.count; i++){
let tab:UITabBarItem? = tabBarController?.tabBar.items![i] as UITabBarItem?
tab?.image = UIImage(named: titoli[i])
tab?.title = titoli[i]
tab?.setTitleTextAttributes(NSDictionary(object: UIColor.whiteColor(), forKey: NSForegroundColorAttributeName) as? [String:AnyObject], forState: UIControlState.Selected)
tab?.setTitleTextAttributes(NSDictionary(object: UIColor(red: 0, green: 0, blue: 0, alpha: 0.6), forKey: NSForegroundColorAttributeName) as? [String:AnyObject], forState: UIControlState.Normal)
}
Am I missing something here?
FYI: just playing with XCode Beta and Swift 2.0
Already answered here but in short, click on the tab bar item you wish to change and you can add a new runtime attribute in the Storyboard which will change the entire item (image & text) when selected.

MDI Child Windows overdraw frame toolbar?

I have write a MDI application with toolbar, but the child window overdraw the frame window's toolbar. Here is the effect, I have to click the left corner to see the toolbar icons.
I create the toolbar with following code:
CToolBar::CToolBar(HINSTANCE hInst, HWND hParent, LPCTSTR lpszWindowName) :
CWindow(hInst, hParent, lpszWindowName)
{
INITCOMMONCONTROLSEX icex;
// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
lstrcpy(m_szClassName, TOOLBARCLASSNAME);
}
BOOL CToolBar::Create()
{
//create the toolbar
m_hWnd = CreateWindowEx(0, TOOLBARCLASSNAME, (LPCTSTR) NULL,
WS_CHILD, 0, 0, 0, 0, m_hParent,
(HMENU) ID_TOOLBAR, m_hInst, NULL);
//for backword compatibility
SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
if (m_hWnd == NULL)
return FALSE;
return TRUE;
}
BOOL CToolBar::Init()
{
TBBUTTON tbb[3];
TBADDBITMAP tbab;
if (! Create() )
return FALSE;
//Add standard toolbar bitmaps
tbab.hInst = HINST_COMMCTRL;
tbab.nID = IDB_STD_SMALL_COLOR;
SendMessage(m_hWnd, TB_ADDBITMAP, 0, (LPARAM)&tbab);
//Add buttons
ZeroMemory(tbb, sizeof(tbb));
tbb[0].iBitmap = STD_CUT;
tbb[0].idCommand = IDS_CUT;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[1].iBitmap = STD_COPY;
tbb[1].idCommand = IDS_COPY;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[2].iBitmap = STD_PASTE;
tbb[2].idCommand = IDS_PASTE;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
SendMessage(m_hWnd, TB_ADDBUTTONS, (WPARAM) 3, (LPARAM) (LPTBBUTTON) &tbb);
ShowWindow(m_hWnd, SW_NORMAL);
return TRUE;
}
I test it with SDI windows, it works well, but after I create the MDICLIENT(client) window, it sucks.
Please help me to work around this peculiar problem.
You COULD get all the source code at https://code.google.com/p/jcyangs-code/source/browse/trunk/com/lib/
Thanks.
Handle WM_SIZE message of Frame Window.

Resources