I'm working on pagination for my C++ app - I want to show currentPage / allPages on CTEXT and I'm having hard time making the printing functionality work.
This is how's widget configured in .rc file (I don't mind switching from CTEXT to any other
IDD_PIC_PLAYER_DIALOG DIALOG 0, 0, 400, 247
STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE
EXSTYLE WS_EX_APPWINDOW | 0x80000000L
FONT 8, "MS Shell Dlg"
BEGIN
CTEXT "Static",IDC_PG,211,183,65,62
END
Widget has .bmp background I'm intending to be writing on.
IDB_PG BITMAP "res\\pg.bmp"
This is how my code looks like :
TCHAR szPageText[64] = TEXT("");
wsprintf(szPageText, TEXT("%d of %d"), iCurSelPage, m_iPageCount);
this->SetDlgItemText(IDC_PG, szPageText);
Code compiles, but does not doing what it's supposed to do - print those 2 integers.
If anybody knows what piece of puzzle am I missing here - I'd be grateful.
Thanks for your insight.
Related
The edges of my tab control (SysTabControl32) are not fully repainted after restoring dialog box from minimized state.
Example:
The control is defined in the resource file (EDIT all occurences of IDD_VJOYCONF):
IDD_VJOYCONF DIALOGEX 0, 0, 245, 282
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "vJoyConf - Configure vJoy Devices"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Reset All",IDC_RSTALL,98,261,50,14
CONTROL "",IDC_DEVTABS,"SysTabControl32",TCS_MULTILINE | TCS_TOOLTIPS,7,7,231,247
END
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_VJOYCONF, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 238
TOPMARGIN, 7
BOTTOMMARGIN, 275
END
END
#endif // APSTUDIO_INVOKED
Developing with VS2013 on Windows 8.
The problem was solved by lifting the margin of the dialog box internal to the tab control.
The more interesting thing is how I found the problem.
I used Sysinternals Process Explorer. It has a 'Find Window's Process' button:
[EDIT:]
I hovered over the entire dialog box, highlighting its various elements until I've highlighted the culprit element:
You can clearly see that it's bottom is clipped exactly where the problem is. This is the dialog box that is embedded in the tab control.
The solution was to raise the dialog box so it won't be clipped.
I'd like to center a dialog box in my Win32 application, but am having trouble passing constants to my resource.rc file. I make the following declaration in resource.h:
const int SCREENX = GetSystemMetrics(SM_CXSCREEN);
However, when I replace 100 with SCREENX in my .rc file (below) and build, I get: error RC2108: expected numerical dialog constant.
#include <windows.h>
#include "resource.h"
#include "afxres.h"
// I'd like to replace "100" with "GetSystemMetrics(SM_CXSCREEN)"
ID_ABOUT DIALOG DISCARDABLE 100, 0, 237, 87
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 10, "MS Sans Serif"
BEGIN
GROUPBOX "Contact", IDC_CONTACT, 7, 43, 98, 39, WS_CHILD | WS_VISIBLE
LTEXT "My info", IDC_CONTACT, 16, 53, 85, 25, WS_CHILD | WS_VISIBLE
END
Neither can I use GetSystemMetrics(SM_CXSCREEN) directly in the desired location (same error).
I'd think it would be routine to pass data types to .rc, so I must be missing something basic here. (Resource files are giving me no end of headaches.) Thank you!
A resource file is compiled into a bunch of static data that is stored in your executable. For example, a dialog resource might be compiled into a DLGTEMPLATE structure.
In other words, everything in a compiled resource is a constant.
GetSystemMetrics(SM_CXSCREEN) is not a constant. It evaluates to the current screen width in pixels at run-time.
As the other answer says, to center your dialog use the DS_CENTER style or handle WM_INITDIALOG.
To center a Dialog on the screen, just OR the DS_CENTER style to the other window style for the dialog.
If you want to use GetSystemMetrics, do this in WM_INITDIALOG and position the dialog there.
A resource file is just a script.
As I'm (finally) learning to code Windows apps in C++ I stumbled upon this: I have a dialog box which I create with CreateDialog() and I also have a default button. However, each time I press TAB or ENTER, nothing happens, nor does the control focus change, nor does the default button activate. Here's the resource for my dialog.
IDD_MAINWIND DIALOG 0, 0, 312, 205
STYLE DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_POPUP | WS_SYSMENU
EXSTYLE WS_EX_WINDOWEDGE
CAPTION "Dialog"
FONT 8, "Tahoma"
{
PUSHBUTTON "&Send", IDC_BUTTON_SEND , 280, 168, 22, 14, BS_DEFPUSHBUTTON
LTEXT "Hello", IDC_STATIC1, 9, 9, 296, 149, SS_LEFT | SS_NOPREFIX | SS_SUNKEN, WS_EX_TRANSPARENT
EDITTEXT IDC_MESSAGE, 9, 168, 265, 13, ES_AUTOHSCROLL
PUSHBUTTON "Tools", IDC_BUTTON_TOOLS, 8, 185, 146, 14
PUSHBUTTON "Exit", IDC_BUTTON_EXIT, 163, 185, 136, 14
}
Any help is greatly appreciated. Especially now on the 3rd day of Christmas.
The solution is to add WS_TABSTOP styles to every child element of the dialog box.
For ex.:
PUSHBUTTON "&Send", IDC_BUTTON_SEND , 280, 168, 22, 14, BS_DEFPUSHBUTTON | WS_TABSTOP
Be sure that every control has WS_VISIBLE | WS_CHILD styles.
Also do not forget to add WS_EX_CONTROLPARENT style to the window and remove WS_GROUP style from the dialog window.
Moreover
Check your dialog proc
Or if you use window proc instead use the following snippet
Tabbing is provided by the dialog manager, not the Window manager. Therefore, to get tab handling, you need to call IsDialogMessage in your message loop with the hwnd of your window:
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
if (!IsDialogMessage(hwnd, &messages))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
}
Please, learn about WS_TABSTOP and WS_GROUP dialog box items attributes.
This link should be helpful for you: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644994.aspx#controls
i have edit text control with text that im loading to it ,
i want some of the text to be in color x and some in color y , how can it be done?
also can i make clickble link inside of the edittext?
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG1 DIALOG 0, 0, 369, 318
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Win32 demo"
FONT 8, "Ms Shell Dlg"
{
EDITTEXT IDC_EDIT2, 8, 1, 353, 86, NOT WS_BORDER | ES_AUTOHSCROLL | ES_MULTILINE | ES_READONLY
}
You can't do that in a standard edit control. You need a rich edit control for that. Based on your previous question I do wonder if what you really need is a hyperlink which you can do with the SysLink control.
I am using the below code to popup the authentication dialog. I want to hard-code the password in my code and make it a read-only text box. What should I do?
IDD_LOGIN_AUTH_DIALOG DIALOG DISCARDABLE 0, 0, 148, 82
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Authentication"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "Host:",IDC_STATIC_HOST,7,8,36,10,SS_CENTERIMAGE |
NOT WS_GROUP
EDITTEXT IDC_VNCHOST,46,7,95,12,ES_AUTOHSCROLL | ES_READONLY |
NOT WS_TABSTOP
CONTROL 108,IDC_STATIC_LOGO,"Static",SS_BITMAP,7,23,32,30
RTEXT "User name:",IDC_STATIC_LOGIN,41,25,39,10,SS_CENTERIMAGE
EDITTEXT IDC_LOGIN_EDIT,84,24,57,12,ES_AUTOHSCROLL
RTEXT "Password:",IDC_STATIC_PASSWD,41,42,39,10,SS_CENTERIMAGE
EDITTEXT IDC_PASSWD_EDIT,84,41,57,12,ES_PASSWORD | ES_READONLY |
NOT WS_TABSTOP
DEFPUSHBUTTON "&OK",IDOK,20,61,50,14
PUSHBUTTON "&Cancel",IDCANCEL,77,61,50,14
END
You get full control over all fields if you use the CONTROL keyword rather than the EDITTEXT keyword, use
CONTROL "mypassword", IDC_PASSWD_EDIT, "Edit",
ES_LEFT | WS_BORDER | ES_PASSWORD | ES_READONLY,
84,41,57,12
instead of
EDITTEXT IDC_PASSWD_EDIT,84,41,57,12,ES_PASSWORD | ES_READONLY | NOT WS_TABSTOP
From memory:
HWND hwnd = ...//handle to the dialog
::SetDlgItemText(hwnd, IDC_STATIC_PASSWD, "YourText");
::EnableWindow(::GetDlgItem(hwnd, IDC_STATIC_PASSWD), FALSE);