📄 wpw_wapi_dialog_95.html
字号:
TProcessDialog::TProcessDialog (TWindow* parent, TResId resId, int startValue,
int endValue, TModule* module):
TDialog(parent, resId, module), start(startValue), finish(endValue)
{
// INSERT>> Your constructor code here.
// IDC_GAUGE + 100 is the resource/child id of gauge
process = new TGauge(this, "", IDC_GAUGE + 100, 0, 0, 0, 0);
// DO NOT INITIALIZE GAUGE!!! IT SEEMS TO ASSUME THE
// VALUES SET ON INIT CONSTRUCTOR!!!!
}
TProcessDialog::~TProcessDialog ()
{
Destroy();
// INSERT>> Your destructor code here.
}
void TProcessDialog::UpdateStatus (int newValue, BOOL doYield)
{
if ( process && IsWindow() ) {
process->SetValue(newValue);
}
}
void TProcessDialog::SetDescription (char* description)
{
if ( IsWindow() ) {
// IDC_DESCRIPTION is id of process description text
SetDlgItemText(IDC_DESCRIPTION, description);
}
}
void TProcessDialog::SetupWindow ()
{
TDialog::SetupWindow();
// INSERT>> Your code here.
// IDC_GAUGE is the id of a static that will be replaced
// by a gauge window
TWindow gaugestatic(GetDlgItem(IDC_GAUGE));
if ( gaugestatic.IsWindow() ) {
TRect windowRect = gaugestatic.GetWindowRect();
::MapWindowPoints(::GetDesktopWindow(), *this,
(LPPOINT)&windowRect, 2);
process->MoveWindow(windowRect.left, windowRect.top,
windowRect.Width(), windowRect.Height());
// Set gauge values!
process->SetRange(start, finish);
process->SetValue(start);
// Remove our gauge static!
gaugestatic.Destroy();
}
}
Okay, here's an example:
TProcessDialog* pr = new TProcessDialog(this, IDD_PROCESS, 0, 999);
newpr->Create();
newpr->Show(SW_SHOW);
// Disable main window
GetApplication()->GetMainWindow()->EnableWindow(FALSE);
for (int i = 0; i < 1000; i++) {
char buf[255];
if ( !newpr->IsWindow() ) {
MessageBeep(0xFFFF);
break; // Break if window doesn't exist
}
wsprintf(buf, "%d progression", i);
newpr->SetDescription(buf);
newpr->UpdateStatus(i);
GetApplication()->PumpWaitingMessages(); // Yield
}
GetApplication()->GetMainWindow()->EnableWindow(TRUE);
newpr->Destroy();
delete newpr;
</PRE>
<HR><A NAME=WINAPI_DIALOG_MAINWIN>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Using Dialog as Main Window</H4><PRE>
Hi,
I'm thinking about porting a Visual Basic application to VC++ 1.5.
The main form of the VB application has lots of controls in it,
which would be tedious to layout at runtime in a VC++ CFrameWnd.
I would much prefer to do the layout with AppStudio, which means
that the main frame has to be a dialog box, right? So, is it
possible to make a dialog box the main window of a VC++ application?
Can this dialog box support a menu bar, toolbar, status bar etc like
a CFrameWnd?
Any suggestions much appreciated.
Regards
John Mason
<HR>
johnm@unipalm.co.uk (John Mason) wrote:
>Hi,
>
> I'm thinking about porting a Visual Basic application to VC++ 1.5.
> The main form of the VB application has lots of controls in it,
> which would be tedious to layout at runtime in a VC++ CFrameWnd.
> I would much prefer to do the layout with AppStudio, which means
> that the main frame has to be a dialog box, right? So, is it
> possible to make a dialog box the main window of a VC++ application?
> Can this dialog box support a menu bar, toolbar, status bar etc like
> a CFrameWnd?
>
> Any suggestions much appreciated.
Check out the book "Inside Visual C++" 2nd ed. by David J. Kruglinski,
from Microsoft Press. ISBN: 1-55615-661-8.
It has some code to do this. Basically, in your C...App::InitInstance()
you put a myDialog.DoModal() statement. A few other things as well. For
details, consult the book.
>Regards
>John Mason
<HR>
In article <3smjo2$is7@soap.pipex.net>, johnm@unipalm.co.uk (John Mason) writes:
> Hi,
>
> I'm thinking about porting a Visual Basic application to VC++ 1.5.
> The main form of the VB application has lots of controls in it,
> which would be tedious to layout at runtime in a VC++ CFrameWnd.
> I would much prefer to do the layout with AppStudio, which means
> that the main frame has to be a dialog box, right? So, is it
> possible to make a dialog box the main window of a VC++ application?
> Can this dialog box support a menu bar, toolbar, status bar etc like
> a CFrameWnd?
>
> Any suggestions much appreciated.
>
> Regards
> John Mason
>
I wrote a dinky little program once which was something along those lines. I'm
assuming the dialog window would be defined in a .RC file. Hope this is what
you mean.
Hmmm... now let me see, the class registration stuff was like this, don't forget
the extra memory block in cbWndExtra.
wndclass.style = CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc = MainWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = DLGWINDOWEXTRA; // THIS IS IMPORTANT
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, szAppName);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = "MENU_1";
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
Create the window like this. Where `DIALOG_1' is your resource script.
hMainWnd = CreateDialog(hInstance, "DIALOG_1", 0, NULL);
ShowWindow(HMainWnd, nCmdShow);
In your message loop you'll need to filter out messages which are for the dialog
window. Otherwise you won't be able to traverse between child windows using the
tab key.
while(GetMessage(&msg, NULL, 0, 0)) {
if(!IsDialogMessage(hMainWnd, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Messages from the Child Windows can be read via the WM_COMMAND. You could have
used a dialog procedure in the CreatDialog call to read these messages.
case WM_COMMAND :
switch(wParam) {
case ID_OK :
/* DO SOMTHING */
break;
case ID_CANCEL :
PostQuitMessage(0);
break;
}
break;
</PRE>
<HR><A NAME=WINAPI_DIALOG_Static_Frame>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: How to add static frame to dialog box?</H4><PRE>
In article <3u1f8i$c82@news.tamu.edu>
tpradeep@cs.tamu.edu "Pradeep K Tapadiya" writes:
>Howdy netters,
>
>I am using VC2.1.
>
>The controls tool bar under AppStudio doesn't show
>static frame/rectangle controls. The only visible
>static control is static text.
>
>Thought I could use static text and then change its style.
>However, there is no style sheet for the static text
>in the "properties" dialog box.
>
>Is there a way to add static frame to a dialog box
>short of editing the resource file manually?
The static frame control in the dialog editor's tool palette is the
one showing the "picture" in the top right corner, next to the "Arrow".
You are correct in saying that this is not at ALL obvious!
Chris
--
--------------------------------------------------------------------------
| Chris Marriott, Warrington, UK | Author of SkyMap v2 shareware |
| chris@chrism.demon.co.uk | astronomy program for Windows. |
| For more info, see http://www.winternet.com/~jasc/skymap.html |
| Author member of Association of Shareware Professionals (ASP) |
--------------------------------------------------------------------------
</PRE>
<HR><A NAME=WINAPI_DIALOG_Wrong_Color_W95>
Return to <a href="wpw_wapi_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Dialog boxes are the wrong color for Win95!</H4><PRE>
In article <139729089wnr@deth.demon.co.uk>, Dave@deth.demon.co.uk wrote:
> When I use the dialog editor to create a new dialog box, a
> box with a dark grey background appears for me to edit.
> when I click the "test" button the box that appears also has
> a dark grey background. However when I call up the new dialog
> box in the application it has a white background. Does anyone
> know why this happens and how to stop it ?
>
> I'm using Microsoft Visual C++ v2.0 and build 490 of windows 95.
> I've also noticed that the "about" dialog box which is created
> by AppWizard is also grey when edited but white in the application.
>
> Thanks
>
> --
> Dave H.
I had this problem...received a solution Friday and just tried it
this morning, and it works. Can't send a thanks to the guy yet
'cause I saved his reply at home...but thanks!
The solution: Go to your link options in the Project | Settings dialog.
At the bottom are a bunch of options. Select one of your targets,
and change the:
/SUBSYSTEM:windows
to:
/SUBSYSTEM:windows,4.0
Rebuild and run. I could've figured that out if I wanted to (Yeah, right!)
Gotta love the 'net.
Craig Oshima
-------------------------------
Design Team Leader, Software Services
Metatec Corporation
</PRE>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -