OK, so i am writing this program in C++ that is supposed to append the clipboard text into the edit control inside the Auto-Clipboard tab. I have setup the program so that it supports unicode text.
The program appends the text correctly when i copy text outside the program. But if i copy text that is from the program, it shows me as if it is copying ansi characters that needs to be converted int unicode.
I am not sure if the problem is from the edit control or from the Clipboard. Is the edit control output not in unicode? Or is the clipboard copying as ansi and pasting as unicode?
Edit: So i find out that according to MSDN documentations, WM_COPY in edit controls are handled in CF_TEXT mode instead of CF_UNICODETEXT for the clipboard:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms649022(v=vs.85).aspx
And so, i added some subclassing starting with my AutoClipboardEdit control but for some reason i get currupted heap error on WM_DRAWCLIPBOARD messages. So i am stuck there:
Edit2: I got it working by not freeing the allocated memory of the text string used on the clipboard. In this case the name of the variable is hMem2. It seems that if i free hMem2, the program crashes with a "corrupted heap" error. My guess is that the OS itself manages and frees the memory. It does seem possible since the SetClipboardData argument for the data is a pointer. I also tried to test if memory actually leaked by sending a WM_COPY message into a infinite loop to see if the heap would increase forever; but far it didn't seem so.
So, i need someone to confirm to me that there is no memory leak or that the OS actually does manage and free the clipboard accordingly.
Here is the complete source code:
#define UNICODE
#define _UNICODE
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#pragma comment(lib, "Comctl32.lib")
#include <tchar.h>
#include <Windows.h>
#include <CommCtrl.h>
#include <sstream>
using namespace std;
TCHAR temp[1024];
enum TabIndexes
{
ID_ReadingPageTab,
ID_AutoClipboardTab
};
enum WindowControls
{
ID_SelectAll,
ID_TabControls,
ID_ReadingPageEdit,
ID_AutoClipboardEdit,
ID_AutoClipboardCheckbox,
ID_AutoReadCheckbox,
ID_AutoClearCheckbox,
ID_ReadPauseResumeButton,
ID_StopButton
};
//***************Global Variables***************
HWND MainWindowHandle;
HWND ClipboardViewer;
HWND TabControls;
HWND ReadingPageEdit;
HWND AutoClipboardEdit;
HWND AutoClipboardCheckbox;
HWND AutoReadCheckbox;
HWND AutoClearCheckbox;
HWND ReadPauseResumeButton;
HWND StopButton;
RECT WindowReactangle;
RECT EditControlsDimension;
HACCEL SelectAll;
int Textlength;
void ShowReport()
{
LPTSTR ErrorText = NULL;
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, //dwFlags
NULL, //lpSource
GetLastError(), //dwMessageId
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //dwLanguageId
(LPTSTR)&ErrorText, //lpBuffer
0, //nSize
NULL //*Arguments
);
MessageBox(NULL, ErrorText, TEXT("Last Error:"), MB_OK);
}
void OutputBox(LPTSTR OutputText)
{
MessageBox(NULL, OutputText, _T("WARNING!!!"), MB_OK);
}
WNDPROC OldProc;
LRESULT CALLBACK EditControl
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
WPARAM StartOfSelectection;
LPARAM EndOfSelection;
int SelectionSize;
int TextSize;
TCHAR* hMem1;
TCHAR* hMem2;
if (uMsg == WM_COPY)
{
OpenClipboard(NULL);
SendMessage(hwnd, EM_GETSEL, (WPARAM)&StartOfSelectection, (LPARAM)&EndOfSelection);
SelectionSize = EndOfSelection - StartOfSelectection + 1;
TextSize = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0);
TextSize -= (TextSize - EndOfSelection - 1);
hMem1 = new TCHAR[TextSize]();
ZeroMemory(hMem1, TextSize*sizeof(TCHAR));
SendMessage(hwnd, WM_GETTEXT, TextSize, (LONG)hMem1);
hMem2 = new TCHAR[SelectionSize]();
ZeroMemory(hMem2, SelectionSize*sizeof(TCHAR));
for(int Index=0; StartOfSelectection<EndOfSelection; ++StartOfSelectection)
hMem2[Index++] = hMem1[StartOfSelectection];
SetClipboardData(CF_UNICODETEXT, (HANDLE)hMem2);
CloseClipboard();
delete[] hMem1;
//delete[] hMem2;
}
return OldProc(hwnd, uMsg, wParam, lParam);
}
void CreateControls(HWND hWndParent)
{
GetClientRect(hWndParent, &WindowReactangle);
const INITCOMMONCONTROLSEX CommonControls = {sizeof(INITCOMMONCONTROLSEX), ICC_TAB_CLASSES};
InitCommonControlsEx(&CommonControls);
TabControls = CreateWindow
(
WC_TABCONTROL, //lpClassName
NULL, //lpWindowName
WS_VISIBLE | WS_CHILD, //dwStyle
WindowReactangle.left, //x
WindowReactangle.top, //y
WindowReactangle.right, //nWidth
WindowReactangle.bottom - 100, //nHeight
hWndParent, //hWndParent
(HMENU)ID_TabControls, //hMenu
NULL, //hInstance
NULL //lpParam
);
TCITEM TabItemStructure = {0};
TabItemStructure.mask = TCIF_TEXT;
TabItemStructure.pszText = _T("Reading Page");
SendMessage(TabControls, TCM_INSERTITEM, ID_ReadingPageTab, (LPARAM)&TabItemStructure);
TabItemStructure.pszText = _T("Auto-Clipboard");
SendMessage(TabControls, TCM_INSERTITEM, ID_AutoClipboardTab, (LPARAM)&TabItemStructure);
ACCEL AcceleratorStructure;
AcceleratorStructure.fVirt = FCONTROL | FVIRTKEY;
AcceleratorStructure.key = 0x41;
AcceleratorStructure.cmd = ID_SelectAll;
SelectAll = CreateAcceleratorTable(&AcceleratorStructure, 1);
ReadingPageEdit = CreateWindow
(
_T("EDIT"), //lpClassName
NULL, //lpWindowName
WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_BORDER | ES_MULTILINE, //dwStyle
5, //x
30, //y
WindowReactangle.right - 10, //nWidth
WindowReactangle.bottom - 135, //nHeight
TabControls, //hWndParent
(HMENU)ID_ReadingPageEdit, //hMenu
NULL, //hInstance
NULL //lpParam
);
AutoClipboardEdit = CreateWindow
(
_T("EDIT"), //lpClassName
NULL, //lpWindowName
WS_CHILD | WS_VSCROLL | WS_BORDER | ES_MULTILINE, //dwStyle
5, //x
30, //y
WindowReactangle.right - 10, //nWidth
WindowReactangle.bottom - 135, //nHeight
TabControls, //hWndParent
(HMENU)ID_AutoClipboardEdit, //hMenu
NULL, //hInstance
NULL //lpParam
);
AutoClipboardCheckbox = CreateWindow
(
_T("BUTTON"), //lpClassName
_T("Auto-Clipboard"), //lpWindowName
BS_AUTOCHECKBOX | WS_VISIBLE | WS_CHILD, //dwStyle
10, //x
WindowReactangle.bottom -100 +10, //y
150, //nWidth
25, //nHeight
hWndParent, //hWndParent
(HMENU)ID_AutoClipboardCheckbox, //hMenu
NULL, //hInstance
NULL //lpParam
);
SendMessage(AutoClipboardCheckbox, BM_CLICK, TRUE, 0);
OldProc = (WNDPROC)SetWindowLongPtr(AutoClipboardEdit, GWLP_WNDPROC, (LONG)EditControl);
AutoReadCheckbox = CreateWindow
(
_T("BUTTON"), //lpClassName
_T("Auto-Read"), //lpWindowName
BS_AUTOCHECKBOX | WS_VISIBLE | WS_CHILD, //dwStyle
10, //x
WindowReactangle.bottom -100 +35, //y
150, //nWidth
25, //nHeight
hWndParent, //hWndParent
(HMENU)ID_AutoReadCheckbox, //hMenu
NULL, //hInstance
NULL //lpParam
);
AutoClearCheckbox = CreateWindow
(
_T("BUTTON"), //lpClassName
_T("Auto-Clear"), //lpWindowName
BS_AUTOCHECKBOX | WS_VISIBLE | WS_CHILD, //dwStyle
10, //x
WindowReactangle.bottom -100 +60, //y
150, //nWidth
25, //nHeight
hWndParent, //hWndParent
(HMENU)ID_AutoReadCheckbox, //hMenu
NULL, //hInstance
NULL //lpParam
);
}
LRESULT WINAPI MainWindowProcedure
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
//Clipboard Events
case WM_CHANGECBCHAIN:
if ((HWND)wParam == ClipboardViewer)
ClipboardViewer = (HWND)lParam;
return 0;
case WM_DRAWCLIPBOARD:
OpenClipboard(NULL);
SendMessage(AutoClipboardEdit, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
SendMessage(AutoClipboardEdit, EM_REPLACESEL, 0, (LPARAM)GetClipboardData(CF_UNICODETEXT)); //CF_TEXT //CF_UNICODETEXT
CloseClipboard();
break;
//Window Controls Events
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_SelectAll:
if (HIWORD(wParam)==1)
SendMessage(GetFocus(), EM_SETSEL, (WPARAM)0, (LPARAM)-1);
break;
case ID_AutoClipboardCheckbox:
if (SendMessage(AutoClipboardCheckbox, BM_GETCHECK, 0, 0) == BST_CHECKED)
ClipboardViewer = SetClipboardViewer(hwnd);
else
ChangeClipboardChain(hwnd, ClipboardViewer);
break;
}
return 0;
//Tab Controls Events
case WM_NOTIFY:
if (SendMessage(TabControls, TCM_GETCURSEL, 0, 0))
{
ShowWindow(ReadingPageEdit, SW_HIDE);
ShowWindow(AutoClipboardEdit, SW_SHOW);
} else
{
ShowWindow(AutoClipboardEdit, SW_HIDE);
ShowWindow(ReadingPageEdit, SW_SHOW);
}
break;
//Main Window Events
case WM_SIZE:
{
int LOPARAM = lParam & 0xFFFF;
int HIPARAM = lParam >> 16;
SetWindowPos(TabControls, NULL, 0, 0, LOPARAM, HIPARAM-100, SWP_DRAWFRAME);
SetWindowPos(ReadingPageEdit, NULL, 5, 30, LOPARAM-10, HIPARAM-100-35, SWP_DRAWFRAME);
SetWindowPos(AutoClipboardEdit, NULL, 5, 30, LOPARAM-10, HIPARAM-100-35, SWP_DRAWFRAME);
SetWindowPos(AutoClipboardCheckbox, NULL, 10, HIPARAM-100+10, 150, 25, SWP_DRAWFRAME);
SetWindowPos(AutoReadCheckbox, NULL, 10, HIPARAM-100+35, 150, 25, SWP_DRAWFRAME);
SetWindowPos(AutoClearCheckbox, NULL, 10, HIPARAM-100+60, 150, 25, SWP_DRAWFRAME);
return 0;
}
case WM_CREATE:
CreateControls(hwnd);
return 0;
case WM_DESTROY:
DestroyAcceleratorTable(SelectAll);
ChangeClipboardChain(hwnd, ClipboardViewer);
PostQuitMessage(ERROR_SUCCESS);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void CreateMainWindow()
{
WNDCLASSEX WindowClassStructure;
WindowClassStructure.cbSize = sizeof(WNDCLASSEX);
WindowClassStructure.style = CS_HREDRAW | CS_VREDRAW;
WindowClassStructure.lpfnWndProc = MainWindowProcedure;
WindowClassStructure.cbClsExtra = 0;
WindowClassStructure.cbWndExtra = 0;
WindowClassStructure.hInstance = NULL;
WindowClassStructure.hIcon = LoadIcon(NULL, IDI_INFORMATION);
WindowClassStructure.hCursor = LoadCursor(NULL, IDC_ARROW);
WindowClassStructure.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
WindowClassStructure.lpszMenuName = NULL;
WindowClassStructure.lpszClassName = _T("MainClass");
WindowClassStructure.hIconSm = LoadIcon(NULL, IDI_INFORMATION);
RegisterClassEx(&WindowClassStructure);
MainWindowHandle = CreateWindow
(
_T("MainClass"), //lpClassName
_T("Clipboard Reader"), //lpWindowName
WS_VISIBLE | WS_OVERLAPPEDWINDOW, //dwStyle
CW_USEDEFAULT, //x
CW_USEDEFAULT, //y
640, //nWidth
480, // nHeight
NULL, //hWndParent
NULL, //hMenu
NULL, //hInstance
NULL //lpParam
);
}
int WINAPI _tWinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{
CreateMainWindow();
MSG MessageStructure = {0};
while(MessageStructure.message != WM_QUIT)
{
if (PeekMessage(&MessageStructure, NULL, 0, 0, PM_REMOVE))
{
if (!TranslateAccelerator(MainWindowHandle, SelectAll, &MessageStructure))
{
TranslateMessage(&MessageStructure);
DispatchMessage(&MessageStructure);
}
}
}
return MessageStructure.wParam;
}
Related
I'm learning to write basic Win32 apps in C++ and am trying to pass typed text from one editable textbox to a new window after pressing a button.
I noticed that the default text buffer capacity for such a transfer is 20 characters in Visual Studio 2019 (I am on 64-bit Windows 10). After I try to pass a string longer than 20 characters, I get an exception thrown.
I would like to know how to increase that buffer capacity, since eventually I want to be able to pass a filepath into the text input window and open that file.
My code:
#include <windows.h>
#include <string>
#include <iostream>
//lresult callback prototype
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//window handles
HWND hMainWindow;
HINSTANCE hMainInstance;
HWND hLblOutput;
HWND hTxtInput;
HWND hButton;
#define IDC_TEXTBOX 1000
#define IDC_BUTTON 1001
//call to winmain - equivalent of main for win32 environments
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg = { 0 };
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = TEXT("NiceWindowsApp");
if (!RegisterClass(&wc))
return 1;
hMainWindow = CreateWindow(wc.lpszClassName, TEXT("My Windows Application"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, 0, 0, hInstance, NULL);
hMainInstance = wc.hInstance;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//callback definition
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int offset = 0;
switch (message) {
case WM_CREATE:
hMainWindow = hWnd;
hTxtInput = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT("Type something here"),
WS_VISIBLE | WS_CHILD | ES_LEFT, 50, 50, 400, 25, hWnd,
(HMENU)IDC_TEXTBOX, hMainInstance, NULL);
hButton = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("BUTTON"), TEXT("Press Me!"), WS_VISIBLE | WS_CHILD | WM_COPY | ES_LEFT, 500, 30, 100, 60, hWnd,
(HMENU)IDC_BUTTON, hMainInstance, NULL);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BUTTON)
{
//CANNOT HANDLE MORE THAN 20 CHARACTERS!!!
std::string input;
GetWindowTextA(hTxtInput, reinterpret_cast<char*> ((char*)input.c_str()), 400);
++offset;
hLblOutput = CreateWindowEx(WS_EX_STATICEDGE, TEXT("EDIT"), input.c_str(), WS_VISIBLE | WS_CHILD | ES_READONLY | ES_LEFT, 50, 200 + offset * 26, 800, 25, hWnd,
(HMENU)IDC_TEXTBOX, hMainInstance, NULL);
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
I have tried to increase the third parameter in GetWindowTextA() to various numbers up to 4000, but it didn't seem to help.
One correct way to do this is:
std::wstring text;
text.resize(GetWindowTextLengthW(hTxtInput));
text.resize(GetWindowTextW(hTxtInput, text.data(), text.size() + 1));
Solved as per the below:
#include <windows.h>
#include <string>
#include <iostream>
//lresult callback prototype
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//window handles
HWND hMainWindow;
HINSTANCE hMainInstance;
HWND hLblOutput;
HWND hTxtInput;
HWND hButton;
CHAR s_text_1[]{ "Some text.." };
CHAR s_text_2[]{ 0 };
#define IDC_TEXTBOX 1000
#define IDC_BUTTON 1001
//call to winmain - equivalent of main for win32 environments
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg = { 0 };
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = TEXT("NiceWindowsApp");
if (!RegisterClass(&wc))
return 1;
hMainWindow = CreateWindow(wc.lpszClassName, TEXT("My Windows Application"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, 0, 0, hInstance, NULL);
hMainInstance = wc.hInstance;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//callback definition
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int offset = 0;
switch (message) {
case WM_CREATE:
hMainWindow = hWnd;
hTxtInput = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), s_text_1,
WS_VISIBLE | WS_CHILD | ES_LEFT, 50, 50, 400, 25, hWnd,
(HMENU)IDC_TEXTBOX, hMainInstance, NULL);
hButton = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("BUTTON"), TEXT("Press Me!"), WS_VISIBLE | WS_CHILD | WM_COPY | ES_LEFT, 500, 30, 100, 60, hWnd,
(HMENU)IDC_BUTTON, hMainInstance, NULL);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BUTTON)
{
//CANNOT HANDLE MORE THAN 20 CHARACTERS!!!
std::wstring input;
//GetWindowTextW(hTxtInput, reinterpret_cast<char*> ((char*)input.c_str()), 400);
int lgth = GetWindowTextLength(hTxtInput);
//GetWindowTextW(hTxtInput, reinterpret_cast<wchar_t*> ((wchar_t*)input.c_str()), lgth);
//GetWindowTextA(hTxtInput, char[], 400);
GetWindowText(hTxtInput, s_text_1, 255);
++offset;
hLblOutput = CreateWindowEx(WS_EX_STATICEDGE, TEXT("EDIT"), s_text_1, WS_VISIBLE | WS_CHILD | ES_READONLY | ES_LEFT, 50, 200 + offset * 26, 800, 25, hWnd,
(HMENU)IDC_TEXTBOX, hMainInstance, NULL);
SetWindowText(hLblOutput, s_text_1);
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Thanks for your hints everybody.
EDIT: I now realise that this solution is not technically perfect and can lead to undefined behaviour and/or memory leaks. I'll take the advice presented in the other answers and comments into account and adjust the code accordingly.
EDIT 2.0 (2023.02.04): My most recent code is below. Hopefully it's more robust.
#include <windows.h>
#include <string>
#include <iostream>
//last update - 04.02.2023 as per StackOverflow thread recommendations.
//lresult callback prototype
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//window handles
HWND hMainWindow;
HINSTANCE hMainInstance;
HWND hLblOutput;
HWND hTxtInput;
HWND hButton;
CHAR s_text_1[]{ "Some text.." };
#define IDC_TEXTBOX 1000
#define IDC_BUTTON 1001
//call to winmain - equivalent of main for win32 environments
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg = { 0 };
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = TEXT("NiceWindowsApp");
if (!RegisterClass(&wc))
return 1;
hMainWindow = CreateWindow(wc.lpszClassName, TEXT("My Windows Application"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, 0, 0, hInstance, NULL);
hMainInstance = wc.hInstance;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//callback definition
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int offset = 0;
switch (message) {
case WM_CREATE:
hMainWindow = hWnd;
hTxtInput = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), s_text_1,
WS_VISIBLE | WS_CHILD | ES_LEFT, 50, 50, 400, 25, hWnd,
(HMENU)IDC_TEXTBOX, hMainInstance, NULL);
hButton = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("BUTTON"), TEXT("Press Me!"), WS_VISIBLE | WS_CHILD | WM_COPY | ES_LEFT, 500, 30, 100, 60, hWnd,
(HMENU)IDC_BUTTON, hMainInstance, NULL);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BUTTON)
{
std::wstring input;
//resize added as suggested
input.resize(GetWindowTextLengthW(hTxtInput));
GetWindowTextW(hTxtInput, input.data(), input.size() + 1);
++offset;
hLblOutput = CreateWindowEx(WS_EX_STATICEDGE, TEXT("EDIT"), s_text_1, WS_VISIBLE | WS_CHILD | ES_READONLY | ES_LEFT, 50, 200 + offset * 26, 800, 25, hWnd,
(HMENU)IDC_TEXTBOX, hMainInstance, NULL);
SetWindowTextW(hLblOutput, input.data());
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
I want to disable the radio buttons when I select the checkbox. It works when I pass hwnd in addFunc2(), however, I need it to be in the second tab but somehow I can't find any way to make it work.
I apologize if its confusing, I'm very new at this, and my first time posting here. Please let me know if I need to clarify it more. Please refer to the images and some of my code below:
Result of code:
What I need:
HWND hRadio1, hRadio2, hTab, g_tabPanes[2];
HWND CreateTabPane(HWND tabctrl, int id, HINSTANCE instance)
{
RECT rcTab;
GetClientRect(tabctrl, &rcTab);
TabCtrl_AdjustRect(tabctrl, FALSE, &rcTab);
int wd = rcTab.right - rcTab.left;
int hgt = rcTab.bottom - rcTab.top;
return CreateWindow(
L"static", L"",
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
rcTab.left, rcTab.top, wd, hgt,
tabctrl,
(HMENU)id,
instance,
NULL
);
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
{
addControl(hwnd);
HINSTANCE hInst = GetModuleHandle(NULL);
RECT rc; int dx, dy;
GetClientRect(hwnd, &rc);
dx = rc.right - rc.left;
dy = rc.bottom - rc.top;
TCITEM tie = {
TCIF_TEXT | TCIF_IMAGE,
0, 0,
NULL,
0, -1, 0
};
hTab = CreateWindowEx(NULL, WC_TABCONTROL, _T(""),
WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
0, 0, dx, dy, hwnd,
(HMENU)1001, hInst, NULL
);
tie.pszText = (LPWSTR)_T("Tab 1");
TabCtrl_InsertItem(hTab, 0, &tie);
tie.pszText = (LPWSTR)_T("Tab 2");
TabCtrl_InsertItem(hTab, 1, &tie);
for (int i = 0; i < 2; i++)
g_tabPanes[i] = CreateTabPane(hTab, TAB_ID + i, hInst);
addFunc1(g_tabPanes[0]);
addFunc2(g_tabPanes[1]);
break;
}
case WM_COMMAND:
{
switch (wParam)
{
case ID_CHECKBOX:
{
switch (HIWORD(wParam))
{
case BN_CLICKED:
if (SendDlgItemMessage(hwnd, ID_CHECKBOX, BM_GETCHECK, 0, 0))
{
EnableWindow(hRadio1, true);
EnableWindow(hRadio2, true);
}
else
{
EnableWindow(hRadio1, false);
EnableWindow(hRadio2, false);
}
break;
}
}
break;
case WM_NOTIFY:
{
LPNMHDR ns = (LPNMHDR)lParam;
if ((ns->idFrom == 1001) && (ns->code == TCN_SELCHANGE))
{
int pane = TabCtrl_GetCurSel(hTab);
for (int i = 0; i < 2; i++)
if (pane == i)
ShowWindow(g_tabPanes[i], SW_SHOW);
else
ShowWindow(g_tabPanes[i], SW_HIDE);
}
}
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
void addFunc2(HWND hwnd)
{
HWND hCheckbox;
CreateWindow(TEXT("static"), TEXT("Duplex: "), WS_CHILD | WS_VISIBLE,
75, 10, 90, 25, hwnd, NULL, NULL, NULL);
hCheckbox = CreateWindow(L"button", L"Print on both sides", WS_CHILD | WS_VISIBLE |
BS_AUTOCHECKBOX | WS_TABSTOP,
75, 30, 150, 30, hwnd, (HMENU)ID_CHECKBOX, g_hinst, NULL);
hRadio1 = CreateWindow(L"button", L"Flip on long edge", WS_CHILD | WS_VISIBLE |
BS_AUTORADIOBUTTON | WS_TABSTOP,
75, 55, 150, 30, hwnd, (HMENU)ID_RADIO1, g_hinst, NULL);
hRadio2 = CreateWindow(L"button", L"Flip on short edge", WS_CHILD | WS_VISIBLE |
BS_AUTORADIOBUTTON | WS_TABSTOP,
75, 80, 150, 30, hwnd, (HMENU)ID_RADIO2, g_hinst, NULL);
SendMessage(hCheckbox, BM_SETCHECK, BST_CHECKED, 0);
SendMessage(hRadio1, BM_SETCHECK, BST_CHECKED, 0);
My goal is to create 5 groups of radio buttons (i know it contradict with the title but you still get the point) for user choice using only Win32 API (so no window form here).
I tried using a combination of groupbox and SetWindowLongPtr but it still not working as expected (note that im using GWLP_WNDPROC as the index). If i use SetWindowLongPtr to a group box then that groupbox is gone and everything else work as expected.
I could use a "virtual" group box but it reduce the efficency of my code. Some one might recommend using WS_GROUP but it only apply if there are 2 group of radio buttons ( I think ). And i also dont like using resource so is there any solution to this problem or i just have to stuck with the "virtual" group box?
Minimal reproducible sample:
#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wp, LPARAM lp)
{
switch (uMsg)
{
default:
return DefWindowProc(hwnd, uMsg, wp, lp);
}
}
int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE hiprevinst, PWSTR nCmdLine, int ncmdshow)
{
const wchar_t CLASS_NAME[] = L"Sample";
WNDCLASS wc = { };
wc.lpfnWndProc = WndProc;
wc.hInstance = hinst;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
0,
CLASS_NAME,
L"Sample window",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, // Window style
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
NULL,
NULL,
hinst,
NULL);
HWND groupbox = CreateWindowEx(0, L"Button", L"Groupbox", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 10, 10, 100, 100, NULL, NULL, hinst, NULL);
HWND radiobutton1 = CreateWindowEx(0, L"Button", L"Groupbox", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 10, 10, 60, 60, groupbox, NULL, hinst, NULL);
SetWindowLongPtr(groupbox, GWLP_WNDPROC, (LONG)WndProc);
SendMessage(groupbox, NULL, NULL, TRUE);
ShowWindow(hwnd, ncmdshow);
MSG msg;
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Due to i stripped so much of the necessary function away, you need to go to task manager and kill the process named "Autoclicker" for some reason to be able to recompile it again
Make sure you handle WM_DESTROY otherwise window won't close properly.
The radio buttons, all child dialog items, and all child windows should be created in WM_CREATE section of parent window. They need the HWND handle from parent window.
SetWindowLongPtr(.. GWLP_WNDPROC ...) is an old method used for subclassing. Your usage is incorrect. You don't need it anyway.
It's unclear what SendMessage(groupbox, NULL, NULL, TRUE); is supposed to do.
Just add the radio buttons, make sure the first radio button has an added WS_TABSTOP|WS_GROUP as shown below
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wp, LPARAM lp)
{
switch (uMsg)
{
case WM_CREATE:
{
HINSTANCE hinst = GetModuleHandle(0);
auto add = [&](const wchar_t* name,
int id, int x, int y, int w, int h, bool first = false)
{
DWORD style = WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON;
if (first) style |= WS_GROUP | WS_TABSTOP;
return CreateWindowEx(0, L"Button", name, style,
x, y, w, h, hwnd, (HMENU)id, hinst, NULL);
};
HWND groupbox1 = CreateWindowEx(0, L"Button", L"Groupbox1",
WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 2, 2, 250, 120, hwnd, NULL, hinst, NULL);
HWND radio1 = add(L"radio1", 1, 10, 30, 200, 20, true);
HWND radio2 = add(L"radio2", 2, 10, 51, 200, 20);
HWND radio3 = add(L"radio3", 3, 10, 72, 200, 20);
HWND radio4 = add(L"radio4", 4, 10, 93, 200, 20);
HWND groupbox2 = CreateWindowEx(0, L"Button", L"Groupbox2",
WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 280, 2, 250, 120, hwnd, NULL, hinst, NULL);
HWND radio11 = add(L"radio1", 11, 300, 30, 200, 20, true);
HWND radio12 = add(L"radio2", 12, 300, 51, 200, 20);
HWND radio13 = add(L"radio3", 13, 300, 72, 200, 20);
HWND radio14 = add(L"radio4", 14, 300, 93, 200, 20);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wp, lp);
}
}
int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE hiprevinst, PWSTR nCmdLine, int ncmdshow)
{
const wchar_t CLASS_NAME[] = L"Sample";
WNDCLASS wc = { };
wc.lpfnWndProc = WndProc;
wc.hInstance = hinst;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"Sample window",
WS_OVERLAPPEDWINDOW, 0, 0, 800, 600,
NULL, NULL, hinst, NULL);
ShowWindow(hwnd, ncmdshow);
MSG msg;
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
I want to implement a listbox and a slider in my window.
I use devcpp, not visual studio.
I have looked up for a way to do that and i have found nothing, except theoritical stuff like msdn.microsoft.com provides.
I want an example, the smallest kind of code to implement listbox and slider.
This is the closer and most helpfull link, but still, it uses visual studio.
Thanks.
I found what i was looking for, it seems that this is the only example code on the entire internet on making listboxes. In order to run it: download and open devc++ (which I use) or any other kind of compiler, open a new Windows application project (otherwise it won't work), erase any default code, paste this code and run it.
And this, is how you help others learn code.
http://www.dreamincode.net/forums/topic/291276-win32-listbox/
#include <Windows.h>
#define IDC_MAIN_BUTTON 101 // Button identifier
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND hWndListL;
HWND hWndListR;
HWND hWndButton;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;
//Settings All Window Class Variables
WNDCLASSEX WndClsEx;
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = "My Window";
//Register Window Class
RegisterClassEx(&WndClsEx);
//Create Window
hWnd = CreateWindowEx(NULL, "My Window", "Windows Application", WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, NULL, NULL, hInstance, NULL);
SendMessage(hWndListL, LB_ADDSTRING, NULL, (LPARAM)"one");
SendMessage(hWndListL, LB_ADDSTRING, NULL, (LPARAM)"two");
//Show Window
ShowWindow(hWnd, SW_SHOWNORMAL);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
char buffer[50] = "";
switch(Msg)
{
case WM_CREATE:
//Create Listbox's
hWndListL = CreateWindowEx(NULL, "LISTBOX", NULL, WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | LBS_NOTIFY, 50, 35, 200, 100, hWnd, NULL, GetModuleHandle(NULL), NULL);
hWndListR = CreateWindowEx(NULL, "LISTBOX", NULL, WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | LBS_NOTIFY, 350, 35, 200, 100, hWnd, NULL, GetModuleHandle(NULL), NULL);
//Create Button
hWndButton = CreateWindowEx(NULL, "BUTTON", "OK", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | WS_DISABLED, 50, 220, 100, 24, hWnd, (HMENU)IDC_MAIN_BUTTON, GetModuleHandle(NULL), NULL);
break;
case WM_COMMAND:
switch(HIWORD(wParam))
{
case LBN_SELCHANGE:
{
//EnableWindow( GetDlgItem( hWnd, (HMENU)IDC_BUTTON_MAIN ), TRUE );
EnableWindow(hWndButton, true);
break;
}
}
switch(LOWORD(wParam))
{
case IDC_MAIN_BUTTON:
{
//length = SendMessage(hWndListL, LB_GETTEXTLEN, NULL, NULL);
SendMessage(hWndListL, LB_GETTEXT, NULL, (LPARAM)buffer);
SendMessage(hWndListR, LB_ADDSTRING, NULL, (LPARAM)buffer);
SendMessage(hWndListL, LB_DELETESTRING, NULL, NULL);
EnableWindow(hWndButton, false);
break;
}
}
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
Here is example code of window with listbox:
#include <Windows.h>
/// unique class name
#define CLASS_NAME "MyWinapiClassNameWithUniqeSetOfCharactersThatAreNotMyPassword_50kz5S99g2Q88bTi3ne"
/// unique ID of our listbox command
#define IDC_LISTBOX_ID 123
static LRESULT WINAPI wndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ){
switch(msg){
case WM_CREATE:{
HWND listboxHwnd= CreateWindow( "LISTBOX", NULL, WS_CHILD | WS_VISIBLE | LBS_STANDARD | LBS_NOTIFY, 10, 10, 200, 100, hwnd, (HMENU)IDC_LISTBOX_ID, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 0" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 1" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 2" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 3" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 4" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 5" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 6" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 7" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 8" );
SendMessage( listboxHwnd, LB_ADDSTRING, 0, (LPARAM)"List Item 9" );
}break;
case WM_COMMAND:{
switch( LOWORD(wParam) ){
case IDC_LISTBOX_ID:{
switch(HIWORD(wParam)){
case LBN_SELCHANGE:{ /// user have selected item in our listbox
int id= SendMessage( (HWND)lParam, LB_GETCARETINDEX, 0, 0 ); /// id of seleted item, starting from 0
char text[]= "Item 0 selected";
text[5] += id; /// thats one way of converting int to string :D
MessageBox( NULL, text, "Debug", MB_OK );
}break;
}
}break;
}
}break;
case WM_DESTROY:{
::PostQuitMessage(0);
}break;
}
return DefWindowProc( hwnd, msg, wParam, lParam);
}
int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd ){
WNDCLASSEX wc= {
sizeof(WNDCLASSEX),
CS_CLASSDC,
wndProc,
0,
0,
hInstance,
LoadIcon( NULL, IDI_APPLICATION ),
LoadCursor( NULL, IDC_ARROW ),
(HBRUSH)(COLOR_WINDOW+0),
NULL,
CLASS_NAME,
NULL
};
if( !RegisterClassEx(&wc) ){
MessageBox( NULL, "Fail to register window class.", "Error - Keyboardlord", MB_ICONERROR );
return -2;
}
HWND hwnd= CreateWindow( CLASS_NAME, "App Browser - Keyboardlord", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 250, 150, NULL, NULL, hInstance, NULL );
if( hwnd==NULL ){
MessageBox( NULL, "Fail to create window", "Error - Keyboardlord", MB_ICONERROR );
return -3;
}
ShowWindow( hwnd, nShowCmd );
MSG msg;
while( 0 < GetMessage( &msg, NULL, 0, 0) ){
TranslateMessage( &msg );
DispatchMessage( &msg );
}
::DestroyWindow( hwnd );
::UnregisterClass( CLASS_NAME, hInstance );
return 0;
}
Alright so this code is pretty long over a short problem so I will kinda use <--- arrows to point it out for you, but down in my switch case WM_COMMAND:
I am kinda confused on using the return 0/ break.
return 0; seems to jump me outside of the whole WndProc function (skips over some code)
break; just breaks out of the switch statement but continues.
So does that mean I should use return 0; at the very end of my switch statement to prevent from moving on? Or is there something just wrong with my WM_MAXMININFO, because I never had that problem until after I changed the return 0 to break; The reason I ask is because once it hits WM_MAXMININFO I get a Access Violation. (That may be that cause of all of this).
// Win32Project2.cpp : Defines the entry point for the application.
#include "stdafx.h"
#include "Win32Project2.h"
#include <Windows.h>
#include <Windowsx.h>
#include <shellapi.h>
#include "ProcessFind.h"
#include <WinUser.h>
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define BUTTON L"button"
#define szDefault L"Awaiting Commands..."
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdShow, int iCmdLine)
{
wchar_t szAppName[] = L"Game Launcher";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
hwnd = CreateWindow(szAppName, L"GameLauncher v1.0", WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 375, 100, NULL, NULL, hInstance, 0);
ShowWindow(hwnd, iCmdLine);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
static HWND hUserBox;
static HWND hWindowButton;
HBITMAP hImage = (HBITMAP)LoadImage(NULL, L"?C:\\Users\\chaos\\Desktop\\Capture.PNG", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
switch (message)
{
case WM_CREATE:
CreateWindowEx(NULL, BUTTON, L"Check for process", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX , 5, 35, 150, 25, hwnd, (HMENU)2, NULL, NULL);
CreateWindow(BUTTON, L"Minecraft", WS_CHILD | WS_VISIBLE, 250, 5, 100, 25, hwnd, (HMENU)1, NULL, NULL);
CreateWindow(BUTTON, L"Options", WS_CHILD | WS_VISIBLE | WS_DISABLED, 250, 30, 100, 25, hwnd, (HMENU)3, NULL, NULL);
hUserBox = CreateWindow(L"static", L"Awaiting Commands...", WS_CHILD | WS_VISIBLE | WS_BORDER, 5, 5, 240, 25, hwnd, (HMENU) 2, NULL, NULL);
return 0;
case WM_COMMAND:
switch (LOWORD(wparam))
{
case 1:
{
wchar_t* szProccessToKill = new wchar_t[20];
GetWindowText(hUserBox, szProccessToKill, 20);
// Checking checked status on checkbox. (Say that 5 times fast lol)
if (IsDlgButtonChecked(hwnd, 2) == BST_CHECKED)
{
ProcessFind testFunction;
SetWindowText(hUserBox, L"Ending process");
Sleep(1000);
testFunction.EndProcess(L"java.exe");
SetWindowText(hUserBox, L"Launching Minecraft...");
Sleep(1000);
ShellExecute(NULL, L"open", L"MinecraftLauncher", NULL, L"C:\\Program Files (x86)\\Minecraft", 6);
SetWindowText(hUserBox, L"Minecraft has launched sucessfully!");
Sleep(1000);
SetWindowText(hUserBox, szDefault);
}
else if (IsDlgButtonChecked(hwnd, 2) == BST_UNCHECKED)
{
SetWindowText(hUserBox, L"Launching Minecraft...");
HINSTANCE ErrorCode = ShellExecute(NULL, L"open", L"C:\\Program Files (x86)\\Minecraft\\MinecraftLauncher", NULL, NULL, 1);
int ErrorCodeInt = (int)ErrorCode;
switch (ErrorCodeInt)
{
case 0:
MessageBox(NULL, L"The operating system is out of memory or resources.", L"Error", MB_OK | MB_ICONERROR);
break;
case ERROR_FILE_NOT_FOUND:
MessageBox(NULL, L"The specified file was not found.", L"Error", MB_OK | MB_ICONERROR);
break;
case ERROR_PATH_NOT_FOUND:
MessageBox(NULL, L"The specified path was not found.", L"Error", MB_OK | MB_ICONERROR);
break;
default:
SetWindowText(hUserBox, L"Minecraft has launched successfully");
Sleep(1500);
break;
}
SetWindowText(hUserBox, szDefault);
}
delete[] szProccessToKill;
break; <--- **If this is not a return 0;**
}
case 3:
{
break;
}
default:
break;
}
//Set Min / Max Width/Height size.
case WM_GETMINMAXINFO: <-- It will jump down here and give me an access violation error:
{
MINMAXINFO* MMI = (MINMAXINFO*)lparam;
MMI->ptMaxTrackSize.x = 375;
MMI->ptMaxTrackSize.y = 100;
MMI->ptMinTrackSize.x = 375;
MMI->ptMinTrackSize.y = 100;
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, message, wparam, lparam);
}
return 0;
}
I will kinda shorten it up straight to the problem for you guys:
SetWindowText(hUserBox, szDefault);
}
delete[] szProccessToKill;
break; <--- **If this is not a return 0;**
}
case 3:
{
break;
}
default:
break;
}
//Set Min / Max Width/Height size.
case WM_GETMINMAXINFO: <-- It will jump down here and give me an access violation error:
{
MINMAXINFO* MMI = (MINMAXINFO*)lparam;
MMI->ptMaxTrackSize.x = 375;
MMI->ptMaxTrackSize.y = 100;
MMI->ptMinTrackSize.x = 375;
MMI->ptMinTrackSize.y = 100;
return 0;
}