Hej
Jeg sidder lige og roder med noget windows programmering, og har lige fået et par spørgsmål undervejs. Min kode ser indtil videre ud som følger:
#include <windows.h>
#include "resource.h"
const char g_szClassName[] = "myWindowClass";
HWND button, g_hInst;
HWND button2, g_hInst;
HWND combo, g_hInst;
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
//Dialog commands
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
//Creating buttons
case WM_CREATE:
{
button = CreateWindow("Button","Bit++ pack",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,2,0,125,25,hwnd,(HMENU)ID_BUTTON,g_hInst,0);
button2 = CreateWindow("Button","Web design pack",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,2,26,125,25,hwnd,(HMENU)ID_BUTTON2,g_hInst,0);
//Creating combobox
combo = CreateWindow("ComboBox",NULL,WS_CHILD | WS_VISIBLE | WS_VSCROLL |CBS_DROPDOWN,2,52,130,800,hwnd,(HMENU)ID_COMBO,g_hInst,0);
SendMessage(combo,CB_ADDSTRING,0,(LPARAM)(LPCTSTR)"Udvikleren.dk");
SendMessage(combo,CB_ADDSTRING,0,(LPARAM)(LPCTSTR)"NNauktion.dk");
}
break;
//Menu system
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_HELP_ABOUT:
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(DIALOG_ABOUT), hwnd, AboutDlgProc);
break;
//Commands for buttons
case ID_BUTTON:
ShellExecute(NULL, "open", "D:\\\\Programmer\\\\BitTorrent++\\\\BT++.exe",NULL, NULL,SW_SHOWNORMAL);
ShellExecute(NULL, "open", "www.thepiratebay.org",NULL, NULL,SW_SHOWNORMAL);
break;
case ID_BUTTON2:
ShellExecute(NULL, "open", "D:\\\\Programmer\\\\TSW\\\\WebCoder 5\\\\TSWWebCoder.exe",NULL, NULL,SW_SHOWNORMAL);
ShellExecute(NULL, "open", "D:\\\\Programmer\\\\Photoshop 7.0\\\\Photoshop.exe",NULL, NULL,SW_SHOWNORMAL);
ShellExecute(NULL, "open", "D:\\\\Programmer\\\\FileZilla\\\\filezilla.exe",NULL, NULL,SW_SHOWNORMAL);
break;
if ( ID_COMBO == "NNauktion.dk" ) { // If the age is less than 100
ShellExecute(NULL, "open", "www.nnauktion.dk",NULL, NULL,SW_SHOWNORMAL); // Just to show you it works...
}
else if ( ID_COMBO == "Udvikleren.dk" ) { // I use else just to show an example
ShellExecute(NULL, "open", "www.udvikleren.dk",NULL, NULL,SW_SHOWNORMAL);
}
else {
//
}
switch(ID_COMBO) {
case 0:
ShellExecute(NULL, "open", "www.nnauktion.dk",NULL, NULL,SW_SHOWNORMAL);
break;
case 1:
ShellExecute(NULL, "open", "www.udvikleren.dk",NULL, NULL,SW_SHOWNORMAL);
break;
}
}
//Standard window procuderes
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, 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(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_TOPMOST,
g_szClassName,
"MacroTech",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 140, 620,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
-Hvordan gør jeg sådan at der ikke er nogen border omkring mit vindue?
-Hvordan skal jeg skrive koden som fortæller hvad der skal ske når man klikker på et objekt i en combobox?
-Hvordan får jeg vinduet til opføre sig som en menu i windows? Altså sådan at når man maksimere et vindue, vil den opfatte mit program som den opfatter status linjen i Windows.
//Nick