Implementing a dialog background image - visual-studio-2010

using c++ under visual studio 2010.
I have a dialog creation section
IDD_LOGON DIALOGEX 0, 0, 265, 70
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
CAPTION "Log On to Windows"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_NAME,61,9,127,14,ES_AUTOSCROLL
EDITTEXT IDC_PASSWORD,61,29,127,14,ES_PASSWORD | ES_AUTOSCROLL
EDITTEXT IDC_DOMAIN,61,49,127,14,ES_AUTOSCROLL
DEFPUSHBUTTON "OK",IDOK,204,8,50,14
PUSHBUTTON "Cancel",IDCANCEL,204,25,50,14
LTEXT "Domain:",IDC_STATIC,21,52,27,8
LTEXT "Password:",IDC_STATIC,21,32,34,8
LTEXT "User Name:",IDC_STATIC,17,12,38,8
PUSHBUTTON "Shutdown",IDC_SHUTDOWN,204,49,50,14
END
I would like to have an image in the background of this dialog.
How would i go about performing this action?
thank you

In your OnInitDialog() use:
this->SetBackgroundImage(IDB_BITMAP1, BACKGR_TOPLEFT, TRUE);
For more info refer : CDialogEx::SetBackgroundImage

There is no way to do this through the dialog template/designer. You will need to handle the WM_ERASEBKGND message in your dialog and paint the background yourself.
Here is some info:
http://www.codeproject.com/Articles/18967/Bitmap-Backgrounds-For-Dialog-Boxes

quick answer... i dropped the image control on the dialog, set the image... then... i went into the code and placed it at the TOP of the stack, and it was painted with no issues. the transparent portion of the other controls was failing, so i grouped them all into an area of the same background color on the image, and walla - all done. thank you

Related

Resizing an edit window

I have a simple edit window:
hwndEdit = CreateWindow(
TEXT("EDIT"),
TEXT("EDIT"),
WS_BORDER | WS_CHILD | ES_LEFT,
100,
100,
100,
30,
gHwnd,
0,
hInst,
0);
I have noticed that when I paste there a text which is longer than an edit window width I get notification (EN_CHANGE) which contains only a portion of the text which fits a window width. I would like to resize an edit window (SetWindowPos) when a text is longer than the edit window width. I can create an edit window based on MSFTEDIT_CLASS and use EN_REQUESTRESIZE. Do you know any other solution or that is the only option ?
The text is truncated by your edit control on paste.
To allow more text in that control without changing the size (which is not practical for many reasons), simply add ES_AUTOHSCROLL style to your CreateWindow call.

Syntax Error from Windres.exe when creating Dialog Template

I am writing a win32 application with the following code in Recourse.rc
IDD_DLGFIRST DIALOG 260, 200, 188, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Win32 Programming"
FONT 8, "MS Shell Dlg"
BEGIN
DEFPUSHBUTTON "OK", IDOK, 130, 10, 50, 14
END
When I try to compiler the following code with MinGW, Windres.exe gives me an error on the second line
I figured out what the problem was.
I forgot to #include windows.h for the style macros.

how to create password field and button in vc++

I am new in vc++ and i need a Password field in my application. I created edit textbox using below code but don't know how to create password field and button control.
CreateWindow(L"EDIT", L"hello", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
ES_AUTOHSCROLL | ES_WANTRETURN, 350, 500, 130, 20, hwnd, NULL, NULL, NULL);
Any help would be grateful. thanks
Try ES_PASSWORD :
Displays an asterisk (*) for each
character typed into the edit control.
This style is valid only for
single-line edit controls.
Windows XP: If the edit control is
from user32.dll, the default password
character is an asterisk. However, if
the edit control is from comctl32.dll
version 6, the default character is a
black circle.
To change the characters that is
displayed, or set or clear this style,
use the EM_SETPASSWORDCHAR message.
Note Comctl32.dll version 6 is not
redistributable but it is included in
Windows XP or later. To use
Comctl32.dll version 6, specify it in
a manifest. For more information on
manifests, see Enabling Visual Styles.
Source : Edit Control Styles
Edit
You mean creating a button ? Via Using Buttons :
HWND hwndButton = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed.
L"OK", // Button text.
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
0, // x position.
0, // y position.
50, // Button width.
50, // Button height.
hwnd_parentwindow,
NULL, // No menu.
(HINSTANCE)GetWindowLong(hwnd_parentwindow, GWL_HINSTANCE),
NULL);
You can select the edit box and right click and choose its properties. In that there is an option called password. Just check it.
Also this link will help you.
http://msdn.microsoft.com/en-us/library/d3223ht2.aspx
Or if you want you can directly add
ES_PASSWORD
also along with rest.

How to add a custom button to windows' minimize/maximize/close (x)

I was wondering if there is a way to add (programatically, of course) an icon/button/whatever besides plain text to a window (Microsoft Windows window...)'s title bar or next to where the minimize/maximize/close buttons are. I could draw it myself and create an illusion it is a part of the window, but I wonder if in the user32 api there is such a method.
So far, I found a way to disable the minimize/maximize/close buttons but not a way to add a custom one to them. It seems strange to me.
Here is what I am trying to achieve:
I have been wondering how it is done here, since drawing a button for every window using gdi/gdi+ and then detecting if it is overlapped by another window and then displaying only the non-overlapped part seems to me like an unlikely solution. Probably the button has been registered in the window class so that every window has this button. Any pointers what to do?
In addition, how do I create a button at all, assuming I DON'T have Unicode enabled. Then in the following piece of code:
HWND hwndCommandLink = CreateWindow(
L"BUTTON", // Class; Unicode assumed.
L"", // Text will be defined later.
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_COMMANDLINK, // Styles.
10, // x position.
10, // y position.
100, // Button width.
100, // Button height.
hDlg, // Parent window.
NULL, // No menu.
(HINSTANCE)GetWindowLong(hDlg, GWL_HINSTANCE),
NULL); // Pointer not needed.
SendMessage(clHwnd, WM_SETTEXT, 0, (LPARAM)L"Command link");
SendMessage(clHwnd, BCM_SETNOTE, 0, (LPARAM)L"with note");
I have to substitute all the nice Windows constants with their long equivalent....However, when I search for them, all i get is this:
http://msdn.microsoft.com/en-us/library/bb775951(v=VS.85).aspx
Any pointers?

Placing a window in WIN CE

How do we specify the placement position of a window using MFC in Win CE? It does not support the WINDOWPLACEMENT class that is available in Windows.
The CreateWindowsEx seems to have a x and y coordinates to position the window.
Update:
Also if you look at the code of the resource file rc you will see:
MYDIALOG_DIALOG DIALOG 0, 0, 182, 97
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW | 0x80000000L
CAPTION "mycaption"
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL 132,IDC_STATIC,"Static",SS_BITMAP,7,7,20,18
LTEXT "blah blah",IDC_STATIC,32,11,133,12
CONTROL "some control",IDC_DEVICE_BTN,"Button",BS_AUTORADIOBUTTON,58,33,64,10
CONTROL "control",IDC_HOST_BTN,"Button",BS_AUTORADIOBUTTON,58,49,57,10
PUSHBUTTON "control",IDC_BUTTON1,64,73,47,17
END
Notice the MYDIALOG_DIALOG DIALOG 0, 0, 182, 97 first 0, 0 - that is the window positioning.

Resources