Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:49:47+00:00 2026-05-23T12:49:47+00:00

And I can’t figure out why. My code: #include <windows.h> #include <commctrl.h> #include <cstdio>

  • 0

And I can’t figure out why. My code:

#include <windows.h>
#include <commctrl.h>
#include <cstdio>
#include <stdarg.h>
#include <string>
#include <cmath>
#include <vector>
#include "resources.hpp"

using std::string;
using std::vector;

struct undostruct{
    /* add later */};

char buffer[2048];
HWND statusbar;
HINSTANCE hinst;
vector<undostruct> undo;

void show_error(const char* format,...){
    va_list args;
    va_start(args,format);
    vsprintf(buffer,format,args);
    va_end(args);
    MessageBox(NULL,buffer,"ERROR",MB_OK);}

HWND create_tooltip(HWND parent,char* tip,unsigned uid,unsigned extraflags=0){
    HWND tt=CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,NULL,WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP,0,0,0,0,parent,NULL,NULL,NULL);
    SetWindowPos(tt,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
    TOOLINFO ti;
    ti.cbSize=sizeof(TOOLINFO);
    ti.uFlags=TTF_SUBCLASS|extraflags;
    ti.hwnd=parent;
    ti.hinst=NULL;
    ti.uId=uid;
    ti.lpszText=tip;
    GetClientRect(parent,&ti.rect);
    SendMessage(tt,TTM_ADDTOOL,0,(LPARAM)(LPTOOLINFO)&ti);
    return tt;}

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

class Font{
    private:
        HFONT hfont;
    public:
        Font(const char* fname){
            hfont=CreateFont(0,0,0,0,FW_NORMAL,false,false,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,fname);}
        ~Font(){
            DeleteObject(hfont);}
        operator HFONT(){
            return hfont;}}courier("Courier New");

bool get_filename(char* fname,int len,HWND hwnd,bool save){
    OPENFILENAME ofn;
    ZeroMemory(&ofn,sizeof(OPENFILENAME));
    ofn.lStructSize=sizeof(OPENFILENAME);
    ofn.hwndOwner=hwnd;
    ofn.lpstrFilter="Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
    ofn.lpstrFile=fname;
    ofn.nMaxFile=len;
    ofn.lpstrTitle="Text Editor";
    ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
    if(save){
        return GetSaveFileName(&ofn);}
    else{
        return GetOpenFileName(&ofn);}}

int WINAPI WinMain(HINSTANCE hprev,HINSTANCE hInst,LPSTR cmdline,int cmdshow){
    WNDCLASSEX wcex;
    //HACCEL haccel=LoadAccelerators(hInst,MAKEINTRESOURCE(ACCELS));
    HWND hwnd;
    MSG msg;
    hinst=hInst;
    //Register the window
    wcex.cbSize=sizeof(WNDCLASSEX);
    wcex.style=CS_HREDRAW|CS_VREDRAW;
    wcex.lpfnWndProc=WndProc;
    wcex.cbClsExtra=0;
    wcex.cbWndExtra=0;
    wcex.hInstance=hinst;
    wcex.hIcon=NULL;
    wcex.hCursor=NULL;
    wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName=MAKEINTRESOURCE(MAINMENU);
    wcex.lpszClassName="ImageEditor";
    wcex.hIconSm=NULL;
    if(!RegisterClassEx(&wcex)){
        show_error("Error %i: Failed to register the window.",GetLastError());
        return -1;}
    //Create the window
    hwnd=CreateWindow("ImageEditor","Image Editor",WS_VISIBLE|WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hinst,NULL);
    if(!hwnd){
        show_error("Error %i: Failed to create the window.",GetLastError());
        return -2;}
    //Show/Update the window
    ShowWindow(hwnd,cmdshow);
    UpdateWindow(hwnd);
    //Initialize common controls
    /*INITCOMMONCONTROLSEX iccex;
    iccex.dwICC=ICC_WIN95_CLASSES;
    iccex.dwSize=sizeof(INITCOMMONCONTROLSEX);
    InitCommonControlsEx(&iccex);*/
    //Go into the main program loop
    while(GetMessage(&msg,NULL,0,0)){
        //if(!TranslateAccelerator(hwnd,haccel,&msg)){
            TranslateMessage(&msg);
            DispatchMessage(&msg);}//}
    return msg.wParam;}

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
    static int sizes[]={260,330,420,520};
    switch(msg){
        case WM_CREATE:
            statusbar=CreateWindow(STATUSCLASSNAME,"",WS_CHILD|WS_BORDER|WS_VISIBLE,-100,-100,10,10,hwnd,NULL,hinst,NULL);
            if(!statusbar){
                show_error("Error %i: Failed to create the statusbar.",GetLastError());}
            //Description|Characters|Size|Lines|Line|Column
            SendMessage(statusbar,SB_SETPARTS,sizeof(sizes),(LPARAM)sizes);
            break;
        case WM_QUIT:
            DestroyWindow(hwnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        case WM_COMMAND:
            //switch(LOWORD(wparam)){}
            //break;
        default:
            return DefWindowProc(hwnd,msg,wparam,lparam);}
    return 0;}

Also, my compiler doesn’t recognize INITCOMMONCONTROLSEX when it should, which is commented out near the end of WinMain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:49:47+00:00Added an answer on May 23, 2026 at 12:49 pm

    The most likely bug in this code is that you need to run InitCommonControls BEFORE creating a window. And forget that InitCommonControlsEx() code, you’ll be better with a plain old InitCommonControls.

    Remember to check every function’s return value and use GetLastError().

    Also, you’re trying to reinvent the wheel and instead of rolling out your own window creating procedure I suggest you to take a look at how others do it, or even use WTL, it’s not that difficult.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you cast a List<int> to List<string> somehow? I know I could loop through
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Does anyone know how can I replace this 2 symbol below from the string
Can anyone help me trying to find out why this doesn't work. The brushes
Can we close all known/unknown connections to database with the code? I'm using Access
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can a LINQ enabled app run on a machine that only has the .NET
Can anyone tell me how I can display a status message like 12 seconds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.