Solved

How to manipulate desktop window and dialog menu

Posted on 2001-08-29
13
395 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
ID: 6439200
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
ID: 6443933
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
ID: 6444666
> 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Parkson
ID: 6454333
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
ID: 6454659
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
ID: 9528465
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
 
LVL 4

Expert Comment

by:jtwine100697
ID: 9528725
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
ID: 9577266
> Recommendations?

On...?

   o Translating Acellerators...

   o Automated Feature that scans...

   o For "Parkson"...?

-=- James.
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 9709993
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
ID: 10366298
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
ID: 10389122
*sigh*

-=- James.
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 10407038
PAQed, with points refunded (75)

SpazMODic
EE Moderator
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 52
Windows Drag & Drop Location 2 111
if loop in java 3 160
Way to decrease size of apk file 9 104
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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