Search code examples
winformsc++-cliformborderstyle

FormBorderStyle issue


Encountered an issue with different FormBorderStyle modes. In 'None' mode everything works fine.

Screenshot 1

But as soon as I change the mode to anything else - this happens:

Screenshot 2

I'm getting strange empty area all around. Like the bounds are off on both axis

void InitializeComponent(void)
{
    this->SuspendLayout();
    // 
    // MainUI
    // 
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::None;
    this->ClientSize = System::Drawing::Size(320, 250);
    this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
    this->MaximizeBox = false;
    this->MinimizeBox = false;
    this->Name = L"MainUI";
    this->Text = L"Dota 2 Efficiency Application";
    this->ResumeLayout(false);
}
[STAThreadAttribute]
int Main(array<System::String ^> ^args){
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Creating a new form
MainUI^ form = gcnew MainUI();

// Creating a new ListView and adding it to the form
createList();
form->globalTimerInit();
form->Controls->Add(myGlobals::Globals::globalListView);
form->Controls->Add(myGlobals::Globals::labelForTimer);
Application::Run(form);

return 0;
}

When I'm trying to get Bounds and ClientRectangle of the Form it spits out this:

{X=0,Y=0,Width=336,Height=284}
{X=0,Y=0,Width=320,Height=250}

Looks like it's correct, but the area is way off.

Any advice?


Solution

  • I had multiple instances of __super::WndProc(m); and it resulted in this behavior.

    ui.h

    #include "stdafx.h"
        ////////////////////////HOTKEYS////////////////////////
    protected: // Function that defines a hotkey
        virtual void OnHandleCreated(EventArgs^ e) override {
            __super::OnHandleCreated(e);
            RegisterHotKey((HWND)this->Handle.ToPointer(), 1,
                MOD_NOREPEAT, (UINT)Keys::NumPad3);
            RegisterHotKey((HWND)this->Handle.ToPointer(), 2,
                MOD_NOREPEAT, (UINT)Keys::NumPad2);
            RegisterHotKey((HWND)this->Handle.ToPointer(), 3,
                MOD_NOREPEAT, (UINT)Keys::NumPad1);
            RegisterHotKey((HWND)this->Handle.ToPointer(), 4,
                MOD_NOREPEAT, (UINT)Keys::NumPad0);
        }
    
    protected: // Function that executes code on hotkey
        virtual void WndProc(Message% m) override {
            if (m.Msg == WM_HOTKEY && m.WParam.ToInt32() == 1) {
                //roshTimer();
            }
            if (m.Msg == WM_HOTKEY && m.WParam.ToInt32() == 2) {
                //wardPurchased();
            }
            __super::WndProc(m);
            if (m.Msg == WM_HOTKEY && m.WParam.ToInt32() == 3) {
                //globalTimerStartPause();
            }
            __super::WndProc(m);
            if (m.Msg == WM_HOTKEY && m.WParam.ToInt32() == 4) {
                //reserved for future needs
            }
            __super::WndProc(m);
        }
        ///////////////////////////////////////////////////////
    

    stdafx.h

    #pragma once
    
    #include <Windows.h>
    #pragma comment(lib, "user32.lib")