MODAL window/Buttons question?

Posted on 2000-03-20
Last Modified: 2012-05-04

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,

Question by:_Wesam

Expert Comment

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

Accepted Solution

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

Modal dialogs in MFC

class CMyDialog: public CDialog
 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 ();

for more info on Windows programming.

Expert Comment

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;

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.

Author Comment

ID: 2639281

 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.




Expert Comment

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

/*------------------------------------------------------- Header Files      */
#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 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


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

862 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

24 Experts available now in Live!

Get 1:1 Help Now