Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Main Window Icon loading

Main Window Icon loading

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    robert_s
    wrote on last edited by
    #1

    Hi. Usual question. How can I load an Icon into my main MFC window. I already searched on this web site for answers but obviously they won't work for me. I tried several differnt ways: I then tried this : BOOL CMyAppView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; m_hIconFrame = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast(COLOR_WINDOW+1), m_hIconFrame ); return TRUE; } Then I tried : in MyApp::InitInstance() { AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); <--- this wont work CWinApp::LoadIcon(IDR_MAINFRAME ); <------------------------- this wont work too m_pMainWnd = pFrame; // create and load the frame with its resources pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); } Then I tried in int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct). Still no luck.. However same function call ie. AfxGetApp()->LoadIcon(IDR_MAINFRAME); in my dialog class displays the bloody icon ok. what is going on? Why can't I see this icon in my main window caption bar? ARGH.... Can somebody help please. thank you.

    I _ R 3 Replies Last reply
    0
    • R robert_s

      Hi. Usual question. How can I load an Icon into my main MFC window. I already searched on this web site for answers but obviously they won't work for me. I tried several differnt ways: I then tried this : BOOL CMyAppView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; m_hIconFrame = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast(COLOR_WINDOW+1), m_hIconFrame ); return TRUE; } Then I tried : in MyApp::InitInstance() { AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); <--- this wont work CWinApp::LoadIcon(IDR_MAINFRAME ); <------------------------- this wont work too m_pMainWnd = pFrame; // create and load the frame with its resources pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); } Then I tried in int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct). Still no luck.. However same function call ie. AfxGetApp()->LoadIcon(IDR_MAINFRAME); in my dialog class displays the bloody icon ok. what is going on? Why can't I see this icon in my main window caption bar? ARGH.... Can somebody help please. thank you.

      I Offline
      I Offline
      Iceberg76
      wrote on last edited by
      #2

      I'm pretty sure you just need to add an icon as a resource and then name it: IDR_MAINFRAME Then when you create the mainframe it should be there. I don't think you need to manually load. Look here to help out in MFC: http://www.adminmod.org/karel/2/index.htm

      1 Reply Last reply
      0
      • R robert_s

        Hi. Usual question. How can I load an Icon into my main MFC window. I already searched on this web site for answers but obviously they won't work for me. I tried several differnt ways: I then tried this : BOOL CMyAppView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; m_hIconFrame = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast(COLOR_WINDOW+1), m_hIconFrame ); return TRUE; } Then I tried : in MyApp::InitInstance() { AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); <--- this wont work CWinApp::LoadIcon(IDR_MAINFRAME ); <------------------------- this wont work too m_pMainWnd = pFrame; // create and load the frame with its resources pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); } Then I tried in int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct). Still no luck.. However same function call ie. AfxGetApp()->LoadIcon(IDR_MAINFRAME); in my dialog class displays the bloody icon ok. what is going on? Why can't I see this icon in my main window caption bar? ARGH.... Can somebody help please. thank you.

        _ Offline
        _ Offline
        _foo
        wrote on last edited by
        #3

        CWnd::SetIcon

        1 Reply Last reply
        0
        • R robert_s

          Hi. Usual question. How can I load an Icon into my main MFC window. I already searched on this web site for answers but obviously they won't work for me. I tried several differnt ways: I then tried this : BOOL CMyAppView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; m_hIconFrame = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast(COLOR_WINDOW+1), m_hIconFrame ); return TRUE; } Then I tried : in MyApp::InitInstance() { AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); <--- this wont work CWinApp::LoadIcon(IDR_MAINFRAME ); <------------------------- this wont work too m_pMainWnd = pFrame; // create and load the frame with its resources pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); } Then I tried in int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct). Still no luck.. However same function call ie. AfxGetApp()->LoadIcon(IDR_MAINFRAME); in my dialog class displays the bloody icon ok. what is going on? Why can't I see this icon in my main window caption bar? ARGH.... Can somebody help please. thank you.

          R Offline
          R Offline
          robert_s
          wrote on last edited by
          #4

          Ok thank you. Cwnd::SetIcon() solved my problem :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups