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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

808 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