SuperABC
Gebruiker
- Lid geworden
- 16 jul 2009
- Berichten
- 327
Hi,
Ik heb een programmatjes gemaakt met de Win32 API in C++. Het werkt wel ongeveer. Maar er zijn echter een tal problemen. Hij doet het niet op Windows XP, daar geef ik deze code de schuld van:
[CPP]#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")[/CPP]
Die code zorgt ervoor dat op Vista de controls in die style zijn. Misschien is er een manier dat je programma automatisch de default style aanneemt? Verder als je een aantal x een enter hebt als input, pakt die niet alles. Maar daar gaat het mij niet zozeer om, meer om de combinatie met Win32 API. Misschien heeft iemand tips, of iets anders op basis van mijn code hoe je met de Win32 API programmeert.
P.S. Hij complineert alleen in Microsofts ding, maar hij doet het wel als je die schuldige regel eruit haalt
Dit is de code:
[CPP]//
#include <windows.h>
#include <Windowsx.h>
#include <commctrl.h>
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
const char g_szClassName[] = "Window_123_ABC_S";
#define ID_Input 100
#define ID_Encode 101
#define ID_Decode 110
#define ID_S_Input 111
#define ID_Key 1000
#define ID_Output 1001
#define ID_Progress 1010
HWND input;
HWND encode;
HWND decode;
HWND key;
HWND output;
HWND st1;
HWND st2;
HWND st3;
HWND progress;
int key_value = 0;
void GetKeyValue()
{
key_value = 0;
int length = GetWindowTextLength(key);
length++;
char *buffer;
buffer = new char[length];
GetWindowText(key,buffer,length);
for(int x=0; x < length -1; x++)
{
key_value += int(buffer[x]) * x;
}
buffer = new char;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
//Encode
case ID_Encode:
switch(HIWORD(wParam))
{
case BN_CLICKED:
GetKeyValue();
//Set the INPUT text into char[] BUFFER
int length = Edit_GetTextLength(input);
if (!(length > 0))
{
MessageBox(hwnd,"Please, enter some text to encode...","No Text",MB_OK | MB_ICONEXCLAMATION);
}
else
{
length++;
char *buffer;
buffer = new char[length];
Edit_GetText(input,buffer,length);
//Encode all char[] of BUFFER to a new BUFFER
Button_Enable(encode,FALSE);
Button_Enable(decode,FALSE);
Edit_Enable(input,FALSE);
Edit_Enable(output,FALSE);
Edit_Enable(key,FALSE);
UpdateWindow(hwnd);
SendMessage(progress,PBM_SETRANGE32,0,length -1);
for(int x=1; x < length; x++)
{
SendMessage(progress,PBM_SETPOS,x,0);
char buf = buffer[x -1];
buffer[x -1] = int(buf) + ((key_value * x) ^(2 * x));
}
//SetWindowText(output,buffer);
Edit_SetText(output,buffer);
delete buffer;
Button_Enable(encode,TRUE);
Button_Enable(decode,TRUE);
Edit_Enable(input,TRUE);
Edit_Enable(output,TRUE);
Edit_Enable(key,TRUE);
}
break;
}
break;
//Decode
case ID_Decode:
switch(HIWORD(wParam))
{
case BN_CLICKED:
GetKeyValue();
//Set the INPUT text into char[] BUFFER
int length = Edit_GetTextLength(input);
if (!(length > 0))
{
MessageBox(hwnd,"Please, enter some text to encode...","No Text",MB_OK | MB_ICONEXCLAMATION);
}
else
{
length++;
char *buffer;
buffer = new char[length];
Edit_GetText(input,buffer,length);
//Encode all char[] of BUFFER to a new BUFFER
Button_Enable(encode,FALSE);
Button_Enable(decode,FALSE);
Edit_Enable(input,FALSE);
Edit_Enable(output,FALSE);
Edit_Enable(key,FALSE);
UpdateWindow(hwnd);
SendMessage(progress,PBM_SETRANGE32,0,length -1);
for(int x=1; x < length; x++)
{
SendMessage(progress,PBM_SETPOS,x,0);
char buf = buffer[x -1];
buffer[x -1] = int(buf) - ((key_value * x) ^(2 * x));
}
//SetWindowText(output,buffer);
Edit_SetText(output,buffer);
delete buffer;
Button_Enable(encode,TRUE);
Button_Enable(decode,TRUE);
Edit_Enable(input,TRUE);
Edit_Enable(output,TRUE);
Edit_Enable(key,TRUE);
}
break;
}
break;
//Other
}
break;
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Encoder | Decoder >> By SuperABC",
WS_OVERLAPPED | \
WS_CAPTION | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 460,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
st1 = CreateWindow("Static","Enter an input text:",WS_CHILD | WS_VISIBLE,12,9,110,20,hwnd,(HMENU)ID_S_Input,GetModuleHandle(NULL),NULL);
input = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 12, 29, 600, 150, hwnd, (HMENU)ID_Input, GetModuleHandle(NULL), NULL);
encode = CreateWindow("Button","Encode",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,12,185,75,27,hwnd,(HMENU)ID_Encode,GetModuleHandle(NULL),NULL);
decode = CreateWindow("Button","Decode",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,93,185,75,27,hwnd,(HMENU)ID_Decode,GetModuleHandle(NULL),NULL);
st3 = CreateWindow("Static","Key:",WS_CHILD | WS_VISIBLE,174,190,32,17,hwnd,(HMENU)ID_S_Input,GetModuleHandle(NULL),NULL);
key = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE, 212, 189, 400, 23, hwnd, (HMENU)ID_Key, GetModuleHandle(NULL), NULL);
st2 = CreateWindow("Static","Output:",WS_CHILD | WS_VISIBLE,12,215,110,17,hwnd,(HMENU)ID_S_Input,GetModuleHandle(NULL),NULL);
output = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 12, 235, 600, 150, hwnd, (HMENU)ID_Output, GetModuleHandle(NULL), NULL);
progress = CreateWindowEx(0, PROGRESS_CLASS,NULL,WS_CHILD | WS_VISIBLE,12,391,600,20,hwnd,(HMENU) ID_Progress,GetModuleHandle(NULL),NULL);
SetFocus(input);
HFONT hFont = CreateFont (18, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Segoe UI");
SendMessage (input, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (output, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (key, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (encode, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (decode, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (st1, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (st2, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (st3, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (progress, PBM_SETSTEP,1,0);
SendMessage (input, EM_LIMITTEXT, INT_MAX, NULL);
SendMessage (output, EM_LIMITTEXT, INT_MAX, NULL);
SendMessage (key, EM_LIMITTEXT, 128, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}[/CPP]
Ik heb een programmatjes gemaakt met de Win32 API in C++. Het werkt wel ongeveer. Maar er zijn echter een tal problemen. Hij doet het niet op Windows XP, daar geef ik deze code de schuld van:
[CPP]#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")[/CPP]
Die code zorgt ervoor dat op Vista de controls in die style zijn. Misschien is er een manier dat je programma automatisch de default style aanneemt? Verder als je een aantal x een enter hebt als input, pakt die niet alles. Maar daar gaat het mij niet zozeer om, meer om de combinatie met Win32 API. Misschien heeft iemand tips, of iets anders op basis van mijn code hoe je met de Win32 API programmeert.
P.S. Hij complineert alleen in Microsofts ding, maar hij doet het wel als je die schuldige regel eruit haalt
Dit is de code:
[CPP]//
#include <windows.h>
#include <Windowsx.h>
#include <commctrl.h>
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
const char g_szClassName[] = "Window_123_ABC_S";
#define ID_Input 100
#define ID_Encode 101
#define ID_Decode 110
#define ID_S_Input 111
#define ID_Key 1000
#define ID_Output 1001
#define ID_Progress 1010
HWND input;
HWND encode;
HWND decode;
HWND key;
HWND output;
HWND st1;
HWND st2;
HWND st3;
HWND progress;
int key_value = 0;
void GetKeyValue()
{
key_value = 0;
int length = GetWindowTextLength(key);
length++;
char *buffer;
buffer = new char[length];
GetWindowText(key,buffer,length);
for(int x=0; x < length -1; x++)
{
key_value += int(buffer[x]) * x;
}
buffer = new char;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
//Encode
case ID_Encode:
switch(HIWORD(wParam))
{
case BN_CLICKED:
GetKeyValue();
//Set the INPUT text into char[] BUFFER
int length = Edit_GetTextLength(input);
if (!(length > 0))
{
MessageBox(hwnd,"Please, enter some text to encode...","No Text",MB_OK | MB_ICONEXCLAMATION);
}
else
{
length++;
char *buffer;
buffer = new char[length];
Edit_GetText(input,buffer,length);
//Encode all char[] of BUFFER to a new BUFFER
Button_Enable(encode,FALSE);
Button_Enable(decode,FALSE);
Edit_Enable(input,FALSE);
Edit_Enable(output,FALSE);
Edit_Enable(key,FALSE);
UpdateWindow(hwnd);
SendMessage(progress,PBM_SETRANGE32,0,length -1);
for(int x=1; x < length; x++)
{
SendMessage(progress,PBM_SETPOS,x,0);
char buf = buffer[x -1];
buffer[x -1] = int(buf) + ((key_value * x) ^(2 * x));
}
//SetWindowText(output,buffer);
Edit_SetText(output,buffer);
delete buffer;
Button_Enable(encode,TRUE);
Button_Enable(decode,TRUE);
Edit_Enable(input,TRUE);
Edit_Enable(output,TRUE);
Edit_Enable(key,TRUE);
}
break;
}
break;
//Decode
case ID_Decode:
switch(HIWORD(wParam))
{
case BN_CLICKED:
GetKeyValue();
//Set the INPUT text into char[] BUFFER
int length = Edit_GetTextLength(input);
if (!(length > 0))
{
MessageBox(hwnd,"Please, enter some text to encode...","No Text",MB_OK | MB_ICONEXCLAMATION);
}
else
{
length++;
char *buffer;
buffer = new char[length];
Edit_GetText(input,buffer,length);
//Encode all char[] of BUFFER to a new BUFFER
Button_Enable(encode,FALSE);
Button_Enable(decode,FALSE);
Edit_Enable(input,FALSE);
Edit_Enable(output,FALSE);
Edit_Enable(key,FALSE);
UpdateWindow(hwnd);
SendMessage(progress,PBM_SETRANGE32,0,length -1);
for(int x=1; x < length; x++)
{
SendMessage(progress,PBM_SETPOS,x,0);
char buf = buffer[x -1];
buffer[x -1] = int(buf) - ((key_value * x) ^(2 * x));
}
//SetWindowText(output,buffer);
Edit_SetText(output,buffer);
delete buffer;
Button_Enable(encode,TRUE);
Button_Enable(decode,TRUE);
Edit_Enable(input,TRUE);
Edit_Enable(output,TRUE);
Edit_Enable(key,TRUE);
}
break;
}
break;
//Other
}
break;
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Encoder | Decoder >> By SuperABC",
WS_OVERLAPPED | \
WS_CAPTION | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 460,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
st1 = CreateWindow("Static","Enter an input text:",WS_CHILD | WS_VISIBLE,12,9,110,20,hwnd,(HMENU)ID_S_Input,GetModuleHandle(NULL),NULL);
input = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 12, 29, 600, 150, hwnd, (HMENU)ID_Input, GetModuleHandle(NULL), NULL);
encode = CreateWindow("Button","Encode",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,12,185,75,27,hwnd,(HMENU)ID_Encode,GetModuleHandle(NULL),NULL);
decode = CreateWindow("Button","Decode",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,93,185,75,27,hwnd,(HMENU)ID_Decode,GetModuleHandle(NULL),NULL);
st3 = CreateWindow("Static","Key:",WS_CHILD | WS_VISIBLE,174,190,32,17,hwnd,(HMENU)ID_S_Input,GetModuleHandle(NULL),NULL);
key = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE, 212, 189, 400, 23, hwnd, (HMENU)ID_Key, GetModuleHandle(NULL), NULL);
st2 = CreateWindow("Static","Output:",WS_CHILD | WS_VISIBLE,12,215,110,17,hwnd,(HMENU)ID_S_Input,GetModuleHandle(NULL),NULL);
output = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 12, 235, 600, 150, hwnd, (HMENU)ID_Output, GetModuleHandle(NULL), NULL);
progress = CreateWindowEx(0, PROGRESS_CLASS,NULL,WS_CHILD | WS_VISIBLE,12,391,600,20,hwnd,(HMENU) ID_Progress,GetModuleHandle(NULL),NULL);
SetFocus(input);
HFONT hFont = CreateFont (18, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Segoe UI");
SendMessage (input, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (output, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (key, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (encode, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (decode, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (st1, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (st2, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (st3, WM_SETFONT, WPARAM (hFont), TRUE);
SendMessage (progress, PBM_SETSTEP,1,0);
SendMessage (input, EM_LIMITTEXT, INT_MAX, NULL);
SendMessage (output, EM_LIMITTEXT, INT_MAX, NULL);
SendMessage (key, EM_LIMITTEXT, 128, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}[/CPP]