MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / CreateWindows

Method CreateWindows

source/script.cpp:827–965  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

825
826
827ResultType Script::CreateWindows()
828// Returns OK or FAIL.
829{
830 if (!mMainWindowTitle || !*mMainWindowTitle) return FAIL; // Init() must be called before this function.
831 // Register a window class for the main window:
832 WNDCLASSEX wc = {0};
833 wc.cbSize = sizeof(wc);
834 wc.lpszClassName = WINDOW_CLASS_MAIN;
835 wc.hInstance = g_hInstance;
836 wc.lpfnWndProc = MainWindowProc;
837 // The following are left at the default of NULL/0 set higher above:
838 //wc.style = 0; // CS_HREDRAW | CS_VREDRAW
839 //wc.cbClsExtra = 0;
840 //wc.cbWndExtra = 0;
841 // Load the main icon in the two sizes needed throughout the program:
842 g_IconLarge = ExtractIconFromExecutable(NULL, -IDI_MAIN, 0, 0);
843 g_IconSmall = ExtractIconFromExecutable(NULL, -IDI_MAIN, GetSystemMetrics(SM_CXSMICON), 0);
844 wc.hIcon = g_IconLarge;
845 wc.hIconSm = g_IconSmall;
846 wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
847 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); // Needed for ProgressBar. Old: (HBRUSH)GetStockObject(WHITE_BRUSH);
848 wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU_MAIN); // NULL; // "MainMenu";
849 if (!RegisterClassEx(&wc))
850 {
851 MsgBox(_T("RegClass")); // Short/generic msg since so rare.
852 return FAIL;
853 }
854
855 TCHAR class_name[64];
856 HWND fore_win = GetForegroundWindow();
857 bool do_minimize = !fore_win || (GetClassName(fore_win, class_name, _countof(class_name))
858 && !_tcsicmp(class_name, _T("Shell_TrayWnd"))); // Shell_TrayWnd is the taskbar's class on Win98/XP and probably the others too.
859
860 // Note: the title below must be constructed the same was as is done by our
861 // WinMain() (so that we can detect whether this script is already running)
862 // which is why it's standardized in g_script.mMainWindowTitle.
863 // Create the main window. Prevent momentary disruption of Start Menu, which
864 // some users understandably don't like, by omitting the taskbar button temporarily.
865 // This is done because testing shows that minimizing the window further below, even
866 // though the window is hidden, would otherwise briefly show the taskbar button (or
867 // at least redraw the taskbar). Sometimes this isn't noticeable, but other times
868 // (such as when the system is under heavy load) a user reported that it is quite
869 // noticeable. WS_EX_TOOLWINDOW is used instead of WS_EX_NOACTIVATE because
870 // WS_EX_NOACTIVATE is available only on 2000/XP.
871 if ( !(g_hWnd = CreateWindowEx(do_minimize ? WS_EX_TOOLWINDOW : 0
872 , WINDOW_CLASS_MAIN
873 , mMainWindowTitle
874 , WS_OVERLAPPEDWINDOW // Style. Alt: WS_POPUP or maybe 0.
875 , CW_USEDEFAULT // xpos
876 , CW_USEDEFAULT // ypos
877 , CW_USEDEFAULT // width
878 , CW_USEDEFAULT // height
879 , NULL // parent window
880 , NULL // Identifies a menu, or specifies a child-window identifier depending on the window style
881 , g_hInstance // passed into WinMain
882 , NULL)) ) // lpParam
883 {
884 MsgBox(_T("CreateWindow")); // Short msg since so rare.

Callers 1

AutoHotkey.cppFile · 0.80

Calls 3

MsgBoxFunction · 0.85
AppendStandardItemsMethod · 0.80

Tested by

no test coverage detected