Zdravim, udělal jsem ve winapi okno, ve kterém mám combobox (drop-down menu). Mám v něm nějaké hodnoty, ale žádná se nezobrazuje defaultně. Když program zapnu, tak se zobrazí combobox, ale není v něm ukázaná žádná hodnota, dokud nekliknu na nějakou hodnotu v comboboxu. Nevíte, jak nastavit dafaultní hodnotu tak, že se bude zobrazovat při spuštění programu? Předem díky :)
#include <WinSock2.h>
#include <windows.h>
#include <iostream>
#include <winuser.h>
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
using namespace std;
//Prototyp:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow);
void EDITCONFIGFILE(bool fullscreen, int v_resolution, int h_resolution, HWND hwnd);
int CheckUpdate(const char ServerIP[16], int ServerPORT, HWND hwnd);
bool fullscreen = 0;
int v_resolution = 0;
int h_resolution = 0;
char Temp[10];
HWND button0;
HWND combobox;
HWND button1;
HWND button2;
HWND button3;
HWND button4;
HWND edit;
HWND text1;
HWND listbox1;
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
#define ID_FILE_EXIT 101
#define IDI_ICON1 102
#define IDI_ICON2 103
#define ID_BUTTON_PLAY 104
#define ID_TEXTBOX 105
#define ID_TEXT 106
#define ID_BUTTON_CANCEL 107
#define ID_LISTBOX 108
#define ID_CHECKBOX 109
#define ID_BUTTON_BEEP 110
#define ID_COMBOBOX 111
#define ID_BUTTON_CHECKUPDATES 112
#define ID_BUTTON_ADD 113
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////***SWITCH***/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
switch(uMsg)
{
case WM_DESTROY:
{PostQuitMessage(0);}
return 0;
/*----------------------------------------------------------------------------------------------*/
case WM_CLOSE:
{
DestroyWindow(hwnd);
}
return 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*---------------VNITŘEK SWITCH-------------------------------------------------------------*/// Vnitřek fce switch
case WM_CREATE:
{
LOGFONT LogFont;
HFONT font;
GetObject (GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &LogFont);
font = CreateFont (LogFont.lfHeight, LogFont.lfWidth,
LogFont.lfEscapement, LogFont.lfOrientation, LogFont.lfWeight,
LogFont.lfItalic, LogFont.lfUnderline, LogFont.lfStrikeOut, LogFont.lfCharSet,
LogFont.lfOutPrecision, LogFont.lfClipPrecision, LogFont.lfQuality,
LogFont.lfPitchAndFamily, LogFont.lfFaceName);
/////////////////////
//Menu
//
// HMENU hMenubar = CreateMenu();
// HMENU hFile = CreateMenu();
// HMENU hOptions = CreateMenu();
//
// AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hFile, "File");
// AppendMenu(hMenubar, MF_POPUP, NULL, "Edit");
//
// AppendMenu(hFile, MF_STRING, ID_FILE_EXIT, "Exit");
//
// SetMenu(hwnd, hMenubar);
/////////////////////////////////////////////////////////////////////////////////////////////////
//CheckBox
//
button0 = CreateWindow(
TEXT("Button"),
TEXT("Run in window"),
BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
5, 335,
85, 28,
hwnd,
(HMENU)ID_CHECKBOX,
NULL,
NULL);
SendMessage (button0, WM_SETFONT, (WPARAM)font, TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////////
//COMBOBOX
//
combobox = CreateWindow(
TEXT("COMBOBOX"),
TEXT("640x480"),
WS_CHILD | WS_VISIBLE | CBS_DROPDOWN,
640-105, 5,
100, 280,
hwnd,
(HMENU) ID_COMBOBOX,
NULL,
NULL);
SendMessage(combobox, WM_SETFONT, (WPARAM)font, TRUE);
const char *resolutions[] = {"640x480", "720x480", "720x576",
"800x600", "848x480", "1024x768",
"1152x864", "1280x720", "1280x768",
"1280x800", "1280x960", "1280x1024",
"1360x768", "1360x1024", "1440x900",
"1600x900", "1600x1200", "1680x1050", "1920x1080"};
for(int i = 0; i < 19; i++)
SendMessage(combobox, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)resolutions[i]));
/////////////////////////////////////////////////////////////////////////////////////////////////
//Tlačítko Play
//
button1 = CreateWindow(
TEXT("BUTTON"),
TEXT("Play!"),
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
640-85, //Pozice Tlačítka x
360-25, //Pozice Tlačítka y
80, //Velikost Tlačítka x
20, //Velikost Tlačítka y
hwnd,
(HMENU) ID_BUTTON_PLAY,
NULL,
NULL,
);
SendMessage (button1, WM_SETFONT, (WPARAM)font, TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////////
//Tlačítko Cancel
//
button2 = CreateWindow(
TEXT("BUTTON"),
TEXT("Cancel"),
WS_CHILD | WS_VISIBLE,
640-170, //Pozice Tlačítka x
360-25, //Pozice Tlačítka y
80, //Velikost Tlačítka x
20, //Velikost Tlačítka y
hwnd,
(HMENU) ID_BUTTON_CANCEL,
NULL,
NULL,
);
SendMessage (button2, WM_SETFONT, (WPARAM)font, TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////////
//Tlačítko Beep
//
button3 = CreateWindow(
TEXT("BUTTON"),
TEXT("Beep ;-)"),
WS_CHILD | WS_VISIBLE,
640-85, //Pozice Tlačítka x
360-50, //Pozice Tlačítka y
80, //Velikost Tlačítka x
20, //Velikost Tlačítka y
hwnd,
(HMENU) ID_BUTTON_BEEP,
NULL,
NULL,
);
SendMessage (button3, WM_SETFONT, (WPARAM)font, TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////////
//Tlačítko Check Update
//
button4 = CreateWindow(
TEXT("BUTTON"),
TEXT("Check Updates..."),
WS_CHILD | WS_VISIBLE,
5, //Pozice Tlačítka x
360-50, //Pozice Tlačítka y
120, //Velikost Tlačítka x
20, //Velikost Tlačítka y
hwnd,
(HMENU) ID_BUTTON_CHECKUPDATES,
NULL,
NULL,
);
SendMessage (button4, WM_SETFONT, (WPARAM)font, TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////////
//TextBox
//
/*edit = CreateWindow(
TEXT("EDIT"),
TEXT("Ahoj"),
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
130, 310,
150, 20,
hwnd,
(HMENU) ID_TEXTBOX,
NULL,
NULL,
);
SendMessage (edit, WM_SETFONT, (WPARAM)font, TRUE);*/
/////////////////////////////////////////////////////////////////////////////////////////////////
//Text Rozlišení
//
text1 = CreateWindow(
TEXT("STATIC"),
TEXT("Resolution:"),
WS_VISIBLE | WS_CHILD,
640-160, 8,
55, 20,
hwnd,
(HMENU) ID_TEXT,
NULL,
NULL,
);
SendMessage (text1, WM_SETFONT, (WPARAM)font, TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////////
/*HWND text2 = CreateWindow(
TEXT("STATIC"),
TEXT("2. Řádek"),
WS_VISIBLE | WS_CHILD,
5, 20,
200, 20,
hwnd,
(HMENU) ID_TEXT,
NULL,
NULL,
);
SendMessage (text2, WM_SETFONT, (WPARAM)font, TRUE);*/
/////////////////////////////////////////////////////////////////////////////////////////////////
//ListBox
//
listbox1 = CreateWindow(
TEXT("LISTBOX"),
Temp,
WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_HASSTRINGS,
100,340,
150,20,
hwnd,
(HMENU) ID_LISTBOX,
NULL,
NULL);
SendMessage(listbox1, WM_SETFONT, (WPARAM)font, TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////////
} //Konec funkce WM_CREATE:
return 0;
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*++++***FUNKCE TLAČÍTEK***+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
case WM_COMMAND:
/*if(LOWORD (wParam) == ID_FILE_EXIT) ///EXIT BUTTON
{
if(MessageBox(hwnd, TEXT("Are You sure, You want to Exit?"), TEXT("Exit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
DestroyWindow(hwnd);
}*/
//Menu File_Exit
if(LOWORD (wParam) == ID_BUTTON_PLAY) /// PLAY BUTTON
{
/*SOCKET sConnect;
SOCKADDR_IN addr;
WSAData wsaData;
WORD DLLVersion;
DLLVersion = MAKEWORD(2,1);
WSAStartup(DLLVersion, &wsaData);
int addrlen = sizeof(addr);
sConnect = socket(AF_INET, SOCK_STREAM, NULL);
addr.sin_addr.s_addr = inet_addr("90.182.102.233");
addr.sin_family = AF_INET;
addr.sin_port = htons(25565);
connect(sConnect, (SOCKADDR*)&addr, sizeof(addr));
MessageBox(hwnd, TEXT("Finding Server Connection"), TEXT("Wait..."),MB_OK | MB_ICONEXCLAMATION);*/
MessageBox(hwnd, TEXT("Suddenly, the game is not done yet"), TEXT("Sorry"), MB_OK | MB_ICONEXCLAMATION);
EDITCONFIGFILE(fullscreen,640,480,hwnd);
}
// Play Button
if(LOWORD (wParam) == ID_BUTTON_CANCEL)
{
DestroyWindow(hwnd);
}
//Cancel Button
if(LOWORD (wParam) == ID_BUTTON_BEEP)
{
MessageBeep(0xFFFFFFFF); //////BEEEEEEEEEEEEEEEEP
GetDlgItemText(hwnd, ID_COMBOBOX, Temp, 10);
SendMessage(listbox1, LB_ADDSTRING, 0, (LPARAM) Temp);
EDITCONFIGFILE(fullscreen,640,480,hwnd);
}
//Beep Button
if(LOWORD (wParam) == ID_BUTTON_CHECKUPDATES)
{
MessageBox(hwnd, TEXT("Checking for updates..."), TEXT("Wait..."),MB_OK | MB_ICONEXCLAMATION);
CheckUpdate("90.182.102.233", 25565, hwnd);
}
//Check updates Button
if(uMsg==WM_COMMAND && LOWORD(wParam)==ID_CHECKBOX)
{
HWND hwnd = (HWND)lParam;
int state = SendMessage(hwnd, BM_GETCHECK, wParam, lParam);
if(state == BST_CHECKED)
{
fullscreen = 1;
}
else
{
fullscreen = 0;
}
}
//Checkbox
return 0;
/*----------------------------------------------------------------------------------------------*/
case WM_KEYDOWN:
switch (wParam)
{
case VK_LEFT:
{
MessageBox(hwnd, TEXT("You Pressed Left Arrow Key"), TEXT("GOTYEA"),MB_OK | MB_ICONINFORMATION);
}
}
/*----------------------------------------------------------------------------------------------*/
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
LOGFONT LogFont;
HFONT font;
SetTextColor(hdc, RGB(255,0,0));
LogFont.lfStrikeOut = 0; // Přeškrtlý text
LogFont.lfUnderline = 1; //Podtržený text
LogFont.lfHeight = 36; //Velikost textu
LogFont.lfEscapement = 0; //Rotace textu | 900 = 90°
LogFont.lfItalic = FALSE; // Šikmé písmo
LogFont.lfWeight = NULL; //FW_BOLD - Tučné písmo
font = CreateFontIndirect(&LogFont);
SelectObject(hdc, font);
LPCSTR Mytext = "ProXicT";
SelectObject(hdc, font);
TextOut(hdc, 10, 10, Mytext, strlen (Mytext) );
DeleteObject(font);
EndPaint(hwnd, &ps);
return 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*--------KONEC SWITCH---------------------------------------------------------------------------------------------------*/
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
TCHAR CLASS_NAME[] = TEXT("Titulek");
WNDCLASSEX wc = { };
wc.cbSize = sizeof(wc);
wc.style = NULL | NULL;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = CLASS_NAME;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE("icon1.ico"));
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE("icon2.ico"));
wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_3DFACE); //GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
/*----------------------------------------------------------------------------------------------*/
RegisterClassEx(&wc);
HWND hwnd = CreateWindowEx
(
NULL,
CLASS_NAME, //(přebírá) název třídy okna
CLASS_NAME,
WS_POPUP | WS_BORDER, //WS_OVERLAPPED | WS_SYSMENU,
640, //pozice okna v ose x
360, //pozice okna v ose y
640, //Velikost okna v ose x
360, //velikost okna v ose y
NULL,
NULL,
hInstance,
NULL);
if (!hwnd)
{
return FALSE;
}
/*----------------------------------------------------------------------------------------------*/
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void EDITCONFIGFILE(bool fullscreen, int v_resolution, int h_resolution, HWND hwnd)
{
FILE *stream;
if(!(stream=fopen("Config.conf", "w")))
{
MessageBox(hwnd, TEXT("\"Cinfig.conf\" does not exist!"), TEXT("ERROR"), MB_OK);
}
fputs("#Ultimate Destiny Configuration File (Please do not edit this file!)\n\n", stream);
//FULLSCREEN
fprintf(stream, "FULLSCREEN = %d\n", fullscreen);
//RESOLUTION
fprintf(stream, "V_RES = %d\n", v_resolution);
fprintf(stream, "H_RES = %d\n", h_resolution);
fclose(stream);
}
int CheckUpdate(const char ServerIP[16], int ServerPORT, HWND hwnd)
{
char MFS[7];
char SGAMEVER[10];
char CGAMEVER[10];
//Read Game Config File (ver.conf)
FILE *stream;
if(!(stream=fopen("bin/configures/ver.conf", "rt")))
{
return 1;
}
char oneline[50];
while(!feof(stream))
{
fgets(oneline, 50, stream);
sscanf(oneline, "GAMEVER = %s", &CGAMEVER);
}
fclose(stream);
//End of Read Function
WSAData wsaData;
WORD DLLVersion;
DLLVersion = MAKEWORD(2,1);
WSAStartup(DLLVersion, &wsaData);
SOCKADDR_IN addr;
int addrlen = sizeof(addr);
SOCKET sConnect;
sConnect = socket(AF_INET, SOCK_STREAM, NULL);
addr.sin_addr.s_addr = inet_addr(ServerIP);
addr.sin_family = AF_INET;
addr.sin_port = htons(ServerPORT);
connect(sConnect, (SOCKADDR*)&addr, sizeof(addr));
send(sConnect, "1d6r1h7q3wt5", 13, NULL);
recv(sConnect, MFS, 7, NULL);
if(MFS[0]=='a')
{
recv(sConnect, SGAMEVER, 10, NULL);
if(CGAMEVER[0]!=SGAMEVER[0]||CGAMEVER[2]!=SGAMEVER[2]||CGAMEVER[4]!=SGAMEVER[4]||CGAMEVER[5]!=SGAMEVER[5])
{
send(sConnect, "inu", 4, NULL);
int Size;
char *Filesize = new char[999999999];
if(recv(sConnect, Filesize, 999999999, 0))
{
Size = atoi((const char*)Filesize);
}
char *Buffer = new char[Size];
if(recv(sConnect, Buffer, Size, 0))
{
//Save recived file
FILE *File;
File = fopen("Update.7z", "wb");
fwrite((const char*)Buffer, 1, Size, File);
fclose(File);
FILE *stream;
//Edit ver.conf
if(!(stream=fopen("bin/configures/ver.conf", "wt")))
{
return 1;
}
fputs("#Game Version\n", stream);
fprintf(stream, "GAMEVER = %s", SGAMEVER);
fclose(stream);
}
}
else
{
send(sConnect, "idnu", 5, NULL);
}
}
//DestroyWindow(hwnd);
return 0;
}