Solved

How to manipulate desktop window and dialog menu

Posted on 2001-08-29
13
391 Views
Last Modified: 2013-11-20
I am writing a MFC application which is dialog base. After my application was executed, the application window that I designed is smaller than destop window.

My problems are:

(1)How can I change the area on the screen outside my application window to whole black, and not allow the mouse move outside my application window ?

(2)How to detect the screen resolution and always change it to my preference(let's say 800 x 600) before my application window shows up, and then restore it after my application is quitted ?

(3)How to set the accelerator keys to the menu of my dialog base application ? I know it is simple to set them in SDI or MDI forms, but it wouldn't work for dialog.

Thanks for your help.  Your comments or answers will be highly appreciated.
0
Comment
Question by:Parkson
13 Comments
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
IMHO, at least two of those are bad ideas...! :/  But...

1: You may be able to paint a rectangle onto the desktop window that surrounds your app window.  That will likely cause decent flickering, though, and may confuse the user when it happens.  You should be able to capture the mouse, and restrict it's movement outside of your app window

2: GetSystemMetrics(...) will get you the display resolution.  I only know of using DirectDraw to change resolutions.  Again, this may confuse the user.

3: TranslateAccelerator(...) should help there.

HTH

-=- James.

0
 

Author Comment

by:Parkson
Comment Utility
Hi James,

Thanks for your comment. But I am not so clear about what you said:

1: "You may be able to paint a rectangle onto the desktop window that surrounds your app window."
---Did you mean painting to destop window? But how to restore to original destop window when quit my app?

  "You should be able to capture the mouse, and restrict it's movement outside of your app window."
---How to capture and how to restrict the mouse movement? Could you give me more detail?

2: "I only know of using DirectDraw to change resolutions."
---What's DirectDraw? how to use it?

3: "TranslateAccelerator(...) should help there."
---Again, could you give me more detail about its usage?

Thanks.

0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
> Did you mean painting to destop window? But how to restore to original destop window when quit my app?

You would be paining on top of the desktop window, not replacing it.  So when your app ends, it would no longer paint onto the desktop.  (In hindsight, this might be harder than I think.  A kludgy way would be to have a fullscreen app window (with no caption bar), with a black background, and have your dialog in the center of it.

> How to capture and how to restrict the mouse movement? Could you give me more detail?

::SetCapture(...) and CWnd::SetCapture(...) allow a window to receive all messages from the mouse, even if the mouse moves outside the boundaries of the window.  When processing the mouse messages, you can force it to be at a certain position.

> What's DirectDraw? how to use it?

DirectDraw is part of DirectX, which is a COM-based multimedia library for Win32.  It is what just about any Win32 game uses for its graphics and sound.  Learning to use DirectX is not something that you can get a fast answer to.  You should have, at least, a basic understanding of COM before working with it, IMHO.

> Again, could you give me more detail about its usage?

The MSDN documentation for TranslateAccelerator(...) should give you all the details that you need.  (You can also search the docs for DirectDraw information on creating surfaces and changing resolutions.)

-=- James.
0
 

Author Comment

by:Parkson
Comment Utility
Hi James,

I am searching DirectX::DirectDraw and already got some useful information.  But could you tell me what components I should install in order to use this utility?  I got some trouble that I couldn't find the DirectDraw library files in my computer, but I did install visual studio 6 and MSDN.

If possible, could you give me more details about what procedure and steps I have to follow to take advantage of DirectDraw.

Thanks.
0
 

Author Comment

by:Parkson
Comment Utility
Hi James,

I got the information about TranslateAccelerator() form MSDN, and wrote the code below in the WM_KEYDOWN handler that was mapped with ClassWizard in my dialog base app.

void CMyDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
     // TODO: Add your message handler code here and/or call default
         HINSTANCE hInstance = AfxGetInstanceHandle( );
     LPTSTR acceName = MAKEINTRESOURCE(IDR_MENU1);
     HACCEL hAccTable = ::LoadAccelerators(hInstance, acceName);
     HWND hWnd = ::GetActiveWindow();
     LPMSG lpMsg;
         ::GetMessage(lpMsg, hWnd, 0, 0);

     ::TranslateAccelerator(hWnd, hAccTable, lpMsg);

     CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

But just as usual, when I press the keys, I heard a sound, which means the key is locked.  I think the problem is the keyboard is always being locked due to the modal dialog, and basically a dialog base app is just a modal dialog.  Could you give me your opinions and look into my code ?

Thanks.
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
Yeouch!  Forgot about this one...!

EE needs an automated feature that scans unlocked questions and automatically sends an email to all involved parties when it finds one whose last comment is more than xxx days old.  This CANNOT be that hard to do, even in Java!

Anyway...  Install the DirectX SDK to use DirectX.  You can get it from MS, and as part of the Platform SDK.  The SDK contains many help examples that demonstrate use of DirectX, and you can even search the net for game source code that uses DirectX as well.

A modal dialog does not "lock the keyboard", it only restricts (most) of an application's messages to that dialog.  (MFC's modal dialogs are not really modal, but that is another story).  ALT and CTRL keys still get through (that is how the system menu and nmemonics get activated).

The call to GetMessage is incorrect because you are passing it an invalid pointer, the first parameter is supposed to be the address of a valid MSG structure:

     MSG msgMSG;

    GetMessage( &msgMSG, ... );

An alternate to translating the accelerators keys is simply to detect them yourself (from within PreTranslateMessage, or maybe OnKeyDown) by looking for specific keys and flags telling you if ALT, CTRL, etc is down as well.

-=- James.
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
> Recommendations?

On...?

   o Translating Acellerators...

   o Automated Feature that scans...

   o For "Parkson"...?

-=- James.
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
Um, hello?

This may be a hard thing for some to understand, but when someone takes the time to assist others, and/or offer their (expensive) services for *free*... Directed questions *demand* timely answers.

In the hopes that this was just a simple mistake, and not intentionaly disregarded, I will take the leap of quessing that "Recommendations?" refers to something off-topic: my offer.

To begin research, I would require:

1: Database platforms (RDBMSs) used
2: Schema of database (the DDL used to create the schema)
3: Sample dataset including recent and "older" records

Check my account information for email address to send information to (ZIPing it would be a good idea).

-=- James.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ/Refund
Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

khkremer
EE Cleanup Volunteer
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
*sigh*

-=- James.
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
Comment Utility
PAQed, with points refunded (75)

SpazMODic
EE Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now