Solved

MODAL window/Buttons question?

Posted on 2000-03-20
5
283 Views
Last Modified: 2012-05-04
Hi,

I have two questions:

- How can I create/set a MODAL window?
- How can I create/set a button to look
  like a button on IE cool toolbar??

As for the first, I tried everything but could not figure out how to make the created window be a MODAL. Note that I created a window that has an icon and tried to make this window a MODAL?! I heard that MODAL windows should not have icons ????
As for the second, I could create a normal button, set its properties, but what I want exactly is a button that work and look like a button on IE toolbar, i.e. a button that looks initially like a normal label with no borders, and when the mouse is pointed over the button it should change its appearance to look like a button (i.e. the borders should appear).

Thank you for your help,

Wesam
0
Comment
Question by:_Wesam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:jamoville
ID: 2637383
Try taking a look at the CReBar class for the buttons you descibed.
0
 

Accepted Solution

by:
leff earned 20 total points
ID: 2637386
To Create a Modal Dialog in API, use
to create a dialog in API, use
Dialogbox(hinstance,nameId,parentID,dialog Procedure Name);

To Exit, use
Enddlg(hDlg,return-code);



Modal dialogs in MFC

class CMyDialog: public CDialog
{
public:
 CMyDialog::CMyDialog(int x,CWnd* pParentWnd=NULL) :
    CDialog (x,pParentWnd) {}
      ....
void CMainWindow:: OnDialog ( )
{
    CMyDialog dlg(IDD_MYDIALOG, this);
    fprintf(f,"do modal\f");fflush(f);
    dlg.DoModal ();
}

Modeless dialogs in MFC
void CMainWindow:: OnDialog ( )
{
    CMyDialog dlg(IDD_MYDIALOG, this);
    fprintf(f,"do modal\f");fflush(f);
    dlg.DoModal ();
}

See http://www.wiu.edu/users/mflll/CS412g
for more info on Windows programming.
0
 

Expert Comment

by:nicholso
ID: 2637395
(1) the first part is easy. For window classes descended from CDialog, just do the following.
example: the about dialog (CAboutDlg).

in your code:
      CAboutDlg aboutDlg;
      aboutDlg.DoModal();

this will launch the about dialog as modal.

(2) this is a bit more work. One thing you could do is define the function CWnd::OnMouseMove() for the dialog this button is in. This gets called everytime the mouse moves. Then every time the move moves you could check if the mouse is over your button. If it is, change the border style like you're talking about.

let me know if you need more clarification/code.
0
 

Author Comment

by:_Wesam
ID: 2639281
Hi,

 Oops .. I made a mistake, I had to say that I used pure API functions (not MFC) for both questions. So I create windows, controls by hand. As for the first idea (creating a dialog box) it has one drawback, I can't assign an icon to the dialog box!!!!!! I want to create a dialog box that has an icon (I could do this in VB - it does this automatically). I didn't use a resource file, because I couldn't change the default icon there either.
As for the second idea, I couldn't manage to have something like creating a label then changing the label properties to appear like a button and assign the other necessary properties when it is clicked PLUS this approach is a little bit complicated and probably there is another way to do the same thing.
Can you provide me with source code in your reply, it would be very helpful for me.

Thanks,

Wesam.

0
 
LVL 2

Expert Comment

by:DarrinE
ID: 2657399
Yu can assign an icon from a resource file to a dialog window using the following code :

/*------------------------------------------------------- Header Files      */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include "resource.h"

#include "define.h"

/*------------------------------------------------------- Local Defines      */

/*-------------------------------------------------- External Data Area      */
extern HINSTANCE                         hInstance;                  // The instance of this program
extern HWND                               MainHwnd ;                  // The handle of the Main Window
/*-------------------------------------------------- External Functions      */
/*---------------------------------------------- Local Data Allocations      */
/*--------------------------------------------- Public Data Allocations      */
/*----------------------------------------------------- Local Functions      */
/*---------------------------------------------------- Public Functions      */

BOOL WINAPI SetWindowIcon( HINSTANCE hInst, HWND hwnd, UINT uID );
/*****************************************************************
FUNCTION :      SetWindowIcon( HINSTANCE hInst, HWND hwnd, UINT uID );
Params :      hInst      = the instance of the program
                  hwnd      = the dialog window handle
                  uID            = the dialog icon resource identifier

Return Value = TRUE if successful or FALSE if not
*****************************************************************/
BOOL WINAPI SetWindowIcon( HINSTANCE hInst, HWND hwnd, UINT uID )
{
      BOOL bRetVal = FALSE;

      if( IsWindow( hwnd ) )
      {
            HINSTANCE hInst = (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE );
            HICON hIconSmall = (HICON)LoadImage( hInst, MAKEINTRESOURCE( uID ), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR );
            HICON hIcon = LoadIcon( hInst, MAKEINTRESOURCE( uID ) );

            if( hIconSmall )
                  SendMessage( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall );


            if( hIcon )
                  SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon );

            bRetVal = TRUE;
      }

  return bRetVal;
}

This is a complete code snippet - you need to call this function in WM_INITDIALOG

As for your explorer type button - I cant help right now but I'll give it some thought

DarrinE
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SetCurrentDirectory path limit 7 144
Template syntax for variable length arrays 9 77
What is sub-make ? 2 88
Copy output image from TWindowsMediaPlayer 6 55
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

733 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