I'm creating a small program of my own on WinAPI, (to practice the WIN API programing)
and I wanted to create an "about us" box, like where it is told who built the program, which version is it and such...
I was able to create the window sucsessfully, though I could only created an empty window..
I was wondering how can I write text in the box?
This is my function that creates the dialog box, where ghInstance is the instance of the window :
void CreateDialogBox(HWND hwnd)
{
CreateWindowEx(WS_EX_DLGMODALFRAME | WS_EX_TOPMOST, TEXT("DialogClass"), TEXT("About Us"), WS_VISIBLE | WS_SYSMENU | WS_CAPTION , 100, 100, 200, 150, NULL, NULL, ghInstance, NULL);
}
So how can I write inside that empty window some stuff?
Thanks!
This tutorial, provided by Microsoft (MSDN) themselves should come in handy:
http://msdn.microsoft.com/en-us/library/vstudio/bb384843.aspx
Take note of the WM_PAINT section. That's for drawing simple text.
You can also create controls on the window, for example:
C++ Win32 Multiline static label
If you are using MS VC++, you can try editing the pre-made About us in the resource script. Or you hand craft it in a resource script.
DialogboxName DIALOGEX 0, 0, 170, 62
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Us"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
ICON 128,IDC_STATIC,14,14,21,20
LTEXT "Program by you, Version 1.0",IDC_STATIC,42,14,114,8,SS_NOPREFIX
LTEXT "Copyright (C) 2016",IDC_STATIC,42,26,114,8
DEFPUSHBUTTON "OK",IDOK,113,41,50,14,WS_GROUP
END
You can reference Charles Petzold Windows programming book, version 5 of it.
Related
I am working on a very Big and old C code. The windows for GUI are designed with Dialog Box Styles (Windows) in a resource file(*.rc). one simple window in this code is designed like this:
ID_DIALOGEX 0, 0, 264, 197
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_CLIPSIBLINGS
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_NAME_ORG,83,39,174,14,ES_AUTOHSCROLL
EDITTEXT IDC_NAME_REF,83,57,174,14,ES_AUTOHSCROLL
LTEXT "Name for field 1:",IDC_STATIC,7,41,73,8
LTEXT "Name for field 2:",IDC_STATIC,7,60,73,8
COMBOBOX IDC_SAVEBIG_FIELD,84,157,144,42,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Data field:",IDC_STATIC,35,158,34,8
EDITTEXT IDC_NAME_XMIN,83,76,174,14,ES_AUTOHSCROLL
EDITTEXT IDC_NAME_XMAX,83,95,174,14,ES_AUTOHSCROLL
LTEXT "Name for x-axis min:",IDC_STATIC,7,79,73,8
LTEXT "Name for x-axis max:",IDC_STATIC,7,98,73,8
EDITTEXT IDC_NAME_YMIN,83,113,174,14,ES_AUTOHSCROLL
EDITTEXT IDC_NAME_YMAX,83,131,174,14,ES_AUTOHSCROLL
LTEXT "Name for y-axis min:",IDC_STATIC,7,115,73,8
LTEXT "Name for y-axis max:",IDC_STATIC,7,135,73,8
CTEXT "don't save the info",IDC_STATIC,34,9,194,25
CONTROL "Use zlib compression",IDC_SAVE_CBX_ZIP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,177,81,10
END
the 4 numbers after each line are the x,y,width andh height. So it is pretty exhausting to edit a window like this. I wanted to know is there a easy graphical designer that can produce code like this?
I'm noticing that standard edit controls are not showing the last line of text if it's not fully visible. Is there a way to override this behavior? If not, is there an equivalent solution to an edit box that does? Preferably in "pure" Win32 API fashion, as I am not using MFC or ATL. This is how I define the edit control at the moment:
CreateWindow(L"EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE, 0, 0, 0, 0, hWnd, (HMENU)ID_EDIT_CONTROL, hInst, NULL);
I have the following dialog:
IDD_REMINDERS DIALOGEX 20, 20, 102, 166
STYLE DS_SETFONT | WS_POPUP | WS_SYSMENU | WS_THICKFRAME
FONT 7, "Small Fonts", 0, 0, 0x0
BEGIN
LISTBOX IDC_REMINDERS_LIST, 1,12,100,152, LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | LBS_USETABSTOPS | LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "×",IDC_CLOSE,90,-1,12,11,WS_GROUP | NOT WS_TABSTOP
LTEXT "...", IDC_REMINDERS_CAP, 1,1,75,8
PUSHBUTTON "+", IDC_REMINDERS_NEW, 78,-1,12,11, WS_GROUP | NOT WS_TABSTOP
END
In this dialog I'd like to display checkboxes on the right side.
I was under the impression that calling the following code should add checkboxes to the listbox:
ListView_SetExtendedListViewStyleEx(hWndListView, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
Though, I now suspect I may be mixing up listboxes and listviews. Either way, I tried the same ListView_SetExtended call on a listview with the following code in the RC:
CONTROL "",IDC_KEYS,"SysListView32", LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED | LVS_OWNERDATA | LVS_NOCOLUMNHEADER | WS_TABSTOP,4,64,250,136
Sadly, this listview refused to show checkboxes as well.
Is it possible to have checkboxes in a listbox? (Without going ahead and drawing them yourself. Which will work fine short term, but seems more of a hassle in terms of longer term OS compatibility.)
Can this work if the listbox is set to "owner draw"? (I'm using that due to custom text coloring.)
With C#, I was easily able to get the effect I wanted:
However, I'm having trouble doing the same thing using the Win32 API in C. I don't know how to create a window that has no icon (at all), but still has a caption, a minimize button, and a close button.
I registered my class properly, but I can't figure out what to put for the window styles/extended window styles.
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
The code above produced:
which still has an icon in the title bar and is not what I wanted.
A standard window requires an icon because it needs some form of representation in the taskbar at the bottom of the screen. What should be displayed when you press Alt+Tab in the window switcher if one of the main windows doesn't have an icon?
You need to specify the WS_EX_DLGMODALFRAME extended style. This is the same effect that WinForms sets when you turn off the icon in the title bar.
You also need to make sure that you do not specify an icon when you register the window class. You need to set the hIcon and hIconSm fields of the WNDCLASSEX structure to 0.
Change your code to the following:
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
On a side note, use Spy++ or other similar tool to see the styles that any given HWND actually uses. Point it at your C# window, then duplicate the reported styles in your C code.
I want to make a button that looks just like the OK button when you go My Computer -> Help -> About Windows.
I am creating a button like this:
hButton = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("BUTTON"), TEXT("Text"), WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 10, 10, 30, 30, hwnd, (HMENU)IDC_MAIN_BUTTON, GetModuleHandle(NULL), NULL);
But it looks like a rough square and does not use the windows styles that the user has selected. I guess I should be using some sort of window class but I am unsure what class?
You want to use version 6 of the common controls library. To do this you need to add an application manifest to your executable. See this MSDN article on how to do that.
Try running ControlSpy which will allow you to try out different styles quickly.